From db1650206aff68eca93b70d488a3145b58b53eed Mon Sep 17 00:00:00 2001 From: jiangx Date: Fri, 27 Oct 2023 09:39:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9mallCode=E4=BB=8Eurl=E5=9C=B0=E5=9D=80=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 7 ++++-- src/components/ScrollList/ScrollList.vue | 23 +++++++++++++++---- .../ScrollListItem/ScrollListItem.vue | 1 + .../WeatherAndTime/WeatherAndTime.vue | 20 +++++++++++++++- src/composables/useAutoBack.ts | 2 +- src/composables/useConfig.ts | 6 ++--- src/composables/useWeather.ts | 17 ++++++++++---- src/http/api/base/index.ts | 5 +--- 8 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/App.vue b/src/App.vue index 192bc1a..758e7e7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,6 @@ diff --git a/src/components/WeatherAndTime/WeatherAndTime.vue b/src/components/WeatherAndTime/WeatherAndTime.vue index 9cd4603..ce636ce 100644 --- a/src/components/WeatherAndTime/WeatherAndTime.vue +++ b/src/components/WeatherAndTime/WeatherAndTime.vue @@ -23,13 +23,31 @@ diff --git a/src/composables/useAutoBack.ts b/src/composables/useAutoBack.ts index 31a8229..2430fbb 100644 --- a/src/composables/useAutoBack.ts +++ b/src/composables/useAutoBack.ts @@ -3,7 +3,7 @@ import { ref } from 'vue' export const useAutoBack = (callback: () => void) => { const MIN_TIME = 0 const CHECK_TIME = 1000 - const TO_INDEX_TIME = 10 + const TO_INDEX_TIME = 60 const toIndexTime = ref(TO_INDEX_TIME) //回首页的时间 const toIndexInterval = ref() diff --git a/src/composables/useConfig.ts b/src/composables/useConfig.ts index 6079475..733b51c 100644 --- a/src/composables/useConfig.ts +++ b/src/composables/useConfig.ts @@ -1,13 +1,11 @@ -import { getWeather, getConfig, getDevice } from '@/http/api/base' +import { getConfig } from '@/http/api/base' import { useRootStore } from '@/store/root' export const useConfig = async () => { const store = useRootStore() try { - const [_weather, _config, _device] = await Promise.all([getWeather(), getConfig(), getDevice()]) - store.SET_WEATHER(_weather.data) + const [_config] = await Promise.all([getConfig()]) store.SET_CONFIG(_config.data) - store.SET_DEVICE(_device.data) Promise.resolve() } catch (error) { console.log('error: ', error) diff --git a/src/composables/useWeather.ts b/src/composables/useWeather.ts index 3adb084..7c76a64 100644 --- a/src/composables/useWeather.ts +++ b/src/composables/useWeather.ts @@ -1,12 +1,19 @@ -import { ref, toRefs } from 'vue' +import { ref, toRefs, computed } from 'vue' import { useRootStore } from '@/store/root' +import { getWeather } from '@/http/api/base' type IconMap = { type: ExtractIcons<'sunny' | 'cloudy' | 'rain' | 'snow' | 'shade'>; status: string } export const useWeather = () => { const store = useRootStore() - const { weather } = toRefs(store) - const icon = ref({} as IconMap) + const { config } = toRefs(store) + const weather = ref({} as Weather) + + function getWeatherStatus(mallCode: string) { + getWeather(config.value.smallUrl, mallCode).then(({ data }) => { + weather.value = data ?? {} + }) + } const status: IconMap[] = [ { type: 'sunny', status: '晴' }, @@ -15,7 +22,7 @@ export const useWeather = () => { { type: 'snow', status: '雪' }, { type: 'shade', status: '阴' } ] - icon.value = status.find(item => weather.value.status?.includes(item.status)) ?? status[0] + const icon = computed(() => status.find(item => weather.value.status?.includes(item.status)) ?? status[0]) - return { weather, icon } + return { weather, icon, getWeatherStatus } } diff --git a/src/http/api/base/index.ts b/src/http/api/base/index.ts index 2b88749..6908ceb 100644 --- a/src/http/api/base/index.ts +++ b/src/http/api/base/index.ts @@ -4,11 +4,8 @@ import { PREFIX } from '@/enums' //获取配置项 export const getConfig = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getConfig.json` }) -//获取设备 -export const getDevice = () => request({ url: `${PREFIX.STATIC_URL}/JSON/GetDevCoordinateByIP.json` }) - //获取天气 -export const getWeather = () => request({ url: `${PREFIX.STATIC_URL}/JSON/GetWeathers.json` }) +export const getWeather = (url: string, mallCode: string) => request({ url: `${url}/Api/Cdn/GetWeathers?mallCode=${mallCode}` }) //获取心声列表 export const getCustomerList = (url: string, params: { pageIndex: number; pageSize: number; mallCode: string }) => {