田源
2023-09-18 da6cc144cc4d60805e4693e4adc5ebdf78b5b37d
Source/UBCS-WEB/src/permission.js
@@ -13,48 +13,60 @@
router.beforeEach((to, from, next) => {
  const meta = to.meta || {};
  const isMenu = meta.menu === undefined ? to.query.menu : meta.menu;
  const updataid=JSON.parse(localStorage.getItem("updataid"))
  store.commit('SET_IS_MENU', isMenu === undefined);
  if (getToken()) {
    if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页
      next({path: lockPage})
    } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
      next({path: '/'})
    } else {
      //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
      if (store.getters.token.length === 0) {
        store.dispatch('FedLogOut').then(() => {
          next({path: '/login'})
        })
    //拿到本地存储的密码策略修改值
      if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页
        next({path: lockPage})
      } else if (to.path === '/login' && updataid.strategyUpdateStatus !=0) {//如果登录成功访问登录页跳转到主页
        //这里再加上判断 如果密码策略修改后没有改密码的情况下刷新页面不会进入首页
        next({path: '/'})
      } else {
        const value = to.query.src || to.fullPath;
        const label = to.query.name || to.name;
        const meta = to.meta || router.$avueRouter.meta || {};
        const i18n = to.query.i18n;
        if (to.query.target) {
          window.open(value)
        } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
          store.commit('ADD_TAG', {
            label: label,
            value: value,
            params: to.params,
            query: to.query,
            meta: (() => {
              if (!i18n) {
                return meta
              }
              return {
                i18n: i18n
              }
            })(),
            group: router.$avueRouter.group || []
          });
        //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
        if (store.getters.token.length === 0 ) {
          store.dispatch('FedLogOut').then(() => {
            next({path: '/login'})
          })
        } else {
          let query=JSON.parse(JSON.stringify(to.query));
         for(var q in to.query) {
           if (to.query[q].indexOf('@name=') != -1) {
             query[q] = to.query[q].split('@name=')[0]
             query['name'] = to.query[q].split('@name=')[1]
           }
         }
          const value = query.src || to.fullPath|| to.path ;
          const label = query.name || to.name;
          const meta = to.meta || router.$avueRouter.meta || {};
          const i18n = to.query.i18n;
          if (to.query.target) {
            window.open(value)
          } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
            store.commit('ADD_TAG', {
              label: label,
              value: value,
              params: to.params,
              query: to.query,
              meta: (() => {
                if (!i18n) {
                  return meta
                }
                return {
                  i18n: i18n
                }
              })(),
              group: router.$avueRouter.group || []
            });
          }
          next()
        }
        next()
      }
    }
  } else {
    //判断是否需要认证,没有登录访问去登录页
    if (meta.isAuth === false) {
    if (meta.isAuth === false ) {
      next()
    } else {
      next('/login')