zjk
2026-09-29 54dcf0a82e7490fa58b1c056d5c0b9cb739c2931
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { extractInviteCode } from './utils.js'
 
const INVITE_CODE_CACHE_KEY = 'openinstallInviteCode'
 
/**
 * 缓存 openinstall 或扫码解析出的医生邀请码,支持稍后注册时继续绑定关系。
 */
export const cacheInviteCode = (value) => {
    const inviteCode = extractInviteCode(value)
    if (!inviteCode) {
        return ''
    }
    uni.setStorageSync(INVITE_CODE_CACHE_KEY, inviteCode)
    return inviteCode
}
 
/**
 * 读取本地缓存的邀请码,只返回合法的 6 位业务码,历史误写入值会自动清理。
 */
export const getCachedInviteCode = () => {
    const cachedValue = uni.getStorageSync(INVITE_CODE_CACHE_KEY)
    const inviteCode = extractInviteCode(cachedValue)
    if (!inviteCode && cachedValue) {
        clearCachedInviteCode()
    }
    return inviteCode
}
 
/**
 * 清理已经完成注册使用的邀请码缓存,避免后续账号误绑定旧关系。
 */
export const clearCachedInviteCode = () => {
    uni.removeStorageSync(INVITE_CODE_CACHE_KEY)
}
 
/**
 * 暴露缓存 key 给清缓存页面保留业务必要数据。
 */
export const getInviteCodeCacheKey = () => INVITE_CODE_CACHE_KEY