From 979b851da3997cd51f7f3995425ff5156b4a61fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Thu, 6 Nov 2025 17:22:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=89=E7=85=A7=E5=88=86=E6=9E=90=E8=81=94?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../headers/components/weather/index.vue | 39 ++++++++++++++++--- .../headers/components/weather/timeLIne.ts | 5 ++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/views/components/headers/components/weather/index.vue b/src/renderer/src/views/components/headers/components/weather/index.vue index c1059b0..d59bde0 100644 --- a/src/renderer/src/views/components/headers/components/weather/index.vue +++ b/src/renderer/src/views/components/headers/components/weather/index.vue @@ -245,7 +245,6 @@ onMounted(() => { weatherData.currWeather = false sunshine.timeBar = item }) - console.log(timeline, 'klklkl') // timeline.updateTime() // timeline.setCurrBar() }) @@ -254,15 +253,39 @@ onBeforeUnmount(() => { sunshine && sunshine.remove() timeline && timeline.clear() }) +let currWeatherData = false var weatherChange = () => { + currWeatherData = true if (weatherData.currWeather) { let ss = getCurrentTime() - sunshine.timeBar = ss + sunshine && (sunshine.timeBar = ss) weatherData.speed = 1 sunshine && (sunshine.speed = weatherData.speed) + + timeline.setCurrBar() + timeline.setSpeed(weatherData.speed) + + //让日期回到当前时间 + + weatherData.time = getDateTimeString() + timeline.closeChangeDate() + + // sunshine && (sunshine.time = weatherData.time) } } +var getDateTimeString = () => { + // 创建一个表示当前时间的 Date 对象 + const now = new Date() + // 获取年份 + const year = now.getFullYear() + // 获取月份(从 0 开始,所以要加 1),并将其转换为两位字符串,不足两位在前面补零 + const month = String(now.getMonth() + 1).padStart(2, '0') + // 获取日期,并将其转换为两位字符串,不足两位在前面补零 + const day = String(now.getDate()).padStart(2, '0') + // 获取小时,并将其转换为两位字符串,不足两位在前面补零 + return `${year}-${month}-${day}` +} watch( () => weatherData.darkness, (newValue) => { @@ -287,7 +310,11 @@ var decrementValue = () => { watch( () => weatherData.speed, (newValue) => { - weatherData.currWeather = false + if (!currWeatherData) { + weatherData.currWeather = false + } else { + currWeatherData = false + } sunshine && (sunshine.speed = newValue) timeline.setSpeed(newValue) } @@ -322,8 +349,8 @@ var switchFunc = () => { //关闭 sunshine && sunshine.remove() sunshine = null - let timeData = now.setHours(0, 0, 0, 0) // 设置为当天0点 - timeline.updateTime(timeData) + // let timeData = now.setHours(0, 0, 0, 0) // 设置为当天0点 + // timeline.updateTime(timeData) timeline.setSunShine(false) } } @@ -360,7 +387,6 @@ var clickIcon = (item: any) => { } var changDarkness = () => { - console.log('changDarkness') sunshine && (sunshine.darkness = weatherData.darkness) } var changSpeed = () => { @@ -373,6 +399,7 @@ var weatherTimeChange = () => { let timeData = now.setHours(0, 0, 0, 0) // 设置为当天0点 timeline.updateTime(timeData) sunshine && (sunshine.time = weatherData.time) + weatherData.currWeather = false } var onClose = () => {} diff --git a/src/renderer/src/views/components/headers/components/weather/timeLIne.ts b/src/renderer/src/views/components/headers/components/weather/timeLIne.ts index 5000372..5ae511c 100644 --- a/src/renderer/src/views/components/headers/components/weather/timeLIne.ts +++ b/src/renderer/src/views/components/headers/components/weather/timeLIne.ts @@ -179,7 +179,6 @@ export default class TimeLine { if (this.changeDate) {//切换日期后让时间从0开始 this.startTime = performance.now() } - let elapsed = (performance.now() - this.startTime) * this.speed; // if (this.elapsed) { // elapsed = elapsed + this.elapsed @@ -217,10 +216,12 @@ export default class TimeLine { // this.speed = v; } this.manualPosition = null; - // this.update(); } + closeChangeDate() { + this.changeDate && (this.changeDate = false) + } updateTime() { this.manualPosition = null; this.startTime = performance.now() - ((this.manualPosition || 0) * 86400 * 1000 / this.speed);