Browse Source

feat: 文章答题弹窗适配新接口并展示CF值

Sisyphus 19 giờ trước cách đây
mục cha
commit
496af7d0ed
1 tập tin đã thay đổi với 12 bổ sung10 xóa
  1. 12 10
      cfc-frontend/pages/article-center/article-detail.vue

+ 12 - 10
cfc-frontend/pages/article-center/article-detail.vue

@@ -77,7 +77,7 @@
       <view class="result-dialog">
         <text class="result-icon">{{ resultIcon }}</text>
         <text class="result-text">答对 {{ quizResult.correctCount }}/{{ quizResult.totalQuestions }} 题</text>
-        <text class="result-energy">获得 {{ quizResult.earnedEnergy }} 能量 ⚡</text>
+        <text class="result-energy">获得 {{ quizResult.cfEarned }} CF值 + {{ quizResult.energyEarned }} 能量 ⚡</text>
         <button class="result-btn" @click="closeResult">知道了</button>
       </view>
     </view>
@@ -104,7 +104,7 @@ export default {
       posterDimension: '', posterSummary: '', posterInviteText: '',
       contentTagStyle: { p: 'font-size:32rpx;color:#444;line-height:1.8;', div: 'font-size:32rpx;color:#444;line-height:1.8;', section: 'font-size:32rpx;color:#444;line-height:1.8;', li: 'font-size:32rpx;color:#444;line-height:1.8;', blockquote: 'font-size:32rpx;color:#444;line-height:1.8;' },
       // 答题
-      showQuiz: false, quizQuestions: [], quizAnswers: [], showResult: false, quizResult: {},
+      showQuiz: false, quizQuestions: [], quizAnswers: [], showResult: false, quizResult: {}, quizRecordId: null,
       mascotList: [{ icon: '🐶', name: '浠宝' }, { icon: '🐼', name: '福宝' }],
       mascotIcon: '🐶', mascotName: '浠宝'
     }
@@ -267,24 +267,26 @@ export default {
           setTimeout(function() { uni.navigateTo({ url: '/pages/membership/upgrade' }) }, 1500)
           return
         }
-        var res = await generateQuiz({ articleId: this.articleId })
-        if (res.code === 200 && res.data && res.data.length > 0) {
-          this.quizQuestions = res.data
+        var memberId = uni.getStorageSync('currentChildId')
+        var res = await generateQuiz({ articleId: this.articleId, memberId: parseInt(memberId || 0) })
+        if (res.code === 200 && res.data && res.data.questions && res.data.questions.length > 0) {
+          this.quizRecordId = res.data.recordId
+          this.quizQuestions = res.data.questions
           this.quizAnswers = []
           this.showQuiz = true
         }
       } catch (e) {}
     },
     async submitQuiz() {
-      var correct = 0
+      var memberId = uni.getStorageSync('currentChildId')
+      var answers = []
       for (var i = 0; i < this.quizQuestions.length; i++) {
-        if (this.quizAnswers[i] === this.quizQuestions[i].answer) correct++
+        answers.push(this.quizAnswers[i] || '')
       }
-      var memberId = uni.getStorageSync('currentChildId')
       try {
-        var res = await submitQuiz({ correctCount: correct, memberId: parseInt(memberId || 0) })
+        var res = await submitQuiz({ recordId: this.quizRecordId, memberId: parseInt(memberId || 0), answers: answers })
         if (res.code === 200) {
-          this.quizResult = res.data || { correctCount: correct, totalQuestions: 3, earnedEnergy: correct * 5 }
+          this.quizResult = res.data || {}
           this.showQuiz = false
           this.showResult = true
         }