duanxiaoduan 1 year ago
parent
commit
7a90b48024
5 changed files with 25 additions and 13 deletions
  1. 0 0
      dist/index.html
  2. 2 2
      src/api/user.js
  3. 1 1
      src/layout/components/Navbar.vue
  4. 8 4
      src/permission.js
  5. 14 6
      src/store/modules/user.js

File diff suppressed because it is too large
+ 0 - 0
dist/index.html


+ 2 - 2
src/api/user.js

@@ -19,7 +19,7 @@ export function getInfo() { // token
 
 export function logout() {
   return request({
-    url: '/authdata/logout',
-    method: 'post'
+    url: '/api/v1/logout',
+    method: 'get'
   })
 }

+ 1 - 1
src/layout/components/Navbar.vue

@@ -104,7 +104,7 @@ export default {
     async logout() {
       await this.$store.dispatch('user/logout')
       this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
-        this.$router.push(`/login`) // 跳转到主页
+        console.log("注销了")
       })
       // this.$router.push(`/login?redirect=${this.$route.fullPath}`)   //跳转到登陆前页面
     },

+ 8 - 4
src/permission.js

@@ -19,7 +19,7 @@ router.beforeEach(async(to, from, next) => {
 
   // determine whether the user has logged in
   const hasToken = getToken()
-  
+
     console.log('hasToken==>',hasToken)
   if (hasToken) {
     if (to.path === '/login') {
@@ -41,7 +41,7 @@ router.beforeEach(async(to, from, next) => {
 
           // generate accessible routes map based on roles
           const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
-
+          console.log(accessRoutes,'accessRoutes')
           // dynamically add accessible routes
           router.addRoutes(accessRoutes)
 
@@ -74,12 +74,16 @@ router.beforeEach(async(to, from, next) => {
       NProgress.done()
        // next({ path: '/login' })
       // 构建要跳转的URL
-       // const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri=http://tmrwatch.cn:8082/api/v1/oauth2/token";
+       const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri=http://tmrwatch.cn:8082/api/v1/oauth2/token";
       // 使用 $router.push 进行页面跳转
       // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
-      // window.open(externalURL, "_self");
+      window.open(externalURL, "_self");
     }
   }
+
+  // 使用 $router.push 进行页面跳转
+  // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+  // window.open(url1, "_self");
 })
 
 router.afterEach(() => {

+ 14 - 6
src/store/modules/user.js

@@ -105,19 +105,23 @@ const actions = {
         const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
         if (codeMatch) {
           // 如果匹配成功,将code的值存储在组件的data中
-          this.code = codeMatch[1];
+          var code = codeMatch[1];
             //TODO 保存token
             // 去除后面的#/login
-          if ( this.code &&  this.code.includes("#/login")) {
-            this.code =  this.code.replace("#/login", "");
+          if ( code &&  code.includes("#/login")) {
+            code =  code.replace("#/login", "");
           }
-          console.log('token',this.code)
+          console.log('token',code)
            //base64解密this.cose
-            console.log('解密token',atob(this.code))
-            let token = atob(this.code)
+            console.log('解密token',atob(code))
+            let token = atob(code)
             commit('SET_TOKEN', token)
             setToken(token)
             resolve()
+            let url = window.location.href;
+            // 使用split方法将URL拆分为数组
+            let jmpurl = url.split('?')[0]+'#/dashboard'
+            window.open(jmpurl, "_self");
           }
         // =============================
         // const { data, msg } = response
@@ -243,6 +247,10 @@ const actions = {
         removeToken()
         resetRouter()
         resolve()
+        const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri=http://tmrwatch.cn:8082/api/v1/oauth2/token";
+        // 使用 $router.push 进行页面跳转
+        // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+        window.open(externalURL, "_self");
         location.reload()
       }).catch(error => {
         reject(error)

Some files were not shown because too many files changed in this diff