From 3835cf1ca8d5ac8475052d3876ebeb4a2c4160f1 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Mon, 22 Jan 2024 14:22:02 +0800
Subject: [PATCH] 根据角色,动态切换首页,及首页变更的一系列相关调整
---
src/permission.js | 75 ++++++++++++++++++++++++-------------
1 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/src/permission.js b/src/permission.js
index 2f88c34..172e2b3 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -1,66 +1,89 @@
+/*
+ * @Author: shuishen 1109946754@qq.com
+ * @Date: 2023-12-14 17:10:00
+ * @LastEditors: shuishen 1109946754@qq.com
+ * @LastEditTime: 2024-01-22 13:30:53
+ * @FilePath: \jczz_web\src\permission.js
+ * @Description:
+ *
+ * Copyright (c) 2024 by shuishen, All Rights Reserved.
+ */
/**
* 全站权限配置
*
*/
-import router from './router/router'
-import store from './store'
-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});
+import router from "./router/router";
+import store from "./store";
+import { validatenull } from "@/util/validate";
+import { getToken } from "@/util/auth";
+import NProgress from "nprogress"; // progress bar
+import "nprogress/nprogress.css"; // progress bar style
+import { getStore } from "@/util/store";
+
+NProgress.configure({ showSpinner: false });
const lockPage = store.getters.website.lockPage; //锁屏页
router.beforeEach((to, from, next) => {
const meta = to.meta || {};
const isMenu = meta.menu === undefined ? to.query.menu : meta.menu;
- store.commit('SET_IS_MENU', isMenu === undefined);
+ 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: '/'})
+ 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'})
- })
+ store.dispatch("FedLogOut").then(() => {
+ next({ path: "/login" });
+ });
} 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', {
+ 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 meta;
}
return {
- i18n: i18n
- }
+ i18n: i18n,
+ };
})(),
- group: router.$avueRouter.group || []
+ group: router.$avueRouter.group || [],
});
}
- next()
+ if (to.path === "/welindex") {
+ next(store.getters.homeFirstPage);
+ return;
+ }
+ next();
}
}
} else {
//判断是否需要认证,没有登录访问去登录页
if (meta.isAuth === false) {
- next()
+ next();
} else {
- next('/login')
+ next("/login");
}
}
-})
+});
router.afterEach(() => {
NProgress.done();
--
Gitblit v1.9.3