|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import formBuilderMap from './formBuilderMap'
|
|
|
|
|
import { CreateElement } from 'vue'
|
|
|
|
|
import { CreateElement, VNode } from 'vue'
|
|
|
|
|
import moment from 'moment'
|
|
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
|
import { deepCopy } from "@/utils/index";
|
|
|
|
|
@ -7,16 +7,19 @@ import {deepCopy} from "@/utils/index";
|
|
|
|
|
* @param {String} device 'desktop' or 'mobile'
|
|
|
|
|
* @param {Object} info field参数
|
|
|
|
|
* @param {CreateElement} h
|
|
|
|
|
* @param {Object} pForm 父级表单对象
|
|
|
|
|
* @param {Object} row 子表单的row
|
|
|
|
|
* @param {Boolean} pWrite 主表单中子表单字段是否可写
|
|
|
|
|
* @return {VNode} 主表单包含el-form-item 子表单表单组件
|
|
|
|
|
**/
|
|
|
|
|
export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
export default function formBuilder (device, info, h, row, pWrite=false) {
|
|
|
|
|
let formItem;
|
|
|
|
|
if (device === 'desktop') {
|
|
|
|
|
if(info._writeable || (info.type === 'relation' && info._readable) || pWrite) {
|
|
|
|
|
switch (info.type) {
|
|
|
|
|
case 'text':
|
|
|
|
|
formItem = h(formBuilderMap(device).get(info.type),{
|
|
|
|
|
props: {
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text
|
|
|
|
|
},
|
|
|
|
|
@ -25,7 +28,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -37,7 +40,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
autosize: {
|
|
|
|
|
minRows: 2
|
|
|
|
|
},
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text
|
|
|
|
|
},
|
|
|
|
|
@ -46,7 +49,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -57,7 +60,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
type: 'date',
|
|
|
|
|
'value-format': 'yyyy-MM-dd',
|
|
|
|
|
format: 'yyyy年MM月dd日',
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
'picker-options': {
|
|
|
|
|
@ -116,7 +119,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -127,7 +130,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
type: 'datetime',
|
|
|
|
|
'value-format': 'yyyy-MM-dd',
|
|
|
|
|
format: 'yyyy年MM月dd日',
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
'picker-options': {
|
|
|
|
|
@ -186,7 +189,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -194,7 +197,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
case 'select':
|
|
|
|
|
formItem = h(formBuilderMap(device).get(info.type),{
|
|
|
|
|
props: {
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text
|
|
|
|
|
},
|
|
|
|
|
@ -203,7 +206,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[1,2,3].map(option => (
|
|
|
|
|
@ -218,14 +221,14 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
case 'radio':
|
|
|
|
|
formItem = h(formBuilderMap(device).get(info.type),{
|
|
|
|
|
props: {
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
},
|
|
|
|
|
attrs: {
|
|
|
|
|
placeholder: info.help_text
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[1,2,3].map(option => (
|
|
|
|
|
@ -356,7 +359,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
type: 'primary'
|
|
|
|
|
},
|
|
|
|
|
attrs: {
|
|
|
|
|
href: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
href: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
target: "_blank"
|
|
|
|
|
}
|
|
|
|
|
},info.label)
|
|
|
|
|
@ -368,7 +371,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
case 'choice':
|
|
|
|
|
formItem = h(formBuilderMap(device).get(info.type),{
|
|
|
|
|
props: {
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text
|
|
|
|
|
},
|
|
|
|
|
@ -377,7 +380,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[1,2,3].map(option => (
|
|
|
|
|
@ -392,7 +395,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
case 'choices':
|
|
|
|
|
formItem = h(formBuilderMap(device).get(info.type),{
|
|
|
|
|
props: {
|
|
|
|
|
value: pForm ? pForm[info.name] : this.form[info.name],
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
multiple: true
|
|
|
|
|
@ -402,7 +405,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: e => {
|
|
|
|
|
pForm ? this.$set(pForm,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
row ? this.$set(row,info.name,e) : this.$set(this.form,info.name,e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[1,2,3].map(option => (
|
|
|
|
|
@ -415,79 +418,123 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
)))
|
|
|
|
|
break;
|
|
|
|
|
case 'relation':
|
|
|
|
|
formItem = h('div',{
|
|
|
|
|
|
|
|
|
|
formItem = h('vxe-table',{
|
|
|
|
|
ref: `subForm-${info.name}`,
|
|
|
|
|
style: {
|
|
|
|
|
'margin-top': '10px'
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
'min-height': '200px',
|
|
|
|
|
border: true,
|
|
|
|
|
stripe: true,
|
|
|
|
|
data: this.form[info.name],
|
|
|
|
|
'keep-source': true,
|
|
|
|
|
'column-config': { resizable: true },
|
|
|
|
|
'show-overflow': true,
|
|
|
|
|
'edit-config': info._writeable ? {
|
|
|
|
|
trigger: 'click',
|
|
|
|
|
mode: 'row',
|
|
|
|
|
showStatus: false,
|
|
|
|
|
isHover: true,
|
|
|
|
|
autoClear: false
|
|
|
|
|
} : {}
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
'edit-closed': ({ row, column }) => {
|
|
|
|
|
const $table = this.$refs[`subForm-${info.name}`]
|
|
|
|
|
if ($table) {
|
|
|
|
|
const field = column.field
|
|
|
|
|
const cellValue = row[field]
|
|
|
|
|
// 判断单元格值是否被修改
|
|
|
|
|
if ($table.isUpdateByRow(row, field)) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
console.log(`局部保存成功! ${field}=${cellValue}`)
|
|
|
|
|
// 局部更新单元格为已保存状态
|
|
|
|
|
$table.reloadRow(row, null, field)
|
|
|
|
|
}, 300)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[
|
|
|
|
|
h('vxe-toolbar',[
|
|
|
|
|
h('el-button',{
|
|
|
|
|
slot: 'buttons',
|
|
|
|
|
h('vxe-column',{
|
|
|
|
|
props: {
|
|
|
|
|
type: 'primary',
|
|
|
|
|
width: 56,
|
|
|
|
|
align: 'center'
|
|
|
|
|
},
|
|
|
|
|
scopedSlots: {
|
|
|
|
|
default: ({ row }) => {
|
|
|
|
|
return h('el-button',{
|
|
|
|
|
slot: 'default',
|
|
|
|
|
style: {
|
|
|
|
|
'padding': '9px'
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
type: 'danger',
|
|
|
|
|
size: 'small',
|
|
|
|
|
icon: "el-icon-plus"
|
|
|
|
|
icon: "el-icon-minus"
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
click: _ => {
|
|
|
|
|
this.form[info.name].push(deepCopy(pForm))
|
|
|
|
|
click: async _ => {
|
|
|
|
|
const $table = this.$refs[`subForm-${info.name}`]
|
|
|
|
|
if ($table) {
|
|
|
|
|
await $table.remove(row)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},'增加')
|
|
|
|
|
]),
|
|
|
|
|
h('vxe-table',{
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},[
|
|
|
|
|
h('el-button',{
|
|
|
|
|
slot: 'header',
|
|
|
|
|
style: {
|
|
|
|
|
'margin-top': '10px'
|
|
|
|
|
'padding': '9px'
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
stripe: true,
|
|
|
|
|
data: this.form[info.name]
|
|
|
|
|
type: 'primary',
|
|
|
|
|
size: 'small',
|
|
|
|
|
icon: "el-icon-plus"
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
click: async _ => {
|
|
|
|
|
const $table = this.$refs[`subForm-${info.name}`]
|
|
|
|
|
if ($table) {
|
|
|
|
|
const record = {}
|
|
|
|
|
const { row: newRow } = await $table.insert(record)
|
|
|
|
|
await this.$nextTick()
|
|
|
|
|
await $table.setEditRow(newRow)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},this.subForm.get(info.sub_custom_model_id)?.customModel?.fields?.map((subField,subIndex) => h('vxe-column',{
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
]),
|
|
|
|
|
...this.subForm.get(info.sub_custom_model_id)?.customModel?.fields?.map((subField,subIndex) => h('vxe-column',{
|
|
|
|
|
props: {
|
|
|
|
|
field: subField.name,
|
|
|
|
|
title: subField.label,
|
|
|
|
|
align: 'center'
|
|
|
|
|
align: 'center',
|
|
|
|
|
'edit-render': {}
|
|
|
|
|
},
|
|
|
|
|
scopedSlots: {
|
|
|
|
|
edit:({ row }) => {
|
|
|
|
|
return formBuilder.bind(this)(device, subField, h, row, info._writeable)
|
|
|
|
|
}
|
|
|
|
|
},formBuilder.bind(this)(device, subField, h, this.form[info.name][subIndex]))))
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
])
|
|
|
|
|
// formItem = h('div', [
|
|
|
|
|
// h('div',[
|
|
|
|
|
// h('el-button',{
|
|
|
|
|
// props: {
|
|
|
|
|
// size: "small",
|
|
|
|
|
// type: "primary",
|
|
|
|
|
// icon: "el-icon-plus"
|
|
|
|
|
// },
|
|
|
|
|
// on: {
|
|
|
|
|
// click: _ => {
|
|
|
|
|
// this.form[info.name].push(deepCopy(pForm))
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// },'增加')
|
|
|
|
|
// ]),
|
|
|
|
|
// ...this.form[info.name]?.map((i,subIndex) => h('el-card',[
|
|
|
|
|
// h('el-button',{
|
|
|
|
|
// props: {
|
|
|
|
|
// size: 'small',
|
|
|
|
|
// type: 'primary'
|
|
|
|
|
// },
|
|
|
|
|
// on: {
|
|
|
|
|
// click: _ => {
|
|
|
|
|
// this.form[info.name].splice(subIndex,1)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// },'删除'),
|
|
|
|
|
// h('el-form', {
|
|
|
|
|
// class: 'form',
|
|
|
|
|
// props: {
|
|
|
|
|
// model: this.form[info.name][subIndex],
|
|
|
|
|
// 'label-position': 'top'
|
|
|
|
|
// }
|
|
|
|
|
// },this.subForm.get(info.sub_custom_model_id)?.customModel?.fields.map(subField => formBuilder.bind(this)(device, subField, h, this.form[info.name][subIndex])))
|
|
|
|
|
// ]))
|
|
|
|
|
// ])
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return h('el-form-item',{
|
|
|
|
|
} else if (info._readable) {
|
|
|
|
|
formItem = h('span',{
|
|
|
|
|
style: {
|
|
|
|
|
color: '#333'
|
|
|
|
|
}
|
|
|
|
|
},this.form[info.name])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (formItem) {
|
|
|
|
|
return row ? formItem : h('el-form-item',{
|
|
|
|
|
props: {
|
|
|
|
|
prop: info.name,
|
|
|
|
|
label: info.label
|
|
|
|
|
@ -500,6 +547,7 @@ export default function formBuilder (device, info,h,pForm) {
|
|
|
|
|
}
|
|
|
|
|
},[formItem])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(device === 'mobile') {
|
|
|
|
|
switch (info.type) {
|
|
|
|
|
case 'text':
|
|
|
|
|
|