From 11506e97dfbb3c49754b8570f5328a6b17d22ed0 Mon Sep 17 00:00:00 2001
From: unknown <qq1940665526@163.com>
Date: 星期五, 07 六月 2024 18:08:48 +0800
Subject: [PATCH] 优化

---
 src/components/examinations/index.vue |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/components/examinations/index.vue b/src/components/examinations/index.vue
index a69612c..4998f9c 100644
--- a/src/components/examinations/index.vue
+++ b/src/components/examinations/index.vue
@@ -1,5 +1,5 @@
 <template>
-  <div class="examination" v-loading="!cardData.length">
+  <div class="examination" v-loading="loading">
     <div
       v-for="(item, nindex) in cardData"
       :key="nindex"
@@ -426,7 +426,6 @@
   props: {
     cardList: {
       type: Array,
-      default: [],
     },
     primaryColor: {
       type: String,
@@ -443,14 +442,27 @@
     return {
       type: "option",
       loading: false,
-      cardData:[]
+      cardData:[],
+      loading:true
     };
   },
-  inject:['changeQuestionData'],
+  watch:{
+    cardList:{
+      handler(newVal) {
+        console.log('11',newVal);
+        this.cardData = this.cardList
+        if(newVal && newVal.length) {
+          this.loading = false
+        }
+      },
+      immediate:true,
+      deep:true
+    }
+  },
   mounted() {
-    this.cardData = this.cardList
-    console.log('this.cardList',this.cardList);
-    console.log('this.cardData',this.cardData);
+    // this.cardData = this.cardList
+    // console.log('this.cardList',this.cardList);
+    // console.log('this.cardData',this.cardData);
   },
   methods: {
     // 鏁扮粍杞负瀛楃涓叉柟娉�
@@ -510,7 +522,7 @@
     },
     // 鎵规敼棰樼洰  (缁冧範,鎴戠殑鍋氶,鎴戠殑鏀惰棌妯″紡涓�)
     handleQuestion() {
-      const list = this.$props.cardData;
+      const list = this.cardData;
       for (let index = 0; index < list.length; index++) {
         const item = list[index];
         for (let cindex = 0; cindex < item.infoList.length; cindex++) {
@@ -555,8 +567,8 @@
           }
         }
       }
-      this.$props.cardData = list;
-      console.log(this.$props.cardData);
+      this.cardData = list;
+      console.log(this.cardData);
     },
     getParentWithClass(element, className) {
       while (element.parentElement) {
@@ -568,20 +580,20 @@
     },
     // 淇濆瓨鎸夐挳
     saveAnswer() {
-      const element = document.getElementsByClassName("examination")[0];
+      const element = (this.container ? this.container : document
+      ).querySelector(".examination");
       if (element) {
         const pageNum = this.getParentWithClass(
           element,
           "page-box"
         ).getAttribute("page");
-        console.log(this.config.activeBook.name, pageNum);
         const oldAnswerData = localStorage.getItem(
           this.config.activeBook.name + "oldAnswerData"
         );
         let oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {};
         const asnwerList = [];
-        for (let index = 0; index < this.$props.cardData.length; index++) {
-          const item = this.$props.cardData[index];
+        for (let index = 0; index < this.cardData.length; index++) {
+          const item = this.cardData[index];
           for (let cindex = 0; cindex < item.infoList.length; cindex++) {
             const citem = item.infoList[cindex];
             asnwerList.push({
@@ -591,11 +603,8 @@
           }
         }
         if(oldData[pageNum]) {
-          oldData[pageNum].push(asnwerList)
-          // for (let dindex = 0; dindex < oldData[pageNum].length; dindex++) {
-          //   const ditem = oldData[pageNum][dindex];
-          //   for(let eindex = 0; eindex < asnwerList.)
-          // }
+          oldData[pageNum] = oldData[pageNum].filter(citem => asnwerList.findIndex(ditem => ditem.id == citem.id) == -1 )
+          oldData[pageNum].push(...asnwerList)
         } else {
           oldData[pageNum] = asnwerList
         }

--
Gitblit v1.9.1