|
@@ -1,11 +1,12 @@
|
|
|
import { ref, computed } from 'vue'
|
|
import { ref, computed } from 'vue'
|
|
|
import { getTenantIdByName, login, smsLogin, smsCode, logout } from '@/api/login/login.js'
|
|
import { getTenantIdByName, login, smsLogin, smsCode, logout } from '@/api/login/login.js'
|
|
|
import { ElLoading, ElMessage } from 'element-plus'
|
|
import { ElLoading, ElMessage } from 'element-plus'
|
|
|
-import { updateAllDictData } from './dictUtils.js';
|
|
|
|
|
|
|
+import { refreshAllDictData } from './dictUtils.js';
|
|
|
// CryptoJS 库(用于密码加密)
|
|
// CryptoJS 库(用于密码加密)
|
|
|
import CryptoJS from 'crypto-js';
|
|
import CryptoJS from 'crypto-js';
|
|
|
// 消息工具
|
|
// 消息工具
|
|
|
import { Message } from './message/Message.js';
|
|
import { Message } from './message/Message.js';
|
|
|
|
|
+import {CONFIG, refreshRoleRoute} from "@/utils/roleUtils.js";
|
|
|
|
|
|
|
|
// 加密密钥 (从环境变量获取)
|
|
// 加密密钥 (从环境变量获取)
|
|
|
const SECRET_KEY = import.meta.env.VITE_SECRET_KEY;
|
|
const SECRET_KEY = import.meta.env.VITE_SECRET_KEY;
|
|
@@ -153,7 +154,7 @@ const loginLogic = async (loginForm, tenantId, isAuthorized, router, redirectPat
|
|
|
|
|
|
|
|
// 校验登录状态
|
|
// 校验登录状态
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
- ElMessage.success('登录成功')
|
|
|
|
|
|
|
+ // ElMessage.success('登录成功')
|
|
|
isLoggedIn.value = true
|
|
isLoggedIn.value = true
|
|
|
// 存储登录状态
|
|
// 存储登录状态
|
|
|
localStorage.setItem('isLoggedIn', 'true')
|
|
localStorage.setItem('isLoggedIn', 'true')
|
|
@@ -180,7 +181,10 @@ const loginLogic = async (loginForm, tenantId, isAuthorized, router, redirectPat
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 获取字典数据
|
|
// 获取字典数据
|
|
|
- await getDictData();
|
|
|
|
|
|
|
+ await refreshDictData();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取角色路由数据
|
|
|
|
|
+ await refreshRoleRouteData();
|
|
|
|
|
|
|
|
// 登录成功后,跳转到指定的页面
|
|
// 登录成功后,跳转到指定的页面
|
|
|
router.push(redirectPath)
|
|
router.push(redirectPath)
|
|
@@ -207,16 +211,6 @@ const loginLogic = async (loginForm, tenantId, isAuthorized, router, redirectPat
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 添加获取字典数据的函数
|
|
|
|
|
-const getDictData = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- // 使用新的字典管理工具更新所有字典
|
|
|
|
|
- await updateAllDictData();
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('获取字典数据失败:', error);
|
|
|
|
|
- }
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
// 本地存储管理
|
|
// 本地存储管理
|
|
|
const loadLoginData = (loginData) => {
|
|
const loadLoginData = (loginData) => {
|
|
|
const storedTenantName = localStorage.getItem('tenantName')
|
|
const storedTenantName = localStorage.getItem('tenantName')
|
|
@@ -241,6 +235,13 @@ const loadLoginData = (loginData) => {
|
|
|
const checkLoginStatus = (router, redirectPath) => {
|
|
const checkLoginStatus = (router, redirectPath) => {
|
|
|
const storedStatus = localStorage.getItem('isLoggedIn')
|
|
const storedStatus = localStorage.getItem('isLoggedIn')
|
|
|
if (storedStatus === 'true') {
|
|
if (storedStatus === 'true') {
|
|
|
|
|
+
|
|
|
|
|
+ // 获取字典数据
|
|
|
|
|
+ refreshDictData();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取角色路由数据
|
|
|
|
|
+ refreshRoleRouteData();
|
|
|
|
|
+
|
|
|
router.push(redirectPath)
|
|
router.push(redirectPath)
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
@@ -329,7 +330,7 @@ const autoLogin = async (tenantName, username, password, router, redirectPath) =
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 退出登录逻辑
|
|
// 退出登录逻辑
|
|
|
-const logoutLogic = async (router) => {
|
|
|
|
|
|
|
+const logoutLogic = async (router, redirectPath = '/login') => {
|
|
|
try {
|
|
try {
|
|
|
// 调用logout API 退出登录
|
|
// 调用logout API 退出登录
|
|
|
const logoutRes = await logout()
|
|
const logoutRes = await logout()
|
|
@@ -338,6 +339,8 @@ const logoutLogic = async (router) => {
|
|
|
localStorage.removeItem('token')
|
|
localStorage.removeItem('token')
|
|
|
localStorage.removeItem('isLoggedIn')
|
|
localStorage.removeItem('isLoggedIn')
|
|
|
localStorage.removeItem('maxCourseSections')
|
|
localStorage.removeItem('maxCourseSections')
|
|
|
|
|
+ localStorage.removeItem(CONFIG.USER_ROLE_ROUTE_KEY)
|
|
|
|
|
+ localStorage.removeItem(CONFIG.USER_ROLE_ROUTE_KEY + CONFIG.EXPIRY_SUFFIX)
|
|
|
|
|
|
|
|
// 检查是否勾选了记住我
|
|
// 检查是否勾选了记住我
|
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
const rememberMe = localStorage.getItem('rememberMe') === 'true'
|
|
@@ -350,7 +353,7 @@ const logoutLogic = async (router) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 跳转到登录页面
|
|
// 跳转到登录页面
|
|
|
- router.push({ path: '/login' })
|
|
|
|
|
|
|
+ router.push({ path: redirectPath })
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('退出登录失败:', error)
|
|
console.error('退出登录失败:', error)
|
|
|
// API调用失败,也清空本地存储
|
|
// API调用失败,也清空本地存储
|
|
@@ -372,6 +375,29 @@ const logoutLogic = async (router) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+// 添加获取字典数据的函数
|
|
|
|
|
+const refreshDictData = async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 使用典管理工具更新所有字典
|
|
|
|
|
+ await refreshAllDictData();
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('获取字典数据失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// 添加获取角色路由数据的函数
|
|
|
|
|
+const refreshRoleRouteData = async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ // 使用角色路由工具更新角色路由
|
|
|
|
|
+ await refreshRoleRoute();
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('获取角色路由数据失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export {
|
|
export {
|
|
|
createLoginData,
|
|
createLoginData,
|
|
|
createVerificationCodeLogic,
|
|
createVerificationCodeLogic,
|