Переглянути джерело

Merge branch '2025鹅状元dev' of https://gogs.mtavip.com/wangguoyu/uniProject into 2025鹅状元dev

tanxue 2 місяців тому
батько
коміт
4de422910f

+ 9 - 13
pages/selectGradesTerms/index.vue

@@ -11,7 +11,7 @@
 					<!-- 产品 -->
 					<view v-for="item in xuekeList" :key="item.id" :id="`s_${item.id}`"  @click="handleSelectGrade(item)"
 						:class="[ 'subject-item', item.typeId === 1 && 'subject-jstx-item' ]">
-							<icon v-if="item.id === activeProduct" class="subject-active-icon"></icon>
+							<icon v-if="item.id == activeProduct" class="subject-active-icon"></icon>
 							<img :src="item.cover" class="subject-item-img" />
 							<view class="subject-item-text"><text>{{item.lable}}</text></view>
 					</view>
@@ -28,7 +28,6 @@
 		reactive,
 		toRefs,
 		computed,
-		nextTick
 	} from "vue";
 	import * as httpApi from "@/api/selectGradesTerms.js";
 	import {
@@ -40,10 +39,7 @@
 		findTreeNode
 	} from "@/utils/common.js"
 	import cacheManager from "@/utils/cacheManager.js"
-	import {
-		getCommonTree,
-		getIndexTree
-	} from "../../api/selectGradesTerms";
+  import {getDataFromStr} from "@/utils/common.js"
 
 	function useSelectGrade() {
 		const userCode = getUserIdentity();
@@ -86,12 +82,16 @@
 			httpApi.getIndexTree().then(res => {
 				data.xuekeData = res.data || [];
 				const {
-					levelId,
+					levelId: levelIdD,
 				} = cacheManager.get('auth');
+
+				let levelId = getDataFromStr(levelIdD)[0];
+
 				if (levelId) {
 					// LevelId 翻找根节点学科,执行选中高亮操作
-					const xuekeObj = findRootNode(data.xuekeData, levelId, 'levelId');
-					const productObj = findTreeNode(data.xuekeData, levelId, 'children','levelId');
+					const xuekeObj = findRootNode(data.xuekeData, +levelId, 'levelId');
+					const productObj = findTreeNode(data.xuekeData, +levelId, 'children','levelId');
+					console.log('productObj',productObj,data.xuekeData,levelId)
 					data.activeProduct = productObj.id;
 					data.activeXueke = xuekeObj.id;
 				} else {
@@ -136,14 +136,10 @@
 			const subjectId = Product.subjectId;
 
 			if (userCode !== 'Visitor') {
-				const auth = cacheManager.get('auth');
 				cacheManager.updateObject('auth', {
 					typeId: typeId,
 					levelId: levelId,
 					subjectId: subjectId,
-					zhangId: data.activeProduct == auth.levelId && data.activeXueke == auth.cardId ? auth.zhangId :
-						0,
-					currentZhang: 0
 				})
 				// 通知岛重新调用接口
 				cacheManager.remove('zhangInfo')

+ 28 - 23
pages/selectVersion/selectVersion.vue

@@ -13,7 +13,8 @@
 				<scroll-view scroll-y="true" class="select-version-body" :scroll-into-view="data.scrollTop">
 					<view class="version-content-box">
 						<!-- 产品 -->
-						<view v-for="item in list" :key="item.id" :id="`s_${item.id}`" @click="handleSelectVersion(item)"
+						<view v-for="item in list" :key="item.id" :id="`s_${item.id}`"
+							@click="handleSelectVersion(item)"
 							:class="[ 'version-item', {'active': item.id == data.shangxiaVersionId} ]">
 							<view class="version-item-border">{{item.lable}}</view>
 						</view>
@@ -29,11 +30,8 @@
 <script setup>
 	import {
 		reactive,
-		toRefs,
-		toRef,
 		computed,
 		nextTick,
-		ref,
 	} from "vue";
 	import * as httpApi from "@/api/selectGradesTerms.js";
 	import {
@@ -43,9 +41,8 @@
 	} from "@/utils/common.js"
 	import cacheManager from "@/utils/cacheManager.js"
 	import {
-		getCommonTree,
-		getIndexTree
-	} from "../../api/selectGradesTerms";
+		getDataFromStr
+	} from "@/utils/common.js"
 	import {
 		onLoad
 	} from "@dcloudio/uni-app";
@@ -61,13 +58,13 @@
 		shangxiaId: 1, // 上下册
 		shangxiaVersionId: null, // 当前版本
 	})
-	
+
 	const list = computed(() => {
 		if (!data.allList.length) {
 			return []
 		}
 		const d_id = data.shangxiaId;
-	
+
 		return data.allList.find(item => item.id == d_id).children
 	})
 
@@ -75,7 +72,6 @@
 		levelId,
 		subjectId,
 		shangxiaId, // 上下册Id
-		shangxiaVersionId, // 上下册版本Id
 		typeId,
 		tipFlag
 	}) => {
@@ -83,10 +79,10 @@
 		if (userCode !== 'Visitor') {
 			initUserProducts();
 		} else {
-			data.levelId = levelId;
+			data.levelId = getDataFromStr(levelId)[0];
 			data.subjectId = subjectId || 1;
 			data.shangxiaId = shangxiaId || 1; // 默认选中上册
-			data.shangxiaVersionId = shangxiaVersionId; // 默认选中上册
+			data.shangxiaVersionId = getDataFromStr(levelId)[1]; // 默认选中上册
 			data.typeId = typeId;
 			data.activeTipFlag = tipFlag || '0';
 			initVisitProducts();
@@ -135,16 +131,25 @@
 		}
 		goDAOToStudy();
 	}
