forked from mt-fe-group/mt-yd-ui
update 一些视图,并且优化dialog
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user