wangxy 3 days ago
parent
commit
b53728245d
3 changed files with 187 additions and 181 deletions
  1. 70 80
      components/catalogue/catalogue.vue
  2. 96 81
      pages/selectGradesTerms/index.vue
  3. 21 20
      utils/common.js

+ 70 - 80
components/catalogue/catalogue.vue

@@ -5,14 +5,14 @@
 			:style="{backgroundImage: 'url(' + catalogueBjFun() + ')'}">
 			:style="{backgroundImage: 'url(' + catalogueBjFun() + ')'}">
 			<uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
 			<uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
 			<!-- 当前上下册只针对数学 -->
 			<!-- 当前上下册只针对数学 -->
-			<view v-if="subjectId == 1" class="catalogue-levelId-title">L{{levelId}}上</view>
+			<view v-if="subjectId == 1" class="catalogue-levelId-title">{{ jieTexts ? jieTexts[0]: ''}}</view>
 			<!-- 目录区域 -->
 			<!-- 目录区域 -->
 			<uni-collapse v-model="activeCollapse" class="ezy-catalogue-collapse"
 			<uni-collapse v-model="activeCollapse" class="ezy-catalogue-collapse"
 				:class="{ 'ezy-catalogue-collapse-vip': AuthCode === 'VIP'}" accordion>
 				:class="{ 'ezy-catalogue-collapse-vip': AuthCode === 'VIP'}" accordion>
 				<template v-for="(item,index) in list">
 				<template v-for="(item,index) in list">
 					<!-- 当前上下册只针对数学 -->
 					<!-- 当前上下册只针对数学 -->
 					<view v-if="subjectId == 1 && index == shuxueShangxia" class="catalogue-levelId-title catalogue-mt">
 					<view v-if="subjectId == 1 && index == shuxueShangxia" class="catalogue-levelId-title catalogue-mt">
-						L{{levelId}}下</view>
+						{{jieTexts ? jieTexts[1]: ''}}</view>
 					<uni-collapse-item title-border="none" :border="false" :name="index+''" class="collapse-item-box"
 					<uni-collapse-item title-border="none" :border="false" :name="index+''" class="collapse-item-box"
 						:class="{ 'collapse-active': activeCollapse === index+''}">
 						:class="{ 'collapse-active': activeCollapse === index+''}">
 						<template v-slot:title>
 						<template v-slot:title>
@@ -21,9 +21,9 @@
 								<!-- 章名 -->
 								<!-- 章名 -->
 								<text class="collapse-name">{{item.zhangName}}</text>
 								<text class="collapse-name">{{item.zhangName}}</text>
 								<!-- 锁 -->
 								<!-- 锁 -->
-								<template v-if="AuthCode !== 'VIP'">
+								<!-- <template v-if="AuthCode !== 'VIP'">
 									<view class="collapse-lock" v-if="index!=0"></view>
 									<view class="collapse-lock" v-if="index!=0"></view>
-								</template>
+								</template> -->
 							</view>
 							</view>
 						</template>
 						</template>
 						<view class="collapse-content-box">
 						<view class="collapse-content-box">
@@ -66,14 +66,14 @@
 		onLoad
 		onLoad
 	} from '@dcloudio/uni-app';
 	} from '@dcloudio/uni-app';
 
 
-
+  // 旧道,上下分册 LevelId
 	const ShuxueObj = {
 	const ShuxueObj = {
-		1: 6,
-		2: 6,
-		3: 11,
-		4: 11,
-		5: 11,
-		6: 12,
+		7: 6,
+		8: 6,
+		9: 11,
+		10: 11,
+		11: 11,
+		12: 12,
 	}
 	}
 
 
 
 
@@ -97,7 +97,7 @@
 			} else {
 			} else {
 				levelId.value = options.levelId;
 				levelId.value = options.levelId;
 			}
 			}
-			shuxueShangxia.value = ShuxueObj[levelId.value];
+			// shuxueShangxia.value = ShuxueObj[levelId.value];
 		}
 		}
 
 
 	})
 	})
@@ -114,33 +114,14 @@
 	const Message = MESSAGE_BEFORE_PAY;
 	const Message = MESSAGE_BEFORE_PAY;
 	const youkeDialogRef = ref(null);
 	const youkeDialogRef = ref(null);
 	const selectZhang = ref(null);
 	const selectZhang = ref(null);
-
-	const props = defineProps({
-		list: {
-			type: Array,
-		}
-	})
+  const list = ref([])
+  const jieTexts = ref([])
 
 
 	function handleJieClick(item, jie, index, cindex) {
 	function handleJieClick(item, jie, index, cindex) {
 		selectZhang.value = item;
 		selectZhang.value = item;
-		if (index == 0) {
-			// 全员可访问 第一章 第一节
-			this.$emit('listSelectJieClick', item, jie, cindex);
-			return;
-		}
-		if (AuthCode.value == 'Visitor') {
-			// 游客
-			youkeDialogRef.value.handleShow();
-			return;
-		}
-		if (AuthCode.value == 'Not-Vip') {
-			// 非VIP
-			confirmDialogRef.value.handleShow();
-			return;
-		}
-
-		// Vip
-		this.$emit('listSelectJieClick', item, jie, cindex);
+		// this.$emit('listSelectJieClick', item, jie, cindex);
+		$emit('change-zhang', Object.assign({}, item));
+		handleClose();
 	}
 	}
 
 
 	function catalogueBjFun() {
 	function catalogueBjFun() {
@@ -163,45 +144,65 @@
 	 * @summary 展示弹窗 暴露函数
 	 * @summary 展示弹窗 暴露函数
 	 */
 	 */
 	async function showPopup(data) {
 	async function showPopup(data) {
-		let callback = null;
-		if (data) {
-			const index = props.list.findIndex(item => item.zhangId == data.zhangId);
-			scrollTop.value = 0;
-			activeCollapse.value = '';
-			// 滚动高度
-			callback = () => {
-				console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
-				if (subjectId.value == 2) {
-					// 英语
-					activeCollapse.value = index + '';
-					scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
-				} else {
-					// 数学
-					if (index < shuxueShangxia.value) {
-						activeCollapse.value = index + '';
-						scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
-							.getSystemInfoSync().screenWidth / 750) * 50;
-					} else {
-						activeCollapse.value = index + '';
-						scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
-							.getSystemInfoSync().screenWidth / 750) * 50 * 2;
-					}
-				}
-			}
-		}
-		handleShow(callback);
+		handleShow(data);
 	}
 	}
 
 
+  function getFormatZhangListByArray(data) {
+
+    const myList = data.reduce((acc, curr) => acc.concat(curr.zhangList || []), [])
+
+    const jiedian = data[0].zhangList.length;
+
+    return {
+      myList,
+      jiedian,
+      jieText: data.map(item => item.lable)
+    }
+  }
 
 
 	/**
 	/**
 	 * @summary 展示目录弹窗
 	 * @summary 展示目录弹窗
 	 */
 	 */
-	function handleShow(callback) {
-		popupRef.value.open('center');
-		if (callback) {
-
-		}
-		setTimeout(() => callback(), 50)
+	function handleShow(data) {
+    getCatalogue().then(([err, wlist]) => {
+      if (err) {
+        return;
+      }
+      const {myList,jiedian, jieText} = getFormatZhangListByArray(wlist)
+      list.value = myList;
+      if (list.value) {
+        jieTexts.value = jieText;
+        shuxueShangxia.value = jiedian;
+        if (data) {
+          let callback = null;
+          const index = myList.findIndex(item => item.zhangId == data.zhangId);
+          scrollTop.value = 0;
+          activeCollapse.value = '';
+          // 滚动高度
+          callback = () => {
+            console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
+            if (subjectId.value == 2) {
+              // 英语
+              activeCollapse.value = index + '';
+              scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
+            } else {
+              // 数学
+              if (index < shuxueShangxia.value) {
+                activeCollapse.value = index + '';
+                scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
+                    .getSystemInfoSync().screenWidth / 750) * 50;
+              } else {
+                activeCollapse.value = index + '';
+                scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
+                    .getSystemInfoSync().screenWidth / 750) * 50 * 2;
+              }
+            }
+          }
+          setTimeout(() => callback(), 50)
+        }
+      }
+      popupRef.value.open('center');
+    })
 	}
 	}
 
 
 	/**
 	/**
@@ -216,17 +217,6 @@
 	 */
 	 */
 	function handleSelectZhang(data, index) {
 	function handleSelectZhang(data, index) {
 		selectZhang.value = data;
 		selectZhang.value = data;
-		if (index != 0 && AuthCode.value == 'Visitor') {
-			// 游客
-			youkeDialogRef.value.handleShow();
-			return;
-		}
-
-		if (index != 0 && AuthCode.value == 'Not-Vip') {
-			// 非VIP
-			confirmDialogRef.value.handleShow();
-			return;
-		}
 		$emit('change-zhang', Object.assign({}, data));
 		$emit('change-zhang', Object.assign({}, data));
 		handleClose();
 		handleClose();
 	}
 	}

+ 96 - 81
pages/selectGradesTerms/index.vue

@@ -2,21 +2,21 @@
 	<view class="grades-terms-page">
 	<view class="grades-terms-page">
 		<view class="icon-title-navBar-box">
 		<view class="icon-title-navBar-box">
 			<!-- 返回按钮↓ -->
 			<!-- 返回按钮↓ -->
-			<view class="nav-bar-icon"  @click="handleBack"></view>
+			<view class="nav-bar-icon" @click="handleBack"></view>
 		</view>
 		</view>
 		<view class="grade-item-box">
 		<view class="grade-item-box">
 			<view :key="xueke.id" @click="handleSelectXueke(xueke)" v-for="xueke in xuekeData"
 			<view :key="xueke.id" @click="handleSelectXueke(xueke)" v-for="xueke in xuekeData"
-					  :class="['grade-item',{active: xueke.id == activeXueke}]">{{xueke.lable}}</view>
+				:class="['grade-item',{active: xueke.id == activeXueke}]">{{xueke.lable}}</view>
 		</view>
 		</view>
 		<view class="subject-body">
 		<view class="subject-body">
 			<view class="subject-content-box">
 			<view class="subject-content-box">
 				<!-- 产品 -->
 				<!-- 产品 -->
 				<view v-for="item in xuekeList" :key="item.id" @click="handleSelectGrade(item)"
 				<view v-for="item in xuekeList" :key="item.id" @click="handleSelectGrade(item)"
-					  :class="['subject-item', {active: item.id == activeProduct}]">
-					  <view class="subject-item-border">
-						  <img :src="item.cover" class="subject-item-img"/>
-						  <view class="subject-item-text">{{item.lable}}</view>
-					  </view>
+					:class="['subject-item', {active: item.id == activeProduct}]">
+					<view class="subject-item-border">
+						<img :src="item.cover" class="subject-item-img" />
+						<view class="subject-item-text">{{item.lable}}</view>
+					</view>
 				</view>
 				</view>
 			</view>
 			</view>
 		</view>
 		</view>
@@ -26,66 +26,76 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-
 	import {
 	import {
 		reactive,
 		reactive,
 		toRefs,
 		toRefs,
-    computed
+		computed
 	} from "vue";
 	} from "vue";
-  import * as httpApi from "@/api/selectGradesTerms.js";
+	import * as httpApi from "@/api/selectGradesTerms.js";
 	import {
 	import {
 		onLoad
 		onLoad
 	} from "@dcloudio/uni-app";
 	} from "@dcloudio/uni-app";
-	import {getUserIdentity,findRootNode,findTreeNode} from "@/utils/common.js"
+	import {
+		getUserIdentity,
+		findRootNode,
+		findTreeNode
+	} from "@/utils/common.js"
 	import cacheManager from "@/utils/cacheManager.js"
 	import cacheManager from "@/utils/cacheManager.js"
