Browse Source
Merge pull request #701 from colinin/Custom-Workbench
仅中文环境查询天气
pull/708/head
yx lin
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
16 additions and
12 deletions
-
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,6 +18,9 @@ export const useWeatherStore = defineStore({ |
|
|
|
}), |
|
|
|
actions: { |
|
|
|
async updateWeather() { |
|
|
|
const localeStore = useLocaleStoreWithOut(); |
|
|
|
// 中文环境天气api有效
|
|
|
|
if (localeStore.getLocale.includes('zh')) { |
|
|
|
const hour = new Date().getHours(); |
|
|
|
if (hour - this.lastUpdateHour != 0) { |
|
|
|
const position = await getPosition(); |
|
|
|
@ -28,9 +32,9 @@ export const useWeatherStore = defineStore({ |
|
|
|
this.weather = weatherResult.data; |
|
|
|
this.lastUpdateHour = hour; |
|
|
|
return Promise.resolve(this.weather); |
|
|
|
} else { |
|
|
|
return Promise.resolve(this.weather); |
|
|
|
} |
|
|
|
} |
|
|
|
return Promise.resolve(this.weather); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|