duanxiaoduan 1 жил өмнө
parent
commit
39cd9dcc51
2 өөрчлөгдсөн 73 нэмэгдсэн , 81 устгасан
  1. 12 16
      src/permission.js
  2. 61 65
      src/store/modules/user.js

+ 12 - 16
src/permission.js

@@ -74,22 +74,18 @@ router.beforeEach(async(to, from, next) => {
 
       next({ path: '/login' })
       NProgress.done()
-       // next({ path: '/login' })
-      // 构建要跳转的URL
-      // const url = window.location.protocol + "//"+window.location.host + '/'
-      // const url = 'http://192.168.61.41/'
-      // const url = 'http://tmrwatch.cn:8082/'
-      var url = process.env.VUE_APP_BASE_API
-      //获取当前url
-      
-      if(url.indexOf('/')==0 && url.length==1){
-        url= window.location.protocol + "//"+window.location.host+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="+url+'api/v1/oauth2/token';
-      // 使用 $router.push 进行页面跳转
-      // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
-      window.open(externalURL, "_self");
+      // // 单点登录
+      // // 构建要跳转的URL
+      // var url = process.env.VUE_APP_BASE_API
+      // console.log(url,'url')
+      // //获取当前url
+      // if(url.indexOf('/')==0 && url.length==1){
+      //   url= window.location.protocol + "//"+window.location.host+url
+      // }
+      // const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri="+url+'api/v1/oauth2/token';
+      // // 使用 $router.push 进行页面跳转
+      // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+      // window.open(externalURL, "_self");
     }
   }
 

+ 61 - 65
src/store/modules/user.js

@@ -99,47 +99,46 @@ const actions = {
     const { username, password } = userInfo
     return new Promise((resolve, reject) => {
       login({ username: username.trim(), password: password }).then(response => {
-        // =============================
-        const fullURL = window.location.href;
-        // 使用正则表达式提取code参数的值
-        const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
-        console.log('codeMatch===>',codeMatch)
-        if (codeMatch) {
-          // 如果匹配成功,将code的值存储在组件的data中
-          var code = codeMatch[1];
-            //TODO 保存token
-            // 去除后面的#/login
-          if ( code &&  code.includes("#/login")) {
-            code =  code.replace("#/login", "");
-          }
-          console.log('token',code)
-           //base64解密this.cose
-            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
-        // if (msg !== 'ok') {
-        //   Message({
-        //     message: data,
-        //     type: 'error',
-        //     duration: 5 * 1000
-        //   })
-        //   reject(data)
-        // }
-        // commit('SET_TOKEN', data.token)
-        // if (Cookies == null) {
-        //   console.log(1)
+        // 单点登录=============================
+        // const fullURL = window.location.href;
+        // // 使用正则表达式提取code参数的值
+        // const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
+        // console.log('codeMatch===>',codeMatch)
+        // if (codeMatch) {
+        //   // 如果匹配成功,将code的值存储在组件的data中
+        //   var code = codeMatch[1];
+        //     //TODO 保存token
+        //     // 去除后面的#/login
+        //   if ( code &&  code.includes("#/login")) {
+        //     code =  code.replace("#/login", "");
+        //   }
+        //  //base64解密this.cose
+        //   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");
         // }
-        // setToken(data.token)
-        // resolve()
+        // =============================
+        const { data, msg } = response
+        if (msg !== 'ok') {
+          Message({
+            message: data,
+            type: 'error',
+            duration: 5 * 1000
+          })
+          reject(data)
+        }
+        commit('SET_TOKEN', data.token)
+        if (Cookies == null) {
+          console.log(1)
+        }
+        setToken(data.token)
+        resolve()
       }).catch(error => {
         reject(error)
       })
@@ -173,19 +172,17 @@ const actions = {
             removeToken()
             resetRouter()
             resolve()
-            // const url = process.env.VUE_APP_BASE_API
-            // const url = 'http://192.168.61.41/'
-            // const url = 'http://tmrwatch.cn:8082/'
-            var url = process.env.VUE_APP_BASE_API
-            //获取当前url
+            // 单点登录
+            // var url = process.env.VUE_APP_BASE_API
+            // //获取当前url
 
-            if(url.indexOf('/')==0 && url.length==1){
-              url= window.location.protocol + "//"+window.location.host+url
-            }
-            const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url="+url+ '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
-            // 使用 $router.push 进行页面跳转
-            // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
-            window.open(externalURL, "_self");
+            // if(url.indexOf('/')==0 && url.length==1){
+            //   url= window.location.protocol + "//"+window.location.host+url
+            // }
+            // const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url="+url+ '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
+            // // 使用 $router.push 进行页面跳转
+            // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+            // window.open(externalURL, "_self");
           },2000)
         }
 
@@ -274,19 +271,18 @@ const actions = {
         removeToken()
         resetRouter()
         resolve()
-        // const url = process.env.VUE_APP_BASE_API
-        // const url = 'http://192.168.61.41/'
-        // const url = 'http://tmrwatch.cn:8082/'
-        var url = process.env.VUE_APP_BASE_API
-        //获取当前url
-        
-        if(url.indexOf('/')==0 && url.length==1){
-          url= window.location.protocol + "//"+window.location.host+url
-        }
-        const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url=" + url + '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
-        // 使用 $router.push 进行页面跳转
-        // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
-        window.open(externalURL, "_self");
+        // 单点登录
+        // var url = process.env.VUE_APP_BASE_API
+        // console.log(url,'url')
+        // //获取当前url
+
+        // if(url.indexOf('/')==0 && url.length==1){
+        //   url= window.location.protocol + "//"+window.location.host+url
+        // }
+        // const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url=" + url + '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
+        // // 使用 $router.push 进行页面跳转
+        // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+        // window.open(externalURL, "_self");
         // location.reload()
       }).catch(error => {
         reject(error)