init
This commit is contained in:
27
pc/stores/app.ts
Normal file
27
pc/stores/app.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getConfig } from '~~/api/app'
|
||||
|
||||
interface AppSate {
|
||||
config: Record<string, any>
|
||||
}
|
||||
export const useAppStore = defineStore({
|
||||
id: 'appStore',
|
||||
state: (): AppSate => ({
|
||||
config: {}
|
||||
}),
|
||||
getters: {
|
||||
getImageUrl: (state) => (url: string) =>
|
||||
url ? `${state.config.domain}${url}` : '',
|
||||
getWebsiteConfig: (state) => state.config.website || {},
|
||||
getLoginConfig: (state) => state.config.login || {},
|
||||
getCopyrightConfig: (state) => state.config.copyright || [],
|
||||
getQrcodeConfig: (state) => state.config.qrcode || {},
|
||||
getAdminUrl: (state) => state.config.admin_url
|
||||
},
|
||||
actions: {
|
||||
async getConfig() {
|
||||
const config = await getConfig()
|
||||
this.config = config
|
||||
}
|
||||
}
|
||||
})
|
43
pc/stores/user.ts
Normal file
43
pc/stores/user.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { getUserCenter } from '@/api/user'
|
||||
import { TOKEN_KEY } from '@/enums/cacheEnums'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface UserSate {
|
||||
userInfo: Record<string, any>
|
||||
token: string | null
|
||||
temToken: string | null
|
||||
}
|
||||
export const useUserStore = defineStore({
|
||||
id: 'userStore',
|
||||
state: (): UserSate => {
|
||||
const TOKEN = useCookie(TOKEN_KEY)
|
||||
return {
|
||||
userInfo: {},
|
||||
token: TOKEN.value || null,
|
||||
temToken: null
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
isLogin: (state) => !!state.token
|
||||
},
|
||||
actions: {
|
||||
async getUser() {
|
||||
const data = await getUserCenter()
|
||||
this.userInfo = data
|
||||
},
|
||||
setUser(userInfo) {
|
||||
this.userInfo = userInfo
|
||||
},
|
||||
login(token: string) {
|
||||
const TOKEN = useCookie(TOKEN_KEY)
|
||||
this.token = token
|
||||
TOKEN.value = token
|
||||
},
|
||||
logout() {
|
||||
const TOKEN = useCookie(TOKEN_KEY)
|
||||
this.token = null
|
||||
this.userInfo = {}
|
||||
TOKEN.value = null
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user