Skip to content

Commit

Permalink
feat: 支持多标签页打开已经登录的系统后无需再登录
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Oct 6, 2023
1 parent be2de40 commit 21c3ab8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 89 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"rollup-plugin-visualizer": "^5.9.2",
"sass": "^1.68.0",
"sass": "^1.69.0",
"sass-loader": "^13.3.2",
"stylelint": "^15.10.3",
"stylelint-config-html": "^1.1.0",
Expand All @@ -157,7 +157,7 @@
"tailwindcss": "^3.3.3",
"terser": "^5.21.0",
"typescript": "^5.2.2",
"vite": "^4.4.10",
"vite": "^4.4.11",
"vite-plugin-cdn-import": "^0.3.5",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-mock": "2.9.6",
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions src/layout/components/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import {
nextTick,
onBeforeMount
} from "vue";
import {
useDark,
debounce,
useGlobal,
storageLocal,
storageSession
} from "@pureadmin/utils";
import { getConfig } from "@/config";
import { useRouter } from "vue-router";
import panel from "../panel/index.vue";
Expand All @@ -27,6 +20,7 @@ import { useAppStoreHook } from "@/store/modules/app";
import { toggleTheme } from "@pureadmin/theme/dist/browser-utils";
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
import { useDark, debounce, useGlobal, storageLocal } from "@pureadmin/utils";
import dayIcon from "@/assets/svg/day.svg?component";
import darkIcon from "@/assets/svg/dark.svg?component";
Expand Down Expand Up @@ -133,7 +127,6 @@ const multiTagsCacheChange = () => {
function onReset() {
removeToken();
storageLocal().clear();
storageSession().clear();
const { Grey, Weak, MultiTagsCache, EpThemeColor, Layout } = getConfig();
useAppStoreHook().setLayout(Layout);
setEpThemeColor(EpThemeColor);
Expand Down
32 changes: 19 additions & 13 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import "@/utils/sso";
import Cookies from "js-cookie";
import { getConfig } from "@/config";
import NProgress from "@/utils/progress";
import { transformI18n } from "@/plugins/i18n";
import { sessionKey, type DataInfo } from "@/utils/auth";
import { buildHierarchyTree } from "@/utils/tree";
import remainingRouter from "./modules/remaining";
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
import { usePermissionStoreHook } from "@/store/modules/permission";
import {
Router,
createRouter,
RouteRecordRaw,
RouteComponent
} from "vue-router";
import { isUrl, openLink, storageLocal, isAllEmpty } from "@pureadmin/utils";
import {
ascending,
getTopMenu,
Expand All @@ -22,10 +19,18 @@ import {
formatTwoStageRoutes,
formatFlatteningRoutes
} from "./utils";
import { buildHierarchyTree } from "@/utils/tree";
import { isUrl, openLink, storageSession, isAllEmpty } from "@pureadmin/utils";

import remainingRouter from "./modules/remaining";
import {
Router,
createRouter,
RouteRecordRaw,
RouteComponent
} from "vue-router";
import {
type DataInfo,
userKey,
removeToken,
multipleTabsKey
} from "@/utils/auth";

/** 自动导入全部静态路由,无需再手动引入!匹配 src/router/modules 目录(任何嵌套级别)中具有 .ts 扩展名的所有文件,除了 remaining.ts 文件
* 如何匹配所有文件请看:https://github.com/mrmlnc/fast-glob#basic-syntax
Expand Down Expand Up @@ -109,7 +114,7 @@ router.beforeEach((to: ToRouteType, _from, next) => {
handleAliveRoute(to);
}
}
const userInfo = storageSession().getItem<DataInfo<number>>(sessionKey);
const userInfo = storageLocal().getItem<DataInfo<number>>(userKey);
NProgress.start();
const externalLink = isUrl(to?.name as string);
if (!externalLink) {
Expand All @@ -125,7 +130,7 @@ router.beforeEach((to: ToRouteType, _from, next) => {
function toCorrectRoute() {
whiteList.includes(to.fullPath) ? next(_from.fullPath) : next();
}
if (userInfo) {
if (Cookies.get(multipleTabsKey) && userInfo) {
// 无权限跳转403页面
if (to.meta?.roles && !isOneOfArray(to.meta?.roles, userInfo?.roles)) {
next({ path: "/error/403" });
Expand Down Expand Up @@ -187,6 +192,7 @@ router.beforeEach((to: ToRouteType, _from, next) => {
if (whiteList.indexOf(to.path) !== -1) {
next();
} else {
removeToken();
next({ path: "/login" });
}
} else {
Expand Down
Loading

0 comments on commit 21c3ab8

Please sign in to comment.