完成50%

This commit is contained in:
2026-07-23 08:23:59 +08:00
parent 9b0ad62df4
commit f1edc6b533
218 changed files with 24318 additions and 5514 deletions
+38 -4
View File
@@ -1,7 +1,41 @@
import { genealogyContext } from "./genealogy-context.js";
const TOKEN_KEY = 'jiapu_token'
export const session = {
getToken: () => uni.getStorageSync(TOKEN_KEY) || '',
saveToken: (token) => uni.setStorageSync(TOKEN_KEY, token),
clear: () => uni.removeStorageSync(TOKEN_KEY)
const normalizeToken = (token) => {
if (typeof token !== 'string' || !token || token.trim() !== token) {
throw new TypeError('会话令牌必须是无边界空白的非空字符串')
}
return token
}
const readToken = () => {
const stored = uni.getStorageSync(TOKEN_KEY)
if (stored === '' || stored === null || stored === undefined) return ''
try {
return normalizeToken(stored)
} catch {
// 损坏令牌与其账号作用域下的当前家谱必须一起失效,避免页面继续展示
// 上一个账号的领域上下文。
uni.removeStorageSync(TOKEN_KEY)
genealogyContext.clearCurrentGenealogyId()
return ''
}
}
export const session = {
getToken: readToken,
saveToken: (token) => {
const normalizedToken = normalizeToken(token)
const previousToken = readToken()
if (previousToken !== normalizedToken) {
genealogyContext.clearCurrentGenealogyId()
}
uni.setStorageSync(TOKEN_KEY, normalizedToken)
return normalizedToken
},
clear: () => {
uni.removeStorageSync(TOKEN_KEY)
genealogyContext.clearCurrentGenealogyId()
}
}