feat: split DA and API layers by domain, add parallel route docs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
|
||||
/** 当前登录用户信息在 Storage 中的 key */
|
||||
export const USER_KEY = 'smart_user_info'
|
||||
/** 当前激活 openid 在 Storage 中的 key */
|
||||
export const ACTIVE_USER_KEY = 'smart_active_openid'
|
||||
|
||||
/** 判断 openid 是否为历史版 mock 残留(形如 mock_xxx) */
|
||||
export function isMockOpenid(openid?: string | null): boolean {
|
||||
return !!openid && (openid.startsWith('mock_') || openid.startsWith('mock-'))
|
||||
}
|
||||
|
||||
/** 取当前用户 openid;没有登录态时回退 _guest_ 并缓存 */
|
||||
function getActiveOpenid(): string {
|
||||
let user: any = null
|
||||
try {
|
||||
user = Taro.getStorageSync(USER_KEY)
|
||||
} catch {
|
||||
user = null
|
||||
}
|
||||
const openid = user?.openid || Taro.getStorageSync(ACTIVE_USER_KEY) || '_guest_'
|
||||
Taro.setStorageSync(ACTIVE_USER_KEY, openid)
|
||||
return openid
|
||||
}
|
||||
|
||||
/** 按当前用户生成作用域 storage key */
|
||||
export function key(scope: string): string {
|
||||
const prefix = getActiveOpenid()
|
||||
return `${scope}_${prefix}`
|
||||
}
|
||||
|
||||
/** 按指定 openid 生成作用域 storage key */
|
||||
export function keyFor(scope: string, openid: string): string {
|
||||
return `${scope}_${openid}`
|
||||
}
|
||||
Reference in New Issue
Block a user