wangxy 1 день назад
Родитель
Сommit
54b2660237
2 измененных файлов с 34 добавлено и 5 удалено
  1. 5 5
      pages/chanpinXuanze/index.vue
  2. 29 0
      utils/common.js

+ 5 - 5
pages/chanpinXuanze/index.vue

@@ -44,7 +44,7 @@
 		getChanpinTongyongIndex
 	} from "@/api/chanpinShuxue";
 	import {
-		getFullTimer
+		useSelectDateForUpdate
 	} from "@/utils/common";
 
 	let currentTabIndex = ref(0)
@@ -68,7 +68,7 @@
 		yingyuList: [],
 		yuwenList: [],
 	})
-
+	const {isNowDate} = useSelectDateForUpdate('xuankeDate')
 
 	function getFormatData(data) {
 		const shuxue = data.shuxue || {};
@@ -114,10 +114,10 @@
 		currentTabIndex.value = 0;
 		data.chanpinActiveSelect = 'shuxue';
 
-		if (getFullTimer() !== `2026-01-28`) {
-			//每日刷新
-			getShuxueList();
+		if (isNowDate()) {
+			// 当天不刷新
 		} else {
+			//每日刷新
 			getShuxueList()
 		}
 	})

+ 29 - 0
utils/common.js

@@ -168,4 +168,33 @@ export function getFullTimer() {
 	const day = now.getDate();
     // 格式:2026-01-29
 	return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
+}
+
+
+export function useSelectDateForUpdate(code) {
+	function getDate() {
+		return cacheManager.get(code);
+	}
+	
+	function updateDate() {
+		console.log(1111)
+		cacheManager.set(code, getFullTimer())
+	}
+	
+	function isNowDate() {
+		const nowDate = getDate();
+		if (!nowDate) {
+			updateDate();
+			return false
+		}
+		if (nowDate != getFullTimer()) {
+			updateDate();
+		}
+		
+		return nowDate == getFullTimer();
+	}
+	
+	return {
+		isNowDate
+	}
 }