From 117da08d652db513d8889924ea12b13aed68fba2 Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期二, 16 七月 2024 14:59:09 +0800
Subject: [PATCH] 提交

---
 pages/tabBar/firstPage/exam.vue |  165 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 130 insertions(+), 35 deletions(-)

diff --git a/pages/tabBar/firstPage/exam.vue b/pages/tabBar/firstPage/exam.vue
index 347c1b8..72f2f06 100644
--- a/pages/tabBar/firstPage/exam.vue
+++ b/pages/tabBar/firstPage/exam.vue
@@ -33,10 +33,11 @@
               v-if="currentQ.questionType==2"
               v-model="currentQ.exExerciseAnswer.answer"
               placement="column"
+              :disabled="viewType==1?false:true"
               @change="checkboxChange"
           >
             <u-checkbox
-                :customStyle="{marginBottom: '20px'}"
+                :customStyle="{marginBottom: '15px'}"
                 v-for="(item, index) in currentQ.content.items"
                 :key="index"
                 :label="item.prefix +':'+ item.content"
@@ -44,9 +45,9 @@
             >
             </u-checkbox>
           </u-checkbox-group>
-          <u-radio-group v-model="currentQ.exExerciseAnswer.answer" placement="column" @change="groupChange" v-if="currentQ.questionType==1||currentQ.questionType==3" >
+          <u-radio-group v-model="currentQ.exExerciseAnswer.answer" placement="column" @change="groupChange" v-if="currentQ.questionType==1||currentQ.questionType==3" :disabled="viewType==1?false:true">
             <u-radio
-                :customStyle="{marginBottom: '20px'}"
+                :customStyle="{marginBottom: '15px'}"
                 v-for="(item, index) in currentQ.content.items"
                 :key="index"
                 shape="square"
@@ -56,11 +57,15 @@
             >
             </u-radio>
           </u-radio-group>
-          <u-button style="width: 90%;margin: 30px auto" v-if="currentQ.exExerciseAnswer && currentQ.exExerciseAnswer.answer" type="primary" shape="circle" size="small" text="确认答案" @click="confirmAnswer"></u-button>
-          <view class="answers" v-if="currentQ.exExerciseAnswer && (currentQ.exExerciseAnswer.passed==0||currentQ.exExerciseAnswer.passed==1)">
+          <u-button style="width: 80%;margin: 30px auto"
+                    v-if="viewType ==1 && (currentQ.exExerciseAnswer && currentQ.exExerciseAnswer.answer && (typeof currentQ.exExerciseAnswer.answer == String?currentQ.exExerciseAnswer.answer !=='':currentQ.exExerciseAnswer.answer.length>0))"
+                    type="primary" shape="circle" text="确认答案"
+                    @click="confirmAnswer">
+          </u-button>
+          <view class="answers" v-if="viewType == 2 && currentQ.studentAnswer && currentQ.studentAnswer.answer">
             <view>你的答案:
-              <span v-if="currentQ.questionType==2" :class="currentQ.answer == currentQ.exExerciseAnswer.answer.join(',')?'right':'wrong'">{{currentQ.exExerciseAnswer.answer.join(',')}}</span>
-              <span v-else :class="currentQ.answer == currentQ.exExerciseAnswer.answer?'right':'wrong'">{{currentQ.exExerciseAnswer.answer}}</span>
+              <span v-if="currentQ.questionType==2" :class="currentQ.answer == currentQ.studentAnswer.answer?'right':'wrong'">{{currentQ.studentAnswer.answer}}</span>
+              <span v-else :class="currentQ.answer == currentQ.studentAnswer.answer?'right':'wrong'">{{currentQ.studentAnswer.answer}}</span>
             </view>
             <view>正确答案:<span class="right">{{currentQ.answer}}</span></view>
           </view>
@@ -71,13 +76,18 @@
       <u-button style="width: 30%" type="error" shape="circle" size="small" text="上一题" @click="prevQ"></u-button>
 <!--      <u-button style="width: 30%" type="error" shape="circle" plain size="small" text="查看答案" @click="showA"></u-button>-->
       <u-button v-if="currentIndex<questionList.length - 1" style="width: 30%" type="error" shape="circle" size="small" text="下一题" @click="nextQ"></u-button>