-	
+
 	// 跳转 岛 学习
 	function goDAOToStudy() {
 		const userCode = getUserIdentity();
 		if (userCode !== 'Visitor') {
-			const auth = cacheManager.get('auth');
+			const {
+				levelId: levelIdD,
+			} = cacheManager.get('auth');
+
+			let levelId = getDataFromStr(levelIdD)[0];
+			
+			console.log('levelId',levelId,data.shangxiaVersionId,levelId + ',' + data.shangxiaVersionId)
+			
 			cacheManager.updateObject('auth', {
 				// 修改上下册+版本字段
-				zhangId: data.shangxiaVersionId,
+				levelId: levelId + ',' + data.shangxiaVersionId,
 			})
+			
+			
 			// 通知岛重新调用接口
 			cacheManager.remove('zhangInfo')
 			uni.redirectTo({
@@ -156,22 +161,24 @@
 				url: `/pages/study/index?levelId=${data.levelId}&typeId=${data.typeId}&subjectId=${data.subjectId}&tipFlag=${data.activeTipFlag}&youkeZhangId=${data.shangxiaVersionId}`
 			})
 		}
-	
+
 	}
-	
+
 
 	function initUserProducts() {
+
 		const {
-			levelId,
+			levelId: levelIdD,
 		} = cacheManager.get('auth');
+
+		let levelId = getDataFromStr(levelIdD)[0];
+
 		data.levelId = levelId;
 		httpApi.getUserZhangList({
 			levelId: data.levelId
 		}).then(res => {
 			data.allList = res.data || [];
-			const {
-				zhangId,
-			} = cacheManager.get('auth');
+			let zhangId = getDataFromStr(levelIdD)[1]
 			if (zhangId) {
 				// LevelId 翻找根节点学科,执行选中高亮操作
 				const obj1 = findRootNode(data.allList, zhangId, 'id');
@@ -198,8 +205,6 @@
 			data.allList = res.data || [];
 		})
 	}
-
-
 </script>
 
 <style>

+ 49 - 68
pages/study/index.vue

@@ -285,22 +285,12 @@
 				})
 			}
 			if (!cacheManager.get('zhangInfo')) {
-				console.log('不实用换葱');
+				console.log('无zhangInfo缓存');
 				chooseMethodNoCache()
 			} else {
-				console.log('shiyonghuancun');
+				console.log('使用缓存Zhanginfo');
 				chooseMethodUseCache()
 			}
-
-			// // 已登录付费未支付选择返回 -> 恢复弹窗
-			// if (options && options.studyWithCatalgue) {
-			// 	// 展开弹窗
-			// 	nextTick(() => {
-			// 		catalogueRef.value.showPopup({
-			// 			zhangId: infoData.zhangId
-			// 		});
-			// 	})
-			// }
 		} else {
 			chooseMethodYouke(options)
 		}
@@ -312,7 +302,6 @@
 			getZhangInfoNewYingyu()
 		} else {
 			// 之前 旧的岛 数学英语 和新的数学
-
 			getZhangInfo()
 		}
 	}
@@ -323,12 +312,20 @@
 			translateData(cacheManager.get('zhangInfo'))
 			zhangList.value = cacheManager.get('zhangInfo').zhangList[0].zList
 			zhangName.value = cacheManager.get('zhangInfo').zhangList[0].zhangName
-			current.value = cacheManager.get('auth').currentZhang
-			zid.value = cacheManager.get('zhangInfo').zhangList[0].zList[cacheManager.get('auth').currentZhang].zhangZid
+			current.value = cacheManager.get('auth').curZid
+			zid.value = cacheManager.get('zhangInfo').zhangList[0].zList[cacheManager.get('auth').curZid].zhangZid
 			infoData.zhangId = cacheManager.get('zhangInfo').zhangList[0].zhangId
 			recordZhangJie()
 		} else {
 			// 之前 旧的岛 数学英语 和新的数学
+
+			const curZhangId = res.data.curZhangId;
+			const resZhangList = res.data.zhangList;
+			const index = resZhangList.findIndex(item => item.zhangId == curZhangId)
+			console.log('index', index);
+			cacheManager.updateObject('auth', {
+				currentZhang: index
+			})
 			translateData(cacheManager.get('zhangInfo'))
 			zhangList.value = cacheManager.get('zhangInfo').zhangList
 			current.value = cacheManager.get('auth').currentZhang
@@ -357,28 +354,22 @@
 
 	// 新的英语 (人教版 之类的 新结构)
 	function getZhangInfoNewYingyu(data) {
+		const arr = localAuth.value.levelId.split(",");
 		let req = {
-			levelId: localAuth.value.levelId,
-			//	levelId: 31,
-			zhangId: localAuth.value.zhangId
-			//	zhangId: 195
+			levelId: arr[0],
+			zhangId: arr[1]
 		}
 		userZhangInfo(req).then(res => {
 			cacheManager.set('zhangInfo', res.data)
-			let zhang = cacheManager.get('zhangInfo').zhangList[0].zList.findIndex(zhang => zhang.zid == localAuth
-				.value.zhangZid);
-			console.log('zhang', zhang);
-			if (zhang != -1) {
-				cacheManager.updateObject('auth', {
-					currentZhang: zhang
-				})
-			} else {
-				cacheManager.updateObject('auth', {
-					currentZhang: 0
-				})
-			}
 
 
+			const curZid = res.data.curZid;
+			const resZList = res.data.zhangList[0].zList;
+			const index = resZList.findIndex(item => item.zid == curZid)
+			console.log('index', index);
+			cacheManager.updateObject('auth', {
+				currentZhang: index
+			})
 			nextTick(() => {
 				translateData(res.data)
 				zhangList.value = res.data.zhangList[0].zList
@@ -391,10 +382,10 @@
 
 		}).catch((err) => {
 			toast('数据异常,请重新登录!')
-			cacheManager.clearAll();
-			uni.reLaunch({
-				url: '/pages/login/index'
-			});
+			// cacheManager.clearAll();
+			// uni.reLaunch({
+			// 	url: '/pages/login/index'
+			// });
 		})
 	}
 
@@ -417,21 +408,13 @@
 		}
 		userZhangInfo(req).then(res => {
 			cacheManager.set('zhangInfo', res.data)
-			let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
-				.value.zhangId);
-			console.log('zhang', zhang);
-
-			if (zhang != -1) {
-				cacheManager.updateObject('auth', {
-					currentZhang: zhang
-				})
-			} else {
-				const zhangIndex = findZhangindex(cacheManager.get('zhangInfo'))
-				console.log(zhangIndex);
-				cacheManager.updateObject('auth', {
-					currentZhang: zhangIndex
-				})
-			}
+			const curZhangId = res.data.curZhangId;
+			const resZhangList = res.data.zhangList;
+			const index = resZhangList.findIndex(item => item.zhangId == curZhangId)
+			console.log('index', index);
+			cacheManager.updateObject('auth', {
+				currentZhang: index
+			})
 			nextTick(() => {
 				translateData(res.data)
 				zhangList.value = res.data.zhangList
@@ -442,10 +425,10 @@
 
 		}).catch((err) => {
 			toast('数据异常,请重新登录!')
-			cacheManager.clearAll();
-			uni.reLaunch({
-				url: '/pages/login/index'
-			});
+			// cacheManager.clearAll();
+			// uni.reLaunch({
+			// 	url: '/pages/login/index'
+			// });
 		})
 	}
 
@@ -463,10 +446,10 @@
 			current.value = 0
 		}).catch((err) => {
 			toast('数据异常,请重新登录!')
-			cacheManager.clearAll();
-			uni.reLaunch({
-				url: '/pages/login/index'
-			});
+			// cacheManager.clearAll();
+			// uni.reLaunch({
+			// 	url: '/pages/login/index'
+			// });
 		})
 	}
 
