diff --git a/src/utils/formBuilder.js b/src/utils/formBuilder.js index 8bdecbc..63fd679 100644 --- a/src/utils/formBuilder.js +++ b/src/utils/formBuilder.js @@ -21,7 +21,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab //下拉选项 let options = []; if (info?.selection_model) { - options = info.selection_model_items; + options = info.selection_model_items || []; } else if (info?.stub) { options = info?.stub?.split(/\r\n/) || []; } @@ -36,7 +36,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab case "text": formItem = h(formBuilderMap(device).get(info.type), { props: { - value: row ? row[info.name] : this.form[info.name], + value: target[info.name], clearable: true, placeholder: info.help_text, }, @@ -45,9 +45,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, on: { input: (e) => { - row - ? this.$set(row, info.name, e) - : this.$set(this.form, info.name, e); + this.$set(target, info.name, e) }, }, }); @@ -59,7 +57,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab autosize: { minRows: 2, }, - value: row ? row[info.name] : this.form[info.name], + value: target[info.name], clearable: true, placeholder: info.help_text, }, @@ -68,9 +66,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, on: { input: (e) => { - row - ? this.$set(row, info.name, e) - : this.$set(this.form, info.name, e); + this.$set(target, info.name, e) }, }, }); @@ -81,7 +77,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab type: "date", "value-format": "yyyy-MM-dd", format: "yyyy年MM月dd日", - value: row ? row[info.name] : this.form[info.name], + value: target[info.name], clearable: true, placeholder: info.help_text, "picker-options": { @@ -148,9 +144,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, on: { input: (e) => { - row - ? this.$set(row, info.name, e) - : this.$set(this.form, info.name, e); + this.$set(target, info.name, e) }, }, }); @@ -161,7 +155,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab type: "datetime", "value-format": "yyyy-MM-dd HH:mm:ss", format: this.datetimeFormat, - value: row ? row[info.name] : this.form[info.name], + value: target[info.name], clearable: true, placeholder: info.help_text, "picker-options": { @@ -176,19 +170,18 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, on: { input: (e) => { - row - ? this.$set(row, info.name, e) - : this.$set(this.form, info.name, e); + this.$set(target, info.name, e) }, }, }); break; + case "choice": case "select": const getSelectValue = () => { if (!!info.multiple) { return target[info.name] ? target[info.name].toString()?.split(/,|\|/).map(i => isNaN(Number(i)) ? i : Number(i)) : [] } else { - return target[info.name] + return isNaN(Number(target[info.name])) ? target[info.name] : Number(target[info.name]) } } formItem = h( @@ -202,6 +195,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab 'multiple-limit': info.multiple, 'collapse-tags': true, filterable: true, + 'value-key': 'id', 'allow-create': !!info.is_select2_tag, 'default-first-option': true }, @@ -219,6 +213,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, options.map((option) => h("el-option", { + key: typeof option === "object" ? option.id : option, props: { label: typeof option === "object" ? option.name : option, value: typeof option === "object" ? option.id : option, @@ -232,16 +227,14 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formBuilderMap(device).get(info.type), { props: { - value: row ? row[info.name] : this.form[info.name], + value: target[info.name], }, attrs: { placeholder: info.help_text, }, on: { input: (e) => { - row - ? this.$set(row, info.name, e) - : this.$set(this.form, info.name, e); + this.$set(target, info.name, e) }, }, }, @@ -321,12 +314,12 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab "application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", multiple: !!info.multiple, limit: info.multiple ? 20 : 1, - fileList: this.form[info.name]?.map(i => { + fileList: this.form[info.name] instanceof Array ? this.form[info.name]?.map(i => { if (i.hasOwnProperty('original_name')) { i.name = i.original_name } return i - }), + }) : [], beforeUpload: (file) => { if (file.size > uploadSize) { this.$message({ @@ -445,7 +438,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab type: "primary", }, attrs: { - href: row ? row[info.name] : this.form[info.name], + href: target[info.name], target: "_blank", }, }, @@ -455,77 +448,6 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab case "hr": formItem = h(formBuilderMap(device).get(info.type), {}, info.label); break; - case "choice": - formItem = h( - formBuilderMap(device).get(info.type), - { - props: { - value: row ? (row[info.name] ? row[info.name].toString()?.split(/,|\|/).map(i => isNaN(Number(i)) ? i : Number(i)) : []) : (this.form[info.name] ? this.form[info.name].toString()?.split(/,|\|/).map(i => Number(i)) : []), - clearable: true, - placeholder: info.help_text, - multiple: !!info.multiple, - 'multiple-limit': info.multiple, - filterable: true - }, - attrs: { - placeholder: info.help_text, - }, - style: { - width: "100%", - }, - on: { - input: (e) => { - row - ? this.$set(row, info.name, e.toString()) - : this.$set(this.form, info.name, e.toString()); - }, - }, - }, - options.map((option) => - h("el-option", { - props: { - label: typeof option === "object" ? option.name : option, - value: typeof option === "object" ? option.id : option, - }, - }) - ) - ); - break; - case "choices": - formItem = h( - formBuilderMap(device).get(info.type), - { - props: { - value: row ? (row[info.name] ? row[info.name].toString()?.split(/,|\|/).map(i => isNaN(Number(i)) ? i : Number(i)) : []) : (this.form[info.name] ? this.form[info.name].toString()?.split(/,|\|/).map(i => isNaN(Number(i)) ? i : Number(i)) : []), - clearable: true, - placeholder: info.help_text, - multiple: true, - filterable: true - }, - attrs: { - placeholder: info.help_text, - }, - style: { - width: '100%' - }, - on: { - input: (e) => { - row - ? this.$set(row, info.name, e.toString()) - : this.$set(this.form, info.name, e.toString()); - }, - }, - }, - options.map((option) => - h("el-option", { - props: { - label: option, - value: option, - }, - }) - ) - ); - break; case "relation-flow": if (!this.flows[info.name]) { flowList('all', { @@ -542,7 +464,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formBuilderMap(device).get(info.type), { props: { - value: row ? (row[info.name] ? row[info.name].toString()?.split(',').map(i => Number(i)) : []) : (this.form[info.name] ? this.form[info.name].toString()?.split(',').map(i => Number(i)) : []), + value: (target[info.name] ? target[info.name].toString()?.split(',').map(i => Number(i)) : []), clearable: true, placeholder: info.help_text, multiple: true, @@ -558,9 +480,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab }, on: { input: (e) => { - row - ? this.$set(row, info.name, e.toString()) - : this.$set(this.form, info.name, e.toString()); + this.$set(target, info.name, e.toString()) } }, }, @@ -742,13 +662,14 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab target[info.name] ? moment(target[info.name]).format("YYYY年MM月DD日 HH时mm分") : '' ); break; + case "choice": case "select": const getDetailSelectValue = () => { let res = '' if (!!info.multiple) { res = target[info.name] ? target[info.name].toString()?.split(/,|\|/).map(i => isNaN(Number(i)) ? i : Number(i)) : [] } else { - res = target[info.name] + res = isNaN(Number(target[info.name])) ? target[info.name] : Number(target[info.name]) } if (res instanceof Array) { return options?.filter((i) => @@ -757,14 +678,13 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab : res.indexOf(i) !== -1 )?.map(i => typeof i === 'object' ? i.name : i)?.toString() } else { - return res + return options?.filter((i) => + typeof i === "object" + ? res === i.id + : res === i + )?.map(i => typeof i === 'object' ? i.name : i)?.toString() } } - let findValue = options.find((i) => - typeof i === "object" - ? i.id == target[info.name] - : i === target[info.name] - ); formItem = h( "span", { @@ -775,41 +695,6 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab getDetailSelectValue() ); break; - case "choice": - formItem = h( - "span", - { - style: { - color: "#333", - }, - }, - target[info.name]?.toString()?.split(/,|\|/).map(j => { - return options.find((i) => i.id == j)?.name; - })?.toString() - ); - break; - case "choices": - let findChoicesValue = options.find((i) => - typeof i === "object" - ? i.id == target[info.name] - : i === target[info.name] - ); - formItem = h( - "span", - { - style: { - color: "#333", - }, - }, - info.multiple ? target[info.name]?.toString()?.split(/,|\|/).map(j => { - return options.find((i) => - typeof i === "object" - ? i.id == j - : i === j - )?.name; - })?.toString() : typeof findChoicesValue === "object" ? findChoicesValue.name : findChoicesValue - ); - break; case "relation-flow": if (!this.flows[info.name]) { flowList('all', { @@ -868,7 +753,6 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab ); break; case "file": - console.log(row ? row[info.name] : '') formItem = row ? h( 'vxe-upload', diff --git a/src/views/attendance/index.vue b/src/views/attendance/index.vue index a8901c7..465daa0 100644 --- a/src/views/attendance/index.vue +++ b/src/views/attendance/index.vue @@ -15,8 +15,10 @@