From a08108139526214a36aba424de99ab2a50825798 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期五, 21 六月 2024 18:30:25 +0800
Subject: [PATCH] 数学资源收藏

---
 src/books/mathBook/view/components/chapter001.vue |   35 ++++++++++++++---
 src/components/examinations/index.vue             |   11 ++---
 src/assets/methods/resources.js                   |   29 ++++++++++++++
 src/books/mathBook/view/components/index.vue      |    1 
 4 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/src/assets/methods/resources.js b/src/assets/methods/resources.js
index bd860ff..74e4315 100644
--- a/src/assets/methods/resources.js
+++ b/src/assets/methods/resources.js
@@ -1,4 +1,5 @@
 import fileApi from "@/assets/js/middleGround/api/file";
+import identityApi from "../js/middleGround/api/identity";
 export const getResourcePath = async (md5, appRefCode = "jingshieke") => {
   let path = "";
   await fileApi
@@ -15,8 +16,36 @@
     });
   return path;
 };
+// 鑾峰彇鏀惰棌鐨勮祫婧�
+export const getCollectResource = async (key) => {
+  let list = []
+  await identityApi
+  .getUserKey({
+    domain: "collectResource",
+    keys: [key],
+  })
+  .then((res) => {
+    if(res.length) {
+      list = JSON.parse(res[0].value)
+    }
+  });
+  return list
+}
+export const setCollectResource = (key,list) => {
+  identityApi.setUserKey({
+    setKeyRequests: [
+      {
+        domain: "collectResource",
+        key,
+        value: JSON.stringify(list),
+      },
+    ],
+  })
+}
 const MT = {
   getResourcePath,
+  getCollectResource,
+  setCollectResource
 };
 
 export default MT;
diff --git a/src/books/mathBook/view/components/chapter001.vue b/src/books/mathBook/view/components/chapter001.vue
index b278ea5..9cf0e20 100644
--- a/src/books/mathBook/view/components/chapter001.vue
+++ b/src/books/mathBook/view/components/chapter001.vue
@@ -156,7 +156,7 @@
               placement="top-start"
             >
               <img
-                :src="chapterData.isCollectImg ? collectCheck : collectImg"
+                :src="collectResourceList.findIndex(item => item.id == '722FE833') > -1 ? collectCheck : collectImg"
                 alt=""
                 class="collect-btn"
                 @click="handleCollect('img')"
@@ -184,7 +184,7 @@
               placement="top-start"
             >
               <img
-                :src="chapterData.isCollectVideo ? collectCheck : collectImg"
+                :src="collectResourceList.findIndex(item => item.id == 'a28cd862d61b5df2201406b76e9f01b0') > -1 ? collectCheck : collectImg"
                 alt=""
                 class="collect-btn"
                 @click="handleCollect('video')"
@@ -819,7 +819,7 @@
 <script>
 import examinations from "@/components/examinations/index.vue";
 import { getResourcePath } from "@/assets/methods/resources";
-import axios from "axios";
+import { getCollectResource,setCollectResource } from "@/assets/methods/resources";
 export default {
   name: "chapter-one",
   components: { examinations },
@@ -832,13 +832,13 @@
       type:Object
     }
   },
-  mounted() {
+  async mounted() {
     const data = localStorage.getItem("math-chapterData");
     if (data) {
       this.chapterData = JSON.parse(data);
     }
     this.getPath();
-    // this.getQuestionData();
+    this.collectResourceList = await getCollectResource(this.config.activeBook.bookId)
   },
   data() {
     return {
@@ -855,6 +855,7 @@
       videoPath: "",
       stepIndex: 1,
       thinkIndex: 1,
+      collectResourceList:[],
       chapterData: {
         isCollectImg: false,
         isCollectVideo: false,
@@ -935,9 +936,10 @@
     // },
     handleCollect(type) {
       if (type == "img") {
-        this.chapterData.isCollectImg = !this.chapterData.isCollectImg;
+        this.handleCollectResource("722FE833","",'images/0101-1.jpg',"鍥剧墖","json",'鍥�3-15')
       } else if (type == "video") {
-        this.chapterData.isCollectVideo = !this.chapterData.isCollectVideo;
+        this.handleCollectResource("a28cd862d61b5df2201406b76e9f01b0","a28cd862d61b5df2201406b76e9f01b0",'',"瑙嗛","bits",'瑙嗛锛氬垽鏁板嚱鏁板鍋舵�х殑鏂规硶鍜屾楠�')
+        // setCollectResource(this.config.activeBook.bookId,[])
       }
       this.handleChapterData();
     },
@@ -962,6 +964,25 @@
         this.stepIndex++;
       }
     },
+    //璧勬簮鏀惰棌浜嬩欢
+    handleCollectResource(id,md5,resourcePath,resourceType,source,resourceName){
+      console.log(this.collectResourceList);
+      let list = this.collectResourceList
+      if(list.findIndex(item => item.id == id) > -1) {
+        list = list.filter(item => item.id != id)
+      } else {
+        list.push({
+          id,
+          md5,
+          resourcePath,
+          resourceType,
+          source,
+          resourceName,
+        })
+      }
+      this.collectResourceList = list
+      setCollectResource(this.config.activeBook.bookId,this.collectResourceList)
+    }
   },
 };
 </script>
diff --git a/src/books/mathBook/view/components/index.vue b/src/books/mathBook/view/components/index.vue
index 0bee8ec..44910de 100644
--- a/src/books/mathBook/view/components/index.vue
+++ b/src/books/mathBook/view/components/index.vue
@@ -826,7 +826,6 @@
             const collect = JSON.parse(res[0].value);
             if (collect.length) {
               this.collectId = collect.find(item => item.type == 'json').collectList
-              console.log('鏀惰棌鍒楄〃',this.collectId);
             }
           } catch (error) {
             console.log("鏆傛棤鏁版嵁");
diff --git a/src/components/examinations/index.vue b/src/components/examinations/index.vue
index 96953e4..98120c7 100644
--- a/src/components/examinations/index.vue
+++ b/src/components/examinations/index.vue
@@ -560,9 +560,6 @@
     },
   },
   mounted() {
-    // this.cardData = this.cardList
-    // console.log('this.cardList',this.cardList);
-    // console.log('this.cardData',this.cardData);
     this.getCollectIdList();
     this.getErrorList()
   },
@@ -681,7 +678,10 @@
           oldErrodId.push(item)
         }
       }
-      this.allError[1].errorList = oldErrodId
+      for (let cindex = 0; cindex < this.allError.length; cindex++) {
+        const citem = this.allError[cindex];
+        if(citem.type == this.sourceType) citem.errorList = oldErrodId
+      }
       this.MG.identity
         .setUserKey({
           setKeyRequests: [
@@ -775,7 +775,7 @@
         const item = this.allCollect[index];
         if (item.type == this.sourceType) item.collectList = this.collectList;
       }
-      console.log(this.allCollect, this.collectList, list);
+      // console.log(this.allCollect, this.collectList, list);
       this.MG.identity
         .setUserKey({
           setKeyRequests: [
@@ -841,7 +841,6 @@
               ).errorList;
             }
           } catch (error) {}
-          console.log('閿欓鍒楄〃',this.allError);
         });
     },
   },

--
Gitblit v1.9.1