feat(应用): 实现带可折叠侧边栏的仪表盘布局
添加从根路径到/app/dashboard的服务器端重定向 创建包含主内容容器的应用布局组件 实现带响应式侧边栏和顶栏的仪表盘页面 添加带平滑过渡效果的侧边栏切换功能 设置基础用户状态管理仓库 使用对等依赖标志更新package-lock.json中的依赖项 从锁定文件中移除冗余的picomatch条目 添加带路径解析导入的登录页面组件
This commit is contained in:
48
src/lib/api/services/authService.ts
Normal file
48
src/lib/api/services/authService.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
import {api} from '$lib/api/httpClient.ts'
|
||||
import type { AuthResponse, LoginPayload } from '$lib/types/auth.ts';
|
||||
import { browser } from '$app/environment';
|
||||
import { authStore } from '$lib/stores/authStore.ts';
|
||||
import { userService } from '$lib/api/services/userService.ts';
|
||||
import { userStore } from '$lib/stores/userStore.ts';
|
||||
|
||||
export const authService = {
|
||||
login: async (payload: LoginPayload): Promise<AuthResponse> => {
|
||||
const response = await api.post<AuthResponse>('/auth/login', payload);
|
||||
|
||||
if (response.code != 200 || !response.data){
|
||||
throw new Error(response.msg);
|
||||
}
|
||||
if (browser){
|
||||
authService._setToken(response.data.token, response.data.tokenHead)
|
||||
}
|
||||
|
||||
const userProfile = await userService.getUserProfile();
|
||||
|
||||
if (browser){
|
||||
userStore.set(userProfile)
|
||||
}
|
||||
|
||||
|
||||
return response.data;
|
||||
},
|
||||
logout: async () => {
|
||||
|
||||
if (browser){
|
||||
|
||||
authStore.clear();
|
||||
userStore.clear();
|
||||
localStorage.removeItem('auth_token');
|
||||
localStorage.removeItem('auth_token_head');
|
||||
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
_setToken: (token:string ,tokenHead: string)=> {
|
||||
authStore.set({ token, tokenHead, isAuthenticated: true });
|
||||
localStorage.setItem('auth_token', token);
|
||||
localStorage.setItem('auth_token_head', tokenHead);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user