zcy 4 anos atrás
pai
commit
a016c1823e
3 arquivos alterados com 23 adições e 27 exclusões
  1. 0 1
      src/api/user.js
  2. 19 23
      src/utils/request.js
  3. 4 3
      src/views/login/index.vue

+ 0 - 1
src/api/user.js

@@ -2,7 +2,6 @@ import request from '@/utils/request'
 export function captchaImage(params) {
   return request({
     url: '/captchaImage',
-    responseType: 'blob',
     method: 'get',
     params
   })

+ 19 - 23
src/utils/request.js

@@ -43,34 +43,30 @@ service.interceptors.response.use(
    * You can also judge the status by HTTP Status Code
    */
   response => {
-    if (response.headers['content-type'] === 'image/jpeg') {
-      return response.data
+    const res = response.data
+    // if the custom code is not 20000, it is judged as an error.
+    if (res.code === 200) {
+      return res
     } else {
-      const res = response.data
-      // if the custom code is not 20000, it is judged as an error.
-      if (res.code === 200) {
-        return res
-      } else {
+      Message({
+        message: res.msg || 'Error',
+        type: 'error',
+        duration: 5 * 1000
+      })
+
+      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+      if (res.code === 401) {
+        // to re-login
         Message({
-          message: res.msg || 'Error',
+          message: '请重新登录',
           type: 'error',
-          duration: 5 * 1000
+          duration: 3 * 1000
+        })
+        store.dispatch('user/resetToken').then(() => {
+          location.reload()
         })
-
-        // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
-        if (res.code === 401) {
-          // to re-login
-          Message({
-            message: '请重新登录',
-            type: 'error',
-            duration: 3 * 1000
-          })
-          store.dispatch('user/resetToken').then(() => {
-            location.reload()
-          })
-        }
-        return Promise.reject(new Error(res.msg || 'Error'))
       }
+      return Promise.reject(new Error(res.msg || 'Error'))
     }
   },
   error => {

+ 4 - 3
src/views/login/index.vue

@@ -55,14 +55,14 @@
             <el-input
               ref="code"
               v-model="loginForm.code"
-              style="width: 70%;vertical-align:middle"
+              style="width: 60%;vertical-align:middle"
               placeholder="请输入验证码"
               tabindex="2"
               auto-complete="on"
               size="mini"
               @keyup.enter.native="handleLogin"
             />
-            <img :src="imgSrc" alt="" style="margin-left:5%;width: 25%;height: 40px;vertical-align:middle;" @click="captchaImage">
+            <img :src="imgSrc" alt="" style="margin-left:5%;width: 35%;height: 40px;vertical-align:middle;" @click="captchaImage">
           </el-form-item>
 
           <el-form-item>
@@ -139,7 +139,8 @@ export default {
   methods: {
     captchaImage() {
       captchaImage({ type: 'math' }).then(res => {
-        const url = window.URL.createObjectURL(res)
+        debugger
+        const url = 'data:image/jpg;base64,' + res.img
         this.imgSrc = url
       })
     },