forked from natuka/web.puabadge.com
Initial commit
This commit is contained in:
commit
84061c9a18
243 files changed
+63148
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { STORAGE_TOKEN_KEY, TOKEN } from './mutation-type'
|
||||
import localStorage from '@/utils/local-storage'
|
||||
import {parseJwt} from "@/utils/utils"
|
||||
|
||||
export const useTokenStore = defineStore(TOKEN, () => {
|
||||
const token = ref(localStorage.get(STORAGE_TOKEN_KEY) || '')
|
||||
let userInfo = ref(parseJwt(token.value))
|
||||
function login(val: string) {
|
||||
localStorage.set(STORAGE_TOKEN_KEY, val)
|
||||
userInfo.value = parseJwt(val);
|
||||
token.value = val
|
||||
}
|
||||
|
||||
function logout() {
|
||||
localStorage.remove(STORAGE_TOKEN_KEY)
|
||||
token.value = ''
|
||||
}
|
||||
|
||||
function isLoggedIn(): boolean {
|
||||
return !!token.value
|
||||
}
|
||||
|
||||
function isWechat(): boolean {
|
||||
return !!userInfo.value?.isWechat
|
||||
}
|
||||
|
||||
return {
|
||||
token,
|
||||
userInfo,
|
||||
login,
|
||||
logout,
|
||||
isLoggedIn,
|
||||
isWechat,
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user