性能优化

This commit is contained in:
Alex-larget
2026-03-17 14:02:09 +08:00
parent 2f35520670
commit c24caf63c5
46 changed files with 1387 additions and 1879 deletions

View File

@@ -92,6 +92,8 @@ App({
// 加载书籍数据
this.loadBookData()
// 加载 mpConfigappId、mchId、withdrawSubscribeTmplId 等,失败时保留默认值)
this.loadMpConfig()
// 检查更新
this.checkUpdate()
@@ -320,6 +322,7 @@ App({
if (res && (res.data || res.chapters)) {
const chapters = res.data || res.chapters || []
this.globalData.bookData = chapters
this.globalData.totalSections = (chapters && chapters.length) ? chapters.length : 62
wx.setStorageSync('bookData', chapters)
}
} catch (e) {
@@ -327,6 +330,21 @@ App({
}
},
// 加载 mpConfigappId、mchId、withdrawSubscribeTmplId 等),失败时保留 globalData 默认值
async loadMpConfig() {
try {
const res = await this.request({ url: '/api/miniprogram/config', silent: true })
const mp = (res && res.mpConfig) || (res && res.configs && res.configs.mp_config)
if (mp && typeof mp === 'object') {
if (mp.appId) this.globalData.appId = mp.appId
if (mp.mchId) this.globalData.mchId = mp.mchId
if (mp.withdrawSubscribeTmplId) this.globalData.withdrawSubscribeTmplId = mp.withdrawSubscribeTmplId
}
} catch (e) {
console.warn('[App] loadMpConfig 失败,使用默认值:', e?.message || e)
}
},
/**
* 小程序更新检测(基于 wx.getUpdateManager
* - 启动时检测;从后台切回前台时也检测(间隔至少 5 分钟,避免频繁请求)