From bf66b4eee07a68307af59c4b70ccca4b6d0f8ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Fri, 23 Feb 2024 20:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/config/tc-dataDir.vue | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/config/tc-dataDir.vue b/src/components/config/tc-dataDir.vue index abfcc696..26da4f41 100644 --- a/src/components/config/tc-dataDir.vue +++ b/src/components/config/tc-dataDir.vue @@ -104,13 +104,12 @@ async function confirmCUD(): Promise { }, 4000); } -// 获取当天日期数字,如 20240204 -function getNowDate(): number { - const now = new Date(); - const year = now.getFullYear().toString(); // 4位年份 - const month = (now.getMonth() + 1).toString().padStart(2, "0"); // 月份 - const day = now.getDate().toString().padStart(2, "0"); // 日期 - return parseInt(year + month + day); +// 判断是否超过一周 +function isOverWeek(date: string): boolean { + const nowTs = Date.now(); + const checkTs = new Date(date).getTime(); + const weekTs = 7 * 24 * 60 * 60 * 1000; + return nowTs - checkTs >= weekTs; } async function confirmCLD(): Promise { @@ -131,11 +130,9 @@ async function confirmCLD(): Promise { // yyyy-mm-dd.log const reg = /(\d{4}-\d{2}-\d{2}\.log)/; const match = file.path.match(reg); - if (match === null) { - return false; - } + if (!Array.isArray(match) || match.length < 1) return false; const date = match[1].replace(".log", ""); - return getNowDate() - parseInt(date.replace(/-/g, "")) > 7; + return isOverWeek(date); }); if (delFiles.length < 1) { showSnackbar({