From df24dcb3e24a007f64bf7cceae6bd986443d8787 Mon Sep 17 00:00:00 2001 From: chuzhongzai Date: Fri, 29 Dec 2023 15:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=AE=9A=E6=97=B6=E5=A4=9C?= =?UTF-8?q?=E9=97=B4=E6=A8=A1=E5=BC=8F;=E6=97=A0=E6=B3=95=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=9C=8B=E6=97=B6=E7=BB=99=E5=87=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA;(=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0)?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=9B=BE=E9=93=BE=E6=8E=A5=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E5=88=87=E6=8D=A2=E5=88=B0=E8=AF=A5=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=9B=BE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DashBoard.vue | 65 +++--------------------------------- src/components/Side.vue | 4 +-- src/store/index.js | 16 ++++++--- 3 files changed, 17 insertions(+), 68 deletions(-) diff --git a/src/components/DashBoard.vue b/src/components/DashBoard.vue index d5dffdf..8516e0e 100644 --- a/src/components/DashBoard.vue +++ b/src/components/DashBoard.vue @@ -98,13 +98,7 @@
夜间模式
夜间模式跟随系统 -
- 自定义起始时间(精确到分) -
- - ~ - - +
在线预览
@@ -293,63 +287,20 @@ function adjustForStyle(){ let darkConfigStr = localStorage.getItem("darkConfig") if(darkConfigStr !== null) { darkConfig.value = JSON.parse(darkConfigStr) - if (darkConfig.value.followSystem) - if (isSystemDark()) { - dark() - isDark.value = true - } - else { - light() - isDark.value = false - } - - if (darkConfig.value.customTime) - if (isDarkTime(darkConfig.value)) { - dark() - isDark.value = true - } - else { - light() - isDark.value = false - } - - if(isDark.value) + if (darkConfig.value.followSystem && isSystemDark()) dark() else light() }else { light() - darkConfig.value = {'followSystem': false, 'customTime': false} + darkConfig.value = {'followSystem': false} } } function isSystemDark(){ return window.matchMedia('(prefers-color-scheme: dark)').matches } -function isDarkTime(darkConfig){ - let date = new Date() - let startTime = darkConfig.startTime - let endTime = darkConfig.endTime - if(startTime.hour > endTime.hour){ //隔夜 22:00 ~ 8:00 - if(date.getHours() > endTime.getHours() && date.getHours() < startTime.getHours()){ // 大于结束时间且小于起始时间 16:00 - return false - }else if(date.getHours() === endTime.getHours()){ //22:00 ~ 8:30 8:26 - return date.getMinutes() <= endTime.getMinutes(); - }else if(date.getHours() === startTime.getHours()){ //22:30 ~ 8:00 22:46 - return date.getMinutes() > startTime.getMinutes(); - }else - return true - }else{ //不隔夜 00:00 ~ 6:00 22:00 ~ 23:00 - if(date.getHours() > endTime.getHours() || date.getHours() < startTime.getHours()){ - return false - }else if(date.getHours() === startTime.getHours()){ // 01:30 ~ 06:00 01:32 - return date.getMinutes() >= startTime.getMinutes(); - }else if(date.getHours() === endTime.getHours()){ // 01:30 ~ 06:30 06:35 - return date.getMinutes() <= endTime.getMinutes(); - }else - return true - } -} function dark(){ + isDark.value = true let html = document.querySelector("html") if(!html.classList.contains("dark")) html.classList.add('dark') @@ -357,6 +308,7 @@ function dark(){ document.querySelector(".app").style.setProperty("background-color", null) } function light(){ + isDark.value = false let html = document.querySelector("html") if(html.classList.contains("dark")) html.classList.remove('dark') @@ -365,13 +317,6 @@ function light(){ document.querySelector(".app").style.setProperty("background-color", "#c6e2ff") } function saveConfig(){ - if(darkConfig.value.customTime) { - if(darkConfig.value.startTime === undefined || darkConfig.value.endTime === undefined){ - ElMessage("请正确选择起始时间") - return - } - } - if(lengthPerPage.value < 0 || lengthPerPage.value > 30) { ElMessage("分页页数设置错误,范围1~30") lengthPerPage.value = 30 diff --git a/src/components/Side.vue b/src/components/Side.vue index c3a61eb..dd38164 100644 --- a/src/components/Side.vue +++ b/src/components/Side.vue @@ -98,8 +98,6 @@