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
|