上饶市警务平台后台管理前端
zhongrj
2023-01-12 a855bc6ae27cec13077bae5a137c93b6c4557f30
首页携带token直接访问设置
4 files modified
49 ■■■■ changed files
src/main.js 20 ●●●●● patch | view | raw | blame | history
src/permission.js 20 ●●●●● 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
@@ -7,7 +7,7 @@
import './error'; // 日志
import './cache';//页面缓存
import store from './store';
import {loadStyle} from './util/util'
import { loadStyle } from './util/util'
import * as urls from '@/config/env';
import Element from 'element-ui';
import {
@@ -26,6 +26,24 @@
// 业务组件
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;
// 加载Vue拓展
src/permission.js
@@ -4,26 +4,30 @@
 */
import router from './router/router'
import store from './store'
import {validatenull} from '@/util/validate'
import {getToken} from '@/util/auth'
import { validatenull } from '@/util/validate'
import { getToken } from '@/util/auth'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
NProgress.configure({showSpinner: false});
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);
  if (getToken()) {
    if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页
      next({path: lockPage})
      next({ path: lockPage })
    } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
      next({path: '/'})
      next({ path: '/' })
    } else {
      //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
      if (store.getters.token.length === 0) {
      if (store.getters.token.length === 0 && tag==false) {
        store.dispatch('FedLogOut').then(() => {
          next({path: '/login'})
          next({ path: '/login' })
        })
      } else {
        const value = to.query.src || to.fullPath;
@@ -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(() => {