hookehuyr

refactor(router): 修改用户信息接口路径并模拟测试接口

将 `getUserInfoAPI` 的路径从 `@/api/user` 更改为 `@/api/users`,并暂时注释掉异步逻辑以模拟测试接口
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-26 09:45:57
* @LastEditTime: 2025-03-26 09:55:40
* @FilePath: /mlaj/src/router/guards.js
* @Description: 路由守卫逻辑
*/
import { getAuthInfoAPI } from '@/api/auth'
import { getUserInfoAPI } from '@/api/user'
import { getUserInfoAPI } from '@/api/users'
import { wxInfo } from "@/utils/tools"
// 需要登录才能访问的路由
......@@ -53,18 +53,20 @@ export const checkWxAuth = async () => {
}
// 登录权限检查
export const checkAuth = async (to) => {
try {
// 先请求用户信息接口
const { code, data } = await getUserInfoAPI();
if (code) {
// 如果成功获取用户信息,更新currentUser并允许访问
localStorage.setItem('currentUser', JSON.stringify(data));
return true;
}
} catch (error) {
console.error('获取用户信息失败:', error);
}
export const checkAuth = (to) => {
// TODO: 模拟测试接口
// export const checkAuth = async (to) => {
// try {
// // 先请求用户信息接口
// const { code, data } = await getUserInfoAPI();
// if (code) {
// // 如果成功获取用户信息,更新currentUser并允许访问
// localStorage.setItem('currentUser', JSON.stringify(data));
// return true;
// }
// } catch (error) {
// console.error('获取用户信息失败:', error);
// }
// 如果接口请求失败或返回401,继续原有的本地存储判断逻辑
const currentUser = JSON.parse(localStorage.getItem('currentUser'))
......