wangguoyu 3 місяців тому
батько
коміт
496771158e
2 змінених файлів з 73 додано та 12 видалено
  1. 12 0
      api/word.js
  2. 61 12
      pages/study/index.vue

+ 12 - 0
api/word.js

@@ -82,3 +82,15 @@ export function getWordShouCang(data = {}) {
     timeout: 20000
   })
 }
+
+export function wordXuewan(data = {}) {
+  return request({
+    'url': '/app/word/xuewan',
+    headers: {
+      isToken: true
+    },
+    method: 'post',
+    data,
+    timeout: 20000
+  })
+}

+ 61 - 12
pages/study/index.vue

@@ -54,7 +54,8 @@
 	} from "@/api/login.js"
 	import {
 		getWordListYk,
-		getWordList
+		getWordList,
+		wordXuewan
 	} from "@/api/word.js"
 	import {
 		reactive,
@@ -570,21 +571,69 @@
 			})
 
 		} else {
-
-			getWordList({
+			wordXuewan({
 				jieId: data.jieId
-			}).then(res => {
-				if (res.code == 0 && res.data.wordList.length > 0) {
-					uni.redirectTo({
-						url: '/pages/wordList/wordList?jieId=' + data.jieId
-					})
-				} else {
-					toast("该单元没有学习内容!");
-					return false
-				}
+			}).then(res => {
+				getZhangInfoNewYingyu()
+				// const localZhangInfo = cacheManager.get('zhangInfo')
+				// const result = updateStudyFlag(localZhangInfo, data.jieId, 1);
+				// console.log('result',result);
+
+				// if (result) {
+				// 	cacheManager.set('zhangInfo', result)
+				// }
+
 			})
+			// getWordList({
+			// 	jieId: data.jieId
+			// }).then(res => {
+			// 	if (res.code == 0 && res.data.wordList.length > 0) {
+			// 		uni.redirectTo({
+			// 			url: '/pages/wordList/wordList?jieId=' + data.jieId
+			// 		})
+			// 	} else {
+			// 		toast("该单元没有学习内容!");
+			// 		console.log('data,jieId', data.jieId);
+			// 		wordXuewan({
+			// 			jieId: data.jieId
+			// 		}).then(res => {
+			// 			const result = updateStudyFlag(responseData, data.jieId, 1);
+			// 			if (result) {
+			// 				cacheManager.set('zhangInfo', result)
+			// 			}
+
+			// 		})
+			// 		return false
+			// 	}
+			// })
 		}
 	}
+	const updateStudyFlag = (data, jieIdToUpdate, newValue) => {
+		// 检查data和必要的数据结构是否存在
+		if (!data || !Array.isArray(data.zhangList)) {
+			console.warn('无效的数据结构');
+			return false;
+		}
+
+		// 遍历zhangList
+		data.zhangList.forEach(zhang => {
+			// 检查zList是否存在且是数组
+			if (zhang && Array.isArray(zhang.zList)) {
+				zhang.zList.forEach(z => {
+					// 检查jieList是否存在且是数组
+					if (z && Array.isArray(z.jieList)) {
+						z.jieList.forEach(jie => {
+							// 检查jie对象和jieId是否存在
+							if (jie && jie.jieId == jieIdToUpdate) {
+								jie.studyFlag = newValue;
+							}
+						});
+					}
+				});
+			}
+		});
+		return data;
+	};
 
 	function goLookShipin(data, index) {