Procházet zdrojové kódy

fix-文件上传类型限制

LAPTOP-U5GOA5HA\zz před 1 rokem
rodič
revize
72c8728a0b

+ 25 - 8
src/components/FileUpload/index.vue

@@ -5,6 +5,7 @@
       :list-type="type == 'image' ? 'picture-card' : 'picture'"
       :show-upload-list="false"
       :headers="headers"
+      accept=".image/jpeg,.image/png,.image/jpg"
       :before-upload="beforeUpload"
       :disabled="disabled"
       @change="handleChange"
@@ -52,10 +53,10 @@ export default {
     title: {
       type: String,
     },
-    disabled:{
-      type:Boolean,
-      default: false
-    }
+    disabled: {
+      type: Boolean,
+      default: false,
+    },
   },
   components: {},
   // watch: {
@@ -100,11 +101,27 @@ export default {
     },
     beforeUpload(file) {
       // 文件类型(file.type)、大小限制(file.size)
-      const isLt2M = file.size / 1024 / 1024 < 20
-      if (!isLt2M) {
-        this.$message.error('图片大小限制 20MB!')
+      const isLt2M = file.size / 1024 / 1024 < 100
+      if (this.type == 'image') {
+        if (!isLt2M) {
+          return this.$message.error('图片大小限制 100M!')
+        }
+        let isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg'
+        if (!isJpgOrPng) {
+          this.$message.error('格式错误,只能上传jpg、jpeg、png')
+          return false
+        }
+      }else if(this.type == 'file'){
+        if (!isLt2M) {
+          return this.$message.error('文件大小限制 100M!')
+        }
+        let isJpgOrPng = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || file.type === 'application/msword' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'||file.type==='application/vnd.ms-excel'||file.type==='application/vnd.ms-powerpoint'||file.type==='application/pdf'
+        if (!isJpgOrPng) {
+          this.$message.error('格式错误,只能上传docx、doc、xls、pdf、ppt')
+          return false
+        }
       }
-      return isLt2M
+      return true
     },
   },
 }

+ 1 - 0
src/views/system/user/modules/CreateForm.vue

@@ -178,6 +178,7 @@
           module="car"
           @UpdateImg="UpdateImgs"
         ></file-upload>
+        
       </a-form-model-item>
       <!-- <a-image :width="200" v-if="formTitle == '用户详情'" :src="photoUrl" /> -->
       <el-image

+ 2 - 2
src/views/user/Login.vue

@@ -121,8 +121,8 @@ export default {
       this.$refs.form.validate((valid) => {
         if (valid) {
           if (this.form.rememberMe) {
-            storage.set(LOGIN_USERNAME, this.loginPwd(this.form.username))
-            storage.set(LOGIN_PASSWORD, this.loginPwd(this.form.password))
+            storage.set(LOGIN_USERNAME,this.form.username)
+            storage.set(LOGIN_PASSWORD, this.form.password)
             storage.set(LOGIN_REMEMBERME, this.form.rememberMe)
           } else {
             storage.remove(LOGIN_USERNAME)

+ 1 - 1
vue.config.js

@@ -111,7 +111,7 @@ const vueConfig = {
       [process.env.VUE_APP_BASE_API]: {
         // target: `https://ruoyi.setworld.net`,
         // target: `http://113.249.153.164:7618/api`,
-        target:`http://172.20.16.92:8080/`,
+        target:`http://172.20.16.92:8081/`,
         changeOrigin: true,
         pathRewrite: {
           ['^' + process.env.VUE_APP_BASE_API]: ''