wangguoyu 4 miesięcy temu
rodzic
commit
2b7e2936fe
2 zmienionych plików z 28 dodań i 23 usunięć
  1. 1 1
      pages/pay/svip.vue
  2. 27 22
      utils/cacheManager.js

+ 1 - 1
pages/pay/svip.vue

@@ -99,7 +99,7 @@
 		}
 		orderAdd(req).then(res=>{
 			console.log('res');
-			cacheManager.updateObject('auth',{cardList:[cardId.value]})
+			cacheManager.updateVipStatus('auth',cardId.value)
 			toast('开通成功!')
 			uni.redirectTo({
 				url: '/pages/study/index'

+ 27 - 22
utils/cacheManager.js

@@ -1,5 +1,6 @@
 const cacheManager = (function() {
 	const STORAGE_PREFIX = 'App_cache_';
+
 	function set(key, value) {
 		const fullKey = STORAGE_PREFIX + key;
 		if (typeof value === 'object' && value !== null) {
@@ -32,44 +33,47 @@ const cacheManager = (function() {
 		let obj = get(key) || {};
 		// 合并更新到对象中
 		//Object.assign(obj, updates);
-		 for (let [keyToUpdate, value] of Object.entries(updates)) {
-		    if (value === null || value === undefined) {
-		      // 如果值为 null 或 undefined,则删除属性
-		      delete obj[keyToUpdate];
-		    } else {
-		      obj[keyToUpdate] = value;
-		    }
-		  }
+		for (let [keyToUpdate, value] of Object.entries(updates)) {
+			if (value === null || value === undefined) {
+				// 如果值为 null 或 undefined,则删除属性
+				delete obj[keyToUpdate];
+			} else {
+				obj[keyToUpdate] = value;
+			}
+		}
 		set(key, obj);
 	}
 	// 用于视频已经看完 修改状态
-	function updateJieStatus(key, index,currentJieId) {
+	function updateJieStatus(key, index, currentJieId) {
 		let obj = get(key) || {};
-		// console.log('obj',obj);
-		// console.log('index',index);
-		// console.log('currentJieId',currentJieId);
-		for(let jie of obj.zhangList[index].jieList){
-			if(jie.jieId ==currentJieId){
-		//		console.log('jie',jie);
+		for (let jie of obj.zhangList[index].jieList) {
+			if (jie.jieId == currentJieId) {
+				//		console.log('jie',jie);
 				jie.studyFlag = 1
 				break
 			}
 		}
 		set(key, obj);
 	}
+	// 更新会员
+	function updateVipStatus(key, cardId) {
+		let obj = get(key) || {};
+		if (!obj.cardList.includes(cardId)) {
+			obj.cardList.push(cardId);
+		}
+		set(key, obj);
+	}
 	// 获得当前jie参数
-	function getCurrentJieData(key, index,currentJieId) {
+	function getCurrentJieData(key, index, currentJieId) {
 		let obj = get(key) || {};
-		// console.log('obj',obj);
-		// console.log('index',index);
-		// console.log('currentJieId',currentJieId);
-		for(let jie of obj.zhangList[index].jieList){
-			if(jie.jieId ==currentJieId){
+		for (let jie of obj.zhangList[index].jieList) {
+			if (jie.jieId == currentJieId) {
 				return jie
 				break
 			}
 		}
 	}
+
 	function clearAll() {
 		const keys = uni.getStorageInfoSync().keys;
 		keys.forEach(key => {
@@ -119,6 +123,7 @@ const cacheManager = (function() {
 		updateJieStatus,
 		getCurrentJieData,
 		updateObject,
+		updateVipStatus,
 		findArrayInObject,
 		clearAll
 	};
@@ -132,7 +137,7 @@ export const SHOW_UNIT_TEST_TISHI = 'SHOW_UNIT_TEST_TISHI';
 // 单元测试大鹅提示缓存
 export function useUnitTestTishi() {
 	return {
-		updateTishi:() => cacheManager.set(SHOW_UNIT_TEST_TISHI,'has'),
+		updateTishi: () => cacheManager.set(SHOW_UNIT_TEST_TISHI, 'has'),
 		getTishi: () => cacheManager.get(SHOW_UNIT_TEST_TISHI)
 	}
 }