update 解决初步获取detail时code被watcher强制替换的问题

This commit is contained in:
lb 2023-07-25 16:47:00 +08:00
parent 96344ed345
commit 9013f8572d

View File

@ -43,7 +43,7 @@
<!-- 表单标签页 --> <!-- 表单标签页 -->
<div v-if="tab.key === 'info'"> <div v-if="tab.key === 'info'">
<!-- form --> <!-- form -->
<el-form ref="dataForm" :model="dataForm" v-loading="formLoading || optionsLoading"> <el-form ref="dataForm" :model="dataForm" v-loading="formLoading || optionsLoading || tableLoading">
<el-row v-for="(row, rowIndex) in configs.form.rows" :key="'row_' + rowIndex" :gutter="20"> <el-row v-for="(row, rowIndex) in configs.form.rows" :key="'row_' + rowIndex" :gutter="20">
<el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length"> <el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
<el-form-item <el-form-item
@ -331,12 +331,13 @@ export default {
this.$watch( this.$watch(
() => this.dataForm[targetProp], () => this.dataForm[targetProp],
(val) => { (val) => {
console.log("[DWM watch]");
if (val && targetProp in dataSource) { if (val && targetProp in dataSource) {
this.dataForm[followerProp] = dataSource[targetProp]?.find((item) => item.id === val)?.[followerProp]; this.dataForm[followerProp] = dataSource[targetProp]?.find((item) => item.id === val)?.[followerProp];
} }
}, },
{ {
immediate: true, immediate: false,
} }
); );
}, },
@ -372,11 +373,11 @@ export default {
console.log("[DWM doRequests] requestList", this.requestList); console.log("[DWM doRequests] requestList", this.requestList);
if (this.requestList.length) { if (this.requestList.length) {
const promiseList = []; const promiseList = [];
this.optionsLoading = true;
try { try {
this.requestList.forEach((opt) => { this.requestList.forEach((opt) => {
console.log("[DWM doRequests]", opt.fetchData); console.log("[DWM doRequests]", opt.fetchData);
promiseList.push(async function () { promiseList.push(async () => {
this.optionsLoading = true;
// const { data: res } = await opt.fetchData(this.dataForm.id ? this.dataForm.id : -1); // const { data: res } = await opt.fetchData(this.dataForm.id ? this.dataForm.id : -1);
const { data: res } = await opt.fetchData(); const { data: res } = await opt.fetchData();
if (opt.cacheFetchedData) this.cached[opt.prop] = "list" in res.data ? res.data.list : res.data || []; if (opt.cacheFetchedData) this.cached[opt.prop] = "list" in res.data ? res.data.list : res.data || [];
@ -412,12 +413,10 @@ export default {
// res.code != 0 // res.code != 0
this.$set(opt, "options", []); this.$set(opt, "options", []);
} }
});
});
const v = await Promise.all(promiseList.map(fn => fn.call(this)));
console.log("v", v);
this.optionsLoading = false; this.optionsLoading = false;
});
});
const v = await Promise.all(promiseList.map((fn) => fn.call(this)));
return true; return true;
} catch (err) { } catch (err) {
this.$message.err("刷新选项失败"); this.$message.err("刷新选项失败");