wangguoyu 2 mēneši atpakaļ
vecāks
revīzija
a9c52ab5a0
2 mainītis faili ar 115 papildinājumiem un 84 dzēšanām
  1. 26 30
      pages/study/index.vue
  2. 89 54
      utils/common.js

+ 26 - 30
pages/study/index.vue

@@ -312,22 +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
-			})
-			
-			
+			// 之前 旧的岛 数学英语 和新的数学
+
+			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
@@ -355,22 +353,22 @@
 	}
 
 	// 新的英语 (人教版 之类的 新结构)
-	function getZhangInfoNewYingyu(data) {
-		const arr =  localAuth.value.levelId.split(",");
+	function getZhangInfoNewYingyu(data) {
+		const arr = localAuth.value.levelId.split(",");
 		let req = {
 			levelId: arr[0],
 			zhangId: arr[1]
 		}
 		userZhangInfo(req).then(res => {
-			cacheManager.set('zhangInfo', res.data)
-			
-		
-			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
+			cacheManager.set('zhangInfo', res.data)
+
+
+			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)
@@ -476,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 => {
 
 		})

+ 89 - 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;
 }