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) : ""; + }, + }, }; diff --git a/ruoyi-ui/src/views/system/oss/config.vue b/ruoyi-ui/src/views/system/oss/config.vue index c6ea3a62e..cc24fcd73 100644 --- a/ruoyi-ui/src/views/system/oss/config.vue +++ b/ruoyi-ui/src/views/system/oss/config.vue @@ -138,7 +138,7 @@ - +