Commit a0c8fa2c authored by Cai Wei's avatar Cai Wei

feat(*): 权限变更监测去除login监听

parent 5c8e9ffa
...@@ -9,7 +9,7 @@ import "element-plus/dist/index.css"; ...@@ -9,7 +9,7 @@ import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue"; import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import { createPinia } from "pinia"; import { createPinia } from "pinia";
import moment from 'moment'; import moment from 'moment';
import { startPermissionCheck } from '@/utils/permissionChecker'; import { startPermissionCheck, stopPermissionCheck } from '@/utils/permissionChecker';
const app = createApp(App); const app = createApp(App);
...@@ -23,7 +23,23 @@ app ...@@ -23,7 +23,23 @@ app
.use(createPinia()) .use(createPinia())
.mount("#app"); .mount("#app");
// 启动权限轮询检查,每5秒检查一次 // 监听路由变化,在登录页停止权限轮询,在其他页面启动权限轮询
router.beforeEach((to, from, next) => {
if (to.path === '/login') {
stopPermissionCheck();
}
next();
});
router.afterEach((to) => {
if (to.path !== '/login') {
startPermissionCheck(5000);
}
});
// 初始启动权限轮询检查
router.isReady().then(() => { router.isReady().then(() => {
startPermissionCheck(5000); if (router.currentRoute.value.path !== '/login') {
startPermissionCheck(5000);
}
}); });
...@@ -7,9 +7,9 @@ let previousPermissionData = null; ...@@ -7,9 +7,9 @@ let previousPermissionData = null;
/** /**
* 开始权限轮询检查 * 开始权限轮询检查
* @param {Number} interval - 轮询间隔,默认5000ms * @param {Number} interval - 轮询间隔,默认10000ms
*/ */
export function startPermissionCheck(interval = 10000) { export function startPermissionCheck(interval = 5000) {
// 如果已经存在轮询,先清除 // 如果已经存在轮询,先清除
if (permissionInterval) { if (permissionInterval) {
clearInterval(permissionInterval); clearInterval(permissionInterval);
......
...@@ -1086,7 +1086,6 @@ export default { ...@@ -1086,7 +1086,6 @@ export default {
path: this.redirect || "/", path: this.redirect || "/",
query: this.otherQuery, query: this.otherQuery,
}); });
startPermissionCheck();
}) })
.catch((e) => { .catch((e) => {
console.log("error fetch verify code!!" + e); console.log("error fetch verify code!!" + e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment