作者 RuoYi

修复文件上传组件格式验证问题(I5V32H)

@@ -73,7 +73,7 @@ export default { @@ -73,7 +73,7 @@ export default {
73 number: 0, 73 number: 0,
74 uploadList: [], 74 uploadList: [],
75 baseUrl: process.env.VUE_APP_BASE_API, 75 baseUrl: process.env.VUE_APP_BASE_API,
76 - uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址 76 + uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
77 headers: { 77 headers: {
78 Authorization: "Bearer " + getToken(), 78 Authorization: "Bearer " + getToken(),
79 }, 79 },
@@ -115,15 +115,9 @@ export default { @@ -115,15 +115,9 @@ export default {
115 handleBeforeUpload(file) { 115 handleBeforeUpload(file) {
116 // 校检文件类型 116 // 校检文件类型
117 if (this.fileType) { 117 if (this.fileType) {
118 - let fileExtension = "";  
119 - if (file.name.lastIndexOf(".") > -1) {  
120 - fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);  
121 - }  
122 - const isTypeOk = this.fileType.some((type) => {  
123 - if (file.type.indexOf(type) > -1) return true;  
124 - if (fileExtension && fileExtension.indexOf(type) > -1) return true;  
125 - return false;  
126 - }); 118 + const fileName = file.name.split('.');
  119 + const fileExt = fileName[fileName.length - 1];
  120 + const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
127 if (!isTypeOk) { 121 if (!isTypeOk) {
128 this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); 122 this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
129 return false; 123 return false;
@@ -147,7 +141,7 @@ export default { @@ -147,7 +141,7 @@ export default {
147 }, 141 },
148 // 上传失败 142 // 上传失败
149 handleUploadError(err) { 143 handleUploadError(err) {
150 - this.$modal.msgError("上传图片失败,请重试"); 144 + this.$modal.msgError("上传文件失败,请重试");
151 this.$modal.closeLoading() 145 this.$modal.closeLoading()
152 }, 146 },
153 // 上传成功回调 147 // 上传成功回调