Browse Source

收藏和错题改版中

JXDS18FUJT 2 năm trước cách đây
mục cha
commit
ba6f4f7afd

+ 42 - 1
src/api/modules/exam.js

@@ -118,11 +118,52 @@ const exam = {
 			data
 		})
 	},
+	//合并本机和云端错题
+	studentQuestionWrongWrongs(data,params={}){
+		return request({
+			url: "student/question/wrong/wrongs",
+			method: "POST",
+			data,
+			params
+		})
+	},
+	//备份本机错题到云端
+	studentQuestionWrongBakWrongs(data){
+		return request({
+			url: "student/question/wrong/bakWrongs",
+			method: "POST",
+			data
+		})
+	},
 	//清空收藏题
 	studentQuestionCollectionCancelAll(data) {
 		return request({
 			url: "student/question/collection/cancelAll",
-			method: "DELETE",
+			method: "delete",
+			data
+		})
+	},
+	//恢复云端收藏到本机
+	studentQuestionCollectionCollectionByUser(params){
+		return request({
+			url: "student/question/collection/collectionByUser",
+			method: "get",
+			params
+		})
+	},
+	//合并本机和云端收藏
+	studentQuestionCollectionCollections(data){
+		return request({
+			url: "student/question/collection/collections",
+			method: "POST",
+			data
+		})
+	},
+	//备份本机收藏到云端
+	studentQuestionCollectionBakCollections(data){
+		return request({
+			url: "student/question/collection/bakCollections",
+			method: "POST",
 			data
 		})
 	},

+ 73 - 36
src/components/m-do-topic/m-do-topic.vue

