feat: uni-app 前端骨架(登录/孩子/地图/闯关/结算)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
const AUTH_KEY = '36wisdom_auth'
|
||||
const CHILD_KEY = '36wisdom_child'
|
||||
|
||||
function loadAuth() {
|
||||
const saved = uni.getStorageSync(AUTH_KEY)
|
||||
return saved || { token: '', parentId: 0 }
|
||||
}
|
||||
|
||||
const state = reactive({
|
||||
token: loadAuth().token,
|
||||
parentId: loadAuth().parentId,
|
||||
childId: Number(uni.getStorageSync(CHILD_KEY) || 0)
|
||||
})
|
||||
|
||||
export function isLoggedIn() {
|
||||
return !!state.token
|
||||
}
|
||||
|
||||
export function getToken() {
|
||||
return state.token
|
||||
}
|
||||
|
||||
export function getParentId() {
|
||||
return state.parentId
|
||||
}
|
||||
|
||||
export function getChildId() {
|
||||
return state.childId
|
||||
}
|
||||
|
||||
export function setChildId(childId) {
|
||||
state.childId = childId
|
||||
uni.setStorageSync(CHILD_KEY, childId)
|
||||
}
|
||||
|
||||
export function setAuth(token, parentId) {
|
||||
state.token = token
|
||||
state.parentId = parentId
|
||||
uni.setStorageSync(AUTH_KEY, { token, parentId })
|
||||
}
|
||||
|
||||
export function clearAuth() {
|
||||
state.token = ''
|
||||
state.parentId = 0
|
||||
uni.removeStorageSync(AUTH_KEY)
|
||||
}
|
||||
Reference in New Issue
Block a user