feat: 新增路由鉴权

This commit is contained in:
duanshuwen
2025-12-16 21:24:42 +08:00
parent cadf0d8098
commit c9a96f1b06
6 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import Cookies from 'js-cookie'
const TokenKey = 'Nianxx-Token'
export function getToken() {
return Cookies.get(TokenKey)
}
export function setToken(token: string) {
return Cookies.set(TokenKey, token)
}
export function removeToken() {
return Cookies.remove(TokenKey)
}

View File

@@ -0,0 +1,12 @@
/**
* 路径匹配器
* @param {string} pattern
* @param {string} path
* @returns {Boolean}
*/
export function isPathMatch(pattern: string, path: string): boolean {
const regexPattern = pattern.replace(/\//g, '\\/').replace(/\*\*/g, '.*').replace(/\*/g, '[^\\/]*')
const regex = new RegExp(`^${regexPattern}$`)
return regex.test(path)
}