|
@@ -12,6 +12,14 @@ import {homeRoutes} from "@/router/index.js";
|
|
|
// 加密密钥 (从环境变量获取)
|
|
// 加密密钥 (从环境变量获取)
|
|
|
const SECRET_KEY = import.meta.env.VITE_SECRET_KEY;
|
|
const SECRET_KEY = import.meta.env.VITE_SECRET_KEY;
|
|
|
|
|
|
|
|
|
|
+//需要删除的缓存key列表
|
|
|
|
|
+const CACHE_KEYS_TO_DELETE = [
|
|
|
|
|
+ 'token',
|
|
|
|
|
+ 'isLoggedIn',
|
|
|
|
|
+ CONFIG.USER_ROLE_ROUTE_KEY,
|
|
|
|
|
+ CONFIG.USER_ROLE_ROUTE_KEY + CONFIG.EXPIRY_SUFFIX,
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
// 密码加密函数(使用AES加密)
|
|
// 密码加密函数(使用AES加密)
|
|
|
const encryptPassword = (password) => {
|
|
const encryptPassword = (password) => {
|
|
|
// 将加密结果转换为字符串并返回 (encrypt加密)
|
|
// 将加密结果转换为字符串并返回 (encrypt加密)
|
|
@@ -173,7 +181,6 @@ const loginLogic = async (loginForm, tenantId, isAuthorized, router, redirectPat
|
|
|
} else {
|
|
} else {
|
|
|
// 如果没有勾选记住我,清除密码
|
|
// 如果没有勾选记住我,清除密码
|
|
|
localStorage.removeItem('password')
|
|
localStorage.removeItem('password')
|
|
|
- localStorage.removeItem('maxCourseSections')
|
|
|
|
|
}
|
|
}
|
|
|
loading.value = ElLoading.service({
|
|
loading.value = ElLoading.service({
|
|
|
lock: true,
|
|
lock: true,
|
|
@@ -336,13 +343,10 @@ const logoutLogic = async (router, redirectPath = homeRoutes.login) => {
|
|
|
// 调用logout API 退出登录
|
|
// 调用logout API 退出登录
|
|
|
const logoutRes = await logout()
|
|
const logoutRes = await logout()
|
|
|
console.log('退出登录:', logoutRes);
|
|
console.log('退出登录:', logoutRes);
|
|
|
- // 清空登录状态相关信息
|
|
|
|
|
- localStorage.removeItem('token')
|
|
|
|
|
- localStorage.removeItem('isLoggedIn')
|
|
|
|
|
- localStorage.removeItem('maxCourseSections')
|
|
|
|
|
- localStorage.removeItem(CONFIG.USER_ROLE_ROUTE_KEY)
|
|
|
|
|
- localStorage.removeItem(CONFIG.USER_ROLE_ROUTE_KEY + CONFIG.EXPIRY_SUFFIX)
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //清除本地存储
|
|
|
|
|
+ removeLocalStorage();
|
|
|
|
|
+
|
|
|
// 检查是否勾选了记住我
|
|
// 检查是否勾选了记住我
|
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
|
|
|
|
|
@@ -358,9 +362,9 @@ const logoutLogic = async (router, redirectPath = homeRoutes.login) => {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('退出登录失败:', error)
|
|
console.error('退出登录失败:', error)
|
|
|
// API调用失败,也清空本地存储
|
|
// API调用失败,也清空本地存储
|
|
|
- localStorage.removeItem('token')
|
|
|
|
|
- localStorage.removeItem('isLoggedIn')
|
|
|
|
|
- localStorage.removeItem('maxCourseSections')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //清除本地存储
|
|
|
|
|
+ removeLocalStorage();
|
|
|
|
|
|
|
|
// 检查是否勾选了记住我
|
|
// 检查是否勾选了记住我
|
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
@@ -376,6 +380,20 @@ const logoutLogic = async (router, redirectPath = homeRoutes.login) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//清除本地存储
|
|
|
|
|
+const removeLocalStorage = () => {
|
|
|
|
|
+ // 清空登录状态相关信息
|
|
|
|
|
+ let token = localStorage.getItem('token');
|
|
|
|
|
+ CACHE_KEYS_TO_DELETE.forEach(key => localStorage.removeItem(key));
|
|
|
|
|
+ if (token) {
|
|
|
|
|
+ for (let i = 0; i < localStorage.length; i++) {
|
|
|
|
|
+ const key = localStorage.key(i);
|
|
|
|
|
+ if (key && key.startsWith(token)) {
|
|
|
|
|
+ localStorage.removeItem(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// 添加获取字典数据的函数
|
|
// 添加获取字典数据的函数
|
|
|
const refreshDictData = async () => {
|
|
const refreshDictData = async () => {
|