@@ -1165,34 +1165,71 @@ export default {
       });
     },
     collectTopics(e) {
-      api.exam
-        .studentQuestionCollection({
-          questionId: this.problemList[this.problemListIndex].id,
-          carType: this.gsMap[this.query.gs],
-          km: this.query.subject === "4" ? "科目四" : "科目一",
-        })
-        .then((res) => {
-          if (!this.problemList[this.problemListIndex].isCollect) {
-            this.$set(
-              this.problemList[this.problemListIndex],
-              "isCollect",
-              true
-            );
-            uni.showToast({
-              title: "收藏成功",
-            });
-          } else {
-            this.$set(
-              this.problemList[this.problemListIndex],
-              "isCollect",
-              false
-            );
-            uni.showToast({
-              title: "取消收藏",
-              icon: "fail",
-            });
-          }
+      let userCollectionIds = uni.getStorageSync("userCollectionIds") || [];
+
+      if (!this.problemList[this.problemListIndex].isCollect) {
+        if (
+          !userCollectionIds.includes(
+            this.problemList[this.problemListIndex].id
+          )
+        ) {
+          userCollectionIds.push(this.problemList[this.problemListIndex].id);
+          uni.setStorageSync("userCollectionIds", userCollectionIds);
+        }
+        this.$set(this.problemList[this.problemListIndex], "isCollect", true);
+        uni.showToast({
+          title: "收藏成功",
+        });
+      } else {
+        if (
+          userCollectionIds.indexOf(
+            this.problemList[this.problemListIndex].id
+          ) > 0
+        ) {
+          userCollectionIds.splice(
+            userCollectionIds.indexOf(
+              this.problemList[this.problemListIndex].id
+            ),
+            1
+          );
+          uni.setStorageSync("userCollectionIds", userCollectionIds);
+        }
+
+        this.$set(this.problemList[this.problemListIndex], "isCollect", false);
+        uni.showToast({
+          title: "取消收藏",
+          icon: "fail",
         });
+      }
+
+      // api.exam
+      //   .studentQuestionCollection({
+      //     questionId: this.problemList[this.problemListIndex].id,
+      //     carType: this.gsMap[this.query.gs],
+      //     km: this.query.subject === "4" ? "科目四" : "科目一",
+      //   })
+      //   .then((res) => {
+      //     if (!this.problemList[this.problemListIndex].isCollect) {
+      //       this.$set(
+      //         this.problemList[this.problemListIndex],
+      //         "isCollect",
+      //         true
+      //       );
+      //       uni.showToast({
+      //         title: "收藏成功",
+      //       });
+      //     } else {
+      //       this.$set(
+      //         this.problemList[this.problemListIndex],
+      //         "isCollect",
+      //         false
+      //       );
+      //       uni.showToast({
+      //         title: "取消收藏",
+      //         icon: "fail",
+      //       });
+      //     }
+      //   });
     },
     readQuestionAndAnswer() {
       let globalAudio = utils.wxUtils.getGlobAudio();
@@ -1622,10 +1659,10 @@ export default {
         //studentQuestionWrongWrongByUser(废弃)
         api.exam
           .studentQuestionInfoGetQuestionInfoByIds({
-            ids: uni.getStorageSync("userWrongIds").join(","),
+            ids: uni.getStorageSync("userWrongIds")?uni.getStorageSync("userWrongIds").join(","):'',
           })
           .then((res) => {
-          console.log(res);
+            console.log(res);
             res.rows.forEach((element) => {
               element.optsArr = [];
               element.opts.split("-").forEach((item, index) => {
@@ -1659,12 +1696,12 @@ export default {
         break;
       case "collect":
         api.exam
-          .studentQuestionCollectionCollectionByUser({
-            carType: this.gsMap[this.query.gs],
-            km: this.query.subject === "1" ? "科目一" : "科目四",
+          .studentQuestionInfoGetQuestionInfoByIds({
+            ids: uni.getStorageSync("userCollectionIds")?uni.getStorageSync("userCollectionIds").join(","):'',
           })
           .then((res) => {
-            res.data.forEach((element) => {
+            console.log(res);
+            res.rows.forEach((element) => {
               element.optsArr = [];
               element.opts.split("-").forEach((item, index) => {
                 if (element.questionType == 3) {
@@ -1687,9 +1724,9 @@ export default {
               element.userAnswer = [];
             });
             that.problemListTotal = res.total;
-            that.problemList = res.data;
-            origProblemList = JSON.parse(JSON.stringify(res.data));
-            that.$emit("update:problemListTotal", res.data.length);
+            that.problemList = res.rows;
+            origProblemList = JSON.parse(JSON.stringify(res.rows));
+            that.$emit("update:problemListTotal", res.rows.length);
 
             uni.hideLoading();
           });

+ 332 - 87
src/otherPages/collection/index.vue

@@ -5,59 +5,173 @@
     </view>
     <view class="choose">
       <view
+        v-if="type == 'wrong'"
         class="choose-img"
-        style="
-          background-image: url('https://ct.zzxcx.net/ctjk/mp-wx/collection/wrongBg1.png');
-        "
-        @tap.stop="goExercise('wrong')"
+        style="overflow: hidden; border-radius: 40rpx"
       >
-        <span class="choose-text1"> 做错题 </span>
-        <view class="choose-text2"> 共 {{ wrongListCount }} 题 </view>
-
-        <image mode="widthFix" class="goArrow" :src="goArrow" />
+        <image
+          style="width: 100%"
+          mode="widthFix"
+          src="https://ct.zzxcx.net/ctjk/mp-wx/collection/wrongBg3.png"
+        ></image>
+        <view class="choose-text1"> 做错题 </view>
         <view
-          :hover-stop-propagation="true"
-          data-type="wrong"
-          @tap.stop="clearTopics('wrong')"
-          style="color: #498ef5"
-          class="clear"
+          @click="
+            () => {
+              type = 'collect';
+            }
+          "
+          class="choose-text1"
+          style="right: 0; color: #8a9099; background: #f2f3f5"
         >
-          清空错题
+          收藏题
+        </view>
+        <view class="choose-text2" style="display: flex">
+          <view class=""> 共 {{ wrongListCount }} 题 </view>
+          <image
+            @tap.stop="goExercise('wrong')"
+            mode="widthFix"
+            class="goArrow"
+            :src="goArrow"
+          />
+        </view>
+        <view class="choose-tool">
+          <view
+            :hover-stop-propagation="true"
+            data-type="wrong"
+            @tap.stop="clearTopics('wrong')"
+            style="color: #498ef5"
+            class="clear"
+          >
+            清空错题
+          </view>
+          <view
+            :hover-stop-propagation="true"
+            data-type="wrong"
+            @tap.stop="
+              () => {
+                wrongSyncShow = true;
+              }
+            "
+            style="color: #498ef5"
+            class="sync"
+          >
+            同步错题
+          </view>
         </view>
       </view>
       <view
+        v-if="type == 'collect'"
         class="choose-img"
-        style="
-          background-image: url('https://ct.zzxcx.net/ctjk/mp-wx/collection/collectionBg1.png');
-        "
-        @tap.stop="goExercise('collect')"
+        style="overflow: hidden; border-radius: 40rpx"
       >
-        <span class="choose-text1">收藏题</span>
-        <span class="choose-text2"> 共 {{ collectionListCount }} 题 </span>
-
-        <image mode="widthFix" class="goArrow" :src="goArrow" />
-        <view
-          :hover-stop-propagation="true"
-          data-type="collect"
-          @tap.stop="clearTopics('collect')"
-          style="color: #01c18d"
-          class="clear"
-        >
-          清空收藏
-        </view>
-      </view>
-    </view>
-    <view style="padding-bottom: 20rpx">
-      <view @click="syncWrongQuestion" class="sync">
         <image
-          style="width: 36rpx;margin-right:15rpx"
+          style="width: 100%"
           mode="widthFix"
-          src="https://ct.zzxcx.net/ctjk/mp-wx/collection/syncIcon.png"
+          src="https://ct.zzxcx.net/ctjk/mp-wx/collection/collectionBg3.png"
         ></image>
-        <text>同步收藏错题</text>
+        <view
+          @click="
+            () => {
+              type = 'wrong';
+            }
+          "
+          style="color: #8a9099; background: #f2f3f5"
+          class="choose-text1"
+        >
+          做错题
+        </view>
+        <view style="right: 0" class="choose-text1"> 收藏题 </view>
+
+        <view class="choose-text2" style="display: flex">
+          <view class=""> 共 {{ collectionListCount }} 题 </view>
+          <image
+            @tap.stop="goExercise('collect')"
+            mode="widthFix"
+            class="goArrow"
+            :src="goArrow"
+          />
+        </view>
+        <view class="choose-tool">
+          <view
+            :hover-stop-propagation="true"
+            data-type="collect"
+            @tap.stop="clearTopics('collect')"
+            style="color: #498ef5"
+            class="clear"
+          >
+            清空收藏
+          </view>
+          <view
+            :hover-stop-propagation="true"
+            data-type="collect"
+            @tap.stop="
+              () => {
+                collectSyncShow = true;
+              }
+            "
+            style="color: #498ef5"
+            class="sync"
+          >
+            同步收藏
+          </view>
+        </view>
       </view>
     </view>
-    <view class="wxad">
+
+    <van-popup
+      @close="
+        () => {
+          wrongSyncShow = false;
+        }
+      "
+      zIndex="1000"
+      position="bottom"
+      :show="wrongSyncShow"
+    >
+      <van-picker
+        @cancel="
+          () => {
+            wrongSyncShow = false;
+          }
+        "
+        @confirm="syncWrongQuestion"
+        :columns="[
+          { text: '合并本机和云端收藏', type: 'wrong', value: 0 },
+          { text: '备份本机收藏到云端', type: 'wrong', value: 1 },
+          { text: '恢复云端收藏到本机', type: 'wrong', value: 2 },
+        ]"
+        show-toolbar
+        title="同步错题"
+      />
+    </van-popup>
+    <van-popup
+      @close="
+        () => {
+          collectSyncShow = false;
+        }
+      "
+      zIndex="1000"
+      position="bottom"
+      :show="collectSyncShow"
+    >
+      <van-picker
+        @cancel="
+          () => {
+            collectSyncShow = false;
+          }
+        "
+        @confirm="syncCollectQuestion"
+        :columns="[
+          { text: '合并本机和云端收藏', type: 'collect', value: 0 },
+          { text: '备份本机收藏到云端', type: 'collect', value: 1 },
+          { text: '恢复云端收藏到本机', type: 'collect', value: 2 },
+        ]"
+        show-toolbar
+        title="同步收藏"
+      />
+    </van-popup>
+    <view v-show="!wrongSyncShow && !collectSyncShow" class="wxad">
       <ad
         :ad-intervals="100"
         ad-type="video"
@@ -80,12 +194,12 @@ import utils from "@/utils/index";
 export default {
   data() {
     return {
-      wrongBg: "https://ct.zzxcx.net/ctjk/mp-wx/collection/wrongBg.png",
-      collectionBottomBg:
-        "https://ct.zzxcx.net/ctjk/mp-wx/collection/collectionBottomBg.png",
+      chooseBg: "https://ct.zzxcx.net/ctjk/mp-wx/collection/wrongBg3.png",
+      type: "wrong",
+      wrongBg: "https://ct.zzxcx.net/ctjk/mp-wx/collection/wrongBg3.png",
       goArrow: "https://ct.zzxcx.net/ctjk/mp-wx/collection/right_arrow.png",
       collectionBg:
-        "https://ct.zzxcx.net/ctjk/mp-wx/collection/collectionBg.png",
+        "https://ct.zzxcx.net/ctjk/mp-wx/collection/collectionBg3.png",
       collectionHeader: "https://ct.zzxcx.net/ctjk/mp-wx/carVideo/banner.png",
       query: {
         questionIds: "",
@@ -96,16 +210,23 @@ export default {
         mtc: "摩托车",
         kc: "客车",
       },
+      wrongSyncShow: false,
+      collectSyncShow: false,
       wrongList: [],
-      wrongListCount: 1,
+      wrongListCount: uni.getStorageSync("userWrongIds")
+        ? uni.getStorageSync("userWrongIds").length
+        : 0,
+
       collectionList: [],
-      collectionListCount: 1,
+      collectionListCount: uni.getStorageSync("userCollectionIds")
+        ? uni.getStorageSync("userCollectionIds").length
+        : 0,
     };
   },
   onLoad(query) {
     this.query = query;
-    let userWrongIds = uni.getStorageSync("userWrongIds") || [];
-    this.wrongListCount = userWrongIds.length;
+    this.user;
+
     // api.exam
     //   .studentQuestionWrongWrongCountByUser({
     //     carType: this.gsMap[query.gs],
@@ -116,23 +237,114 @@ export default {
     //   .then((res) => {
     //     this.wrongListCount = res.data;
     //   });
-    api.exam
-      .studentQuestionCollectionCollectionCountByUser({
-        carType: this.gsMap[query.gs],
-        km: query.subject === "1" ? "科目一" : "科目四",
-        pageNum: 1,
-        pageSize: 10000,
-      })
-      .then((res) => {
-        this.collectionListCount = res.data;
-      });
   },
   methods: {
-    syncWrongQuestion(){
-      api.exam.studentQuestionWrongWrongByUser().then(res=>{
-        console.log(res)
-      })
-
+    syncCollectQuestion(e) {
+      let select = e.detail.value;
+      switch (select.value) {
+      case 0:
+          api.exam
+            .studentQuestionCollectionBakCollections({
+              km: Number(this.query.subject),
+              questionIds: uni
+                .getStorageSync("userCollectionIds")
+                .map((item) => item),
+            })
+            .then((res) => {
+              api.exam.studentQuestionCollectionCollectionByUser().then((result) => {
+                let userCollectionIds = result.data.map((item) => {
+                  return item.id;
+                });
+                uni.setStorageSync("userCollectionIds", userCollectionIds);
+                this.collectionListCount = userCollectionIds.length;
+              });
+            });
+          break;
+        case 1:
+          api.exam
+            .studentQuestionWrongBakWrongs({
+              km: Number(this.query.subject),
+              questionIds: uni
+                .getStorageSync("userCollectionIds")
+                .map((item) => item),
+            })
+            .then((res) => {
+              api.exam.studentQuestionWrongWrongByUser().then((result) => {
+                let userCollectionIds = result.data.map((item) => {
+                  return item.id;
+                });
+                uni.setStorageSync("userCollectionIds", userCollectionIds);
+                this.collectionListCount = userCollectionIds.length;
+              });
+            });
+          break;
+        case 2:
+          api.exam.studentQuestionWrongWrongByUser().then((result) => {
+            let userCollectionIds = result.data.map((item) => {
+              return item.id;
+            });
+            uni.setStorageSync("userCollectionIds", userCollectionIds);
+            this.collectionListCount = userCollectionIds.length;
+          });
+          break;
+        default:
+          break;
+      }
+      this.collectSyncShow = false;
+    },
+    syncWrongQuestion(e) {
+      let select = e.detail.value;
+      console.log(e);
+      switch (select.value) {
+        case 0:
+          api.exam
+            .studentQuestionWrongWrongs({
+              km: Number(this.query.subject),
+              questionIds: uni
+                .getStorageSync("userWrongIds")
+                .map((item) => item),
+            })
+            .then((res) => {
+              api.exam.studentQuestionWrongWrongByUser().then((result) => {
+                let userWrongIds = result.data.map((item) => {
+                  return item.id;
+                });
+                uni.setStorageSync("userWrongIds", userWrongIds);
+                this.wrongListCount = userWrongIds.length;
+              });
+            });
+          break;
+        case 1:
+          api.exam
+            .studentQuestionWrongBakWrongs({
+              km: Number(this.query.subject),
+              questionIds: uni
+                .getStorageSync("userWrongIds")
+                .map((item) => item),
+            })
+            .then((res) => {
+              api.exam.studentQuestionWrongWrongByUser().then((result) => {
+                let userWrongIds = result.data.map((item) => {
+                  return item.id;
+                });
+                uni.setStorageSync("userWrongIds", userWrongIds);
+                this.wrongListCount = userWrongIds.length;
+              });
+            });
+          break;
+        case 2:
+          api.exam.studentQuestionWrongWrongByUser().then((result) => {
+            let userWrongIds = result.data.map((item) => {
+              return item.id;
+            });
+            uni.setStorageSync("userWrongIds", userWrongIds);
+            this.wrongListCount = userWrongIds.length;
+          });
+          break;
+        default:
+          break;
+      }
+      this.wrongSyncShow = false;
     },
     goExercise(type) {
       let query = Object.assign({}, this.query);
@@ -176,6 +388,7 @@ export default {
                   km: that.query.subject === "1" ? "科目一" : "科目四",
                 })
                 .then((res) => {
+                  uni.setStorageSync("userWrongIds", []);
                   api.exam
                     .studentQuestionWrongWrongCountByUser({
                       carType: that.gsMap[that.query.gs],
@@ -201,6 +414,7 @@ export default {
                   km: that.query.subject === "1" ? "科目一" : "科目四",
                 })
                 .then((res) => {
+                  uni.setStorageSync("userCollectionIds", []);
                   api.exam
                     .studentQuestionCollectionCollectionCountByUser({
                       carType: that.gsMap[that.query.gs],
@@ -247,53 +461,83 @@ export default {
   align-content: space-between;
   align-items: space-between;
   flex-wrap: wrap;
-  margin-top: 70rpx;
-
+  margin-top: 40rpx;
+  .choose-bg {
+    position: absolute;
+    top: 142rpx;
+    left: 424rpx;
+    width: 212rpx;
+  }
   .choose-img {
-    width: 334rpx;
+    width: 690rpx;
     position: relative;
     margin-bottom: 25rpx;
     height: 548rpx;
-    background-size: 100%;
+    background-size: 100% 100%;
+    background-repeat: no-repeat;
+    background-attachment: fixed;
     .bg {
       width: 690rpx;
     }
-    .clear {
-      background: #fff;
-      border-radius: 30rpx;
-      position: absolute;
-      bottom: 40rpx;
-      width: 200rpx;
-      height: 60rpx;
-      left: 40rpx;
-      bottom: 40rpx;
-      border: 0;
-      font-size: 26rpx;
-      line-height: 60rpx;
-      text-align: center;
+    .choose-tool {
+      .clear {
+        background: #ccedff;
+        border-radius: 30rpx;
+        position: absolute;
+        bottom: 40rpx;
+        width: 200rpx;
+        height: 60rpx;
+        left: 54rpx;
+        bottom: 40rpx;
+        border: 0;
+        font-size: 26rpx;
+        line-height: 60rpx;
+        text-align: center;
+        color: #0067a7;
+      }
+      .sync {
+        background: #ccedff;
+        border-radius: 30rpx;
+        position: absolute;
+        bottom: 40rpx;
+        width: 200rpx;
+        height: 60rpx;
+        left: 422rpx;
+        bottom: 40rpx;
+        border: 0;
+        font-size: 26rpx;
+        line-height: 60rpx;
+        text-align: center;
+        color: #0067a7;
+      }
     }
+
     .goArrow {
-      position: absolute;
-      top: 44rpx;
-      right: 40rpx;
+      margin-left: 40rpx;
       width: 56rpx;
       height: 56rpx;
     }
     .choose-text1 {
       position: absolute;
-      font-size: 50rpx;
+      top: 0;
+      font-size: 34rpx;
+      line-height: 90rpx;
+      height: 90rpx;
       color: #fff;
-      left: 40rpx;
-      top: 40rpx;
+
+      top: 0rpx;
       color: #004e81;
+      width: 50%;
+      text-align: center;
     }
     .choose-text2 {
       position: absolute;
-      top: 112rpx;
-      left: 44rpx;
+      top: 212rpx;
+      left: 46rpx;
       color: #1477b4;
       width: 100%;
       font-size: 38rpx;
+      display: flex;
     }
     img {
       width: 100%;
@@ -308,5 +552,6 @@ export default {
   display: flex;
   flex-direction: column;
   padding: 0 30rpx;
+  background: #fff;
 }
 </style>