mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-11-08 03:50:50 +08:00
feat(uniapp): 集成 Pinia 状态管理并实现用户认证流程
This commit is contained in:
4
source/clients/uniapp/src/store/index.js
Normal file
4
source/clients/uniapp/src/store/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
export const pinia = createPinia()
|
||||
|
||||
29
source/clients/uniapp/src/store/user.js
Normal file
29
source/clients/uniapp/src/store/user.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
const TOKEN_KEY = 'ULTHON_ADMIN_TOKEN'
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: () => ({
|
||||
token: '',
|
||||
inited: false,
|
||||
}),
|
||||
getters: {
|
||||
isLoggedIn: (state) => !!state.token,
|
||||
},
|
||||
actions: {
|
||||
init() {
|
||||
if (this.inited) return
|
||||
this.token = uni.getStorageSync(TOKEN_KEY) || ''
|
||||
this.inited = true
|
||||
},
|
||||
setToken(token) {
|
||||
this.token = token || ''
|
||||
uni.setStorageSync(TOKEN_KEY, this.token)
|
||||
},
|
||||
logout() {
|
||||
this.token = ''
|
||||
uni.removeStorageSync(TOKEN_KEY)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user