update 附件上传功能
This commit is contained in:
@@ -53,8 +53,8 @@ export default {
|
||||
},
|
||||
detailMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -83,9 +83,19 @@ export default {
|
||||
attachmentId: file.id,
|
||||
type: 1,
|
||||
},
|
||||
responseType: "blob",
|
||||
})
|
||||
.then(({ data: res }) => {
|
||||
const blob = new Blob([res]);
|
||||
|
||||
/** 通知 */
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "开始下载",
|
||||
type: "success",
|
||||
duration: 1200,
|
||||
});
|
||||
|
||||
if ("download" in document.createElement("a")) {
|
||||
const alink = document.createElement("a");
|
||||
alink.download = file.name;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
:show-file-list="false"
|
||||
:headers="uploadHeaders"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleUploadCheck"
|
||||
>
|
||||
<el-button :disabled="disabled" size="small" type="primary">{{ buttonText }}</el-button>
|
||||
<div slot="tip" class="el-upload__tip">
|
||||
@@ -42,7 +43,7 @@ export default {
|
||||
tips: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
hint: "只能上传jpg/png文件, 且不超过500kb",
|
||||
hint: "文件大小不超过 2MB",
|
||||
success: "上传成功!",
|
||||
}),
|
||||
},
|
||||
@@ -64,14 +65,9 @@ export default {
|
||||
return { showMsg: false, uploadedFileList: [] };
|
||||
},
|
||||
watch: {
|
||||
// fileList: {
|
||||
// handler: (arr) => {
|
||||
// if (arr && arr.length > 0) {
|
||||
// this.uploadedFileList = arr;
|
||||
// }
|
||||
// },
|
||||
// immediate: true,
|
||||
// },
|
||||
fileList(val) {
|
||||
this.uploadedFileList = val ?? [];
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
uploadHeaders() {
|
||||
@@ -103,6 +99,18 @@ export default {
|
||||
.catch(() => {});
|
||||
},
|
||||
|
||||
handleUploadCheck(file) {
|
||||
const LIMIT = 2 * 1024 * 1024; // bytes
|
||||
if (file.size > LIMIT) {
|
||||
this.$message({
|
||||
message: "文件大小不能超过 2MB",
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
return false;
|
||||
} else return true;
|
||||
},
|
||||
|
||||
handleUploadSuccess(response, file, fileList) {
|
||||
console.log("[UploadBtn] uploadedFileList", response, file, fileList, this.uploadedFileList);
|
||||
|
||||
@@ -115,13 +123,6 @@ export default {
|
||||
typeCode: file.typeCode,
|
||||
};
|
||||
|
||||
/** 通知 */
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "上传成功",
|
||||
type: "success",
|
||||
});
|
||||
|
||||
this.uploadedFileList.push(fileItem);
|
||||
this.$emit("update-file-list", this.uploadedFileList);
|
||||
// this.showMsg = true;
|
||||
|
||||
Reference in New Issue
Block a user