Explorar el Código

update第三方跳转ticket

huac hace 3 años
padre
commit
58b8f66657
Se han modificado 2 ficheros con 217 adiciones y 69 borrados
  1. 26 10
      src/components/main.vue
  2. 191 59
      src/config/routerBefore.js

+ 26 - 10
src/components/main.vue

@@ -1146,16 +1146,32 @@ export default {
                         // window.location.href = './index.html';
                         // /*
                         // ajax
-                        this.store.dispatch('loginOut').then(function (res) {
-                            instance.confirmButtonText = '确定';
-                            instance.confirmButtonLoading = false;
-                            done();
-                            window.location.href = './index.html';
-                        }).catch(function () {
-                            instance.confirmButtonText = '确定';
-                            instance.confirmButtonLoading = false;
-                            done();
-                        });
+                        if (getCookie('ticket')) {
+                            let res = this.axios.get('pass/logout', {
+                                params: {
+                                    authorization: getCookie('accessToken')
+                                }
+                                });
+                                res.then(function (res) {
+                                    console.log(111)
+                                    instance.confirmButtonText = "确定";
+                                    instance.confirmButtonLoading = false;
+                                    done();
+                                    window.location.href = "./index.html";
+                                    })
+                            }
+                            else {
+                            this.store.dispatch('loginOut').then(function (res) {
+                                instance.confirmButtonText = '确定';
+                                instance.confirmButtonLoading = false;
+                                done();
+                                window.location.href = './index.html';
+                            }).catch(function () {
+                                instance.confirmButtonText = '确定';
+                                instance.confirmButtonLoading = false;
+                                done();
+                            });                                
+                            }
                         // */
                     } else {
                         done();

+ 191 - 59
src/config/routerBefore.js

@@ -8,8 +8,15 @@ import {
   setCookie,
   dgTree
 } from '@/utils/util.js';
+import axios from '@/config/axios.js';
+import {
+  stDev,
+  stProd,
+  proPath
+} from '@/config/config.js';
+
 // 免登录白名单
-const whiteList = ['/', '/login'];
+const whiteList = ['/', '/login', '/page404', '/dingtalkTaskMobileEnd', '/dingtalkWorkFlowMobileEnd'];
 
 /**
  * 当前路由取标题
@@ -86,14 +93,15 @@ const breadcrumbFn = function (to, menu) {
   });
   return data;
 }
-
 //  路由前置操作
 const routerBefore = function (router, constantRouterMap) {
   let flag = false
   router.beforeEach((to, from, next) => {
     //  面包屑
-    console.log('进入路由', to.name)
-
+    console.log('进入路由', to)
+    if (document.domain.indexOf('steerinfo.com') > -1) {
+      document.domain = 'steerinfo.com';
+    }
     store.commit('breadcrumb', breadcrumbFn(to, store.state.routes));
     //  标题
     if (to.meta && !to.meta.title) {
@@ -101,80 +109,204 @@ const routerBefore = function (router, constantRouterMap) {
     } else {
       document.title = to.meta.title + ' ' + document.title.substr(document.title.indexOf('-'));
     }
-    //
-    if (getCookie('accessToken')) { // 判断是否有token
-      if (window.top.document.URL === window.document.URL && !window.top.localStorage.getItem('ownPrivilege')) {
-        store.dispatch('getOwnMenuUrl');
+    if (to.query.ticket) {
+      setCookie('ticket', to.query.ticket, '', '/');
+      let res = axios.get('pass/auth/ticket', {
+        params: {
+          ticket: to.query.ticket || '-5696372145848366561'
+        }
+      });
+        res.then(res => {
+            if (res.succeed) {
+              DoneCookie(to, from, next, res.data.accessToken, flag)
+            }
+        }).catch(err => {
+          console.log(err)
+          Message('登陆账户异常, 请联系管理员')
+        });
+    } else {
+      DoneCookie(to, from, next, to.query.accessToken, flag)
+    }
+  });
+}
+function DoneCookie (to, from, next, accessToken, flag) {
+  if (accessToken) {
+    if (to.query.menuLeave) {
+      setCookie('menuLeave', to.query.menuLeave, '', '/', '', '', true);
+    } else {
+      setCookie('menuLeave', '', '', '/', '', '', true);
+    }
+    setCookie('accessToken', accessToken, '', '/');
+    store.dispatch('getLoginInfo').then(res => { // 拉取info
+      if (res.code === '0') {
+        setCookie('userId', res.data.user.userId);
+        setCookie('loginId', res.data.user.userId); // 为配合bms取值添加
+        setCookie('loginName', res.data.user.userCode);
+        let info = JSON.parse(JSON.stringify(res.data.user));
+        for (let k in info) {
+          if (k === 'sysGroup' || k === 'sysCompanys' || k === 'sysRoles') {
+            delete info[k];
+          }
+        }
+        setCookie('userInfo', JSON.stringify(info));
+        // 判断用户集团公司情况跳转
+        let userInfo = res.data.user;
+        // 超级管理员
+        if (userInfo.userCode === 'admin') {
+          if (userInfo.sysCompanys) {
+            // 公司列表过多时cookie存放失败,存至localStorage
+            // setCookie('companys', JSON.stringify(userInfo.sysCompanys));
+            window.top.localStorage.setItem('sysGroup', JSON.stringify(userInfo.sysGroup));
+            window.top.localStorage.setItem('companys', JSON.stringify(userInfo.sysCompanys));
+            if (userInfo.hasOwnProperty('sysCompanys')) {
+              window.top.localStorage.setItem('companyId', userInfo.sysCompanys[0].id);
+            }
+          }
+          next({
+            path: '/default'
+          });
+          // 普通用户
+        } else {
+          if (userInfo.hasOwnProperty('sysGroup') && userInfo.sysGroup !== '' && userInfo.sysGroup !== null && JSON.stringify(userInfo.sysGroup) !== '{}' && JSON.stringify(userInfo.sysGroup) !== '[]') {
+            window.top.localStorage.setItem('sysGroup', JSON.stringify(userInfo.sysGroup));
+            if (userInfo.hasOwnProperty('sysCompanys')) {
+              window.top.localStorage.setItem('companys', JSON.stringify(userInfo.sysCompanys));
+              window.top.localStorage.setItem('companyId', userInfo.sysCompanys[0].id);
+              if (userInfo.sysCompanys.length > 1) {
+                // 跳转选择集团公司页面
+                next({
+                  path: '/selectCompany'
+                });
+              } else {
+                next({
+                  path: '/default'
+                });
+              }
+            } else {
+              this.$message.error('后台返回数据缺少company信息,请联系开发人员!');
+            }
+          } else {
+            this.$message.error('必须隶属一个集团!请先联系管理员添加集团信息!');
+          }
+        }
+      } else {
+        Message('登录已过期,请重新登录');
+        setCookie('accessToken', '', -1, '/');
+        setCookie('refreshToken', '', -1, '/');
+        setCookie('workDate', '', -1);
+        setCookie('appId', '', -1, '/');
+        setCookie('ticket', '', -1, '/');
+        setTimeout(() => {
+          window.top.location.href = store.getters.ctx;
+        }, 500)
       }
-      if (to.path === '/login') {
+    }).catch(err => {
+      console.log(err);
+      Message('登录已过期,请重新登录');
+      setCookie('accessToken', '', -1, '/');
+      setCookie('refreshToken', '', -1, '/');
+      setCookie('workDate', '', -1);
+      setCookie('appId', '', -1, '/');
+      setCookie('ticket', '', -1, '/');
+      window.top.location.href = store.getters.ctx;
+    });
+  } else if (getCookie('accessToken')) { // 判断是否有token
+    if (window.top.document.URL === window.document.URL && !window.top.localStorage.getItem('allPrivilege')) {
+      let userInfo = JSON.parse(getCookie('userInfo'));
+      setCookie('userId', userInfo.userId);
+      let companyId = window.top.localStorage.getItem('companyId');
+      let menuId = window.top.localStorage.getItem('activeMenu');
+      // 查询所有注释掉
+      // store.dispatch('getAllMenuUrl', { companyId: companyId });
+      // store.dispatch('getOwnMenuUrl', { userId: userId, menuId: menuId });
+      store.dispatch('getOwnMenuUrl', { companyId: companyId });
+    }
+    if (to.path === '/login' || to.path === '/') {
+      // 判断非本地模式登录页面不可访问
+      if (document.location.origin.indexOf('steerinfo.com') !== -1) {
         next({
-          path: '/'
+          path: '/page404'
         });
       } else {
-        if (window.top.document.URL === window.document.URL && store.state.userInfo === null) { // 判断当前用户是否已拉取完路由信息
-          // 前期无后台测试用
-          // next();
-          // /*
-          store.dispatch('getUserInfo').then(res => { // 拉取info
-            if (res.code === '0') {
-              const userInfo = res.data;
-              store.dispatch('generateRoutes', {
-                userInfo
-              }).then(() => { // 生成可访问的路由表
-                // router.addRoutes(store.state.routes) // 动态添加可访问路由表
-                if (flag) {
-                  next()
-                } else {
-                  next({
-                    ...to,
-                    replace: true
-                  })
-                  flag = true
-                }
-                // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
-                console.log('这是个什么东西', {
+        next({
+          path: '/'
+        });
+      }
+    } else {
+      if (window.top.document.URL === window.document.URL && store.state.userInfo === null) { // 判断当前用户是否已拉取完路由信息
+        store.dispatch('getUserInfo').then(res => { // 拉取info
+          if (res.code === '0') {
+            const userInfo = res.data;
+            let appId = getCookie('appId');
+            userInfo.appId = appId;
+            store.dispatch('generateRoutes', {
+              userInfo
+            }).then(() => { // 生成可访问的路由表
+              // router.addRoutes(store.state.routes) // 动态添加可访问路由表
+              if (flag) {
+                next()
+              } else {
+                next({
                   ...to,
                   replace: true
                 })
+                flag = true
+              }
+              // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
+              console.log('这是个什么东西', {
+                ...to,
+                replace: true
               })
-            } else {
-              Message('登录已过期,请重新登录');
-              // next('/login'); // 否则全部重定向到登录页
-              // window.location.href = '/views/index.html';
-              setCookie('accessToken', '', -1, '/');
-              setCookie('refreshToken', '', -1, '/');
-              setCookie('workDate', '', -1);
-              window.top.location.href = store.getters.ctx;
-            }
-          }).catch(err => {
-            console.log(err);
+            })
+          } else {
             Message('登录已过期,请重新登录');
             // next('/login'); // 否则全部重定向到登录页
             // window.location.href = '/views/index.html';
             setCookie('accessToken', '', -1, '/');
             setCookie('refreshToken', '', -1, '/');
+            setCookie('appId', '', -1, '/');
             setCookie('workDate', '', -1);
+            setCookie('ticket', '', -1, '/');
             window.top.location.href = store.getters.ctx;
-          });
-          // */
-        } else {
-          next() // 当有用户权限的时候,说明所有可访问路由已生成 如访问没权限的全面会自动进入404页面
-        }
+          }
+        }).catch(err => {
+          console.log(err);
+          Message('登录已过期,请重新登录');
+          // next('/login'); // 否则全部重定向到登录页
+          // window.location.href = '/views/index.html';
+          setCookie('accessToken', '', -1, '/');
+          setCookie('refreshToken', '', -1, '/');
+          setCookie('appId', '', -1, '/');
+          setCookie('workDate', '', -1);
+          setCookie('ticket', '', -1, '/');
+          window.top.location.href = store.getters.ctx;
+        });
+      } else {
+        next() // 当有用户权限的时候,说明所有可访问路由已生成 如访问没权限的全面会自动进入404页面
       }
-    } else {
-      if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
-        next();
+    }
+  } else {
+    if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
+      // 判断非本地模式登录页面不可访问
+      if ((to.path === '/login' || to.path === '/') && document.location.origin.indexOf('steerinfo.com') !== -1) {
+        next({
+          path: '/page404'
+        });
       } else {
-        Message('未登录');
-        // next('/login'); // 否则全部重定向到登录页
-        // window.location.href = '/views/index.html';
-        setCookie('accessToken', '', -1, '/');
-        setCookie('refreshToken', '', -1, '/');
-        setCookie('workDate', '', -1);
-        window.top.location.href = store.getters.ctx;
+        next();
       }
+    } else {
+      Message('未登录');
+      // next('/login'); // 否则全部重定向到登录页
+      // window.location.href = '/views/index.html';
+      setCookie('accessToken', '', -1, '/');
+      setCookie('refreshToken', '', -1, '/');
+      setCookie('workDate', '', -1);
+      setCookie('appId', '', -1, '/');
+      setCookie('ticket', '', -1, '/');
+      window.top.location.href = store.getters.ctx;
     }
-  });
+  }
 }
 
 export default routerBefore;