Просмотр исходного кода

fix: 统一文章/商品/活动推广分享邀请人参数 + 兼容旧分享链接

- join.vue: 解析 query.inviteCode/refCode/场景值(ref=/裸6位), 无参数旧链接跳首页
- 三个详情页: onLoad 显式处理 inviteCode + 海报二维码 scene 带 &ref= 邀请码
- promotion/index.vue: onShareAppMessage 带上 inviteCode=分享码(与 invite.vue 一致)
Xiaogang Liao 2 месяцев назад
Родитель
Сommit
dea7fb76f5

+ 14 - 1
cfc-frontend/pages/activity/activity-detail/activity-detail.vue

@@ -314,6 +314,10 @@ export default {
     }
     }
   },
   },
   onLoad: function(options) {
   onLoad: function(options) {
+    // 兼容旧分享链接:inviteCode 参数(shareMixin onLoad 也会处理,此处显式兜底)
+    if (options && options.inviteCode) {
+      this.autoBindInviteCode(options.inviteCode)
+    }
     var aid = ''
     var aid = ''
     if (options && options.id) {
     if (options && options.id) {
       aid = options.id
       aid = options.id
@@ -323,6 +327,8 @@ export default {
         var sceneDecoded = decodeURIComponent(options.scene)
         var sceneDecoded = decodeURIComponent(options.scene)
         var idMatch = sceneDecoded.match(/id=(\d+)/)
         var idMatch = sceneDecoded.match(/id=(\d+)/)
         if (idMatch && idMatch[1]) aid = idMatch[1]
         if (idMatch && idMatch[1]) aid = idMatch[1]
+        var refMatch = sceneDecoded.match(/ref=([^&]+)/)
+        if (refMatch && refMatch[1]) this.autoBindInviteCode(refMatch[1])
       } catch (e) {}
       } catch (e) {}
     }
     }
     if (aid) {
     if (aid) {
@@ -663,7 +669,14 @@ export default {
       }
       }
       uni.showLoading({ title: '生成海报中...' })
       uni.showLoading({ title: '生成海报中...' })
       try {
       try {
-        var res = await getShareQrCode('pages/activity/activity-detail/activity-detail', 'id=' + this.activity.id)
+        if (!this.referralCode) {
+          await this.loadReferralCode()
+        }
+        var scene = 'id=' + this.activity.id + (this.referralCode ? '&ref=' + this.referralCode : '')
+        if (scene.length > 32) {
+          scene = scene.substring(0, 32)
+        }
+        var res = await getShareQrCode('pages/activity/activity-detail/activity-detail', scene)
         if (res && res.data) {
         if (res && res.data) {
           this.posterQrCode = res.data.qrCodeBase64 || ''
           this.posterQrCode = res.data.qrCodeBase64 || ''
           this.posterSummary = this.buildPosterSummary()
           this.posterSummary = this.buildPosterSummary()

+ 14 - 1
cfc-frontend/pages/article-center/article-detail.vue

@@ -105,6 +105,10 @@ export default {
   onLoad(options) {
   onLoad(options) {
     this.mascotIcon = this.mascotList[Math.floor(Math.random() * 2)].icon
     this.mascotIcon = this.mascotList[Math.floor(Math.random() * 2)].icon
     this.mascotName = this.mascotList[Math.floor(Math.random() * 2)].name
     this.mascotName = this.mascotList[Math.floor(Math.random() * 2)].name
+    // 兼容旧分享链接:inviteCode 参数(shareMixin onLoad 也会处理,此处显式兜底)
+    if (options && options.inviteCode) {
+      this.autoBindInviteCode(options.inviteCode)
+    }
     var aid = ''
     var aid = ''
     if (options && options.id) {
     if (options && options.id) {
       aid = options.id
       aid = options.id
@@ -113,6 +117,8 @@ export default {
         var sceneDecoded = decodeURIComponent(options.scene)
         var sceneDecoded = decodeURIComponent(options.scene)
         var idMatch = sceneDecoded.match(/id=(\d+)/)
         var idMatch = sceneDecoded.match(/id=(\d+)/)
         if (idMatch && idMatch[1]) aid = idMatch[1]
         if (idMatch && idMatch[1]) aid = idMatch[1]
+        var refMatch = sceneDecoded.match(/ref=([^&]+)/)
+        if (refMatch && refMatch[1]) this.autoBindInviteCode(refMatch[1])
       } catch (e) {}
       } catch (e) {}
     }
     }
     if (aid) { this.articleId = aid; this.loadDetail(aid) }
     if (aid) { this.articleId = aid; this.loadDetail(aid) }
@@ -219,7 +225,14 @@ export default {
       if (!this.articleId) return
       if (!this.articleId) return
       uni.showLoading({ title: '生成海报中...' })
       uni.showLoading({ title: '生成海报中...' })
       try {
       try {
-        var res = await getShareQrCode('pages/article-center/article-detail', 'id=' + this.articleId)
+        if (!this.referralCode) {
+          await this.loadReferralCode()
+        }
+        var scene = 'id=' + this.articleId + (this.referralCode ? '&ref=' + this.referralCode : '')
+        if (scene.length > 32) {
+          scene = scene.substring(0, 32)
+        }
+        var res = await getShareQrCode('pages/article-center/article-detail', scene)
         if (res && res.data) {
         if (res && res.data) {
           this.posterQrCode = res.data.qrCodeBase64 || ''
           this.posterQrCode = res.data.qrCodeBase64 || ''
           this.posterDimension = this.getMainDimension()
           this.posterDimension = this.getMainDimension()

+ 4 - 0
cfc-frontend/pages/discover-detail/product-detail/product-detail.vue

@@ -283,6 +283,10 @@ export default {
     }
     }
   },
   },
   onLoad(options) {
   onLoad(options) {
+    // 兼容旧分享链接:inviteCode 参数(shareMixin onLoad 也会处理,此处显式兜底)
+    if (options && options.inviteCode) {
+      this.autoBindInviteCode(options.inviteCode)
+    }
     var pid = options && options.id ? options.id : ''
     var pid = options && options.id ? options.id : ''
     if (options && options.scene) {
     if (options && options.scene) {
       try {
       try {

+ 26 - 11
cfc-frontend/pages/invite/join.vue

@@ -173,7 +173,17 @@ export default {
     }
     }
   },
   },
   onLoad(query) {
   onLoad(query) {
-    // token:优先从 query 参数,其次从场景值
+    // 邀请码(推荐人)统一解析:query.inviteCode / query.refCode / 场景值 ref=xxx
+    // 分享链接用 inviteCode,落地页内部用 refCode,二维码场景值用 ref= 前缀
+    var refCode = query.refCode || query.inviteCode || ''
+    if (!refCode && query.scene) {
+      var refScene = decodeURIComponent(query.scene)
+      if (refScene.indexOf('ref=') === 0) {
+        refCode = refScene.substring(4)
+      }
+    }
+
+    // token(家庭邀请):优先从 query 参数,其次从场景值
     var token = query.token || query.inviteToken || ''
     var token = query.token || query.inviteToken || ''
     if (!token) {
     if (!token) {
       var scene = query.scene
       var scene = query.scene
@@ -190,23 +200,24 @@ export default {
         } else if (sceneDecoded.indexOf('invite=') === 0) {
         } else if (sceneDecoded.indexOf('invite=') === 0) {
           // 旧格式兼容
           // 旧格式兼容
           token = sceneDecoded.substring(7)
           token = sceneDecoded.substring(7)
+        } else if (sceneDecoded.indexOf('ref=') === 0) {
+          // 推广码场景值(ref=xxx),已在上方解析为 refCode,不作为 token
+          token = ''
+        } else if (sceneDecoded.length === 6) {
+          // 裸邀请码场景值(InviteController 生成的二维码 scene=referralCode,6位)
+          // 归为推广码,不作为家庭 token
+          refCode = refCode || sceneDecoded
+          token = ''
         } else {
         } else {
           token = sceneDecoded
           token = sceneDecoded
         }
         }
       }
       }
     }
     }
 
 
-    // refCode:query.refCode 或场景值(ref=xxx)— 推广码注册绑定
-    var refCode = query.refCode || ''
-    if (!refCode && query.scene) {
-      var refScene = decodeURIComponent(query.scene)
-      if (refScene.indexOf('ref=') === 0) {
-        refCode = refScene.substring(4)
-      }
-    }
     if (!token && !refCode) {
     if (!token && !refCode) {
-      this.error = '邀请链接无效'
-      this.loading = false
+      // 兼容旧分享链接(promotion/index.vue 旧版 onShareAppMessage 不带参数)
+      // 无有效邀请信息时跳转首页,不显示"邀请链接无效"死页面
+      uni.reLaunch({ url: '/pages/index-home/index' })
       return
       return
     }
     }
     if (refCode) {
     if (refCode) {
@@ -327,6 +338,10 @@ export default {
 
 
           this.isLoggedIn = true
           this.isLoggedIn = true
           uni.showToast({ title: '登录成功', icon: 'success' })
           uni.showToast({ title: '登录成功', icon: 'success' })
+          // 兼容旧分享链接:登录成功后自动绑定推广码(与 login.vue 流程一致)
+          if (this.refCode && !this.bindDone) {
+            await this.bindRef()
+          }
           // 重新检查家庭状态
           // 重新检查家庭状态
           await this.checkFamily()
           await this.checkFamily()
         }
         }

+ 14 - 8
cfc-frontend/pages/promotion/index.vue

@@ -264,6 +264,7 @@ export default {
   },
   },
   onLoad() {
   onLoad() {
     this.loadData()
     this.loadData()
+    this.ensureShareCode()
   },
   },
   onShow() {
   onShow() {
     this.loadStats()
     this.loadStats()
@@ -272,6 +273,9 @@ export default {
   },
   },
   onShareAppMessage() {
   onShareAppMessage() {
     var path = '/pages/invite/join'
     var path = '/pages/invite/join'
+    if (this.shareReferralCode) {
+      path = path + '?inviteCode=' + this.shareReferralCode
+    }
     return {
     return {
       title: '我在浠艾福发现了好用的家庭成长工具,快来加入!',
       title: '我在浠艾福发现了好用的家庭成长工具,快来加入!',
       path: path,
       path: path,
@@ -279,6 +283,15 @@ export default {
     }
     }
   },
   },
   methods: {
   methods: {
+    async ensureShareCode() {
+      if (this.shareReferralCode) return
+      try {
+        var codeRes = await getReferralCode()
+        if (codeRes && codeRes.data) {
+          this.shareReferralCode = codeRes.data.referralCode || codeRes.data.code || ''
+        }
+      } catch (e) {}
+    },
     async loadData() {
     async loadData() {
       try {
       try {
         var summaryRes = await getReferralSummary()
         var summaryRes = await getReferralSummary()
@@ -485,14 +498,7 @@ export default {
     async shareToFriend() {
     async shareToFriend() {
       uni.showLoading({ title: '生成中...' })
       uni.showLoading({ title: '生成中...' })
       try {
       try {
-        if (!this.shareReferralCode) {
-          try {
-            var codeRes = await getReferralCode()
-            if (codeRes && codeRes.data) {
-              this.shareReferralCode = codeRes.data.referralCode || codeRes.data.code || ''
-            }
-          } catch (e) {}
-        }
+        await this.ensureShareCode()
         var qrRes = await getInviteQrCode()
         var qrRes = await getInviteQrCode()
         if (qrRes && qrRes.data) {
         if (qrRes && qrRes.data) {
           this.inviteQrCode = qrRes.data.qrCodeBase64 || ''
           this.inviteQrCode = qrRes.data.qrCodeBase64 || ''