Enhance mini program environment configuration and chapter loading logic

- Introduced a debugging environment configuration in app.js, allowing for dynamic API endpoint selection based on the environment.
- Implemented lazy loading for chapter parts in chapters.js, improving performance by only fetching necessary data.
- Updated UI elements in chapters.wxml to reflect changes in chapter loading and added loading indicators.
- Enhanced error handling and data management for chapter retrieval, ensuring a smoother user experience.
- Added functionality for switching API environments in settings.js, visible only in development mode.
This commit is contained in:
Alex-larget
2026-03-14 18:04:05 +08:00
parent 1edceda4db
commit d82ef6d8e4
22 changed files with 1184 additions and 899 deletions

View File

@@ -14,6 +14,8 @@ Page({
// 切换账号(开发)
showSwitchAccountModal: false,
// 调试环境:当前 API 环境标签
apiEnvLabel: '自动',
switchAccountUserId: '',
switchAccountLoading: false,
@@ -36,17 +38,30 @@ Page({
wx.showShareMenu({ withShareTimeline: true })
const accountInfo = wx.getAccountInfoSync ? wx.getAccountInfoSync() : null
const envVersion = accountInfo?.miniProgram?.envVersion || ''
const envInfo = app.getDebugEnvInfo()
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
isLoggedIn: app.globalData.isLoggedIn,
userInfo: app.globalData.userInfo,
isDevMode: envVersion === 'develop'
isDevMode: envVersion === 'develop',
apiEnvLabel: envInfo.label
})
this.loadBindingInfo()
},
onShow() {
this.loadBindingInfo()
if (this.data.isDevMode) {
const envInfo = getApp().getDebugEnvInfo()
this.setData({ apiEnvLabel: envInfo.label })
}
},
// 一键切换 API 环境(开发版)
switchApiEnv() {
const next = getApp().switchDebugEnv()
this.setData({ apiEnvLabel: next.label })
wx.showToast({ title: `已切到 ${next.label}`, icon: 'none' })
},
// 加载绑定信息