天气未配置时的提示(#14)

This commit is contained in:
xiaozzzi 2023-10-06 17:22:26 +08:00
parent 0323f84b51
commit 1db4efc0fe
2 changed files with 17 additions and 9 deletions

View File

@ -47,7 +47,11 @@ public class WeatherManager {
Map<String, Object> 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<String, Object> initParam(String location) {
Map<String, String> 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<String, Object> map = new HashMap<>(2);
map.put("location", location);
map.put("key", paramMap.get(ParamEnum.HEFENG_KEY.name()));

View File

@ -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 => {
console.log(resp.data);
if (resp.data.now) {
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'
}
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 = resp.data
}
weather.value = { ...weather.value, ...resp.data }
})
}, 0);
}