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,3 @@
|
||||
export const LOGIN = 'login'
|
||||
export const USER = 'user'
|
||||
export const LOCAL_STORAGE_USER = 'user'
|
||||
@@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia'
|
||||
export const useStore = defineStore("index", {
|
||||
state: () => {
|
||||
return {
|
||||
orderInfo: ref({}),
|
||||
navTitle: ref(""),
|
||||
brandInfo: ref({}),
|
||||
redirect: ""
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
updateOrderInfo(data) {
|
||||
this.orderInfo = data;
|
||||
},
|
||||
setBrandInfo(data) {
|
||||
this.brandInfo = data;
|
||||
},
|
||||
updateTitle(data) {
|
||||
this.navTitle = data
|
||||
},
|
||||
setRedirect(path: string) {
|
||||
this.redirect = path
|
||||
},
|
||||
redirectUrl() {
|
||||
return this.redirect
|
||||
}
|
||||
},
|
||||
persist:true //store数据持久化
|
||||
})
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export const STORAGE_TOKEN_KEY = 'authorization'
|
||||
export const STORAGE_LANG_KEY = 'app_lang'
|
||||
export const TOKEN = 'token'
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { LOCAL_STORAGE_USER, USER } from '@/stores/consts'
|
||||
import localStorage from '@/utils/local-storage'
|
||||
|
||||
export const useUserStore = defineStore(USER, () => {
|
||||
const userInfo = ref(localStorage.get(LOCAL_STORAGE_USER) || {})
|
||||
|
||||
function login(info: any) {
|
||||
localStorage.set(LOCAL_STORAGE_USER, info)
|
||||
userInfo.value = info
|
||||
}
|
||||
|
||||
function logout() {
|
||||
localStorage.remove(LOCAL_STORAGE_USER)
|
||||
userInfo.value = null
|
||||
}
|
||||
|
||||
function isLoggedIn(): boolean {
|
||||
return userInfo.value?.id > 0 || !!userInfo.value?.email
|
||||
}
|
||||
|
||||
return {
|
||||
user: userInfo,
|
||||
login,
|
||||
logout,
|
||||
isLoggedIn,
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user