Bladeren bron

收藏和错题的模式更改

JXDS18FUJT 2 jaren geleden
bovenliggende
commit
1c6a776e81
3 gewijzigde bestanden met toevoegingen van 19 en 39 verwijderingen
  1. 15 36
      src/hooks/exercise/list.ts
  2. 2 1
      src/route/guard.ts
  3. 2 2
      src/views/collection/index.vue

+ 15 - 36
src/hooks/exercise/list.ts

@@ -42,7 +42,8 @@ export const useSubjectList = (type: ExerciseType.ListType) => {
 			let ids = userWrongIds.map(item => {
 				return item.id
 			})
-			const result = testModel.getBatchList({
+			ids.sort((a, b) => a - b)
+			 testModel.getBatchList({
 				ids: ids
 			}).then(res => {
 				subjectList.value = res.list;
@@ -53,42 +54,20 @@ export const useSubjectList = (type: ExerciseType.ListType) => {
 			// const questionList.value.push(...result.rows)
 		}
 		else if (type == "collection") {
-			const collectionModel = new CollectionModel(type);
-			const result = await collectionModel.getList({
-				carType: query.vehicle as CollectionAndWrongType.CarType,
-				km: query.name as CollectionAndWrongType.Km,
-				pageNum: 1,
-				pageSize: 50
-			});
-			console.log(result.collectionList)
-			if (result.rows.length == 0) {
-				return
-			}
-			result.rows.forEach(item => {
-				item.isTrue = null
-				if (typeof item.opts == "string") {
-					item.opts = item.opts.split("-")
-				}
-			})
-			let questionItem: Test.QuestionInfo = result.rows[0]
-			let questionIndex = 0
-			//排序
-			if (query.questionId) {
-				result.rows.forEach((item, index) => {
-					if (item.id == Number(query.questionId)) {
-						questionIndex = index
-						questionItem = item
-					}
-				})
-				result.rows.splice(questionIndex, 1)
-				result.rows.unshift(questionItem)
-
-			}
-			res = {
-				total: result.total,
-				list: result.rows
-			}
+			let localVuex = JSON.parse(window.localStorage.getItem('vuex') || '{}')
+			let userCollectKey = localVuex.userData.openid + "_用户收藏id_" + subject;
+			let userCollectIds: { id: number, timestamp: number }[] = JSON.parse(window.localStorage.getItem(userCollectKey) || "[]")
 
+			let ids = userCollectIds.map(item => {
+				return item.id
+			})
+			ids.sort((a, b) => a - b)
+			testModel.getBatchList({
+				ids: ids
+			}).then(res => {
+				subjectList.value = res.list;
+				subjectTotal.value = res.total;
+			})
 		}
 		else {
 			res = await testModel.getFreeList({

+ 2 - 1
src/route/guard.ts

@@ -22,6 +22,7 @@ const guard = (router: Router) => {
 			await useLogin(to.query);
 			// Toast("登录成功")
 			next("./")
+			useUpdateUserInfo();
 			// try {
 			// 	await useLogin(to.query);
 			// 	toast.message = `登陆成功`;
@@ -37,7 +38,7 @@ const guard = (router: Router) => {
 			// }
 		}
 		//更新用户的信息
-		useUpdateUserInfo();
+		
 		//检测token状态,token失效直接跳转至登陆链接
 		// try {
 		// 	useUpdateUserInfo();

+ 2 - 2
src/views/collection/index.vue

@@ -53,8 +53,8 @@
 				@confirm="sendWrongSync"
 				:columns="[
 					{ text: '合并本机和云端错题', value: 0 },
-					{ text: '备份本机收藏到错题', value: 1 },
-					{ text: '恢复云端收藏到错题', value: 2 },
+					{ text: '备份本机错题到云端', value: 1 },
+					{ text: '恢复云端错题到本机', value: 2 },
 				]"></van-picker>
 		</van-popup>