fix -- 修复表单文件上传下载问题

This commit is contained in:
konbai
2022-05-10 00:49:39 +08:00
parent f62f7b25d6
commit 78916deee2
2 changed files with 37 additions and 9 deletions

View File

@@ -499,7 +499,7 @@ export const selectComponents = [
__slot__: {
'list-type': true
},
action: 'https://jsonplaceholder.typicode.com/posts/',
action: process.env.VUE_APP_BASE_API + "/system/oss/upload",
disabled: false,
accept: '',
name: 'file',

View File

@@ -1,5 +1,6 @@
import { deepClone } from '@/utils/index'
import render from '@/utils/generator/render'
import { deepClone } from '@/utils/index';
import { getToken } from '@/utils/auth';
import render from '@/utils/generator/render';
const ruleTrigger = {
'el-input': 'blur',
@@ -10,7 +11,8 @@ const ruleTrigger = {
'el-cascader': 'change',
'el-time-picker': 'change',
'el-date-picker': 'change',
'el-rate': 'change'
'el-rate': 'change',
'el-upload': 'change'
}
const layouts = {
@@ -138,9 +140,37 @@ export default {
methods: {
initFormData(componentList, formData) {
componentList.forEach(cur => {
const config = cur.__config__
if (cur.__vModel__) formData[cur.__vModel__] = config.defaultValue
if (config.children) this.initFormData(config.children, formData)
const config = cur.__config__;
if (cur.__vModel__) {
formData[cur.__vModel__] = config.defaultValue;
// 初始化文件列表
if (cur.action && config.defaultValue) {
cur['file-list'] = config.defaultValue;
}
}
if (cur.action) {
cur['headers'] = {
Authorization: "Bearer " + getToken(),
}
cur['on-success'] = (res, file, fileList) => {
formData[cur.__vModel__] = fileList;
if (res.code === 200 && fileList) {
config.defaultValue = fileList;
config.defaultValue.forEach(val => {
val.url = file.response.data.url;
val.ossId = file.response.data.ossId;
val.response = null
})
}
};
// 点击文件列表中已上传的文件时的钩子
cur['on-preview'] = (file) => {
this.$download.oss(file.ossId)
}
}
if (config.children) {
this.initFormData(config.children, formData);
}
})
},
buildRules(componentList, rules) {
@@ -172,8 +202,6 @@ export default {
submitForm() {
this.$refs[this.formConf.formRef].validate(valid => {
if (!valid) return false
// 触发sumit事件
// this.$emit('submit', this[this.formConf.formModel])
const params = {
formData: this.formConfCopy,
valData: this[this.formConf.formModel]