update order/DialogJustForm
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
:disabled="detailMode"
|
||||
v-bind="col.elparams" />
|
||||
|
||||
<div class="" v-if="col.component" style="margin: 42px 0 0">
|
||||
<div class="" v-if="col.component" style="margin: 32px 0 0">
|
||||
<!-- 下面这个 component 几乎是为 富文本 quill 定制的了... TODO:后续可能会根据业务需求创建新的版本 -->
|
||||
<component
|
||||
:is="col.component"
|
||||
@@ -75,7 +75,6 @@
|
||||
:mode="detailMode ? 'detail' : dataForm.id ? 'edit' : 'create'"
|
||||
v-bind="col.bind" />
|
||||
</div>
|
||||
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -126,58 +125,63 @@ export default {
|
||||
const watchList = [];
|
||||
const cachedList = {};
|
||||
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
dataForm[col.prop] = col.default ?? null;
|
||||
this.configs.form.field.forEach((field) => {
|
||||
field.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if (!col.prop) return;
|
||||
|
||||
if (col.fetchData)
|
||||
col.fetchData().then(({ data: res }) => {
|
||||
if (res.code === 0) {
|
||||
if (typeof res.data === "object" && "list" in res.data) {
|
||||
if ("injectTo" in col) {
|
||||
// 保存完整的数据列表,用于自动更新关联字段
|
||||
cachedList[col.prop] = res.data.list;
|
||||
dataForm[col.prop] = col.default ?? null;
|
||||
|
||||
if (col.fetchData)
|
||||
col.fetchData().then(({ data: res }) => {
|
||||
if (res.code === 0) {
|
||||
if (typeof res.data === "object" && "list" in res.data) {
|
||||
if ("injectTo" in col) {
|
||||
// 保存完整的数据列表,用于自动更新关联字段
|
||||
cachedList[col.prop] = res.data.list;
|
||||
}
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.list.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
} else if (Array.isArray(res.data)) {
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
}
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.list.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
} else if (Array.isArray(res.data)) {
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
res.data.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
} else {
|
||||
// error 静默失败
|
||||
col.options.splice(0);
|
||||
}
|
||||
} else {
|
||||
// error 静默失败
|
||||
col.options.splice(0);
|
||||
}
|
||||
});
|
||||
else if (col.fetchTreeData) {
|
||||
// 获取设备类型时触发的,用于前端构建属性结构,约定,parentId 为0时是顶级节点
|
||||
col.fetchTreeData().then(({ data: res }) => {
|
||||
// console.log("[DialogJustForm fetchTreeData -->]", res.data);
|
||||
if (res.code === 0 && res.data) {
|
||||
if ("list" in res.data) {
|
||||
this.$set(col, "options", res.data.list);
|
||||
} else if (Array.isArray(res.data)) {
|
||||
this.$set(col, "options", res.data);
|
||||
});
|
||||
else if (col.fetchTreeData) {
|
||||
// 获取设备类型时触发的,用于前端构建属性结构,约定,parentId 为0时是顶级节点
|
||||
col.fetchTreeData().then(({ data: res }) => {
|
||||
// console.log("[DialogJustForm fetchTreeData -->]", res.data);
|
||||
if (res.code === 0 && res.data) {
|
||||
if ("list" in res.data) {
|
||||
this.$set(col, "options", res.data.list);
|
||||
} else if (Array.isArray(res.data)) {
|
||||
this.$set(col, "options", res.data);
|
||||
}
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
loadingStatus: false,
|
||||
dataForm,
|
||||
@@ -190,27 +194,29 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
/** 处理 injectTo 选项 */
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if ("injectTo" in col && Array.isArray(col.injectTo)) {
|
||||
// console.log("watching options ..... ", col);
|
||||
col.injectTo.map((item) => {
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[col.prop],
|
||||
(newVal) => {
|
||||
const chosenObject = this.cachedList[col.prop].find((i) => i.id === newVal);
|
||||
if (chosenObject) {
|
||||
// 如果找到了
|
||||
this.$set(this.dataForm, item[0], chosenObject[item[1]]);
|
||||
this.configs.form.field.forEach((field) => {
|
||||
field.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if ("injectTo" in col && Array.isArray(col.injectTo)) {
|
||||
// console.log("watching options ..... ", col);
|
||||
col.injectTo.map((item) => {
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[col.prop],
|
||||
(newVal) => {
|
||||
const chosenObject = this.cachedList[col.prop].find((i) => i.id === newVal);
|
||||
if (chosenObject) {
|
||||
// 如果找到了
|
||||
this.$set(this.dataForm, item[0], chosenObject[item[1]]);
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
});
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user