优化小程序推荐码处理逻辑,支持通过扫码场景解析推荐码和初始章节ID。新增获取用户邀请码的功能以便于分享。更新分享配置,确保分享时自动带上推荐码。调整部分页面逻辑以提升用户体验。

This commit is contained in:
2026-02-12 15:09:52 +08:00
parent c57866ffe0
commit 448e908855
40 changed files with 1068 additions and 318 deletions

View File

@@ -82,10 +82,24 @@ App({
this.handleReferralCode(options)
},
// 处理推荐码绑定
// 处理推荐码绑定(支持 query.ref 与扫码 scenescene 可能为 ref=SOULXXX 或 id=1.1_ref=xxx后端会把 & 转成 _
handleReferralCode(options) {
const query = options?.query || {}
const refCode = query.ref || query.referralCode
let refCode = query.ref || query.referralCode
if (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) {
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 (refCode) {
console.log('[App] 检测到推荐码:', refCode)
@@ -161,6 +175,15 @@ App({
}
},
// 获取当前用户的邀请码(用于分享带 ref未登录返回空字符串
getMyReferralCode() {
const user = this.globalData.userInfo
if (!user) return ''
if (user.referralCode) return user.referralCode
if (user.id) return 'SOUL' + String(user.id).toUpperCase().slice(-6)
return ''
},
// 获取系统信息
getSystemInfo() {
try {