1、修复在线表单初始化表单组件信息错误。

This commit is contained in:
Jerry
2024-07-23 14:37:29 +08:00
parent ab3d7549e9
commit 51ff5033e1
14 changed files with 107 additions and 80 deletions

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>加载中</title>
<title>橙单代码生成平台</title>
</head>
<body>
<div id="app"></div>

View File

@@ -25,6 +25,7 @@
"highlight.js": "^11.9.0",
"jsencrypt": "^3.3.2",
"json-bigint": "^1.0.0",
"lodash": "^4.17.21",
"pinia": "^2.1.6",
"pinia-plugin-persist": "^1.0.0",
"vant": "^4.7.3",
@@ -58,7 +59,6 @@
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.8.0",
"lodash": "^4.17.21",
"node-polyfill-webpack-plugin": "^4.0.0",
"postcss": "^8.4.20",
"postcss-html": "^1.5.0",

View File

@@ -1,5 +1,5 @@
{
"name": "vite",
"name": "orange",
"private": true,
"version": "0.0.0",
"scripts": {

View File

@@ -1,5 +1,5 @@
import { getCurrentInstance } from 'vue';
import { Delete, Search, Edit, Plus, Refresh, Picture } from '@element-plus/icons-vue';
import { EpPropMergeType } from 'element-plus/es/utils';
import { useDate } from '@/common/hooks/useDate';
import { usePermissions } from '@/common/hooks/usePermission';
import { Dialog } from '@/components/Dialog';

View File

@@ -43,43 +43,24 @@ export const useDate = () => {
* @param {String} statsType 转换类型day, month, year
* @param {String} format 输出格式
*/
const getDateRangeFilter = (date: string, statsType = 'day', format = 'YYYY-MM-dd HH:mm:ss') => {
const getDateRangeFilter = (date: string, statsType = 'day', format = 'YYYY-MM-DD HH:mm:ss') => {
if (date == null) return [];
statsType = allowStatsType.indexOf(statsType) === -1 ? 'day' : statsType;
date = date.substring(0, date.indexOf(' '));
const tempList = date.split('-');
const year = Number.parseInt(tempList[0]);
const month = Number.parseInt(tempList[1]);
const day = Number.parseInt(tempList[2]);
if (isNaN(year) || isNaN(month) || isNaN(day)) {
return [];
}
const tempDate = new Date(year, month - 1, day);
// 判断是否正确的日期
if (isNaN(tempDate.getTime())) return [];
tempDate.setHours(0, 0, 0, 0);
let retDate: Date[] = [];
// TODO 如果类型为'time', 'datetime'会出错
const tempDate = parseDate(date, format);
console.log('tempDate', tempDate);
if (tempDate && tempDate.isValid()) {
switch (statsType) {
case 'day':
retDate = [new Date(tempDate), new Date(tempDate.setDate(tempDate.getDate() + 1))];
break;
return [tempDate.startOf('d').format(format), tempDate.endOf('d').format(format)];
case 'month':
tempDate.setDate(1);
retDate = [new Date(tempDate), new Date(tempDate.setMonth(tempDate.getMonth() + 1))];
break;
return [tempDate.startOf('M').format(format), tempDate.endOf('M').format(format)];
case 'year':
tempDate.setDate(1);
tempDate.setMonth(0);
retDate = [new Date(tempDate), new Date(tempDate.setFullYear(tempDate.getFullYear() + 1))];
break;
return [tempDate.startOf('y').format(format), tempDate.endOf('y').format(format)];
default:
return [];
}
} else {
return [];
}
retDate[1] = new Date(retDate[1].getTime() - 1);
return [formatDate(retDate[0], format), formatDate(retDate[1], format)];
};
return {

View File

@@ -1,7 +1,7 @@
<template>
<div class="dept-select">
<el-select
:model-value="value"
:model-value="modelValue"
style="width: 100%"
:multiple="multiple"
:disabled="disabled"
@@ -32,11 +32,14 @@ import { SysCommonBizController } from '@/api/system';
import { Dialog } from '@/components/Dialog';
import DeptSelectDlg from './DeptSelectDlg.vue';
const emit = defineEmits<{ input: [ANY_OBJECT]; change: [ANY_OBJECT] }>();
const emit = defineEmits<{
'update:modelValue': [string | number | ANY_OBJECT[]];
change: [string | number | ANY_OBJECT[], string | number | ANY_OBJECT[]];
}>();
const props = withDefaults(
defineProps<{
value: string | number | Array<ANY_OBJECT>;
modelValue: string | number | Array<ANY_OBJECT> | undefined;
size?: '' | 'default' | 'small' | 'large';
placeholder?: string;
props?: ANY_OBJECT;
@@ -69,12 +72,11 @@ const refreshData = (data: ANY_OBJECT) => {
}
};
const handlerEditOperate = (items: Ref<ANY_OBJECT>) => {
console.log('DeptSelect > handlerEditOperate', items);
selectedItems.value = [];
if (props.multiple) {
if (Array.isArray(items.value)) selectedItems.value = items.value;
if (Array.isArray(items)) selectedItems.value = items;
} else {
if (items.value != null) selectedItems.value.push(items.value);
if (items != null) selectedItems.value.push(items);
}
if (!checkSelectChange()) return;
emitChange();
@@ -115,7 +117,7 @@ const onClear = () => {
emitChange();
};
const emitChange = () => {
let tempValue;
let tempValue: string | number | ANY_OBJECT[];
if (props.multiple) {
tempValue = selectedItems.value.map(item => {
return item[props.props.value];
@@ -123,19 +125,19 @@ const emitChange = () => {
} else {
tempValue = (selectedItems.value[0] || {})[props.props.value];
}
emit('input', tempValue);
emit('change', tempValue);
emit('update:modelValue', tempValue);
emit('change', tempValue, selectedItems.value);
};
const checkSelectChange = () => {
let valueIdString =
props.multiple && Array.isArray(props.value)
? (props.value || [])
props.multiple && Array.isArray(props.modelValue)
? (props.modelValue || [])
.sort((val1: ANY_OBJECT, val2: ANY_OBJECT) => {
if (val1 === val2) return 0;
return val1 < val2 ? -1 : 1;
})
.join(',')
: props.value || '';
: props.modelValue || '';
let selectedItemsString = selectedItems.value
.sort((item1, item2) => {
if (item1[props.props.value] === item2[props.props.value]) return 0;
@@ -149,12 +151,16 @@ const getSelectDeptList = () => {
let params: ANY_OBJECT = {
widgetType: 'upms_dept',
};
if (props.value == null || props.value === '' || props.value.length <= 0)
if (
props.modelValue == null ||
props.modelValue === '' ||
(props.modelValue as ANY_OBJECT[]).length <= 0
)
selectedItems.value = [];
if (props.multiple) {
params.fieldValues = Array.isArray(props.value) ? props.value : [];
params.fieldValues = Array.isArray(props.modelValue) ? props.modelValue : [];
} else {
params.fieldValues = Array.isArray(props.value) ? props.value[0] : props.value;
params.fieldValues = Array.isArray(props.modelValue) ? props.modelValue[0] : props.modelValue;
params.fieldValues = params.fieldValues == null ? [] : [params.fieldValues];
}
if (Array.isArray(params.fieldValues) && params.fieldValues.length > 0) {
@@ -173,9 +179,9 @@ const getSelectDeptList = () => {
}
};
watch(
() => props.value,
() => props.modelValue,
() => {
if (props.value) getSelectDeptList();
if (props.modelValue) getSelectDeptList();
},
{
immediate: true,

View File

@@ -1,7 +1,7 @@
<template>
<div class="user-select">
<el-select
:model-value="value"
:model-value="modelValue"
style="width: 100%"
:multiple="multiple"
:disabled="disabled"
@@ -32,11 +32,14 @@ import { SysCommonBizController } from '@/api/system';
import { Dialog } from '@/components/Dialog';
import UserSelectDlg from './UserSelectDlg.vue';
const emit = defineEmits<{ input: [ANY_OBJECT]; change: [ANY_OBJECT, ANY_OBJECT[]] }>();
const emit = defineEmits<{
'update:modelValue': [string | number | ANY_OBJECT[]];
change: [string | number | ANY_OBJECT[], string | number | ANY_OBJECT[]];
}>();
const pps = withDefaults(
defineProps<{
value: string | number;
modelValue: string | number | Array<ANY_OBJECT> | undefined;
size?: '' | 'default' | 'small' | 'large';
placeholder?: string;
props?: ANY_OBJECT;
@@ -68,13 +71,15 @@ const refreshData = (data: ANY_OBJECT) => {
}
};
const handlerEditOperate = (items: Ref<ANY_OBJECT>) => {
console.log('handlerEditOperate', items);
selectedItems.value = [];
if (pps.multiple) {
if (Array.isArray(items.value)) selectedItems.value = items.value;
if (Array.isArray(items)) selectedItems.value = items;
} else {
if (items.value != null) selectedItems.value.push(items.value);
if (items != null) selectedItems.value.push(items);
}
if (!checkSelectChange()) return;
console.log('1111', selectedItems.value);
emitChange();
};
const onVisibleChange = (visible: boolean) => {
@@ -119,7 +124,7 @@ const emitChange = () => {
return item;
});
emit(
'input',
'update:modelValue',
tempValue.map(item => item[pps.props.value]),
);
emit(
@@ -129,19 +134,19 @@ const emitChange = () => {
);
} else {
tempValue = selectedItems.value[0] || {};
emit('input', tempValue[pps.props.value]);
emit('update:modelValue', tempValue[pps.props.value]);
emit('change', tempValue[pps.props.value], selectedItems.value);
}
};
const checkSelectChange = () => {
let valueIdString = pps.multiple
? (pps.value || [])
.sort((val1, val2) => {
? ((pps.modelValue || []) as ANY_OBJECT[])
.sort((val1: ANY_OBJECT, val2: ANY_OBJECT) => {
if (val1 === val2) return 0;
return val1 < val2 ? -1 : 1;
})
.join(',')
: pps.value || '';
: pps.modelValue || '';
let selectedItemsString = selectedItems.value
.sort((item1, item2) => {
if (item1[pps.props.value] === item2[pps.props.value]) return 0;
@@ -155,12 +160,16 @@ const getSelectUserList = () => {
let params: ANY_OBJECT = {
widgetType: 'upms_user',
};
if (pps.value == null || pps.value === '' || (Array.isArray(pps.value) && pps.value.length <= 0))
if (
pps.modelValue == null ||
pps.modelValue === '' ||
(Array.isArray(pps.modelValue) && pps.modelValue.length <= 0)
)
selectedItems.value = [];
if (pps.multiple) {
params.fieldValues = Array.isArray(pps.value) ? pps.value : [];
params.fieldValues = Array.isArray(pps.modelValue) ? pps.modelValue : [];
} else {
params.fieldValues = Array.isArray(pps.value) ? pps.value[0] : pps.value;
params.fieldValues = Array.isArray(pps.modelValue) ? pps.modelValue[0] : pps.modelValue;
params.fieldValues = params.fieldValues == null ? [] : [params.fieldValues];
}
if (Array.isArray(params.fieldValues) && params.fieldValues.length > 0) {
@@ -179,9 +188,9 @@ const getSelectUserList = () => {
}
};
watch(
() => pps.value,
() => pps.modelValue,
() => {
if (pps.value) getSelectUserList();
if (pps.modelValue) getSelectUserList();
},
{
immediate: true,

View File

@@ -1,10 +1,13 @@
import { createApp } from 'vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import '@/common/http/request';
// eslint-disable-next-line import/named
import { debounce } from 'lodash';
import { VxeTable, VxeColumn, Edit } from 'vxe-table';
import App from '@/App.vue';
import { router } from '@/router/index';
import pinia from '@/store';
import useStaticDictStore from '@/store/staticDict';
// 表格样式
import 'vxe-table/lib/style.css';
@@ -31,17 +34,20 @@ import * as olineDicgt from '@/common/staticDict/online';
import * as flowDict from '@/common/staticDict/flow';
import { ANY_OBJECT } from '@/types/generic';
import { debounce } from 'lodash';
// vxe-table设置
function useTable(app: ANY_OBJECT) {
app.use(VxeTable).use(VxeColumn).use(Edit);
}
// 静态字典设置
function useStaticDict(app: ANY_OBJECT, staticDict: ANY_OBJECT) {
if (app.config.globalProperties.StaticDict == null) {
app.config.globalProperties.StaticDict = {};
}
Object.keys(staticDict).forEach(key => {
app.config.globalProperties[key] = staticDict[key];
app.config.globalProperties.StaticDict[key] = staticDict[key];
});
}
// webpack需要重写ResizeObserver否则会报错
const resizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends resizeObserver {
@@ -60,3 +66,6 @@ useStaticDict(app, olineDicgt);
useStaticDict(app, flowDict);
app.use(pinia).use(router).use(useTable);
app.mount('#app');
// 设置静态字典
const staticDictStore = useStaticDictStore();
staticDictStore.setStaticDict(app.config.globalProperties.StaticDict);

View File

@@ -150,7 +150,6 @@ const isMobileFilter = computed(() => {
);
});
const getAllDropdownData = computed(() => {
console.log('widget getAllDropdownData', pps.widget.props.supportAll, dictDataList);
if (pps.widget.props.supportAll) {
return [
{

View File

@@ -156,7 +156,9 @@ import { downloadBlob, post } from '@/common/http/request';
import { useDownload } from '@/common/hooks/useDownload';
import { useUpload } from '@/common/hooks/useUpload';
import { API_CONTEXT } from '@/api/config';
import { useLayoutStore } from '@/store';
const layoutStore = useLayoutStore();
const emit = defineEmits<{
viewWorkOrder: [ANY_OBJECT, ANY_OBJECT | null];
handlerWorkOrder: [ANY_OBJECT, ANY_OBJECT | null];
@@ -194,8 +196,6 @@ const props = withDefaults(defineProps<IProps>(), {
operationList: () => [],
});
import { useLayoutStore } from '@/store';
const layoutStore = useLayoutStore();
const form = inject('form', () => {
console.error('OnlineCustomWorkFlowTable: form not injected');
return { isEdit: false } as ANY_OBJECT;
@@ -210,6 +210,11 @@ const tableColumnList = computed(() => {
props.widget && props.widget.props && Array.isArray(props.widget.props.tableColumnList)
? props.widget.props.tableColumnList
: [];
tempList = tempList.map(item => {
return {
...item,
};
});
tempList.forEach((item: ANY_OBJECT) => {
if (item.fieldType === 0 || item.fieldType == null) {
// 绑定表字段

View File

@@ -51,8 +51,8 @@ export const useForm = (props: ANY_OBJECT, formRef: Ref<FormInstance> | null = n
});
const form = computed(() => {
const temp: ANY_OBJECT = buildFormConfig(dialogParams.value.formConfig) || {};
return temp;
buildFormConfig(dialogParams.value.formConfig);
return dialogParams.value.formConfig;
});
const loginStore = useLoginStore();

View File

@@ -245,7 +245,8 @@ export const useFormConfig = () => {
};
const buildFormConfig = (formData: ANY_OBJECT) => {
if (formData == null) return;
if (formData == null || formData.rawData == null || formData.rawData.onlineTableList == null)
return;
const formConfig = formData;
formConfig.datasourceMap = new Map();
formConfig.relationMap = new Map();

View File

@@ -4,7 +4,9 @@ import useLoginStore from './login';
import useLayoutStore from './layout';
import useOtherStore from './other';
import useMessage from './message';
import useStaticDictStore from './staticDict';
const pinia = createPinia();
pinia?.use(piniaPersist);
export { useLoginStore, useLayoutStore, useMessage, useOtherStore };
export { useLoginStore, useLayoutStore, useMessage, useOtherStore, useStaticDictStore };
export default pinia;

View File

@@ -0,0 +1,15 @@
import { defineStore } from 'pinia';
import { ANY_OBJECT } from '@/types/generic';
export default defineStore('staticDict', {
state: () => {
return {
staticDict: {} as ANY_OBJECT,
};
},
actions: {
setStaticDict(dict: ANY_OBJECT) {
this.staticDict = dict;
},
},
});