-      <u-button v-if="currentIndex==questionList.length - 1" style="width: 30%" type="primary" shape="circle" size="small" text="保存退出" @click="goBack"></u-button>
+      <u-button v-if="currentIndex==questionList.length - 1 && viewType == 1" style="width: 30%" type="primary" shape="circle" size="small" text="保存退出" @click="endExam"></u-button>
+      <u-button v-if="currentIndex==questionList.length - 1 && viewType == 2" style="width: 30%" type="primary" shape="circle" size="small" text="退出" @click="goBack"></u-button>
     </view>
 	</view>
 </template>
 
 <script>
-import {getQuestionIdList,getQuestionByIds,postExerciseAnswer} from '../../../api/wearhouse.js'
+import {
+  getExamIdIdList,
+  getExamListByIds, postExamAnswer,postEndExam
+} from '../../../api/wearhouse.js'
+import Vue from 'vue'
 
 export default {
 	components: {
@@ -90,17 +100,19 @@
       idList: [],
       questionList: [],
       currentIndex: 0,
-      currentQ: {}
+      currentQ: {},
+      currentA: '',
+      currentB: [],
+      viewType: null
 		}
 	},
   onReady(){
   },
 	onLoad(e) {
-    this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
-    this.bank = e.bank && JSON.parse(decodeURIComponent(e.bank));
-    this.currentIndex = this.bank.exerciseCount
-    console.log(this.bank,this.currentIndex,66)
-    this.getQuestionIds(this.bank.id)
+    this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight']
+    this.bank = e.bank && JSON.parse(decodeURIComponent(e.bank))
+    this.viewType = e.type && JSON.parse(decodeURIComponent(e.type))
+    this.getQuestionIds(this.bank.paperId)
 	},
 	onShow(){
 
@@ -121,15 +133,20 @@
 
   methods: {
     async getQuestionIds(id){
-      const res = await getQuestionIdList({bankId: id})
+      const res = await getExamIdIdList({paperId: id,viewType: this.viewType})
       if(res.code == 200){
         let list = res.data || []
         if(list.length>0){
           this.idList = list
-          getQuestionByIds({questionIds: list.map(i=>i.id)}).then(re=>{
+          getExamListByIds({paperId: id,questionIds: list.map(i=>i.id)}).then(re=>{
             if(re.code == 200){
               this.questionList = re.data.map(i=>{
                 i.content = JSON.parse(i.content)
+                Vue.set(i,'passed',null)
+                if(i.studentAnswer){
+                  i.exExerciseAnswer.answer = i.studentAnswer.answer
+                  i.exExerciseAnswer.passed = i.studentAnswer.passed
+                }
                 if(i.questionType == 2){
                   if(i.exExerciseAnswer.answer){
                     i.exExerciseAnswer.answer = i.exExerciseAnswer.answer.split(',')
@@ -138,7 +155,6 @@
                 return i
               })
               this.currentQ = this.questionList[this.currentIndex]
-              // this.currentQ.content = JSON.parse(this.currentQ.content)
               console.log(this.currentQ,'当前问题')
             }else{
               uni.$u.toast(res.message)
@@ -168,12 +184,14 @@
     confirmAnswer(){
       const data = {
         answer: this.currentQ.questionType==2?this.currentQ.exExerciseAnswer.answer.join(','):this.currentQ.exExerciseAnswer.answer,
-        bankId: this.bank.id,
-        questionId: this.currentQ.id
+        paperId: this.bank.paperId,
+        questionId: this.currentQ.id,
+        studentId: uni.getStorageSync('uid')
       }
-      postExerciseAnswer(data).then(res=>{
+      postExamAnswer(data).then(res=>{
         if(res.code == 200){
-          this.currentQ.exExerciseAnswer.passed = res.data.passed
+          this.currentQ.passed = res.data
+          uni.$u.toast('答案已提交')
         }else{
           uni.$u.toast(res.message)
         }
@@ -190,11 +208,10 @@
           duration: 1000
         });
       }
-      console.log(this.currentQ,'current')
     },
 
     nextQ(){
-      if(this.currentQ.exExerciseAnswer.passed==null){
+      if(this.currentQ.passed==null && this.currentQ.exExerciseAnswer.passed == null){
         uni.$u.toast('请先完成当前题目')
         return
       }
@@ -208,6 +225,46 @@
         });
       }
       console.log(this.currentQ,'current')
+    },
+
+    endExam(){
+      if(this.currentQ.passed==null && this.currentQ.exExerciseAnswer.passed == null){
+        uni.$u.toast('请先完成当前题目')
+        return
+      }
+      const data = {
+        id: this.bank.id,
+        // paperId: this.bank.paperId,
+        // studentId: uni.getStorageSync('uid')
+      }
+      postEndExam(data).then(res=>{
+        if(res.code == 200){
+          uni.showToast({
+            title: '本次考试结束',
+            duration: 1500
+          })
+          setTimeout(()=>{
+            const url = uni.getStorageSync("prevPage");
+            if(url){
+              if(url == '/pages/tabBar/firstPage/firstPage'){
+                uni.reLaunch({
+                  url:'/pages/tabBar/firstPage/firstPage'
+                });
+              }else{
+                uni.navigateTo({
+                  url: url
+                })
+              }
+            } else{
+              uni.reLaunch({
+                url: '/pages/tabBar/firstPage/firstPage'
+              })
+            }
+          },1500)
+        }else{
+          uni.$u.toast(res.message)
+        }
+      })
     },
 
     showA(){
@@ -226,18 +283,12 @@
     goBack(){
       const url = uni.getStorageSync("prevPage");
       if(url){
-        if(url == '/pages/tabBar/wearhouse/wearhouse'){
-          uni.reLaunch({
-            url:'/pages/tabBar/wearhouse/wearhouse'
-          });
-        }else{
-          uni.navigateTo({
-            url: url
-          })
-        }
+        uni.reLaunch({
+          url: url
+        });
       } else{
         uni.reLaunch({
-          url: '/pages/tabBar/wearhouse/wearhouse'
+          url: '/pages/tabBar/firstPage/firstPage'
         })
       }
     }
@@ -294,7 +345,10 @@
 
       .answers{
         background: #ecf5ff;
-        padding: 5px 10px;
+        padding: 10px;
+        &>view{
+          margin-bottom: 5px;
+        }
 
         span{
           font-weight: bolder;
@@ -319,4 +373,45 @@
   bottom: 60px;
   left: 0;
 }
+
+/deep/ .u-checkbox{
+  background: #fff;
+  padding: 10px;
+  box-sizing: border-box;
+  border-radius: 8px;
+}
+
+/deep/ .u-radio,.u-checkbox{
+  padding: 12px 10px;
+  box-sizing: border-box;
+  border-radius: 8px;
+  background: #f5f7fa;
+  border: 1px solid #fff;
+  box-shadow: 7px 7px 15px rgba(55, 84, 170, .15),
+  -7px -7px 20px rgba(255, 255, 255, 1),
+  inset 0px 0px 4px rgba(255, 255, 255, .2),
+  inset 7px 7px 15px rgba(55, 84, 170, 0),
+  inset -7px -7px 20px rgba(255, 255, 255, 0),
+  0px 0px 4px rgba(255, 255, 255, 0) !important;
+  transition: box-shadow .25s ease !important;
+}
+
+/deep/ .u-checkbox:active {
+  box-shadow: 7px 7px 15px rgba(55, 84, 170, .15),
+  -7px -7px 20px rgba(255, 255, 255, 1),
+  inset 0px 0px 4px rgba(255, 255, 255, 0),
+  inset 7px 7px 15px rgba(55, 84, 170, .15),
+  inset -7px -7px 20px rgba(255, 255, 255, 1),
+  0px 0px 4px rgba(255, 255, 255, .2) !important;
+}
+
+/deep/ .u-radio:active {
+  box-shadow: 7px 7px 15px rgba(55, 84, 170, .15),
+  -7px -7px 20px rgba(255, 255, 255, 1),
+  inset 0px 0px 4px rgba(255, 255, 255, 0),
+  inset 7px 7px 15px rgba(55, 84, 170, .15),
+  inset -7px -7px 20px rgba(255, 255, 255, 1),
+  0px 0px 4px rgba(255, 255, 255, .2) !important;
+}
+
 </style>

--
Gitblit v1.9.2