fix(企业ID获取): 优化企业ID获取逻辑并添加本地缓存
添加本地缓存机制避免重复获取企业ID,优先使用参数中的cid获取企业ID,若无则使用本地缓存,最后使用默认值
This commit is contained in:
parent
022d307271
commit
8f46ad1840
|
|
@ -72,12 +72,26 @@ onLoad(async (query) => {
|
||||||
if (query && query.scene) {
|
if (query && query.scene) {
|
||||||
const scene = decodeURIComponent(query.scene);
|
const scene = decodeURIComponent(query.scene);
|
||||||
wxParamsStore.parseScene(scene);
|
wxParamsStore.parseScene(scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cid = wxParamsStore.getNumberParam('cid');
|
const cid = wxParamsStore.getNumberParam('cid', -1);
|
||||||
|
let corpid = uni.getStorageSync('local_corpid');
|
||||||
|
|
||||||
const corpid = (await getCorpidById(cid)).data;
|
// 企业ID获取逻辑:根据不同的条件获取企业ID并缓存到本地
|
||||||
|
if (cid > 0) {
|
||||||
|
// 如果存在有效的企业ID参数(cid > 0),则通过API获取对应的企业ID
|
||||||
|
corpid = (await getCorpidById(cid)).data;
|
||||||
|
// 将获取到的企业ID存储到本地缓存中
|
||||||
|
uni.setStorageSync('local_corpid', corpid || '');
|
||||||
|
} else if (corpid) {
|
||||||
|
// 如果本地已存在企业ID,则直接使用,无需重新获取
|
||||||
|
// 空语句块,表示保持现有的corpid值不变
|
||||||
|
} else {
|
||||||
|
// 如果既没有有效的cid参数,也没有本地缓存的corpid,则获取默认企业ID(cid=0)
|
||||||
|
corpid = (await getCorpidById(0)).data;
|
||||||
|
// 将默认企业ID存储到本地缓存中
|
||||||
|
uni.setStorageSync('local_corpid', corpid || '');
|
||||||
|
}
|
||||||
|
|
||||||
let openid = uni.getStorageSync('local_openid');
|
let openid = uni.getStorageSync('local_openid');
|
||||||
if (!openid) {
|
if (!openid) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue