优化
This commit is contained in:
46
monisuo-admin/src/stores/auth.ts
Normal file
46
monisuo-admin/src/stores/auth.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import type { AdminInfo } from '@/services/api/monisuo-admin.api'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const isLogin = ref(false)
|
||||
const token = ref<string | null>(localStorage.getItem('admin_token'))
|
||||
const adminInfo = ref<AdminInfo | null>(
|
||||
localStorage.getItem('admin_info')
|
||||
? JSON.parse(localStorage.getItem('admin_info')!)
|
||||
: null,
|
||||
)
|
||||
|
||||
// 初始化时检查 token
|
||||
if (token.value) {
|
||||
isLogin.value = true
|
||||
}
|
||||
|
||||
function setToken(newToken: string) {
|
||||
token.value = newToken
|
||||
localStorage.setItem('admin_token', newToken)
|
||||
isLogin.value = true
|
||||
}
|
||||
|
||||
function setAdminInfo(info: AdminInfo) {
|
||||
adminInfo.value = info
|
||||
localStorage.setItem('admin_info', JSON.stringify(info))
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = null
|
||||
adminInfo.value = null
|
||||
isLogin.value = false
|
||||
localStorage.removeItem('admin_token')
|
||||
localStorage.removeItem('admin_info')
|
||||
}
|
||||
|
||||
return {
|
||||
isLogin,
|
||||
token,
|
||||
adminInfo,
|
||||
setToken,
|
||||
setAdminInfo,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
31
monisuo-admin/src/stores/theme.ts
Normal file
31
monisuo-admin/src/stores/theme.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import type { ContentLayout, Radius, Theme } from '@/constants/themes'
|
||||
|
||||
export const useThemeStore = defineStore('system-config', () => {
|
||||
const radius = ref(0.5)
|
||||
function setRadius(newRadius: Radius) {
|
||||
radius.value = newRadius
|
||||
}
|
||||
const theme = ref<Theme>('zinc')
|
||||
function setTheme(newTheme: Theme) {
|
||||
theme.value = newTheme
|
||||
}
|
||||
|
||||
const contentLayout = ref<ContentLayout>('centered')
|
||||
function setContentLayout(newContentLayout: ContentLayout) {
|
||||
contentLayout.value = newContentLayout
|
||||
}
|
||||
return {
|
||||
radius,
|
||||
setRadius,
|
||||
|
||||
theme,
|
||||
setTheme,
|
||||
|
||||
contentLayout,
|
||||
setContentLayout,
|
||||
}
|
||||
}, {
|
||||
persist: true,
|
||||
})
|
||||
Reference in New Issue
Block a user