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

@@ -83,11 +83,14 @@ App({
},
// 处理推荐码绑定(支持 query.ref 与扫码 scenescene 可能为 ref=SOULXXX 或 id=1.1_ref=xxx后端会把 & 转成 _
// 扫码进入时options.scene 为场景值(1047),自定义 scene 在 options.query.scene
handleReferralCode(options) {
const query = options?.query || {}
let refCode = query.ref || query.referralCode
if (options?.scene) {
const scene = (typeof options.scene === 'string' ? decodeURIComponent(options.scene) : '').trim()
// 扫码进入时自定义 scene 在 query.sceneoptions.scene 为场景值(1047)
const sceneStr = query?.scene || (typeof options?.scene === 'string' ? options.scene : null)
if (sceneStr) {
const scene = (typeof sceneStr === 'string' ? decodeURIComponent(sceneStr) : '').trim()
// 支持 _ 或 & 作为参数分隔符(后端生成小程序码时会把 & 转为 _
const parts = scene.split(/[&_]/)
for (const part of parts) {

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,

View File

@@ -23,12 +23,19 @@
"condition": {
"miniprogram": {
"list": [
{
"name": "ces",
"pathName": "pages/read/read",
"query": "scene=id%3D1.1",
"scene": null,
"launchMode": "default"
},
{
"name": "pages/read/read",
"pathName": "pages/read/read",
"query": "id=1.2",
"scene": null,
"launchMode": "default"
"launchMode": "default",
"scene": null
}
]
}