diff --git a/blossom-backend/backend/src/main/java/com/blossom/backend/thirdparty/hefeng/WeatherManager.java b/blossom-backend/backend/src/main/java/com/blossom/backend/thirdparty/hefeng/WeatherManager.java index a5b7d1c..79f1fbf 100644 --- a/blossom-backend/backend/src/main/java/com/blossom/backend/thirdparty/hefeng/WeatherManager.java +++ b/blossom-backend/backend/src/main/java/com/blossom/backend/thirdparty/hefeng/WeatherManager.java @@ -47,7 +47,11 @@ public class WeatherManager { Map maps = initParam(location); if (maps == null) { log.info("未配置天气信息, 忽略天气查询"); - return null; + HeWeatherDTO weather = new HeWeatherDTO(); + HeWeatherDTO.Location l = new HeWeatherDTO.Location(); + l.setName("未配置天气"); + weather.setLocation(l); + return weather; } HttpResponse city; HttpResponse now; @@ -130,7 +134,7 @@ public class WeatherManager { */ public Map initParam(String location) { Map paramMap = paramService.selectMap(false, ParamEnum.HEFENG_KEY); - if (MapUtil.isNotEmpty(paramMap) && StrUtil.isBlank(paramMap.get(ParamEnum.HEFENG_KEY.name()))) { + if (MapUtil.isNotEmpty(paramMap) && StrUtil.isNotBlank(paramMap.get(ParamEnum.HEFENG_KEY.name()))) { Map map = new HashMap<>(2); map.put("location", location); map.put("key", paramMap.get(ParamEnum.HEFENG_KEY.name())); diff --git a/blossom-editor/src/renderer/src/components/Weather.vue b/blossom-editor/src/renderer/src/components/Weather.vue index 5dca8a5..4243560 100644 --- a/blossom-editor/src/renderer/src/components/Weather.vue +++ b/blossom-editor/src/renderer/src/components/Weather.vue @@ -112,7 +112,7 @@ const getImgUrl = (name: string) => { const weather = ref({ location: { - name: '' + name: '未配置天气' }, now: { iconValue: '#wt-qing', @@ -134,12 +134,16 @@ const getWeather = () => { weatherResult.value = 'LOADING'; setTimeout(() => { getAll({ location: userStore.userinfo.location }).then(resp => { - resp.data.now.img = getImgUrl(resp.data.now.iconValue.replaceAll('#wt-', '')) - // resp.data.now.img = '@renderer/assets/imgs/weather/' + resp.data.now.iconValue.replaceAll('#wt-', '') + '.png' - resp.data.daily[0].img = getImgUrl(resp.data.daily[0].iconValueDay.replaceAll('#wt-', '') + '-s') - resp.data.daily[1].img = getImgUrl(resp.data.daily[1].iconValueDay.replaceAll('#wt-', '') + '-s') - resp.data.daily[2].img = getImgUrl(resp.data.daily[2].iconValueDay.replaceAll('#wt-', '') + '-s') - weather.value = resp.data + console.log(resp.data); + if (resp.data.now) { + resp.data.now.img = getImgUrl(resp.data.now.iconValue.replaceAll('#wt-', '')) + } + if (resp.data.daily) { + resp.data.daily[0].img = getImgUrl(resp.data.daily[0].iconValueDay.replaceAll('#wt-', '') + '-s') + resp.data.daily[1].img = getImgUrl(resp.data.daily[1].iconValueDay.replaceAll('#wt-', '') + '-s') + resp.data.daily[2].img = getImgUrl(resp.data.daily[2].iconValueDay.replaceAll('#wt-', '') + '-s') + } + weather.value = { ...weather.value, ...resp.data } }) }, 0); }