feat: 做好了扫描兼容处理
This commit is contained in:
@@ -73,11 +73,30 @@ Page({
|
||||
},
|
||||
|
||||
async onLoad(options) {
|
||||
// 扫码进入时 id 可能在 app.globalData.initialSectionId(scene 里 id=1.1 由 app 解析)
|
||||
// 扫码进入时:options.id 无;id 可能在 app.globalData.initialSectionId(App 解析 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] 未获取到章节 id,options:', options)
|
||||
wx.showToast({ title: '章节参数缺失', icon: 'none' })
|
||||
this.setData({ accessState: 'error', loading: false })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
statusBarHeight: app.globalData.statusBarHeight,
|
||||
navBarHeight: app.globalData.navBarHeight,
|
||||
|
||||
Reference in New Issue
Block a user