master
xy 3 years ago
parent f93efeb418
commit f4a882d432

@ -41,111 +41,108 @@ export default {
}, },
(() => { (() => {
let dom = []; let dom = [];
this.formInfo.forEach((i, index) => { this.formInfo.filter(i => i.form_show).forEach((i, index) => {
if (i.list_show) { dom.push(
dom.push( h(
h( "el-form-item",
"el-form-item", {
{ ref: `elFormItem${i.field}`,
ref: `elFormItem${i.field}`, style: {
style: { width: "100%",
width: "100%",
},
props: {
label: i.name,
prop: i.field,
required:
i.validation instanceof Array
? !!i.validation.find((i) => i === "required")
: false,
},
}, },
this.$scopedSlots[i.field] props: {
? this.$scopedSlots[i.field]({ fieldInfo: i, form: this.form }) label: i.name,
: [ prop: i.field,
h( required:
domMap.get(i.edit_input), i.validation instanceof Array
{ ? !!i.validation.find((i) => i === "required")
ref: `elEdit_${i.field}`, : false,
style: { },
width: "100%", },
}, this.$scopedSlots[i.field]
props: { ? this.$scopedSlots[i.field]({ fieldInfo: i, form: this.form })
...addPropsMap.get(i.edit_input), : [
...this.extraProps(i), h(
placeholder: i.help, domMap.get(i.edit_input),
value: this.form[i.field], {
}, ref: `elEdit_${i.field}`,
attrs: { style: {
placeholder: i.help || `请填写${i.name}`, width: "100%",
}, },
on: { props: {
[this.getEventType(i.edit_input)]: (e) => { ...addPropsMap.get(i.edit_input),
if (i.field) { ...this.extraProps(i),
this.form[i.field] = e; placeholder: i.help,
this.form = Object.assign({}, this.form); value: this.form[i.field],
} },
}, attrs: {
['visible-change']:_ => i._params.set() placeholder: i.help || `请填写${i.name}`,
}, },
scopedSlots: on: {
i.edit_input === "file" || [this.getEventType(i.edit_input)]: (e) => {
i.edit_input === "files" if (i.field) {
? { this.form[i.field] = e;
file: (scope) => { this.form = Object.assign({}, this.form);
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",
},
},
file.name
),
]),
h("i", {
class: "el-icon-close",
on: {
["click"]: () =>
this.fileRemoveHandler(
file,
i.field
),
},
}),
];
},
}
: "",
}, },
this.optionsRender(h, i) },
), scopedSlots:
] i.edit_input === "file" ||
) i.edit_input === "files"
); ? {
} 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",
},
},
file.name
),
]),
h("i", {
class: "el-icon-close",
on: {
["click"]: () =>
this.fileRemoveHandler(
file,
i.field
),
},
}),
];
},
}
: "",
},
this.optionsRender(h, i)
),
]
)
);
}); });
return dom; return dom;
})() })()
@ -215,12 +212,12 @@ export default {
// //
optionsRender(h, info) { optionsRender(h, info) {
if (info.edit_input === "checkbox" || info.edit_input === "radio") { if (info.edit_input === "checkbox" || info.edit_input === "radio") {
return info._params.get() && info._params.get() instanceof Array return info._params && info._params instanceof Array
? info._params.get().map((i) => ? info._params.map((i) =>
h("el-option", { h("el-option", {
props: { props: {
label: i.name || i.no || i.value || i.id, label: i.key || i.name || i.no || i.value || i.id,
value: i[info._relations.foreign_key], value: info._relations ? i[info._relations.foreign_key] : i.value,
}, },
}) })
) )

@ -63,9 +63,9 @@
<Option <Option
v-for="item in getColumnParams(select.filter[0].key)" v-for="item in getColumnParams(select.filter[0].key)"
:key="item.id" :key="item.id"
:value="item.id" :value="getColumnField(select.filter[0].key)._relations ? item[getColumnField(select.filter[0].key)._relations.foreign_key] : item.value"
>{{ >{{
item.value || item.name || item.no || item.id item.key || item.value || item.name || item.no || item.id
}}</Option }}</Option
> >
</Select> </Select>
@ -160,9 +160,9 @@
<Option <Option
v-for="item in getColumnParams(item.key)" v-for="item in getColumnParams(item.key)"
:key="item.id" :key="item.id"
:value="item.id" :value="getColumnField(item.key)._relations ? item[getColumnField(item.key)._relations.foreign_key] : item.value"
>{{ >{{
item.value || item.name || item.no || item.id item.key || item.value || item.name || item.no || item.id
}}</Option }}</Option
> >
</Select> </Select>
@ -414,26 +414,28 @@ export default {
} }
fields.forEach((i, index) => { fields.forEach((i, index) => {
i._relations = relation.find((j) => j.local_key === i.field); i._relations = relation.find((j) => j.local_key === i.field);
i._params = { if (i.select_item && typeof i.select_item === 'object') {
value: [], let keys = Object.keys(i.select_item)
load: false, i._params = keys.map(key => {
get: () => i._params.value, return {
set: () => { key,
if(i._params.load) return value: i.select_item[key]
i._relations.parameter_id }
? getparameter({ id: i._relations.parameter_id },false).then((res) => { })
i._params.value = res.detail; }
}) if (i._relations) {
: this.index({ i._params = i._relations.parameter_id
table_name: i._relations.link_table_name, ? getparameter({ id: i._relations.parameter_id },false).then((res) => {
page: 1, i._params = res.detail;
page_size: 9999, })
}).then((res) => { : this.index({
i._params.value = res.data; table_name: i._relations.link_table_name,
}); page: 1,
i._params.load = true page_size: 9999,
}, }).then((res) => {
}; i._params = res.data;
});
}
}); });
this.form = fields; this.form = fields;
console.log(111, this.form); console.log(111, this.form);
@ -469,6 +471,21 @@ export default {
.map((i) => { .map((i) => {
let linkOb = {}; let linkOb = {};
if (i.select_item && typeof i.select_item === 'object') {
let keys = Object.keys(i.select_item)
linkOb.customFn = row => {
let paramMap = new Map()
keys.forEach(key => {
paramMap.set(i.select_item[key],key)
})
return (
<span>
{ paramMap.get(row[i.field].toString()) }
</span>
)
}
}
if (i._relations) { if (i._relations) {
let { link_relation, foreign_key, link_with_name } = i._relations let { link_relation, foreign_key, link_with_name } = i._relations
if (link_relation === 'newHasOne' || link_relation === 'hasOne') { if (link_relation === 'newHasOne' || link_relation === 'hasOne') {
@ -485,9 +502,9 @@ export default {
} else { } else {
return ( return (
<span> <span>
{row[link_with_name]?.name || { row[link_with_name]?.name ||
row[link_with_name]?.no || row[link_with_name]?.no ||
row[link_with_name]?.value} row[link_with_name]?.value }
</span> </span>
); );
} }
@ -528,17 +545,24 @@ export default {
columnArrTest() { columnArrTest() {
return function (field) { return function (field) {
return this.form.find((i) => i.field === field) return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field).search_input === "checkbox" ? this.form.find((i) => i.field === field).search_input === "checkbox" || this.form.find((i) => i.field === field).search_input === "radio"
: false; : false;
}; };
}, },
getColumnField() {
return function (field) {
return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field)
: {};
};
},
getColumnParams() { getColumnParams() {
return function (field) { return function (field) {
return this.form.find((i) => i.field === field) return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field)._paramters ? this.form.find((i) => i.field === field)._params
: []; : [];
}; };
}, }
}, },
created() { created() {
this.getFormDetail(); this.getFormDetail();

Loading…
Cancel
Save