上饶市警务平台后台管理前端
zhongrj
2023-01-12 a855bc6ae27cec13077bae5a137c93b6c4557f30
首页携带token直接访问设置
4 files modified
35 ■■■■■ changed files
src/main.js 18 ●●●●● patch | view | raw | blame | history
src/permission.js 8 ●●●● patch | view | raw | blame | history
src/util/store.js 1 ●●●● patch | view | raw | blame | history
src/views/security/security.vue 8 ●●●●● patch | view | raw | blame | history
src/main.js
@@ -25,6 +25,24 @@
import crudCommon from '@/mixins/crud';
// 业务组件
import tenantPackage from './views/system/tenantpackage';
import Cookies from 'js-cookie'
// 携带token跳转页面设置
const tokenLength = window.location.href.indexOf('=');
if(tokenLength>0){
  //取“=”之后的token
  let z = window.location.href.substring(tokenLength + 1)
  // 把token存进B系统
  let obj = {
    dataType: typeof (z),
    content: z,
    datetime: new Date().getTime()
  }
  window.localStorage.setItem('saber-token', JSON.stringify(obj));
  Cookies.set('saber-access-token', z)
}
// 注册全局crud驱动
window.$crudCommon = crudCommon;
src/permission.js
@@ -11,6 +11,10 @@
NProgress.configure({showSpinner: false});
const lockPage = store.getters.website.lockPage; //锁屏页
router.beforeEach((to, from, next) => {
  var tag = false;
  if (to.fullPath.indexOf("token") > 0) {
    tag = true;
  }
  const meta = to.meta || {};
  const isMenu = meta.menu === undefined ? to.query.menu : meta.menu;
  store.commit('SET_IS_MENU', isMenu === undefined);
@@ -21,7 +25,7 @@
      next({path: '/'})
    } else {
      //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
      if (store.getters.token.length === 0) {
      if (store.getters.token.length === 0 && tag==false) {
        store.dispatch('FedLogOut').then(() => {
          next({path: '/login'})
        })
@@ -32,7 +36,7 @@
        const i18n = to.query.i18n;
        if (to.query.target) {
          window.open(value)
        } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
        } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label) && tag==false) {
          store.commit('ADD_TAG', {
            label: label,
            value: value,
src/util/store.js
@@ -55,6 +55,7 @@
    } else if (obj.dataType == 'object') {
        content = obj.content;
    }
    console.log(content,9999)
    return content;
}
/**
src/views/security/security.vue
@@ -222,6 +222,14 @@
      return ids.join(",");
    }
  },
  created(){
    const tokenLength = window.location.href.indexOf('=');
    if(tokenLength>0){
      //取“=”之后的token
      let z = window.location.href.substring(tokenLength + 1)
      this.$store.commit('SET_TOKEN', z);
    }
  },
  methods: {
    rowSave(row, done, loading) {
      add(row).then(() => {