From a9f5d315bf7def050588c4ea6716b3e790d9e990 Mon Sep 17 00:00:00 2001 From: liyang Date: Wed, 18 Aug 2021 18:48:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87/?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=A4=B1=E8=B4=A5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/components/FileUpload/index.vue | 60 ++++++++++++------ ruoyi-ui/src/components/ImageUpload/index.vue | 63 +++++++++++-------- 2 files changed, 80 insertions(+), 43 deletions(-) diff --git a/ruoyi-ui/src/components/FileUpload/index.vue b/ruoyi-ui/src/components/FileUpload/index.vue index 244ac2891..0e1c218f5 100644 --- a/ruoyi-ui/src/components/FileUpload/index.vue +++ b/ruoyi-ui/src/components/FileUpload/index.vue @@ -18,20 +18,34 @@
请上传 - - + + 的文件
- -
  • + +
  • {{ getFileName(file.name) }}
    - 删除 + 删除
  • @@ -64,8 +78,8 @@ export default { // 是否显示提示 isShowTip: { type: Boolean, - default: true - } + default: true, + }, }, data() { return { @@ -83,9 +97,9 @@ export default { if (val) { let temp = 1; // 首先将值转为数组 - const list = Array.isArray(val) ? val : this.value.split(','); + const list = Array.isArray(val) ? val : this.value.split(","); // 然后将数组转为对象数组 - this.fileList = list.map(item => { + this.fileList = list.map((item) => { if (typeof item === "string") { item = { name: item, url: item }; } @@ -98,8 +112,8 @@ export default { } }, deep: true, - immediate: true - } + immediate: true, + }, }, computed: { // 是否显示提示 @@ -122,7 +136,9 @@ export default { return false; }); if (!isTypeOk) { - this.$message.error(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); + this.$message.error( + `文件格式不正确, 请上传${this.fileType.join("/")}格式文件!` + ); return false; } } @@ -146,9 +162,17 @@ export default { }, // 上传成功回调 handleUploadSuccess(res, file) { - this.$message.success("上传成功"); - this.fileList.push({ name: res.data.fileName, url: res.data.fileName }); - this.$emit("input", this.listToString(this.fileList)); + if (res.code === 200) { + this.$message.success("上传成功"); + this.fileList.push({ name: res.data.fileName, url: res.data.fileName }); + this.$emit("input", this.listToString(this.fileList)); + } else { + this.$message({ + type: "error", + message: res.msg, + }); + this.loading.close(); + } }, // 删除文件 handleDelete(index) { @@ -170,9 +194,9 @@ export default { for (let i in list) { strs += list[i].url + separator; } - return strs != '' ? strs.substr(0, strs.length - 1) : ''; - } - } + return strs != "" ? strs.substr(0, strs.length - 1) : ""; + }, + }, }; diff --git a/ruoyi-ui/src/components/ImageUpload/index.vue b/ruoyi-ui/src/components/ImageUpload/index.vue index e074b381b..254bc8198 100644 --- a/ruoyi-ui/src/components/ImageUpload/index.vue +++ b/ruoyi-ui/src/components/ImageUpload/index.vue @@ -14,7 +14,7 @@ :headers="headers" :file-list="fileList" :on-preview="handlePictureCardPreview" - :class="{hide: this.fileList.length >= this.limit}" + :class="{ hide: this.fileList.length >= this.limit }" > @@ -22,8 +22,12 @@
    请上传 - - + + 的文件
    @@ -54,7 +58,7 @@ export default { }, // 大小限制(MB) fileSize: { - type: Number, + type: Number, default: 5, }, // 文件类型, 例如['png', 'jpg', 'jpeg'] @@ -65,8 +69,8 @@ export default { // 是否显示提示 isShowTip: { type: Boolean, - default: true - } + default: true, + }, }, data() { return { @@ -78,7 +82,7 @@ export default { headers: { Authorization: "Bearer " + getToken(), }, - fileList: [] + fileList: [], }; }, watch: { @@ -86,9 +90,9 @@ export default { handler(val) { if (val) { // 首先将值转为数组 - const list = Array.isArray(val) ? val : this.value.split(','); + const list = Array.isArray(val) ? val : this.value.split(","); // 然后将数组转为对象数组 - this.fileList = list.map(item => { + this.fileList = list.map((item) => { if (typeof item === "string") { item = { name: item, url: item }; } @@ -100,8 +104,8 @@ export default { } }, deep: true, - immediate: true - } + immediate: true, + }, }, computed: { // 是否显示提示 @@ -112,15 +116,23 @@ export default { methods: { // 删除图片 handleRemove(file, fileList) { - const findex = this.fileList.map(f => f.name).indexOf(file.name); + const findex = this.fileList.map((f) => f.name).indexOf(file.name); this.fileList.splice(findex, 1); this.$emit("input", this.listToString(this.fileList)); }, // 上传成功回调 handleUploadSuccess(res) { - this.fileList.push({ name: res.data.fileName, url: res.data.url }); - this.$emit("input", this.listToString(this.fileList)); - this.loading.close(); + if (res.code == 200) { + this.fileList.push({ name: res.data.fileName, url: res.data.url }); + this.$emit("input", this.listToString(this.fileList)); + this.loading.close(); + } else { + this.$message({ + type: "error", + message: res.msg, + }); + this.loading.close(); + } }, // 上传前loading加载 handleBeforeUpload(file) { @@ -130,7 +142,7 @@ export default { if (file.name.lastIndexOf(".") > -1) { fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1); } - isImg = this.fileType.some(type => { + isImg = this.fileType.some((type) => { if (file.type.indexOf(type) > -1) return true; if (fileExtension && fileExtension.indexOf(type) > -1) return true; return false; @@ -163,7 +175,7 @@ export default { this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); }, // 上传失败 - handleUploadError() { + handleUploadError(res) { this.$message({ type: "error", message: "上传失败", @@ -182,25 +194,26 @@ export default { for (let i in list) { strs += list[i].url + separator; } - return strs != '' ? strs.substr(0, strs.length - 1) : ''; - } - } + return strs != "" ? strs.substr(0, strs.length - 1) : ""; + }, + }, }; From 470fda420c4eae64ed12d36e4b1cb752e417fcc4 Mon Sep 17 00:00:00 2001 From: liyang Date: Wed, 18 Aug 2021 19:03:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87/?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=A4=B1=E8=B4=A5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/system/oss/config.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/system/oss/config.vue b/ruoyi-ui/src/views/system/oss/config.vue index c6ea3a62e..6277336f5 100644 --- a/ruoyi-ui/src/views/system/oss/config.vue +++ b/ruoyi-ui/src/views/system/oss/config.vue @@ -138,7 +138,7 @@ - + From 1475e0b60bbd47df2991a225fd7e163d949882ff Mon Sep 17 00:00:00 2001 From: liyang Date: Wed, 18 Aug 2021 19:05:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=A7=98=E9=92=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=9A=90=E8=97=8F=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/system/oss/config.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/system/oss/config.vue b/ruoyi-ui/src/views/system/oss/config.vue index 6277336f5..cc24fcd73 100644 --- a/ruoyi-ui/src/views/system/oss/config.vue +++ b/ruoyi-ui/src/views/system/oss/config.vue @@ -138,7 +138,7 @@ - +