提交 397da8ad authored 作者: 张伊明's avatar 张伊明

合并分支 'zz-dev' 到 'pre'

feat:登录页功能开发 查看合并请求 !317
流水线 #364 已通过 于阶段
in 3 分 47 秒
import { createRouter, createWebHistory } from "vue-router";
import { getIsLoggedIn } from "@/utils/auth";
const Home = () => import('@/views/home/index.vue')
const DataLibrary = () => import('@/views/dataLibrary/index.vue')
......@@ -21,6 +22,14 @@ const dataRoutes = Object.keys(datas).reduce((acc, path) => {
}, [])
const routes = [
{
path: "/login",
name: "Login",
component: () => import("@/views/login/index.vue"),
meta: {
title: "登录"
}
},
{
path: "/",
name: "Home",
......@@ -66,6 +75,19 @@ const router = createRouter({
// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
// 登录态仅保存在运行时内存:刷新/重启后都需重新登录
const isAuthed = getIsLoggedIn();
const isLoginRoute = to.name === "Login" || /^\/login\/?$/.test(String(to.path || ""));
if (!isLoginRoute && !isAuthed) {
next({
path: "/login",
query: { redirect: to.fullPath }
});
return;
}
if (to.meta.title) {
if (to.meta.dynamicTitle) {
console.log('to', to);
......
......@@ -4,7 +4,7 @@ const ZMOverview = () => import('@/views/ZMOverView/index.vue')
const ZMOverviewRoutes = [
{
path: "/",
redirect: "/ZMOverView"
redirect: "/login"
},
{
path: "/ZMOverView",
......
let isLoggedIn = false;
export const getIsLoggedIn = () => isLoggedIn;
export const setIsLoggedIn = (val) => {
isLoggedIn = Boolean(val);
};
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论