|
|
|
|
@ -9,15 +9,16 @@ import { deepCopy } from "@/utils/index";
|
|
|
|
|
* @param {CreateElement} h
|
|
|
|
|
* @param {Object} row 子表单的row
|
|
|
|
|
* @param {Boolean} pWrite 主表单中子表单字段是否可写
|
|
|
|
|
* @param {Boolean} pReadable
|
|
|
|
|
* @return {VNode} 主表单包含el-form-item 子表单表单组件
|
|
|
|
|
**/
|
|
|
|
|
export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
export default function formBuilder(device, info, h, row, pWrite = false,pReadable = false) {
|
|
|
|
|
let formItem;
|
|
|
|
|
//下拉选项
|
|
|
|
|
if (info?.stub) {
|
|
|
|
|
options = info?.stub?.split("|") || [];
|
|
|
|
|
} else if (info?.selection_model) {
|
|
|
|
|
if (info?.selection_model) {
|
|
|
|
|
options = info.selection_model_items;
|
|
|
|
|
} else if (info?.stub) {
|
|
|
|
|
options = info?.stub?.split(/\n/) || [];
|
|
|
|
|
}
|
|
|
|
|
let options;
|
|
|
|
|
if (device === "desktop") {
|
|
|
|
|
@ -238,6 +239,8 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
multiple: !!info.multiple,
|
|
|
|
|
'multiple-limit': info.multiple,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
width: "100%",
|
|
|
|
|
@ -444,10 +447,15 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
multiple: !!info.multiple,
|
|
|
|
|
'multiple-limit': info.multiple,
|
|
|
|
|
},
|
|
|
|
|
attrs: {
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
width: "100%",
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: (e) => {
|
|
|
|
|
row
|
|
|
|
|
@ -459,8 +467,8 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
options.map((option) =>
|
|
|
|
|
h("el-option", {
|
|
|
|
|
props: {
|
|
|
|
|
label: option,
|
|
|
|
|
value: option,
|
|
|
|
|
label: typeof option === "object" ? option.name : option,
|
|
|
|
|
value: typeof option === "object" ? option.id : option,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
@ -479,6 +487,9 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
attrs: {
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
width: '100%'
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
input: (e) => {
|
|
|
|
|
row
|
|
|
|
|
@ -615,7 +626,8 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
subField,
|
|
|
|
|
h,
|
|
|
|
|
row,
|
|
|
|
|
info._writeable
|
|
|
|
|
info._writeable,
|
|
|
|
|
info._readable,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -820,6 +832,7 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
on: {
|
|
|
|
|
click: (_) => {
|
|
|
|
|
this.vanCalendarOption.forFormName = info.name;
|
|
|
|
|
this.vanCalendarOption.originalObj = row;
|
|
|
|
|
this.$set(this.vanCalendarOption, "isShow", true);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -839,32 +852,307 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
on: {
|
|
|
|
|
click: (_) => {
|
|
|
|
|
this.vanTimePickerOption.forFormName = info.name;
|
|
|
|
|
this.vanTimePickerOption.originalObj = row;
|
|
|
|
|
this.$set(this.vanTimePickerOption, "isShow", true);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "select":
|
|
|
|
|
let findValue = options.find((i) =>
|
|
|
|
|
typeof i === "object"
|
|
|
|
|
? i.id === (row ? row[info.name] : this.form[info.name])
|
|
|
|
|
: i === (row ? row[info.name] : this.form[info.name])
|
|
|
|
|
);
|
|
|
|
|
formItem = h("van-field", {
|
|
|
|
|
props: {
|
|
|
|
|
readonly: true,
|
|
|
|
|
clickable: true,
|
|
|
|
|
name: info.name,
|
|
|
|
|
label: info.label,
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name],
|
|
|
|
|
value: typeof findValue === "object" ? findValue.name : findValue,
|
|
|
|
|
clearable: true,
|
|
|
|
|
placeholder: info.help_text,
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
click: (_) => {
|
|
|
|
|
this.vanPopupOption.forFormName = info.name;
|
|
|
|
|
this.vanPopupOption.originalObj = row;
|
|
|
|
|
this.$set(this.vanPopupOption, "columns", options);
|
|
|
|
|
this.$set(this.vanPopupOption, "isShow", true);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "file":
|
|
|
|
|
formItem = h('van-cell',{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
}
|
|
|
|
|
},[
|
|
|
|
|
h(
|
|
|
|
|
formBuilderMap(device).get(info.type),
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
action: process.env.VUE_APP_UPLOAD_API,
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${getToken()}`,
|
|
|
|
|
},
|
|
|
|
|
accept:
|
|
|
|
|
"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: true,
|
|
|
|
|
fileList: this.file[info.name],
|
|
|
|
|
beforeUpload: (file) => {
|
|
|
|
|
if (file.size / 1024 / 1024 > 20) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "warning",
|
|
|
|
|
message: "上传图片大小超过20Mb!",
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onSuccess: (response, file, fileList) => {
|
|
|
|
|
fileList.forEach((file) => {
|
|
|
|
|
if (file.response?.data && !file.response?.code) {
|
|
|
|
|
file.response = file.response.data;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.file[info.name] = fileList;
|
|
|
|
|
},
|
|
|
|
|
onRemove: (file, fileList) => {
|
|
|
|
|
this.file[info.name] = fileList;
|
|
|
|
|
},
|
|
|
|
|
onError: (err, file, fileList) => {
|
|
|
|
|
this.file[info.name] = fileList;
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "warning",
|
|
|
|
|
message: err,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
scopedSlots: {
|
|
|
|
|
file: (scope) => {
|
|
|
|
|
let { file } = scope;
|
|
|
|
|
return [
|
|
|
|
|
h("div", {}, [
|
|
|
|
|
h("i", {
|
|
|
|
|
class: {
|
|
|
|
|
"el-icon-circle-check": file.status === "success",
|
|
|
|
|
"el-icon-loading": file.status === "uploading",
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
color: file.status === "success" ? "green" : "",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
h(
|
|
|
|
|
"a",
|
|
|
|
|
{
|
|
|
|
|
attrs: {
|
|
|
|
|
href: file.url,
|
|
|
|
|
download: file.name,
|
|
|
|
|
},
|
|
|
|
|
class: {
|
|
|
|
|
"uploaded-a": file.status === "success",
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
padding: "0 4px",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
file.name
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
h("i", {
|
|
|
|
|
class: "el-icon-close",
|
|
|
|
|
on: {
|
|
|
|
|
["click"]: () => {
|
|
|
|
|
this.$set(
|
|
|
|
|
this.file,
|
|
|
|
|
info.field,
|
|
|
|
|
this.file[info.field].filter(
|
|
|
|
|
(item) => item !== file
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
[
|
|
|
|
|
h(
|
|
|
|
|
"el-button",
|
|
|
|
|
{
|
|
|
|
|
slot: "trigger",
|
|
|
|
|
props: {
|
|
|
|
|
size: "mini",
|
|
|
|
|
type: "primary",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"选取文件"
|
|
|
|
|
),
|
|
|
|
|
h(
|
|
|
|
|
"div",
|
|
|
|
|
{
|
|
|
|
|
class: "el-upload__tip",
|
|
|
|
|
slot: "tip",
|
|
|
|
|
},
|
|
|
|
|
"文件不超过20Mb"
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
break;
|
|
|
|
|
case "relation":
|
|
|
|
|
let copySubForm = deepCopy(this.form[info.name][0])
|
|
|
|
|
formItem = h("div", [
|
|
|
|
|
h("van-cell", {
|
|
|
|
|
props: {
|
|
|
|
|
"arrow-direction": "down",
|
|
|
|
|
title: info.label,
|
|
|
|
|
},
|
|
|
|
|
},[
|
|
|
|
|
h('van-button',{
|
|
|
|
|
props: {
|
|
|
|
|
type: 'info',
|
|
|
|
|
icon: 'plus',
|
|
|
|
|
size: 'small'
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
'click':_ => {
|
|
|
|
|
this.form[info.name].push(copySubForm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},'新增')
|
|
|
|
|
]),
|
|
|
|
|
h(
|
|
|
|
|
"div",
|
|
|
|
|
this.form[info.name].map((sForm, sIndex) =>
|
|
|
|
|
h(
|
|
|
|
|
"van-cell-group",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
inset: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[
|
|
|
|
|
h("van-cell", {
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label + "-" + (sIndex + 1)
|
|
|
|
|
}
|
|
|
|
|
},[
|
|
|
|
|
h('van-button',{
|
|
|
|
|
props: {
|
|
|
|
|
size: 'mini',
|
|
|
|
|
type: 'danger',
|
|
|
|
|
icon: 'minus'
|
|
|
|
|
},
|
|
|
|
|
on: {
|
|
|
|
|
click: _ => {
|
|
|
|
|
this.form[info.name].splice(sIndex, 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},'删除')
|
|
|
|
|
]),
|
|
|
|
|
h(
|
|
|
|
|
"van-form",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
"scroll-to-error": true,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
margin: '0 10px'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Array.from(this.subForm)
|
|
|
|
|
.map((i) => i[1]?.customModel?.fields)
|
|
|
|
|
?.flat()
|
|
|
|
|
.map((subField) =>
|
|
|
|
|
formBuilder.bind(this)(
|
|
|
|
|
device,
|
|
|
|
|
subField,
|
|
|
|
|
h,
|
|
|
|
|
sForm,
|
|
|
|
|
info._writeable,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if(info._readable || pReadable) {
|
|
|
|
|
switch (info.type) {
|
|
|
|
|
case "date":
|
|
|
|
|
formItem = h(
|
|
|
|
|
"van-cell",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
value: this.form[info.name] ? moment(this.form[info.name]).format("YYYY年MM月DD日") : ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "datetime":
|
|
|
|
|
formItem = h(
|
|
|
|
|
"van-cell",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
value: this.form[info.name] ? moment(this.form[info.name]).format("YYYY年MM月DD日 HH时mm分ss秒") : ''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "select":
|
|
|
|
|
let findValue = options.find((i) =>
|
|
|
|
|
typeof i === "object"
|
|
|
|
|
? i.id === this.form[info.name]
|
|
|
|
|
: i === this.form[info.name]
|
|
|
|
|
);
|
|
|
|
|
formItem = h(
|
|
|
|
|
"van-cell",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
value: typeof findValue === "object" ? findValue.name : findValue
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'file':
|
|
|
|
|
formItem = h(
|
|
|
|
|
"van-cell",
|
|
|
|
|
{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
this.file[info.name].map(file => h("div", {}, [
|
|
|
|
|
h(
|
|
|
|
|
"a",
|
|
|
|
|
{
|
|
|
|
|
attrs: {
|
|
|
|
|
href: file.url,
|
|
|
|
|
download: file.name,
|
|
|
|
|
},
|
|
|
|
|
class: {
|
|
|
|
|
"uploaded-a": file.status === "success",
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
padding: "0 4px",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
file.name
|
|
|
|
|
),
|
|
|
|
|
]))
|
|
|
|
|
);
|
|
|
|
|
break
|
|
|
|
|
case 'relation':
|
|
|
|
|
formItem = h("div", [
|
|
|
|
|
h("van-cell", {
|
|
|
|
|
props: {
|
|
|
|
|
@ -894,6 +1182,9 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
props: {
|
|
|
|
|
"scroll-to-error": true,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
margin: '0 10px'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Array.from(this.subForm)
|
|
|
|
|
.map((i) => i[1]?.customModel?.fields)
|
|
|
|
|
@ -904,7 +1195,8 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
subField,
|
|
|
|
|
h,
|
|
|
|
|
sForm,
|
|
|
|
|
info._writeable
|
|
|
|
|
info._writeable,
|
|
|
|
|
info._readable
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
@ -914,8 +1206,15 @@ export default function formBuilder(device, info, h, row, pWrite = false) {
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
formItem = h('van-cell',{
|
|
|
|
|
props: {
|
|
|
|
|
title: info.label,
|
|
|
|
|
value: row ? row[info.name] : this.form[info.name]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return formItem;
|
|
|
|
|
}
|
|
|
|
|
return formItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|