-  import {getCommonTree, getIndexTree} from "../../api/selectGradesTerms";
+	import {
+		getCommonTree,
+		getIndexTree
+	} from "../../api/selectGradesTerms";
 
 
 	function useSelectGrade() {
 	function useSelectGrade() {
 		const userCode = getUserIdentity();
 		const userCode = getUserIdentity();
 
 
 		const data = reactive({
 		const data = reactive({
 			activeProduct: null, // 当前年级
 			activeProduct: null, // 当前年级
-			activeXueke: null, // 当前学期
+			activeXueke: 1, // 当前学期
 			activeTipFlag: null, // 当前学期
 			activeTipFlag: null, // 当前学期
-      xuekeData: [], // 学科总数据
+			xuekeData: [], // 学科总数据
 		});
 		});
 
 
-		onLoad(({productId,xuekeId,tipFlag}) => {
+		onLoad(({
+			productId,
+			xuekeId,
+			tipFlag
+		}) => {
 			if (userCode !== 'Visitor') {
 			if (userCode !== 'Visitor') {
-        initUserProducts();
+				initUserProducts();
 			} else {
 			} else {
-        data.activeProduct = productId;
-        data.activeXueke = xuekeId;
-        data.activeTipFlag = tipFlag || '0';
-        initVisitProducts();
+				data.activeProduct = productId;
+				data.activeXueke = xuekeId;
+				data.activeTipFlag = tipFlag || '0';
+				initVisitProducts();
 			}
 			}
 		});
 		});
 
 
-    // 初始化游客产品数据
-    function initVisitProducts() {
-      httpApi.getCommonTree().then(res => {
-        data.xuekeData = res.data||[];
-      })
-    }
-
-    function initUserProducts() {
-      httpApi.getIndexTree().then(res => {
-        data.xuekeData = res.data||[];
-        const {
-          levelId,
-        } = cacheManager.get('auth');
-        if (levelId) {
-          // LevelId 翻找根节点学科,执行选中高亮操作
-          const xuekeObj = findRootNode(data.xuekeData, levelId,'levelId');
-          const productObj = findTreeNode(data.xuekeData, levelId,'levelId');
-          data.activeProduct = productObj.id;
-          data.activeXueke = xuekeObj.id;
-        } else {
-          data.activeProduct = null;
-          data.activeXueke = null
-        }
-      })
-    }
+		// 初始化游客产品数据
+		function initVisitProducts() {
+			httpApi.getCommonTree().then(res => {
+				data.xuekeData = res.data || [];
+			})
+		}
+
+		function initUserProducts() {
+			httpApi.getIndexTree().then(res => {
+				data.xuekeData = res.data || [];
+				const {
+					levelId,
+				} = cacheManager.get('auth');
+				if (levelId) {
+					// LevelId 翻找根节点学科,执行选中高亮操作
+					const xuekeObj = findRootNode(data.xuekeData, levelId, 'levelId');
+					const productObj = findTreeNode(data.xuekeData, levelId, 'children','levelId');
+					data.activeProduct = productObj.id;
+					data.activeXueke = xuekeObj.id;
+				} else {
+					data.activeProduct = null;
+					data.activeXueke = null
+				}
+			})
+		}
 
 
 		// 选择 年级+学期
 		// 选择 年级+学期
 		function handleConfirm() {
 		function handleConfirm() {
@@ -105,53 +115,60 @@
 				});
 				});
 				return;
 				return;
 			}
 			}
-      goDAOToStudy();
+			goDAOToStudy();
 		}
 		}
 
 
 		// 跳转 岛 学习
 		// 跳转 岛 学习
 		function goDAOToStudy() {
 		function goDAOToStudy() {
-      const Product = data.xuekeData.find(item => item.id == data.activeXueke).children.find(item => item.id == data.activeProduct)
-      const levelId = Product.levelId;
-      const typeId = Product.typeId;
-      const subjectId = Product.subjectId;
+			const Product = data.xuekeData.find(item => item.id == data.activeXueke).children.find(item => item.id == data
+				.activeProduct)
+			const levelId = Product.levelId;
+			const typeId = Product.typeId;
+			const subjectId = Product.subjectId;
 
 
 			if (userCode !== 'Visitor') {
 			if (userCode !== 'Visitor') {
 				const auth = cacheManager.get('auth');
 				const auth = cacheManager.get('auth');
 				cacheManager.updateObject('auth', {
 				cacheManager.updateObject('auth', {
-          typeId: typeId,
-          levelId: levelId,
-          subjectId: subjectId,
-          zhangId: data.activeProduct == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId: 0,
-          currentZhang: 0
+					typeId: typeId,
+					levelId: levelId,
+					subjectId: subjectId,
+					zhangId: data.activeProduct == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId :
+						0,
+					currentZhang: 0
 				})
 				})
 				cacheManager.remove('daoPageCache')
 				cacheManager.remove('daoPageCache')
 				uni.redirectTo({
 				uni.redirectTo({
 					url: `/pages/study/index`
 					url: `/pages/study/index`
 				})
 				})
 			} else {
 			} else {
-        if (typeId == 1) {
-          // 新岛
-          uni.redirectTo({
-            url: `/pages/study/index?levelId=${levelId}&typeId=${typeId}&subjectId=${subjectId}&tipFlag=${data.activeTipFlag}`
-          })
-        } else {
-          // 旧岛
-          uni.redirectTo({
-            url: `/pages/study/index?levelId=${levelId}&typeId=${typeId}&subjectId=${subjectId}&zhangId=0&tipFlag=${data.activeTipFlag}`
-          })
-        }
+				if (typeId == 1) {
+					// 新岛
+					uni.redirectTo({
+						url: `/pages/study/index?levelId=${levelId}&typeId=${typeId}&subjectId=${subjectId}&tipFlag=${data.activeTipFlag}`
+					})
+				} else {
+					// 旧岛
+					uni.redirectTo({
+						url: `/pages/study/index?levelId=${levelId}&typeId=${typeId}&subjectId=${subjectId}&zhangId=0&tipFlag=${data.activeTipFlag}`
+					})
+				}
 
 
 			}
 			}
 
 
 		}
 		}
