From 12cf68ea971e5c39e884474734ef51cbc52bec8d Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期六, 23 三月 2024 18:05:29 +0800
Subject: [PATCH] 登录接口重新联调

---
 src/common/untils/request.js    |   36 ++++++++++++++++++++++++------------
 src/api/admin/login.js          |    2 +-
 src/views/other/login/index.vue |   12 ++++++++----
 3 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/api/admin/login.js b/src/api/admin/login.js
index 3907183..6af264b 100644
--- a/src/api/admin/login.js
+++ b/src/api/admin/login.js
@@ -11,7 +11,7 @@
 // 鐧诲綍
 export function login(data) {
   return request({
-    url: "/api/base/login",
+    url: "/api/base/outsideUser/login",
     method: "post",
     data
   })
diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 4541c17..92567d0 100644
--- a/src/common/untils/request.js
+++ b/src/common/untils/request.js
@@ -28,7 +28,7 @@
   const loginPathMap = {
     prod: `//${window.location.hostname}:9080`,
     test: `//192.168.20.119:9080`,
-    dev: `//192.168.8.107:8080`
+    dev: `//localhost:8081`
   }
   return loginPathMap[environmentType()]
 }
@@ -41,8 +41,8 @@
     // // if (token != undefined) {
     // //   config.headers.Authorization = "Bearer " + token;
     // // }
-    // let token = localStorage.getItem("token")
-    let token = document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")
+    let token = localStorage.getItem("token")
+    // let token = document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")
     if (isDev) {
       token = token || DEV_TOKEN
     }
@@ -89,20 +89,32 @@
       // if(window.location.pathname && window.location.pathname !== '/login'){
       //   window.location = window.location.origin+'/login'
       // }
+    } else if ([3003].includes(res.data.code)) {
+      // 姝ょ姸鎬佷笅涓嶅脊鍑篹rror message
+      console.log("3003")
+      return Promise.resolve(res.data)
     } else {
+      if (!res.config.loadingFlag) {
+        Message({
+          // message: res.data.msg==res.data.data?res.data.data:res.data.msg+','+res.data.data,
+          message: res.data.msg,
+          type: "error",
+          duration: 5 * 1000
+        })
+      }
       return res.data ? res.data : {}
     }
   },
   (error) => {
-    // if (error.response.status === 401) {
-    //   if (isDev) {
-    //     alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
-    //     window.location = getApsPage() + "/login"
-    //   } else {
-    //     //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-    //     window.location = getApsPage() + "/login"
-    //   }
-    // }
+    if (error.response.status === 401) {
+      if (isDev) {
+        alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
+        window.location = getApsPage() + "/login"
+      } else {
+        //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
+        window.location = getApsPage() + "/login"
+      }
+    }
     let { message } = error
     if (message === "Network Error") {
       message = "鍚庣鎺ュ彛杩炴帴寮傚父"
diff --git a/src/views/other/login/index.vue b/src/views/other/login/index.vue
index 0d8cfde..df4544e 100644
--- a/src/views/other/login/index.vue
+++ b/src/views/other/login/index.vue
@@ -145,28 +145,32 @@
      */
     // 鎻愪氦鐧诲綍淇℃伅
     submit() {
-      this.$refs.loginForm.validate((valid) => {
+      this.$refs.loginForm.validate(async (valid) => {
         if (valid) {
           // 鐧诲綍
-          login({
+          await login({
             username: this.formLogin.username,
             password: this.formLogin.password,
             captcha: this.formLogin.code,
             captchaId: this.captchaId
           }).then((res) => {
+            console.log(res, "dddd")
             if (res.code == 200) {
+              console.log(res, "8888")
               this.$message.success("鐧诲綍鎴愬姛")
-              this.$router.push({ path: "/orderManageModule/orderManage" })
               localStorage.setItem("token", res.data.token)
               localStorage.setItem("username", res.data.user.username)
               localStorage.setItem("uuid", res.data.user.id)
+              setTimeout(() => {
+                this.$router.push({ path: "/orderManageModule/orderManage" })
+              }, 2000)
             } else {
               this.$message.warning(res.msg)
               if (res.msg == "楠岃瘉鐮侀敊璇�") {
                 this.getCaptchaData()
               }
+              return
             }
-            console.log(res, "dddd")
           })
         } else {
           // 鐧诲綍琛ㄥ崟鏍¢獙澶辫触

--
Gitblit v1.8.0