feat: 做好了扫描兼容处理

This commit is contained in:
乘风
2026-02-12 15:17:39 +08:00
parent df359f0a35
commit 046e686cda
3 changed files with 34 additions and 5 deletions

View File

@@ -73,11 +73,30 @@ Page({
},
async onLoad(options) {
// 扫码进入时 id 可能在 app.globalData.initialSectionIdscene 里 id=1.1 由 app 解析
// 扫码进入时options.id 无;id 可能在 app.globalData.initialSectionIdApp 解析 query.scene
// 或直接在 options.scene 中(页面 query 为 ?scene=id%3D1.1,后端把 & 转成 _
let id = options.id || app.globalData.initialSectionId
if (!id && options.scene) {
const scene = (typeof options.scene === 'string' ? decodeURIComponent(options.scene) : '').trim()
const parts = scene.split(/[&_]/)
for (const part of parts) {
const eq = part.indexOf('=')
if (eq > 0 && part.slice(0, eq) === 'id') {
id = part.slice(eq + 1)
break
}
}
}
if (app.globalData.initialSectionId) delete app.globalData.initialSectionId
const ref = options.ref
if (!id) {
console.warn('[Read] 未获取到章节 idoptions:', options)
wx.showToast({ title: '章节参数缺失', icon: 'none' })
this.setData({ accessState: 'error', loading: false })
return
}
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
navBarHeight: app.globalData.navBarHeight,