update 一些视图,并且优化dialog

This commit is contained in:
2022-08-11 15:23:48 +08:00
parent cd9beb120a
commit 0ef30e1985
11 changed files with 163 additions and 114 deletions

View File

@@ -150,9 +150,10 @@ export default {
visible: false,
isEdit: false,
isDetail: false,
isUpdated: false,
dataForm: {},
dataFormRules: {}
dataFormRules: {},
tempForm: [], // 临时保存自动生成的code或其他数据
shouldWait: null
}
},
computed: {
@@ -162,6 +163,7 @@ export default {
}
},
mounted() {
console.log('mounted>..')
/** 计算 defaultPlaceholders */
const prefix = '请输入'
Object.entries(this.defaultNames).map(([key, value]) => {
@@ -182,12 +184,14 @@ export default {
this.$set(this.dataForm, [item.name], '')
if (item.api) {
/** 自动请求并填充 */
this.$http({
// or this.shouldWaitPool = []
this.shouldWait = this.$http({
url: this.$http.adornUrl(item.api),
method: 'POST' // 也可以改成动态决定
}).then(({ data: res }) => {
if (res && res.code === 0) {
this.dataForm[item.name] = res.data // <=== 此处需要对接口
// this.dataForm[item.name] = res.data // <=== 此处需要对接口
this.tempForm.push({ name: item.name, data: res.data })
}
})
} // end if (item.api)
@@ -236,9 +240,6 @@ export default {
this.$set(this.dataForm, 'id', null)
})
},
updated() {
this.isUpdated = true // 此时如果点击保存就会 emit(refreshDataList)
},
methods: {
getLabel(n, c) {
@@ -286,6 +287,16 @@ export default {
this.dataForm = pick(res.data, dataFormKeys)
}
})
} else {
/** 如果不是编辑,就填充自动生成的数据 */
if (this.shouldWait)
this.shouldWait.then(() => {
if (this.tempForm.length) {
this.tempForm.forEach(item => {
this.dataForm[item.name] = item.data
})
}
})
}
})
},
@@ -351,7 +362,7 @@ export default {
},
handleClose() {
if (this.isAdd || this.isUpdated) this.$emit('refreshDataList')
this.$emit('destory-dialog')
this.visible = false
}
}