去除定时夜间模式;无法在线看时给出错误提示;(同步更新)预览图链接为空时不切换到该预览图;

This commit is contained in:
chuzhongzai
2023-12-29 15:24:48 +08:00
parent 5cf7549b35
commit df24dcb3e2
3 changed files with 17 additions and 68 deletions
+5 -60
View File
@@ -98,13 +98,7 @@
<div>
夜间模式<hr>
<span style="display: inline-block">夜间模式跟随系统</span>
<el-switch v-model="darkConfig.followSystem"></el-switch><br>
<span style="display: inline-block">自定义起始时间(精确到分)</span>
<el-switch v-model="darkConfig.customTime"></el-switch><br>
<el-form :disabled="!darkConfig.customTime">
<el-time-picker v-model="darkConfig.startTime" /> ~
<el-time-picker v-model="darkConfig.endTime"/>
</el-form>
<el-switch v-model="darkConfig.followSystem"></el-switch>
</div>
<div>
在线预览<hr>
@@ -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