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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
import { getCurrentInstance } from 'vue';
import { Delete, Search, Edit, Plus, Refresh, Picture } from '@element-plus/icons-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 { useDate } from '@/common/hooks/useDate';
import { usePermissions } from '@/common/hooks/usePermission'; import { usePermissions } from '@/common/hooks/usePermission';
import { Dialog } from '@/components/Dialog'; import { Dialog } from '@/components/Dialog';

View File

@@ -43,43 +43,24 @@ export const useDate = () => {
* @param {String} statsType 转换类型day, month, year * @param {String} statsType 转换类型day, month, year
* @param {String} format 输出格式 * @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 []; if (date == null) return [];
const tempDate = parseDate(date, format);
statsType = allowStatsType.indexOf(statsType) === -1 ? 'day' : statsType; console.log('tempDate', tempDate);
date = date.substring(0, date.indexOf(' ')); if (tempDate && tempDate.isValid()) {
const tempList = date.split('-'); switch (statsType) {
const year = Number.parseInt(tempList[0]); case 'day':
const month = Number.parseInt(tempList[1]); return [tempDate.startOf('d').format(format), tempDate.endOf('d').format(format)];
const day = Number.parseInt(tempList[2]); case 'month':
if (isNaN(year) || isNaN(month) || isNaN(day)) { return [tempDate.startOf('M').format(format), tempDate.endOf('M').format(format)];
case 'year':
return [tempDate.startOf('y').format(format), tempDate.endOf('y').format(format)];
default:
return [];
}
} else {
return []; 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'会出错
switch (statsType) {
case 'day':
retDate = [new Date(tempDate), new Date(tempDate.setDate(tempDate.getDate() + 1))];
break;
case 'month':
tempDate.setDate(1);
retDate = [new Date(tempDate), new Date(tempDate.setMonth(tempDate.getMonth() + 1))];
break;
case 'year':
tempDate.setDate(1);
tempDate.setMonth(0);
retDate = [new Date(tempDate), new Date(tempDate.setFullYear(tempDate.getFullYear() + 1))];
break;
}
retDate[1] = new Date(retDate[1].getTime() - 1);
return [formatDate(retDate[0], format), formatDate(retDate[1], format)];
}; };
return { return {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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