页面优化

This commit is contained in:
Dev
2026-10-19 15:46:10 +08:00
parent 44405743bb
commit 6beeeb2383
14 changed files with 229 additions and 120 deletions
+40 -10
View File
@@ -52,9 +52,46 @@ export function fetchHome() {
});
}
/** 获取配置数据 */
export function fetchConfig() {
return wx.$util.request(wx.$api.CommonGetMiniConfig, {}, 'GET', { auth: false });
const CONFIG_TTL = 60000;
let configCache = null;
let configTask = null;
// 与后端 site.platform_commission_ratio 默认值一致,接口失败时兜底
const DEFAULT_COMMISSION_RATIO = 0.1;
let commissionRatioCache = null;
const CASE_VIEW_STORAGE_KEY = 'goodsCaseView';
let caseViewCache = null;
/**
* 获取小程序配置。成功结果缓存 60 秒,同时进行中的请求合并成一次
* @param {{force?: boolean}} options force 为 true 时忽略缓存(下拉刷新)
*/
export function fetchConfig(options = {}) {
const force = options === true || options.force === true;
if (configTask) {
return configTask;
}
if (!force && configCache && Date.now() - configCache.at < CONFIG_TTL) {
return Promise.resolve(configCache.res);
}
configTask = wx.$util.request(wx.$api.CommonGetMiniConfig, {}, 'GET', { auth: false }).then((res) => {
if (res && res.code === 1) {
configCache = { at: Date.now(), res };
const ratio = Number(res.data?.platform_commission_ratio);
if (ratio >= 0 && ratio <= 1) {
commissionRatioCache = ratio;
}
caseViewCache = res.data?.goods_case_view === true || res.data?.goods_case_view === 1;
wx.setStorageSync(CASE_VIEW_STORAGE_KEY, caseViewCache);
}
return res;
}).then((res) => {
configTask = null;
return res;
}, (err) => {
configTask = null;
throw err;
});
return configTask;
}
/** 获取首页轮播(分类类型 banner) */
@@ -62,10 +99,6 @@ export function fetchHomeBanners() {
return wx.$util.request(wx.$api.CatalogList, { type: 'banner' }, 'GET', { auth: false });
}
// 与后端 site.platform_commission_ratio 默认值一致,接口失败时兜底
const DEFAULT_COMMISSION_RATIO = 0.1;
let commissionRatioCache = null;
/**
* 获取平台服务费比例(0~1),成功后缓存,失败返回默认值且不缓存,下次重新请求
* @returns {Promise<number>}
@@ -87,9 +120,6 @@ export async function fetchPlatformCommissionRatio() {
return DEFAULT_COMMISSION_RATIO;
}
const CASE_VIEW_STORAGE_KEY = 'goodsCaseView';
let caseViewCache = null;
/**
* 商品是否按案例展示(不显示价格和购买入口)
* 成功后缓存;失败时用上次成功的本地记录