@@ -491,12 +474,10 @@
 
 	function recordZhangJie() {
 		let req = {
-			levelId: localAuth.value.levelId,
-			userId: localAuth.value.userId,
-			zhangId: infoData.zhangId,
-			subjectId: currentProduct.value,
-			zhangZid: zid.value
-		}
+				levelId: localAuth.value.levelId,
+				userId: localAuth.value.userId,
+				subjectId: currentProduct.value,
+			}
 		userLocate(req).then(res => {
 
 		})
@@ -691,17 +672,17 @@
 	function chooseMethodListClick(data, data2, index) {
 
 		console.log('data', data); // 节内容
-		 console.log('data2', data2); //章内容
+		console.log('data2', data2); //章内容
 		const authCode = getUserIdentity();
 
 		if (currentProduct.value == 2 && typeId.value == 1) {
-		//	const isFirst = data.jieName == data2.jieList[0].jieName
-			if (!cacheManager.get('auth') && data.number !=1) {
+			//	const isFirst = data.jieName == data2.jieList[0].jieName
+			if (!cacheManager.get('auth') && data.number != 1) {
 				youkeDialogRef.value.handleShow();
 				return false;
 			}
 			// console.log('authCode', authCode);
-			if (!(authCode == 'VIP' || data.number ==1)) {
+			if (!(authCode == 'VIP' || data.number == 1)) {
 				goPayDialogRef.value.handleShow();
 				return false
 			}

+ 3 - 7
pages/unitTest/index.vue

@@ -128,13 +128,9 @@
 	}
 	// 继续学习
 	async function goStudyContinue() {
-		const list = cacheManager.get('zhangInfo').zhangList;
-		// 设置 从单元测试 到 岛 的路由参数
-		activeZhang.value.nextZhang ? activeZhang.value.nextZhang.zhangId : null;
-		cacheManager.updateObject('auth', {
-			currentZhang: list.findIndex(item => item.zhangId == activeZhang.value.nextZhang.zhangId),
-			zhangId: activeZhang.value.nextZhang.zhangId
-		})
+    cacheManager.updateObject('zhangInfo', {
+      curZhangId: activeZhang.value.nextZhang.zhangId
+    })
 		uni.redirectTo({
 			url: `/pages/study/index`
 		})

+ 5 - 5
unpackage/dist/cache/.vite/deps/_metadata.json

@@ -1,19 +1,19 @@
 {
-  "hash": "9089c2c2",
-  "configHash": "5978ec27",
+  "hash": "09b26b97",
+  "configHash": "d5858f9f",
   "lockfileHash": "32571fb3",
-  "browserHash": "e7ddfcd6",
+  "browserHash": "d09af41c",
   "optimized": {
     "uview-plus": {
       "src": "../../../../../node_modules/uview-plus/index.js",
       "file": "uview-plus.js",
-      "fileHash": "d88180c2",
+      "fileHash": "fe99ea43",
       "needsInterop": false
     },
     "ts-md5/dist/md5": {
       "src": "../../../../../node_modules/ts-md5/dist/md5.js",
       "file": "ts-md5_dist_md5.js",
-      "fileHash": "9b180fa3",
+      "fileHash": "44ce76a2",
       "needsInterop": true
     }
   },

+ 97 - 54
utils/common.js

@@ -1,42 +1,42 @@
 import cacheManager from "./cacheManager.js"
 
 /**
-* 显示消息提示框
-* @param content 提示的标题
-*/
+ * 显示消息提示框
+ * @param content 提示的标题
+ */
 export function toast(content) {
-  uni.showToast({
-    icon: 'none',
-    title: content
-  })
+	uni.showToast({
+		icon: 'none',
+		title: content
+	})
 }
 
 /**
-* 显示模态弹窗
-* @param content 提示的标题
-*/
+ * 显示模态弹窗
+ * @param content 提示的标题
+ */
 export function showConfirm(content) {
-  return new Promise((resolve, reject) => {
-    uni.showModal({
-      title: '提示',
-      content: content,
-      cancelText: '取消',
-      confirmText: '确定',
-      success: function(res) {
-        resolve(res)
-      }
-    })
-  })
+	return new Promise((resolve, reject) => {
+		uni.showModal({
+			title: '提示',
+			content: content,
+			cancelText: '取消',
+			confirmText: '确定',
+			success: function(res) {
+				resolve(res)
+			}
+		})
+	})
 }
 
 /**
-* 参数处理
-* @param params 参数
-*/
+ * 参数处理
+ * @param params 参数
+ */
 export function tansParams(params) {
-  let result = ''
-  // FIXME   拼接参数 
-  return result
+	let result = ''
+	// FIXME   拼接参数 
+	return result
 }
 
 /**
@@ -44,18 +44,51 @@ export function tansParams(params) {
  * @param {Object} promise
  */
 export function catchError(promise) {
-	return new Promise((resolve,reject) => {
+	return new Promise((resolve, reject) => {
 		promise.then(data => {
-			resolve([undefined, data.data]) 
+			resolve([undefined, data.data])
 		}).catch(err => {
-			reject([err]) 
+			reject([err])
 		})
 	})
 }
 
 // 是否是会员
+const IdentityType = {
+	VIP: 'VIP',
+	NOT_VIP: 'Not-Vip',
+	VISITOR: 'Visitor'
+};
+
+// export function getUserIdentity() {
+// 	const auth = cacheManager.get('auth');
+// 	if (!auth) return IdentityType.VISITOR;
+
+// 	const hasPurchased = auth.subjectId == 2 && auth.typeId == 1 ?
+// 		(auth.levelIdList || []).includes(auth.levelId.split(',')[0]) :
+// 		(auth.levelIdList || []).includes(auth.levelId);
+// 		console.log('hasPurchased',hasPurchased);
+
+// 	return hasPurchased ? IdentityType.VIP : IdentityType.NOT_VIP;
+// }
+
 export function getUserIdentity() {
 	const auth = cacheManager.get('auth');
+	if(auth.subjectId == 2 && auth.typeId == 1){
+	if (auth) {
+		const arr = auth.levelId.split(",");
+		if ((auth.levelIdList || []).some(item => item == arr[0])) {
+			// 购买此levelId
+			return 'VIP'
+		}
+		// 无购买此levelId
+		return 'Not-Vip';
+	} else {
+		// 游客
+		return 'Visitor';
+	}
+	}else{
+		//旧数学 新数学 旧英语
 	if (auth) {
 		if ((auth.levelIdList || []).some(item => item == auth.levelId)) {
 			// 购买此levelId
@@ -67,8 +100,10 @@ export function getUserIdentity() {
 		// 游客
 		return 'Visitor';
 	}
+	}
 }
 
+
 export function hasUserIdentity() {
 	const auth = cacheManager.get('auth');
 	if (auth) {
@@ -85,40 +120,40 @@ export function hasUserIdentity() {
 }
 
 export function debounce(func, wait) {
-  let timeout;
+	let timeout;
 
-  return function(...args) {
-    // 清除之前的定时器
-    clearTimeout(timeout);
+	return function(...args) {
+		// 清除之前的定时器
+		clearTimeout(timeout);
 
-    // 设置新的定时器
-    timeout = setTimeout(() => {
-      func.apply(this, args);
-    }, wait);
-  };
+		// 设置新的定时器
+		timeout = setTimeout(() => {
+			func.apply(this, args);
+		}, wait);
+	};
 }
 
 
 export function findRootNode(tree, targetId, idKey = 'id') {
 	const path = [];
-	
+
 	function traverse(node) {
-	  if (node[idKey] === targetId) return true;
-	  if (node.children) {
-	    for (const child of node.children) {
-	      if (traverse(child)) {
-	        path.unshift(node);
-	        return true;
-	      }
-	    }
-	  }
-	  return false;
+		if (node[idKey] === targetId) return true;
+		if (node.children) {
+			for (const child of node.children) {
+				if (traverse(child)) {
+					path.unshift(node);
+					return true;
+				}
+			}
+		}
+		return false;
 	}
-	
+
 	for (const root of tree) {
-	  if (traverse(root)) {
-	    return path.length > 0 ? path[0] : root;
-	  }
+		if (traverse(root)) {
+			return path.length > 0 ? path[0] : root;
+		}
 	}
 	return null;
 }
@@ -133,4 +168,12 @@ export function findTreeNode(tree, targetId, childrenKey = 'children', idKey = '
 		}
 	}
 	return null;
+}
+
+
+export function getDataFromStr(strdata) {
+	if (!strdata) {
+		return []
+	}
+	return strdata.toString().split(',')
 }