瀏覽代碼

调整页面

wangxy 3 周之前
父節點
當前提交
84960ab88d
共有 3 個文件被更改,包括 65 次插入7 次删除
  1. 29 4
      pages/client/Kaoshi/exam.vue
  2. 13 2
      pages/client/Kaoshi/examTools.js
  3. 23 1
      utils/userCache.js

+ 29 - 4
pages/client/Kaoshi/exam.vue

@@ -139,7 +139,8 @@
 	const {
 		saveCacheKs,
 		getCacheKs,
-		removeCacheKs
+		removeCacheKs,
+		removeCacheKsOther
 	} = useKaoShiCache();
 
 	const {
@@ -302,6 +303,26 @@
 	}
 
 	// 考试得分相关 end
+	function handleSave1() {
+		const result = []
+		questionData.value.forEach(dl => {
+			dl.qas.forEach(st => {
+				const opt = {
+					stId: st.stId,
+					reply: st.reply,
+				}
+				result.push(opt)
+			})
+		})
+		// 保存试题答案
+		saveCacheKs(data.operId, {
+			replyList: result,
+			position: {
+				dlIndex: progress.dlIndex,
+				dtIndex: progress.dtIndex
+			}
+		})
+	}	
 
 	// 保存相关
 	function handleSave(showToast) {
@@ -577,7 +598,7 @@
 			progress.dlIndex = result.dlIndex;
 			progress.dtIndex = result.dtIndex
 		}
-
+		handleSave1()
 	}
 
 	function handleNext() {
@@ -588,6 +609,7 @@
 			progress.dlIndex = result.dlIndex;
 			progress.dtIndex = result.dtIndex
 		}
+		handleSave1()
 	}
 
 	function formatDuanluoList(dlData) {
@@ -762,16 +784,19 @@
 			data.zhuapai = zhuapai;
 			data.duanluo = duanluoList;
 			formatDuanluoList(data.duanluo);
+			
 			// 设置缓存
 			formatKaoshiData();
 			// 设置抓拍监听
+			
+			removeCacheKsOther(operId)
 
-			if (data.zhuapai && data.zhuapai > 0) {
+		/* 	if (data.zhuapai && data.zhuapai > 0) {
 				zhuapaiRef.value.init({
 					zhuapai: zhuapai,
 					operId: operId
 				});
-			}
+			} */
 			// 设置切屏
 			qiepingInit({
 				zhuapaiFlag: !!data.zhuapai,

+ 13 - 2
pages/client/Kaoshi/examTools.js

@@ -30,7 +30,7 @@ export function useIdentificationTools() {
 
 const ksCache = 'kaoshiCache'
 export function useKaoShiCache() {
-	const {saveCache,getCache,removeCache} = useUserCache();
+	const {saveCache,getCache,removeCache,getCacheOtherNotKey} = useUserCache();
 	
 	function saveCacheKs(key,data) {
 		saveCache(ksCache,key, data)
@@ -45,9 +45,20 @@ export function useKaoShiCache() {
 	}
 	
 	
+	// 清理考试缓存其他,保留目标缓存 务必使考试缓存保持唯一
+	function removeCacheKsOther(key) {
+		const data = getCacheOtherNotKey(ksCache)
+		if (data) {
+			const newData = data[key];
+			saveCache(ksCache, key, newData)
+		}
+	}
+	
+	
 	return {
 		saveCacheKs,
 		getCacheKs,
-		removeCacheKs
+		removeCacheKs,
+		removeCacheKsOther
 	}
 }

+ 23 - 1
utils/userCache.js

@@ -82,6 +82,27 @@ export function useUserCache() {
 		}
 		return pageData[userId][pageId][key];
 	}
+	function getCacheOtherNotKey() {
+		let pageId;
+		pageId = arguments[0];
+
+		const auth = cacheManager.get('auth');
+		if (!auth) {
+			throw new Error('用户未登录!')
+			return;
+		}
+		const userId = auth.userId;
+		if (!userId) {
+			throw new Error('数据异常用户Id异常!')
+			return;
+		}
+
+		let pageData = uni.getStorageSync(TokenKey);
+		if (!pageData || !pageData[userId] || !pageData[userId][pageId]) {
+			return null;
+		}
+		return pageData[userId][pageId];
+	}
 
 	function removeCache() {
 		let pageId, key;
@@ -131,6 +152,7 @@ export function useUserCache() {
 	return {
 		saveCache,
 		getCache,
-		removeCache
+		removeCache,
+		getCacheOtherNotKey
 	}
 }