From 0650969cf1b9cfa0742ee8c9ec4f8230951167e2 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E4=B8=AD=E6=96=87=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=A4=A9=E6=B0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/vue/src/store/modules/weather.ts | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/vue/src/store/modules/weather.ts b/apps/vue/src/store/modules/weather.ts index 4d43899c4..680b1211f 100644 --- a/apps/vue/src/store/modules/weather.ts +++ b/apps/vue/src/store/modules/weather.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia'; import { Position, WeatherInfo } from '/@/api/weather/model'; import { getPosition, getWeather } from '/@/api/weather'; +import { useLocaleStoreWithOut } from './locale'; interface WeatherState { currentCity?: Position; @@ -17,20 +18,23 @@ export const useWeatherStore = defineStore({ }), actions: { async updateWeather() { - const hour = new Date().getHours(); - if (hour - this.lastUpdateHour != 0) { - const position = await getPosition(); - const weatherResult = await getWeather(position.code); - if (weatherResult.code !== 0) { - return Promise.reject(weatherResult.msg); + const localeStore = useLocaleStoreWithOut(); + // 中文环境天气api有效 + if (localeStore.getLocale.includes('zh')) { + const hour = new Date().getHours(); + if (hour - this.lastUpdateHour != 0) { + const position = await getPosition(); + const weatherResult = await getWeather(position.code); + if (weatherResult.code !== 0) { + return Promise.reject(weatherResult.msg); + } + this.currentCity = position; + this.weather = weatherResult.data; + this.lastUpdateHour = hour; + return Promise.resolve(this.weather); } - this.currentCity = position; - this.weather = weatherResult.data; - this.lastUpdateHour = hour; - return Promise.resolve(this.weather); - } else { - return Promise.resolve(this.weather); } + return Promise.resolve(this.weather); } } });