From 6505432bf48dccc22ba58b28ecf7b71919cef43a Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期三, 12 十月 2022 19:33:58 +0800 Subject: [PATCH] 修复文件上传组件格式验证问题(I5V32H) --- ruoyi-ui/src/components/FileUpload/index.vue | 16 +++++----------- 1 files changed, 5 insertions(+), 11 deletions(-) diff --git a/ruoyi-ui/src/components/FileUpload/index.vue b/ruoyi-ui/src/components/FileUpload/index.vue index 4e94cb0..6c583cf 100644 --- a/ruoyi-ui/src/components/FileUpload/index.vue +++ b/ruoyi-ui/src/components/FileUpload/index.vue @@ -73,7 +73,7 @@ number: 0, uploadList: [], baseUrl: process.env.VUE_APP_BASE_API, - uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃 + uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 涓婁紶鏂囦欢鏈嶅姟鍣ㄥ湴鍧� headers: { Authorization: "Bearer " + getToken(), }, @@ -115,15 +115,9 @@ handleBeforeUpload(file) { // 鏍℃鏂囦欢绫诲瀷 if (this.fileType) { - let fileExtension = ""; - if (file.name.lastIndexOf(".") > -1) { - fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1); - } - const isTypeOk = this.fileType.some((type) => { - if (file.type.indexOf(type) > -1) return true; - if (fileExtension && fileExtension.indexOf(type) > -1) return true; - return false; - }); + const fileName = file.name.split('.'); + const fileExt = fileName[fileName.length - 1]; + const isTypeOk = this.fileType.indexOf(fileExt) >= 0; if (!isTypeOk) { this.$modal.msgError(`鏂囦欢鏍煎紡涓嶆纭�, 璇蜂笂浼�${this.fileType.join("/")}鏍煎紡鏂囦欢!`); return false; @@ -147,7 +141,7 @@ }, // 涓婁紶澶辫触 handleUploadError(err) { - this.$modal.msgError("涓婁紶鍥剧墖澶辫触锛岃閲嶈瘯"); + this.$modal.msgError("涓婁紶鏂囦欢澶辫触锛岃閲嶈瘯"); this.$modal.closeLoading() }, // 涓婁紶鎴愬姛鍥炶皟 -- Gitblit v1.9.3