feat: 🚀 钉钉跳转

This commit is contained in:
2025-10-16 15:35:43 +08:00
parent 3c72a248fa
commit 574c46580f
6 changed files with 137 additions and 27 deletions

View File

@@ -29,6 +29,22 @@ const router = createRouter({
scrollBehavior: () => ({ left: 0, top: 0 })
});
// 1. 定义获取URL参数的函数
function getUrlParam(paramName: any) {
// 获取当前页面URL的查询参数部分如 "?redirect_path=xxx&t=xxx"
const searchStr = window.location.search.slice(1);
// 将参数按 "&" 分割成数组(如 ["redirect_path=xxx", "t=xxx"]
const paramArr = searchStr.split("&");
// 遍历数组匹配目标参数
for (let item of paramArr) {
const [key, value] = item.split("=");
if (key === paramName) {
return decodeURIComponent(value); // 解码特殊字符,确保内容准确
}
}
return null; // 未找到参数时返回null
}
/**
* @description 路由拦截 beforeEach
* */
@@ -38,6 +54,7 @@ router.beforeEach(async (to, from, next) => {
// 1.NProgress 开始
NProgress.start();
let redirect_path = getUrlParam("redirect_path");
// 2.动态设置标题
const title = import.meta.env.VITE_GLOB_APP_TITLE;
@@ -51,6 +68,17 @@ router.beforeEach(async (to, from, next) => {
// 4.判断访问页面是否在路由白名单地址(静态路由)中,如果存在直接放行
if (ROUTER_WHITE_LIST.includes(to.path)) return next();
// 4.判断访问页面是否在路由白名单地址(静态路由)中,如果存在直接放行
if (ROUTER_WHITE_LIST.includes(to.path)) return next();
// 如果没有token但是有订阅路由就将订阅路由当参数携带
if (!userStore.newUserToken && redirect_path) {
return next({
path: LOGIN_URL,
replace: true,
query: { redirect_path: redirect_path } // 通过query传递参数
});
}
// 5.判断是否有 Token没有重定向到 login 页面
if (!userStore.newUserToken) return next({ path: LOGIN_URL, replace: true });