This commit is contained in:
Alex-larget
2026-03-24 15:44:08 +08:00
parent 346e8ab057
commit 28ad08da84
62 changed files with 814 additions and 840 deletions

View File

@@ -11,6 +11,8 @@ const DEFAULT_MCH_ID = '1318592501'
const DEFAULT_WITHDRAW_TMPL_ID = 'u3MbZGPRkrZIk-I7QdpwzFxnO_CeQPaCWF2FkiIablE'
// 与上传版本号对齐;设置页展示优先用 wx.getAccountInfoSync().miniProgram.version正式版否则用本字段
const APP_DISPLAY_VERSION = '1.7.1'
// 章节总数API 获取失败时的统一兜底,避免 90/62 混用
const FALLBACK_TOTAL_SECTIONS = 62
App({
globalData: {
@@ -40,7 +42,7 @@ App({
// 书籍数据bookData 由 chapters-by-part 等逐步填充,不再预加载 all-chapters
bookData: null,
totalSections: 90,
totalSections: FALLBACK_TOTAL_SECTIONS, // 来自 book/parts 或 book/stats失败时用常量
// 购买记录
purchasedSections: [],
@@ -910,8 +912,12 @@ App({
if (msg && (msg.includes('用户不存在') || msg.toLowerCase().includes('user not found'))) {
this.logout()
}
showError(msg)
reject(new Error(msg))
const err = new Error(msg)
err.response = data
const skipToast = data.needBindWechat === true || data.needBind === true ||
(data.errorCode && String(data.errorCode).indexOf('ERR_') === 0)
if (!silent && !skipToast) showError(msg)
reject(err)
return
}
resolve(data)
@@ -947,8 +953,12 @@ App({
}
// 4xx/5xx优先用返回体的 message/error
const msg = this._getApiErrorMsg(data, res.statusCode >= 500 ? '服务器异常,请稍后重试' : '请求失败')
showError(msg)
reject(new Error(msg))
const err = new Error(msg)
if (data && typeof data === 'object') err.response = data
const skipToast = data && (data.needBindWechat === true || data.needBind === true ||
(data.errorCode && String(data.errorCode).indexOf('ERR_') === 0))
if (!silent && !skipToast) showError(msg)
reject(err)
},
fail: (err) => {
const msg = (err && err.errMsg) ? (err.errMsg.indexOf('timeout') !== -1 ? '请求超时,请重试' : '网络异常,请重试') : '网络异常,请重试'
@@ -1124,6 +1134,11 @@ App({
if (res.success && res.data) {
const user = res.data.user
const oid = res.data.openId || user.openId
if (oid) {
this.globalData.openId = oid
wx.setStorageSync('openId', oid)
}
this.globalData.userInfo = user
this.globalData.isLoggedIn = true
this.globalData.purchasedSections = user.purchasedSections || []
@@ -1154,6 +1169,7 @@ App({
} else {
checkAndExecute('after_login', null)
setTimeout(() => this.checkVipContactRequiredAndGuide(), 1200)
setTimeout(() => this.connectWsHeartbeat(), 2000)
}
return res.data
@@ -1198,9 +1214,10 @@ App({
return (this.globalData.readSectionIds || []).length
},
// 获取章节总数
// 获取章节总数(优先 API 已加载值,失败时返回统一兜底常量)
getTotalSections() {
return this.globalData.totalSections
const v = this.globalData.totalSections
return (v != null && v > 0) ? v : FALLBACK_TOTAL_SECTIONS
},
// 切换TabBar