+
 		function handleBack() {
 		function handleBack() {
 			if (userCode !== 'Visitor') {
 			if (userCode !== 'Visitor') {
-				uni.redirectTo({ url: `/pages/study/index`})
+				uni.redirectTo({
+					url: `/pages/study/index`
+				})
 			} else {
 			} else {
-				uni.redirectTo({url: '/pages/login/index'})
+				uni.redirectTo({
+					url: '/pages/login/index'
+				})
 			}
 			}
 		}
 		}
-		
+
 		return {
 		return {
 			...toRefs(data),
 			...toRefs(data),
 			handleBack,
 			handleBack,
@@ -163,28 +180,26 @@
 	const {
 	const {
 		activeProduct,
 		activeProduct,
 		activeXueke,
 		activeXueke,
-    xuekeData,
+		xuekeData,
 		handleConfirm,
 		handleConfirm,
 		handleBack
 		handleBack
 	} = useSelectGrade()
 	} = useSelectGrade()
 
 
-  const xuekeList = computed(() => {
+	const xuekeList = computed(() => {
 
 
-    if (!xuekeData.value.length) {
-      return []
-    }
-    const d_id = activeXueke.value || xuekeData.value[0].id;
-    return xuekeData.value.find(item => item.id == d_id).children
-  })
+		if (!xuekeData.value.length) {
+			return []
+		}
+		const d_id = activeXueke.value;
+		return xuekeData.value.find(item => item.id == d_id).children
+	})
 
 
-  function handleSelectGrade(item) {
+	function handleSelectGrade(item) {
 		activeProduct.value = item.id;
 		activeProduct.value = item.id;
 	}
 	}
 
 
 	function handleSelectXueke(item) {
 	function handleSelectXueke(item) {
 		activeXueke.value = item.id;
 		activeXueke.value = item.id;
-    activeProduct.value = null;
+		activeProduct.value = null;
 	}
 	}
-	
-
 </script>
 </script>

+ 21 - 20
utils/common.js

@@ -99,27 +99,28 @@ export function debounce(func, wait) {
 }
 }
 
 
 
 
-export function findRootNode(tree, targetId, idKey = 'id', childrenKey = 'children') {
-	let root = null;
-
-	function traverse(nodes) {
-		for (const node of nodes) {
-			if (node[idKey] === targetId) {
-				root = nodes[0]; // 当前子树根即为目标根:ml-citation{ref="3" data="citationList"}
-				return true;
-			}
-			if (node[childrenKey]?.length) {
-				if (traverse(node[childrenKey]) && !root) {
-					root = node; // 当子树找到目标时,当前节点为根:ml-citation{ref="3,8" data="citationList"}
-					return true;
-				}
-			}
-		}
-		return false;
+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;
 	}
 	}
-
-	traverse(tree);
-	return root;
+	
+	for (const root of tree) {
+	  if (traverse(root)) {
+	    return path.length > 0 ? path[0] : root;
+	  }
+	}
+	return null;
 }
 }