Parcourir la source

fix(frontend): 海报扫码进入文章/活动详情页解析 scene 参数,修复参数错误

asus il y a 3 semaines
Parent
commit
94969a17bc

+ 13 - 2
cfc-frontend/pages/activity/activity-detail/activity-detail.vue

@@ -314,9 +314,20 @@ export default {
     }
   },
   onLoad: function(options) {
+    var aid = ''
     if (options && options.id) {
-      this.activityId = options.id
-      this.loadDetail(options.id)
+      aid = options.id
+    } else if (options && options.scene) {
+      // 扫码进入:getUnlimited 小程序码把参数放在 options.scene(URL编码)
+      try {
+        var sceneDecoded = decodeURIComponent(options.scene)
+        var idMatch = sceneDecoded.match(/id=(\d+)/)
+        if (idMatch && idMatch[1]) aid = idMatch[1]
+      } catch (e) {}
+    }
+    if (aid) {
+      this.activityId = aid
+      this.loadDetail(aid)
     } else {
       this.error = true
       this.errorMsg = '缺少活动ID'

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

@@ -105,7 +105,17 @@ export default {
   onLoad(options) {
     this.mascotIcon = this.mascotList[Math.floor(Math.random() * 2)].icon
     this.mascotName = this.mascotList[Math.floor(Math.random() * 2)].name
-    if (options && options.id) { this.articleId = options.id; this.loadDetail(options.id) }
+    var aid = ''
+    if (options && options.id) {
+      aid = options.id
+    } else if (options && options.scene) {
+      try {
+        var sceneDecoded = decodeURIComponent(options.scene)
+        var idMatch = sceneDecoded.match(/id=(\d+)/)
+        if (idMatch && idMatch[1]) aid = idMatch[1]
+      } catch (e) {}
+    }
+    if (aid) { this.articleId = aid; this.loadDetail(aid) }
     else { this.error = true; this.errorMsg = '参数错误'; this.loading = false }
   },
   onShow() { if (this.article && !this.error) this.startNewReadingSession() },