重构推荐码处理逻辑,整合 scene 解析功能,优化扫码参数接收。更新阅读页面逻辑,支持通过 scene 解析 mid、id 和 ref,提升用户体验。新增二维码生成逻辑,确保与 scene 生成闭环。
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
* 开发: 卡若
|
||||
*/
|
||||
|
||||
const { parseScene } = require('./utils/scene.js')
|
||||
|
||||
App({
|
||||
globalData: {
|
||||
// API基础地址 - 连接真实后端
|
||||
@@ -83,29 +85,17 @@ App({
|
||||
this.handleReferralCode(options)
|
||||
},
|
||||
|
||||
// 处理推荐码绑定(支持 query.ref 与扫码 scene;scene 可能为 ref=SOULXXX 或 id=1.1_ref=xxx,后端会把 & 转成 _)
|
||||
// 扫码进入时:options.scene 为场景值(1047),自定义 scene 在 options.query.scene
|
||||
// 处理推荐码绑定:官方以 options.scene 接收扫码参数(可同时带 mid/id + ref),与 utils/scene 解析闭环
|
||||
handleReferralCode(options) {
|
||||
const query = options?.query || {}
|
||||
let refCode = query.ref || query.referralCode
|
||||
// 扫码进入时自定义 scene 在 query.scene;options.scene 为场景值(1047)
|
||||
const sceneStr = query?.scene || (typeof options?.scene === 'string' ? options.scene : null)
|
||||
const sceneStr = (options && (typeof options.scene === 'string' ? options.scene : '')) || ''
|
||||
if (sceneStr) {
|
||||
const scene = (typeof sceneStr === 'string' ? decodeURIComponent(sceneStr) : '').trim()
|
||||
// 支持 _ 或 & 作为参数分隔符(后端生成小程序码时会把 & 转为 _)
|
||||
const parts = scene.split(/[&_]/)
|
||||
for (const part of parts) {
|
||||
const eq = part.indexOf('=')
|
||||
if (eq > 0) {
|
||||
const key = part.slice(0, eq)
|
||||
const val = part.slice(eq + 1)
|
||||
if (key === 'ref') refCode = val
|
||||
if (key === 'id' && val) this.globalData.initialSectionId = val
|
||||
if (key === 'mid' && val) this.globalData.initialSectionMid = parseInt(val, 10) || 0
|
||||
}
|
||||
}
|
||||
const parsed = parseScene(sceneStr)
|
||||
if (parsed.mid) this.globalData.initialSectionMid = parsed.mid
|
||||
if (parsed.id) this.globalData.initialSectionId = parsed.id
|
||||
if (parsed.ref) refCode = parsed.ref
|
||||
}
|
||||
|
||||
if (refCode) {
|
||||
console.log('[App] 检测到推荐码:', refCode)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user