update 基本完成上传

This commit is contained in:
2022-08-15 10:23:39 +08:00
parent a9265d6708
commit b4e00bbca0
3 changed files with 83 additions and 12 deletions

View File

@@ -46,7 +46,7 @@
<template v-if="configs.extraComponents && configs.extraComponents.length > 0">
<el-form-item v-for="ec in configs.extraComponents" :key="ec.name" :label="ec.label">
<!-- <component :is="ec.component" v-model="dataForm[ec.name]"></component> -->
<component :is="ec.component" v-bind="ec.props" />
<component :is="ec.component" v-bind="ec.props" @uploader-update-filelist="handleUploadListUpdate" :uploader-inject-file-list="dataForm.files"/>
</el-form-item>
</template>
</el-form>
@@ -137,6 +137,11 @@ export default {
return defaultNames[name]
}
},
// provide() {
// return {
// _df: this.dataForm
// }
// },
data() {
return {
COLUMN_PER_ROW,
@@ -236,15 +241,26 @@ export default {
} // end if (item.rules)
})
/** 计算默认值 */
function calDefault(type) {
switch (type) {
case 'array':
return []
// more case...
default:
return ''
}
}
/** 检查是否需要额外的组件 */
this.configs.extraComponents &&
this.configs.extraComponents.forEach(item => {
this.$set(this.dataForm, [item.name], '')
this.$set(this.dataForm, [item.name], calDefault(item.fieldType))
})
/** 单独设置 id */
this.$set(this.dataForm, 'id', null)
})
console.log("mounted: this.dataForm", JSON.stringify(this.dataForm))
},
methods: {
@@ -302,6 +318,7 @@ export default {
}).then(({ data: res }) => {
if (res && res.code === 0) {
const dataFormKeys = Object.keys(this.dataForm)
console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys))
this.dataForm = pick(res.data, dataFormKeys)
}
})
@@ -310,9 +327,12 @@ export default {
if (this.shouldWait)
this.shouldWait.then(() => {
if (this.tempForm.length) {
console.log("create new, tempform", JSON.stringify(this.tempForm.length))
this.tempForm.forEach(item => {
console.log('item data', item.data)
this.dataForm[item.name] = item.data
})
console.log("create new, dataform", JSON.stringify(this.dataForm))
}
})
}
@@ -381,6 +401,12 @@ export default {
}
},
handleUploadListUpdate(filelist) {
// 此处需要参照‘设备类型’新增的接口,灵活地设置 dataForm
this.$set(this.dataForm, 'fileIds', filelist.map(item => item.id))
console.log('handleUploadListUpdate(): ', this.dataForm)
},
handleClose() {
this.$emit('destory-dialog')
this.visible = false