fix -- 修复表单文件上传下载问题
This commit is contained in:
@@ -499,7 +499,7 @@ export const selectComponents = [
|
|||||||
__slot__: {
|
__slot__: {
|
||||||
'list-type': true
|
'list-type': true
|
||||||
},
|
},
|
||||||
action: 'https://jsonplaceholder.typicode.com/posts/',
|
action: process.env.VUE_APP_BASE_API + "/system/oss/upload",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
accept: '',
|
accept: '',
|
||||||
name: 'file',
|
name: 'file',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { deepClone } from '@/utils/index'
|
import { deepClone } from '@/utils/index';
|
||||||
import render from '@/utils/generator/render'
|
import { getToken } from '@/utils/auth';
|
||||||
|
import render from '@/utils/generator/render';
|
||||||
|
|
||||||
const ruleTrigger = {
|
const ruleTrigger = {
|
||||||
'el-input': 'blur',
|
'el-input': 'blur',
|
||||||
@@ -10,7 +11,8 @@ const ruleTrigger = {
|
|||||||
'el-cascader': 'change',
|
'el-cascader': 'change',
|
||||||
'el-time-picker': 'change',
|
'el-time-picker': 'change',
|
||||||
'el-date-picker': 'change',
|
'el-date-picker': 'change',
|
||||||
'el-rate': 'change'
|
'el-rate': 'change',
|
||||||
|
'el-upload': 'change'
|
||||||
}
|
}
|
||||||
|
|
||||||
const layouts = {
|
const layouts = {
|
||||||
@@ -138,9 +140,37 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
initFormData(componentList, formData) {
|
initFormData(componentList, formData) {
|
||||||
componentList.forEach(cur => {
|
componentList.forEach(cur => {
|
||||||
const config = cur.__config__
|
const config = cur.__config__;
|
||||||
if (cur.__vModel__) formData[cur.__vModel__] = config.defaultValue
|
if (cur.__vModel__) {
|
||||||
if (config.children) this.initFormData(config.children, formData)
|
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) {
|
buildRules(componentList, rules) {
|
||||||
@@ -172,8 +202,6 @@ export default {
|
|||||||
submitForm() {
|
submitForm() {
|
||||||
this.$refs[this.formConf.formRef].validate(valid => {
|
this.$refs[this.formConf.formRef].validate(valid => {
|
||||||
if (!valid) return false
|
if (!valid) return false
|
||||||
// 触发sumit事件
|
|
||||||
// this.$emit('submit', this[this.formConf.formModel])
|
|
||||||
const params = {
|
const params = {
|
||||||
formData: this.formConfCopy,
|
formData: this.formConfCopy,
|
||||||
valData: this[this.formConf.formModel]
|
valData: this[this.formConf.formModel]
|
||||||
|
|||||||
Reference in New Issue
Block a user