mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 完善路由配置
This commit is contained in:
@ -1,13 +1,2 @@
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
|
||||
export function getToken() {
|
||||
return '';
|
||||
}
|
||||
|
||||
export function getUserInfo() {}
|
||||
|
||||
/** 获取登录模块的正则字符串 */
|
||||
export function getLoginModuleRegExp() {
|
||||
const arr: LoginModuleType[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat'];
|
||||
return arr.join('|');
|
||||
}
|
||||
export { getToken, setToken, getUserInfo, getLoginModuleRegExp } from './user';
|
||||
export { getLoginRedirectUrl, toLoginRedirectUrl, toHomeByLocation } from './location';
|
||||
|
14
src/utils/auth/location.ts
Normal file
14
src/utils/auth/location.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/** 获取登录重定向的地址 */
|
||||
export function getLoginRedirectUrl() {
|
||||
return window.location.href;
|
||||
}
|
||||
|
||||
/** 登录后跳转重定向的地址 */
|
||||
export function toLoginRedirectUrl(redirectUrl: string) {
|
||||
window.location.href = redirectUrl;
|
||||
}
|
||||
|
||||
/** 回到首页 */
|
||||
export function toHomeByLocation() {
|
||||
window.location.href = '/';
|
||||
}
|
21
src/utils/auth/user.ts
Normal file
21
src/utils/auth/user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { EnumStorageKey } from '@/enum';
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
import { setLocal, getLocal } from '../storage';
|
||||
|
||||
/** 设置token */
|
||||
export function getToken() {
|
||||
return getLocal<string>(EnumStorageKey.token) || '';
|
||||
}
|
||||
|
||||
/** 获取token */
|
||||
export function setToken(token: string) {
|
||||
setLocal(EnumStorageKey.token, token);
|
||||
}
|
||||
|
||||
export function getUserInfo() {}
|
||||
|
||||
/** 获取登录模块的正则字符串 */
|
||||
export function getLoginModuleRegExp() {
|
||||
const arr: LoginModuleType[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat'];
|
||||
return arr.join('|');
|
||||
}
|
@ -1,4 +1,13 @@
|
||||
export { getToken, getUserInfo, getLoginModuleRegExp } from './auth';
|
||||
export {
|
||||
setToken,
|
||||
getToken,
|
||||
getUserInfo,
|
||||
getLoginModuleRegExp,
|
||||
getLoginRedirectUrl,
|
||||
toLoginRedirectUrl,
|
||||
toHomeByLocation
|
||||
} from './auth';
|
||||
|
||||
export {
|
||||
isNumber,
|
||||
isString,
|
||||
@ -14,3 +23,5 @@ export {
|
||||
brightenColor,
|
||||
darkenColor
|
||||
} from './common';
|
||||
|
||||
export { setLocal, getLocal, setSession, getSession } from './storage';
|
||||
|
2
src/utils/storage/index.ts
Normal file
2
src/utils/storage/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { setLocal, getLocal } from './local';
|
||||
export { setSession, getSession } from './session';
|
@ -0,0 +1,12 @@
|
||||
export function setLocal(key: string, value: unknown) {
|
||||
const json = JSON.stringify(value);
|
||||
localStorage.setItem(key, json);
|
||||
}
|
||||
|
||||
export function getLocal<T>(key: string) {
|
||||
const json = localStorage.getItem(key);
|
||||
if (json) {
|
||||
return JSON.parse(json) as T;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
export function setSession(key: string, value: unknown) {
|
||||
const json = JSON.stringify(value);
|
||||
sessionStorage.setItem(key, json);
|
||||
}
|
||||
|
||||
export function getSession<T>(key: string) {
|
||||
const json = sessionStorage.getItem(key);
|
||||
if (json) {
|
||||
return JSON.parse(json) as T;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
Reference in New Issue
Block a user