!10 【Fix】修复文件上传成功触发非空校验的问题;增加文件预览和下载;

Merge pull request !10 from 逸尘/master
rf
tony 2023-03-24 00:20:35 +00:00 committed by Gitee
commit f816b906ae
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 112 additions and 19 deletions

View File

@ -104,18 +104,75 @@ function setValue(event, config, scheme) {
} }
function buildListeners(scheme) { function buildListeners(scheme) {
const config = scheme.__config__ const config = scheme.__config__;
const methods = this.formConf.__methods__ || {} const methods = this.formConf.__methods__ || {};
const listeners = {} const listeners = {};
// __methods__thisevent // __methods__thisevent
Object.keys(methods).forEach(key => { Object.keys(methods).forEach((key) => {
listeners[key] = event => methods[key].call(this, event) listeners[key] = (event) => methods[key].call(this, event);
}) });
// render.js vModel $emit('input', val)
listeners.input = event => setValue.call(this, event, config, scheme)
return listeners // render.js vModel $emit('input', val)
listeners.input = (event) => setValue.call(this, event, config, scheme);
//
if (config.tag === "el-upload") {
listeners.upload = (response, file, fileList) =>
setUpload.call(this, config, scheme, response, file, fileList);
listeners.deleteUpload = (file, fileList) =>
deleteUpload.call(this, config, scheme, file, fileList);
listeners.previewUpload = (file, fileList) =>
window.open(file.url, "_blank");
}
return listeners;
}
//
function setUpload(config, scheme, response, file, fileList) {
//response:
let fileObj = {
name: response.fileName,
url: response.url,
fileType: response.contentType,
};
let oldValue = "";
try {
oldValue = JSON.parse(this[this.formConf.formModel][scheme.__vModel__]);
} catch (err) {
console.warn(err);
}
if (oldValue) {
oldValue.push(fileObj);
} else {
oldValue = [fileObj];
}
this.$set(config, "defaultValue", JSON.stringify(oldValue));
this.$set(
this[this.formConf.formModel],
scheme.__vModel__,
JSON.stringify(oldValue)
);
}
//
function deleteUpload(config, scheme, file, fileList) {
let oldValue = JSON.parse(this[this.formConf.formModel][scheme.__vModel__]);
//file
//
let newValue = oldValue.filter((item) => item.name !== file.name);
this.$set(config, "defaultValue", JSON.stringify(newValue));
this.$set(
this[this.formConf.formModel],
scheme.__vModel__,
JSON.stringify(newValue)
);
} }
export default { export default {

View File

@ -14,12 +14,37 @@ keys.forEach(key => {
componentChild[tag] = value componentChild[tag] = value
}) })
function vModel(dataObject, defaultValue) { function vModel(dataObject, defaultValue, config) {
dataObject.props.value = defaultValue // 获取上传表单元素组件上传的文件
if (config.tag === "el-upload") {
// 上传表单元素组件的成功和移除事件
dataObject.attrs["on-success"] = (response, file, fileList) => {
this.$emit("upload", response, file, fileList);
};
dataObject.on.input = val => { dataObject.attrs["on-remove"] = (file, fileList) => {
this.$emit('input', val) this.$emit("deleteUpload", file, fileList);
};
dataObject.attrs["on-preview"] = (file, fileList) => {
this.$emit("previewUpload", file, fileList);
};
// 获取上传表单元素的默认值
try {
dataObject.props["file-list"] = JSON.parse(defaultValue);
} catch (err) {
console.warn(err);
}
return;
} }
// 获取普通表单元素的值
dataObject.props.value = defaultValue;
dataObject.on.input = (val) => {
this.$emit("input", val);
};
} }
function mountSlotFiles(h, confClone, children) { function mountSlotFiles(h, confClone, children) {
@ -50,7 +75,7 @@ function buildDataObject(confClone, dataObject) {
Object.keys(confClone).forEach(key => { Object.keys(confClone).forEach(key => {
const val = confClone[key] const val = confClone[key]
if (key === '__vModel__') { if (key === '__vModel__') {
vModel.call(this, dataObject, confClone.__config__.defaultValue) vModel.call(this, dataObject, confClone.__config__.defaultValue, confClone.__config__)
} else if (dataObject[key] !== undefined) { } else if (dataObject[key] !== undefined) {
if (dataObject[key] === null if (dataObject[key] === null
|| dataObject[key] instanceof RegExp || dataObject[key] instanceof RegExp

View File

@ -154,12 +154,23 @@ export default {
}) })
}, },
fillFormData(form, data) { fillFormData(form, data) {
form.fields.forEach(item => { form.fields.forEach((item) => {
const val = data[item.__vModel__] const vModel = item.__vModel__;
if (val) { const val = data[item.__vModel__];
item.__config__.defaultValue = val
// el-upload
if (item.__config__.tag === "el-upload") {
//
item["file-list"] = (val || []).map((url) => ({
name: `${vModel}${i}`,
url,
}));
} }
})
if (val) {
item.__config__.defaultValue = val;
}
});
}, },
/** 获取流程变量内容 */ /** 获取流程变量内容 */
processVariables(taskId) { processVariables(taskId) {