Преглед изворни кода

更新用户信息和收藏

JXDS18FUJT пре 2 година
родитељ
комит
254aa659da

+ 23 - 5
src/api/modules/exam.js

@@ -168,15 +168,15 @@ const exam = {
 		})
 	},
 	//批量取题
-	studentQuestionInfoGetQuestionInfoByIds(params) {
+	studentQuestionInfoGetQuestionInfoByIds(data) {
 		return request({
 			url: "student/question/info/getQuestionInfoByIds",
-			method: "GET",
-			params
+			method: "POST",
+			data
 		})
 
 	},
-	//根据用户获取错题数
+	//小程序恢复云端错题到本机(根据用户获取错题)
 	studentQuestionWrongWrongCountByUser(params) {
 		return request({
 			url: "student/question/wrong/wrongCountByUser",
@@ -184,6 +184,16 @@ const exam = {
 			params
 		})
 
+	},
+	//app恢复云端错题到本机(根据用户获取错题)
+	studentQuestionWrongAppWrongByUser(params){
+		return request({
+			url: "student/question/wrong/appWrongByUser",
+			method: "get",
+			params
+		})
+
+
 	},
 	//根据用户获取收藏数
 	studentQuestionCollectionCollectionCountByUser(params) {
@@ -202,7 +212,7 @@ const exam = {
 		})
 
 	},
-	//根据用户获取收藏列表
+	//小程序恢复云端收藏到本机(根据用户获取收藏题)
 	studentQuestionCollectionCollectionByUser(params) {
 		return request({
 			url: "student/question/collection/collectionByUser",
@@ -211,6 +221,14 @@ const exam = {
 		})
 
 	},
+	//app恢复云端收藏到本机(根据用户获取收藏题
+	studentQuestionCollectionAppCollectionByUser(params){
+		return request({
+			url: "student/question/collection/appCollectionByUser",
+			method: "get",
+			params
+		})
+	},
 	//查询秘密卷
 	studentQuestionInfoSelectMiQuestionInfoList(params) {
 		return request({

+ 5 - 4
src/api/modules/user.js

@@ -79,7 +79,7 @@ const user = {
 		})
 
 	},
-	//更新用户信息
+	//更新昵称、手机号码、头像
 	userInfoUserInfo(params){
 		return request({
 			url:'/user/info/userInfo',
@@ -96,13 +96,14 @@ const user = {
 			params
 		})
 	},
-	//更新昵称、手机号码、头像
-	userInfoUserInfo(params){
+	//根据code获取手机号
+	userInfoGetPhoneByCode(params){
 		return request({
-			url:'/user/info/userInfo',
+			url:"user/info/getPhoneByCode",
 			method:'GET',
 			params
 		})
+
 	}
 }
 

+ 49 - 18
src/components/m-do-topic/m-do-topic.vue

@@ -1165,16 +1165,22 @@ export default {
       });
     },
     collectTopics(e) {
-      let storageName = uni.getStorageSync("userInfo").xcxOpenid+'_userCollectionIds_'+this.query.subject
+      let storageName =
+        uni.getStorageSync("userInfo").xcxOpenid +
+        "_userCollectionIds_" +
+        this.query.subject;
       let userCollectionIds = uni.getStorageSync(storageName) || [];
 
       if (!this.problemList[this.problemListIndex].isCollect) {
         if (
-          !userCollectionIds.includes(
-            this.problemList[this.problemListIndex].id
-          )
+          !userCollectionIds.some((item) => {
+            return item.id === this.problemList[this.problemListIndex].id;
+          })
         ) {
-          userCollectionIds.push(this.problemList[this.problemListIndex].id);
+          userCollectionIds.push({
+            id: this.problemList[this.problemListIndex].id,
+            timestamp: +new Date(),
+          });
           uni.setStorageSync(storageName, userCollectionIds);
         }
         this.$set(this.problemList[this.problemListIndex], "isCollect", true);
@@ -1260,7 +1266,10 @@ export default {
       return String.fromCharCode(index + 65);
     },
     confirmMult(e) {
-      let storageName = uni.getStorageSync("userInfo").xcxOpenid+'_userWrongIds_'+this.query.subject
+      let storageName =
+        uni.getStorageSync("userInfo").xcxOpenid +
+        "_userWrongIds_" +
+        this.query.subject;
       this.$set(this.problemList[this.problemListIndex], "isCompleted", true);
       if (
         JSON.stringify(
@@ -1282,9 +1291,14 @@ export default {
             );
         let userWrongIds = uni.getStorageSync(storageName) || [];
         if (
-          !userWrongIds.includes(this.problemList[this.problemListIndex].id)
+          !userWrongIds.some((item) => {
+            return item.id === this.problemList[this.problemListIndex].id;
+          })
         ) {
-          userWrongIds.push(this.problemList[this.problemListIndex].id);
+          userWrongIds.push({
+            id: this.problemList[this.problemListIndex].id,
+            timestamp: +new Date(),
+          });
           uni.setStorageSync(storageName, userWrongIds);
         }
         // 目前改为保存本地
@@ -1355,7 +1369,10 @@ export default {
     changeRadioGroup(e) {
       console.log(e, "changeRadioGroup");
       // #ifdef MP-WEIXIN
-      let storageName = uni.getStorageSync("userInfo").xcxOpenid+ '_userWrongIds_'+this.query.subject
+      let storageName =
+        uni.getStorageSync("userInfo").xcxOpenid +
+        "_userWrongIds_" +
+        this.query.subject;
       this.$set(this.problemList[this.problemListIndex], "isCompleted", true);
       if (e.detail == this.problemList[this.problemListIndex].answer) {
         this.trueNum = this.trueNum + 1;
@@ -1365,9 +1382,14 @@ export default {
         let userWrongIds = uni.getStorageSync(storageName) || [];
 
         if (
-          !userWrongIds.includes(this.problemList[this.problemListIndex].id)
+          !userWrongIds.some((item) => {
+            return item.id === this.problemList[this.problemListIndex].id;
+          })
         ) {
-          userWrongIds.push(this.problemList[this.problemListIndex].id);
+          userWrongIds.push({
+            id: this.problemList[this.problemListIndex].id,
+            timestamp: +new Date(),
+          });
           uni.setStorageSync(storageName, userWrongIds);
         }
 
@@ -1484,7 +1506,7 @@ export default {
   },
   mounted() {
     let that = this;
-    let storageName=''
+    let storageName = "";
     uni.showLoading({
       title: "加载题目中",
     });
@@ -1509,9 +1531,8 @@ export default {
     //   })
 
     // }
-    
+
     switch (that.type) {
-      
       case "specify":
         api.exam
           .studentQuestionInfoGetQuestionInfoByIds({
@@ -1662,10 +1683,15 @@ export default {
         break;
       case "wrong":
         //studentQuestionWrongWrongByUser(废弃)
-         storageName = uni.getStorageSync("userInfo").xcxOpenid+'_userWrongIds_'+this.query.subject
+        storageName =
+          uni.getStorageSync("userInfo").xcxOpenid +
+          "_userWrongIds_" +
+          this.query.subject;
         api.exam
           .studentQuestionInfoGetQuestionInfoByIds({
-            ids: uni.getStorageSync(storageName)?uni.getStorageSync(storageName).join(","):null,
+            ids: uni.getStorageSync(storageName)
+              ? uni.getStorageSync(storageName).map(item=>{return item.id})
+              : null,
           })
           .then((res) => {
             console.log(res);
@@ -1701,10 +1727,15 @@ export default {
 
         break;
       case "collect":
-          storageName = uni.getStorageSync("userInfo").xcxOpenid+'_userCollectionIds_'+this.query.subject
+        storageName =
+          uni.getStorageSync("userInfo").xcxOpenid +
+          "_userCollectionIds_" +
+          this.query.subject;
         api.exam
           .studentQuestionInfoGetQuestionInfoByIds({
-            ids: uni.getStorageSync(storageName)?uni.getStorageSync(storageName).join(","):null,
+            ids: uni.getStorageSync(storageName)
+              ? uni.getStorageSync(storageName).map(item=>{return item.id})
+              : null,
           })
           .then((res) => {
             console.log(res);

+ 48 - 32
src/otherPages/collection/index.vue

@@ -265,19 +265,19 @@ export default {
           api.exam
             .studentQuestionCollectionCollections({
               km: Number(this.query.subject),
-              questionIds: uni.getStorageSync(storageName).map((item) => item),
+              cols: uni.getStorageSync(storageName).map((item) => item),
             })
             .then((res) => {
               uni.showToast({
-                title:"合并成功"
-              })
+                title: "合并成功",
+              });
               api.exam
-                .studentQuestionCollectionCollectionByUser({
+                .studentQuestionCollectionAppCollectionByUser({
                   km: Number(this.query.subject),
                 })
                 .then((result) => {
                   let userCollectionIds = result.data.map((item) => {
-                    return item.id;
+                    return item;
                   });
                   uni.setStorageSync(storageName, userCollectionIds);
                   this.collectionListCount = userCollectionIds.length;
@@ -288,19 +288,19 @@ export default {
           api.exam
             .studentQuestionCollectionBakCollections({
               km: Number(this.query.subject),
-              questionIds: uni.getStorageSync(storageName).map((item) => item),
+              cols: uni.getStorageSync(storageName).map((item) => item),
             })
             .then((res) => {
-               uni.showToast({
-                title:"备份成功"
-              })
+              uni.showToast({
+                title: "备份成功",
+              });
               api.exam
-                .studentQuestionCollectionCollectionByUser({
+                .studentQuestionCollectionAppCollectionByUser({
                   km: Number(this.query.subject),
                 })
                 .then((result) => {
                   let userCollectionIds = result.data.map((item) => {
-                    return item.id;
+                    return item;
                   });
                   uni.setStorageSync(storageName, userCollectionIds);
                   this.collectionListCount = userCollectionIds.length;
@@ -309,15 +309,15 @@ export default {
           break;
         case 2:
           api.exam
-            .studentQuestionCollectionCollectionByUser({
+            .studentQuestionCollectionAppCollectionByUser({
               km: Number(this.query.subject),
             })
             .then((result) => {
-               uni.showToast({
-                title:"恢复成功"
-              })
+              uni.showToast({
+                title: "恢复成功",
+              });
               let userCollectionIds = result.data.map((item) => {
-                return item.id;
+                return item;
               });
               uni.setStorageSync(storageName, userCollectionIds);
               this.collectionListCount = userCollectionIds.length;
@@ -344,19 +344,19 @@ export default {
           api.exam
             .studentQuestionWrongWrongs({
               km: Number(this.query.subject),
-              questionIds: uni.getStorageSync(storageName).map((item) => item),
+              wrongs: uni.getStorageSync(storageName).map((item) => item),
             })
             .then((res) => {
               uni.showToast({
-                title:'合并成功'
-              })
+                title: "合并成功",
+              });
               api.exam
-                .studentQuestionWrongWrongByUser({
+                .studentQuestionWrongAppWrongByUser({
                   km: Number(this.query.subject),
                 })
                 .then((result) => {
                   let userWrongIds = result.data.map((item) => {
-                    return item.id;
+                    return item;
                   });
                   uni.setStorageSync(storageName, userWrongIds);
                   this.wrongListCount = userWrongIds.length;
@@ -367,19 +367,19 @@ export default {
           api.exam
             .studentQuestionWrongBakWrongs({
               km: Number(this.query.subject),
-              questionIds: uni.getStorageSync(storageName).map((item) => item),
+              wrongs: uni.getStorageSync(storageName).map((item) => item),
             })
             .then((res) => {
-               uni.showToast({
-                title:'备份成功'
-              })
+              uni.showToast({
+                title: "备份成功",
+              });
               api.exam
-                .studentQuestionWrongWrongByUser({
+                .studentQuestionWrongAppWrongByUser({
                   km: Number(this.query.subject),
                 })
                 .then((result) => {
                   let userWrongIds = result.data.map((item) => {
-                    return item.id;
+                    return item;
                   });
                   uni.setStorageSync(storageName, userWrongIds);
                   this.wrongListCount = userWrongIds.length;
@@ -388,15 +388,15 @@ export default {
           break;
         case 2:
           api.exam
-            .studentQuestionWrongWrongByUser({
+            .studentQuestionWrongAppWrongByUser({
               km: Number(this.query.subject),
             })
             .then((result) => {
-               uni.showToast({
-                title:'恢复成功'
-              })
+              uni.showToast({
+                title: "恢复成功",
+              });
               let userWrongIds = result.data.map((item) => {
-                return item.id;
+                return item;
               });
               uni.setStorageSync(storageName, userWrongIds);
               this.wrongListCount = userWrongIds.length;
@@ -408,7 +408,17 @@ export default {
       this.wrongSyncShow = false;
     },
     goExercise(type) {
+      let storageName1 =
+        uni.getStorageSync("userInfo").xcxOpenid +
+        "_userWrongIds_" +
+        this.query.subject;
+
+      let storageName2 =
+        uni.getStorageSync("userInfo").xcxOpenid +
+        "_userCollectionIds_" +
+        this.query.subject;
       let query = Object.assign({}, this.query);
+      console.log(query)
       if (type == "wrong" && this.wrongListCount == 0) {
         uni.showToast({
           title: "没有题目了",
@@ -425,11 +435,17 @@ export default {
       }
 
       if (type == "wrong") {
+        // query.questionIds =uni.getStorageSync(storageName1)? uni.getStorageSync(storageName1).map((item) => {
+        //   return item.id;
+        // }).join(','):'';
         uni.navigateTo({
           url: "/otherPages/exerciseWrong/index?" + utils.mapToUrlQuery(query),
         });
       }
       if (type === "collect") {
+        // query.questionIds =uni.getStorageSync(storageName2)? uni.getStorageSync(storageName2).map((item) => {
+        //   return item.id;
+        // }).join(','):'';
         uni.navigateTo({
           url:
             "/otherPages/exerciseCollect/index?" + utils.mapToUrlQuery(query),

+ 23 - 7
src/pages/user/index.vue

@@ -7,7 +7,7 @@
             @click="
               () => {
                 userFormShow = true;
-                username = userInfo.nickName||'新用户';
+                nickName = userInfo.nickName||'新用户';
               }
             "
             class="userButton"
@@ -139,7 +139,7 @@
           </view>
           <view>
             <van-field
-              :value="username"
+              :value="nickName"
               required
               clearable
               label="用户名"
@@ -148,7 +148,7 @@
             />
             <van-field
               readonly
-              :value="userphone"
+              :value="phone"
               clearable
               label="手机号"
               placeholder="请绑定手机号"
@@ -165,7 +165,7 @@
             </van-field>
           </view>
           <view class="userform-bind">
-            <van-button custom-style="width:690rpx;" round type="primary"
+            <van-button @click="sendUserInfo" custom-style="width:690rpx;" round type="primary"
               >修改用户信息</van-button
             >
           </view>
@@ -203,20 +203,36 @@ export default {
   data() {
     return {
       userFormShow: false,
-      username: "",
-      userphone: "",
+      nickName: "",
+      phone: "",
     };
   },
   mounted() {
     this.$store.dispatch("GetInfo");
   },
   methods: {
+    sendUserInfo(){
+      api.user.userInfoUserInfo({
+        nickName:this.nickName,
+        phone:this.phone
+      }).then(res=>{
+        this.userFormShow=false
+        this.$store.dispatch("GetInfo");
+      })
+
+    },
     changeUserName(e) {
       console.log(e);
-      this.username = e.detail;
+      this.nickName = e.detail;
     },
     getPhoneByUser(e) {
       console.log(e);
+      api.user.userInfoGetPhoneByCode({
+        code:e.detail.code
+      }).then(res=>{
+        this.phone = res.data
+        
+      })
     },
     goPath(url) {
       uni.navigateTo({