对话、重新生成、评价完成

This commit is contained in:
2025-11-05 16:55:58 +08:00
parent 8850a06fea
commit d9d62e22de
34 changed files with 1658 additions and 965 deletions

View File

@@ -26,24 +26,45 @@ export interface AuthState {
// 存储工具函数
const StorageUtil = {
// 保存数据根据rememberMe选择存储方式
// 保存数据(始终使用localStorage根据rememberMe设置过期时间
setItem(key: string, value: string, rememberMe = false) {
if (rememberMe) {
localStorage.setItem(key, value);
} else {
sessionStorage.setItem(key, value);
const data = {
value,
timestamp: Date.now(),
// 如果不勾选"记住我"设置1天过期时间勾选则7天
expiresIn: rememberMe ? 7 * 24 * 60 * 60 * 1000 : 1 * 24 * 60 * 60 * 1000
};
localStorage.setItem(key, JSON.stringify(data));
},
// 获取数据(检查是否过期)
getItem(key: string): string | null {
const itemStr = localStorage.getItem(key);
if (!itemStr) return null;
try {
const item = JSON.parse(itemStr);
const now = Date.now();
// 检查是否过期
if (item.timestamp && item.expiresIn) {
if (now - item.timestamp > item.expiresIn) {
// 已过期,删除
localStorage.removeItem(key);
return null;
}
}
return item.value || itemStr; // 兼容旧数据
} catch {
// 如果不是JSON格式直接返回兼容旧数据
return itemStr;
}
},
// 获取数据优先从localStorage其次sessionStorage
getItem(key: string): string | null {
return localStorage.getItem(key) || sessionStorage.getItem(key);
},
// 删除数据(从两个存储中都删除)
// 删除数据
removeItem(key: string) {
localStorage.removeItem(key);
sessionStorage.removeItem(key);
},
// 清除所有认证相关数据
@@ -51,7 +72,6 @@ const StorageUtil = {
const keys = ['token', 'loginDomain', 'menus', 'permissions', 'rememberMe'];
keys.forEach(key => {
localStorage.removeItem(key);
sessionStorage.removeItem(key);
});
}
};