feat(frontend): S0 Vue3 脚手架 + auth + Layout shell(4入口,模拟/实盘灰显)
- Vite+TS+ElementPlus+ECharts+Pinia+Router+Axios - auth store + JWT axios 拦截器 + 路由守卫 - 登录页 + Layout(侧栏 4 入口,回测/投研 active,模拟/实盘 disabled) - 占位页(backtest/factor,S1/S2 填充) - vitest auth store 3 tests passed + build 通过(dist 生成)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface AuthState {
|
||||
token: string | null
|
||||
username: string | null
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
state: (): AuthState => ({
|
||||
token: localStorage.getItem('token'),
|
||||
username: localStorage.getItem('username'),
|
||||
}),
|
||||
getters: {
|
||||
isAuthenticated: (state): boolean => !!state.token,
|
||||
},
|
||||
actions: {
|
||||
setToken(token: string, username: string): void {
|
||||
this.token = token
|
||||
this.username = username
|
||||
localStorage.setItem('token', token)
|
||||
localStorage.setItem('username', username)
|
||||
},
|
||||
logout(): void {
|
||||
this.token = null
|
||||
this.username = null
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('username')
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user