From 3d73fb33c46aada16a6060adcd4ea14bb33b6b2a Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 09 四月 2024 10:39:11 +0800
Subject: [PATCH] 详情页tabs样式优化,答题添加页面退出拦截,合并代码

---
 packageBookService/pages/bookServices/examination/questionOptions/index.js |  230 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 121 insertions(+), 109 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/questionOptions/index.js b/packageBookService/pages/bookServices/examination/questionOptions/index.js
index e627970..40919c9 100644
--- a/packageBookService/pages/bookServices/examination/questionOptions/index.js
+++ b/packageBookService/pages/bookServices/examination/questionOptions/index.js
@@ -1,4 +1,3 @@
-
 // pages/bookServices/examination/questionOptions/index.js
 Component({
   /**
@@ -11,15 +10,15 @@
     },
     questionDataList: {
       type: Array,
-      value: []
+      value: [],
     },
     cardList: {
       type: Array,
-      value: []
+      value: [],
     },
     subjectiveTotal: {
       type: Number,
-      value: 0
+      value: 0,
     },
     countdownTime: {
       type: Number,
@@ -27,23 +26,23 @@
     },
     answerType: {
       type: String,
-      value: ''
+      value: "",
     },
     subjectiveNum: {
       type: Number,
-      value: 0
+      value: 0,
     },
     subjectiveGrade: {
       type: Number,
-      value: 0
+      value: 0,
     },
     correctNum: {
       type: Number,
-      value: 0
+      value: 0,
     },
     submitStatus: {
       type: Boolean,
-      value: false
+      value: false,
     },
     mockSumTime: {
       type: Number,
@@ -51,8 +50,8 @@
     },
     isNight: {
       type: Boolean,
-      value: false
-    }
+      value: false,
+    },
   },
 
   /**
@@ -65,28 +64,34 @@
     setUpPopup: false,
     testReportState: false,
     sliderValue: 36,
-    useTime: '',
-    radioItem: 'daytime'
+    useTime: "",
+    radioItem: "daytime",
   },
   observers: {
-    "countdownTime": function (newValue, oldValue) {
-      if (this.properties.answerType == 'option') {
+    countdownTime: function (newValue, oldValue) {
+      if (this.properties.answerType == "option") {
         this.setData({
-          useTime: this.formatTime(2 * 60 * 60 * 1000 - this.properties.countdownTime)
-        })
-      }
-      else if (this.properties.answerType == 'option') {
+          useTime: this.formatTime(
+            2 * 60 * 60 * 1000 - this.properties.countdownTime
+          ),
+        });
+      } else if (this.properties.answerType == "option") {
         this.setData({
-          useTime: this.formatTime(this.properties.mockSumTime - this.properties.countdownTime)
-        })
+          useTime: this.formatTime(
+            this.properties.mockSumTime - this.properties.countdownTime
+          ),
+        });
       }
-      if (newValue == 0 && (this.properties.answerType == 'option' || this.properties.answerType == 'mock')) {
-        this.timeout()
+      if (
+        newValue == 0 &&
+        (this.properties.answerType == "option" ||
+          this.properties.answerType == "mock")
+      ) {
+        this.timeout();
       }
     },
   },
-  created() {
-  },
+  created() {},
 
   /**
    * 缁勪欢鐨勬柟娉曞垪琛�
@@ -96,61 +101,60 @@
     formatTime(ms) {
       const hours = Math.floor((ms / (1000 * 60 * 60)) % 24)
         .toString()
-        .padStart(2, '0')
+        .padStart(2, "0");
       const minutes = Math.floor((ms / (1000 * 60)) % 60)
         .toString()
-        .padStart(2, '0')
+        .padStart(2, "0");
       const seconds = Math.floor((ms / 1000) % 60)
         .toString()
-        .padStart(2, '0')
-      return `${hours}:${minutes}:${seconds}`
+        .padStart(2, "0");
+      return `${hours}:${minutes}:${seconds}`;
     },
     // 鍒ゆ柇鏄惁杈撳叆绛旀
     isHaveAnswer(data) {
-      if (typeof data == 'string') {
+      if (typeof data == "string") {
         data = data
-          .replace(/<[^>]*>/g, '')
-          .replace(/&nbsp;/g, '')
-          .trim()
+          .replace(/<[^>]*>/g, "")
+          .replace(/&nbsp;/g, "")
+          .trim();
         if (data.length) {
-          return true
+          return true;
         } else {
-          return false
+          return false;
         }
       } else {
-        const answer = data.find((item) => item.length > 0)
+        const answer = data.find((item) => item.length > 0);
         if (answer) {
-          return true
+          return true;
         } else {
-          return false
+          return false;
         }
       }
     },
     setCollect() {
-      var myEventDetail = {
-      }
+      var myEventDetail = {};
       var myEventOption = {
         bubbles: true,
         composed: true,
-      }
-      this.triggerEvent('setCollect', myEventDetail, myEventOption)
+      };
+      this.triggerEvent("setCollect", myEventDetail, myEventOption);
     },
     // 绛旈鍗℃寜閽�
     handlePopup() {
       this.setData({
-        questionCardState: true
-      })
+        questionCardState: true,
+      });
     },
     // 绛旈鍗¤烦杞鐩�
     goQuestion(e) {
       var myEventDetail = {
-        id: e.currentTarget.dataset.id
-      }
+        id: e.currentTarget.dataset.id,
+      };
       var myEventOption = {
         bubbles: true,
         composed: true,
-      }
-      this.triggerEvent('goQuestion', myEventDetail, myEventOption)
+      };
+      this.triggerEvent("goQuestion", myEventDetail, myEventOption);
     },
     // 绛旈鍗¢伄缃╁眰鐐瑰嚮
     onVisibleChange(e) {
@@ -161,136 +165,144 @@
     // 璁剧疆鎸夐挳
     setUpBtn() {
       this.setData({
-        setUpPopup: true
-      })
+        setUpPopup: true,
+      });
     },
     // 婊戝潡鍙樺寲
     onChangeSlider(e) {
-      const value = e.detail.value
+      const value = e.detail.value;
       console.log(value);
-      this.triggerEvent('onChangeSlider', { value })
+      this.triggerEvent("onChangeSlider", { value });
     },
     // 璁剧疆閬僵灞傜偣鍑�
     onSetUpChange(e) {
       this.setData({
-        setUpPopup: e.detail.visible
-      })
+        setUpPopup: e.detail.visible,
+      });
     },
     // 璁剧疆妯″紡鍒囨崲
     onRadioChange(e) {
       this.setData({
-        radioItem: e.detail.value
-      })
-      const value = e.detail.value == 'night' ? true : false
+        radioItem: e.detail.value,
+      });
+      const value = e.detail.value == "night" ? true : false;
       wx.setNavigationBarColor({
-        backgroundColor: '#222',
-        frontColor: '#222',
-      })
+        backgroundColor: "#222",
+        frontColor: "#222",
+      });
 
-      this.triggerEvent('changeBGColor', { value })
+      this.triggerEvent("changeBGColor", { value });
     },
     // 閲嶅仛鎸夐挳
     resterBtn() {
       wx.showModal({
-        title: '鎻愮ず',
-        content: '鏄惁閲嶆柊寮�濮嬬瓟棰橈紵',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
-        editable: false,//鏄惁鏄剧ず杈撳叆妗�
+        title: "鎻愮ず",
+        content: "鏄惁閲嶆柊寮�濮嬬瓟棰橈紵", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+        confirmColor: "#ff6c00",
+        cancelColor: "#949494",
+        editable: false, //鏄惁鏄剧ず杈撳叆妗�
         success: (res) => {
           if (res.confirm) {
-            this.restart()
+            this.restart();
           }
-        }
-      })
+        },
+      });
     },
     // 閲嶅仛浜嬩欢
     restart() {
-      var myEventDetail = {
-      }
+      var myEventDetail = {};
       var myEventOption = {
         bubbles: true,
         composed: true,
-      }
-      this.triggerEvent('restart', myEventDetail, myEventOption)
+      };
+      this.triggerEvent("restart", myEventDetail, myEventOption);
     },
 
     // 杩樻湁N閬撻鏈仛寮圭獥
     confrimPromptDialog() {
       wx.showModal({
-        title: '鎻愮ず',
-        content: `鎮ㄨ繕鏈� ${this.data.noReady}閬撻鏈瓟锛屾槸鍚︽彁浜わ紵`,//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
-        editable: false,//鏄惁鏄剧ず杈撳叆妗�
+        title: "鎻愮ず",
+        content: `鎮ㄨ繕鏈� ${this.data.noReady}閬撻鏈瓟锛屾槸鍚︽彁浜わ紵`, //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+        confirmColor: "#ff6c00",
+        cancelColor: "#949494",
+        editable: false, //鏄惁鏄剧ず杈撳叆妗�
         success: (res) => {
           if (res.confirm) {
-            this.submitPaper()
+            this.submitPaper();
           }
-        }
-      })
+        },
+      });
     },
     // 搴曢儴鎻愪氦鎸夐挳
     submitBtn() {
       this.setData({
-        noReady: 0
-      })
+        noReady: 0,
+      });
       // 鎴戠殑閿欓鍜屾敹钘�  鐩存帴璧版彁浜ら�昏緫
-      if (this.properties.answerType == 'collectQuestion' || this.properties.answerType == 'errorQuestion') {
-        this.submitPaper()
-        return wx.navigateBack()
-      } else if (this.properties.answerType == 'option' || this.properties.answerType == 'mock') {
-        if (this.properties.submitStatus) return wx.navigateBack()
-        this.properties.questionDataList.forEach(item => {
+      if (
+        this.properties.answerType == "collectQuestion" ||
+        this.properties.answerType == "errorQuestion"
+      ) {
+        this.submitPaper();
+        return wx.navigateBack();
+      } else if (
+        this.properties.answerType == "option" ||
+        this.properties.answerType == "mock"
+      ) {
+        if (this.properties.submitStatus) return wx.navigateBack();
+        this.properties.questionDataList.forEach((item) => {
           if (!this.isHaveAnswer(item.userAnswer)) {
             this.setData({
-              noReady: this.data.noReady + 1
-            })
+              noReady: this.data.noReady + 1,
+            });
           }
-        })
+        });
         // 鏈仛瀹岋紝鎵撳紑鎻愮ず寮圭獥
         if (this.data.noReady > 0) {
-          this.confrimPromptDialog()
+          this.confrimPromptDialog();
         } else {
           // 鍋氬畬浜嗙洿鎺ユ墽琛屾彁浜や簨浠�
-          this.submitPaper()
+          this.submitPaper();
         }
       }
-
     },
     // 鎻愪氦浜嬩欢
     submitPaper() {
-      var myEventDetail = {
-      }
+      var myEventDetail = {};
       var myEventOption = {
         bubbles: true,
         composed: true,
-      }
-      this.triggerEvent('submitPaper', myEventDetail, myEventOption)
+      };
+      this.triggerEvent("submitPaper", myEventDetail, myEventOption);
     },
     // 鎵撳紑娴嬭瘯鎶ュ憡寮圭獥
     openTestReportDialog() {
       this.setData({
-        testReportState: true
-      })
+        testReportState: true,
+      });
     },
     // 鍏抽棴娴嬭瘯鎶ュ憡寮圭獥
     closeTestReportDialog(e) {
       this.setData({
-        testReportState: false
-      })
+        testReportState: false,
+      });
     },
     // 娴嬭瘯鎶ュ憡寮圭獥鏌ョ湅绛旀瑙f瀽鎸夐挳
     viewAnswer() {
-      this.closeTestReportDialog()
+      this.closeTestReportDialog();
     },
     // 绛旈鏃堕棿鍒�
     timeout() {
       wx.showModal({
-        title: '鎻愮ず',
-        content: '绛旈鏃堕棿宸插埌',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
-        editable: false,//鏄惁鏄剧ず杈撳叆妗�
+        title: "鎻愮ず",
+        content: "绛旈鏃堕棿宸插埌", //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+        confirmColor: "#ff6c00",
+        cancelColor: "#949494",
+        editable: false, //鏄惁鏄剧ず杈撳叆妗�
         showCancel: false,
-        success: (res) => {
-        }
-      })
-      this.submitPaper()
+        success: (res) => {},
+      });
+      this.submitPaper();
     },
-  }
-})
+  },
+});

--
Gitblit v1.9.1