Description
If you shed tears when you miss the sun, you also miss the stars.
雾霾的频繁出现已严重的影响到人们的出行,对人们的健康造成了重大影响。因此,能在出行前查看雾霾的指数,并采取相应的措施来把雾霾的影响降到最小就显得尤为重要。本系统在分析多种因子的影响下,设计一个手机端天气查询网站。
包含以下功能:
a.定位功能:将定位城市保存在服务器端,并同时显示在客户端。
b.界面设计:包含显示天气和空气质量指数的动态显示。
c.天气详情和空气质量指数:定位后的城市在服务器端获取后,传给天气详情界面,通过所传城市用百度天气api获取对应的天气详情和空气质量指数,并保存在服务器端。
后续可以添加出行建议等功能。
项目地址:Devinwain-Github-天气查询 (opens new window)
根据任务需求,我们计划设计一个适配手机端的天气查询网页,页面信息包含空气质量指数、温度等,并包含了未来10小时的预报。同时产品同学制作出相应的原型图交付给开发同学。开发同学根据原型图确定好技术选型,从而开始着手开发。
原型图:Figma原型图 (opens new window)
下面具体阐述系统的技术方案:
目前只有一个页面,所以代码都写在index.vue中,由于用了echarts画图,所以中间的配置项特别长,其实页面可以分成几个组件,这样更方便维护。
config用来配置允许跨域,controller用来相应请求,且共享一个Address对象,目前只考虑了单用户的情况,多用户访问的话可能会有问题(待验证)。domain里是一个Address的POJO,包含ip、province、city还有一个画图需要的属性。utils里封装了获取ip的方法。
访问页面后,自动定位到所在城市,结果如下图:
自定义城市后,如河北省石家庄市,结果如下:
服务端打印所有查询结果:
通过ip判断是否为本地用户,若是则发送请求到http://pv.sohu.com/cityjson?ie=utf-8 (opens new window)可以获取外网ip及所在城市。
每次数据更新后都要重新setOption来更新。
暂时用一个hashmap来接收请求参数,所有参数会存在hashmap的第一个键里,取出来后转成json对象再去按键取值。后续可以看看哪里出问题了,或者转成一个get请求。
到时候用别的api吧。
描述:根据请求过来的ip通过百度的ip查询接口获取它的位置信息。本地用户会特殊处理,参考问题1。
请求类型:POST 请求参数:无
{
"data": {
"country": "中国",
"country_id": "CN",
"area": "西北",
"region": "陕西",
"region_id": "610000",
"city": "西安",
"city_id": "610100",
"ip": "111.111.111.6",
"long_ip": "1999977155",
"isp": "联通"
},
"msg": "成功",
"success": true,
"code": 200,
"taskNo": "54119621271131057206"
}
描述:目前这个api会配合/api/location一起使用,从而保证ip不为空,然后通过ip查询该城市的天气信息。返回的数据是经过处理的(信息太多,方便前端处理)。后续还需要优化,与/api/location解耦。 请求类型:POST 请求参数:无
{
"ip": "113.200.174.6",
"city": "西安",
"province": "陕西",
"aqi": 53,
"fut_10_hour": [
"现在",
"05/11",
"01:00",
"02:00",
"03:00",
"04:00",
"05:00",
"06:00",
"07:00",
"08:00"
],
"fut_10_temp": [
15,
17,
17,
16,
15,
15,
15,
15,
16,
16
],
"fut_10_aqi": [
50,
44,
44,
44,
44,
44,
44,
44,
46,
46
]
}
{
"cityid": "101010100",
"date": "2022-05-10",
"week": "星期二",
"update_time": "14:05",
"city": "北京",
"cityEn": "beijing",
"country": "中国",
"countryEn": "China",
"wea": "霾",
"wea_img": "wu",
"tem": "14",
"tem1": "14",
"tem2": "10",
"win": "南风",
"win_speed": "2级",
"win_meter": "8km/h",
"humidity": "67%",
"visibility": "5km",
"pressure": "1007",
"air": "63",
"air_pm25": "45",
"air_level": "良",
"air_tips": "空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!",
"alarm": {
"alarm_type": "",
"alarm_level": "",
"alarm_content": ""
},
"wea_day": "小雨",
"wea_day_img": "yu",
"wea_night": "小雨",
"wea_night_img": "yu",
"sunrise": "05:04",
"sunset": "19:17",
"hours": [
{
"hours": "现在",
"wea": "多云",
"wea_img": "yun",
"tem": "13",
"win": "南风",
"win_speed": "3级",
"aqi": "良",
"aqinum": "72"
},
{
"hours": "15:00",
"wea": "多云",
"wea_img": "yun",
"tem": "13",
"win": "南风",
"win_speed": "3级",
"aqi": "良",
"aqinum": "69"
},
{
"hours": "16:00",
"wea": "多云",
"wea_img": "yun",
"tem": "13",
"win": "南风",
"win_speed": "3级",
"aqi": "良",
"aqinum": "69"
},
{
"hours": "17:00",
"wea": "阴转多云",
"wea_img": "yun",
"tem": "13",
"win": "西南风",
"win_speed": "2级",
"aqi": "良",
"aqinum": "70"
},
{
"hours": "18:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "西南风",
"win_speed": "2级",
"aqi": "良",
"aqinum": "70"
},
{
"hours": "19:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "西北风",
"win_speed": "1级",
"aqi": "良",
"aqinum": "71"
},
{
"hours": "20:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "西北风",
"win_speed": "2级",
"aqi": "良",
"aqinum": "74"
},
{
"hours": "21:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "西北风",
"win_speed": "2级",
"aqi": "良",
"aqinum": "74"
},
{
"hours": "22:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "北风",
"win_speed": "3级",
"aqi": "良",
"aqinum": "71"
},
{
"hours": "23:00",
"wea": "小雨",
"wea_img": "yu",
"tem": "12",
"win": "东北风",
"win_speed": "3级",
"aqi": "良",
"aqinum": "65"
},
{
"hours": "05/11",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "北风",
"win_speed": "3级",
"aqi": "优",
"aqinum": "57"
},
{
"hours": "01:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "3级",
"aqi": "优",
"aqinum": "51"
},
{
"hours": "02:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "49"
},
{
"hours": "03:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "49"
},
{
"hours": "04:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "49"
},
{
"hours": "05:00",
"wea": "晴",
"wea_img": "qing",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "46"
},
{
"hours": "06:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "43"
},
{
"hours": "07:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "东北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "40"
},
{
"hours": "08:00",
"wea": "多云",
"wea_img": "yun",
"tem": "12",
"win": "北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "40"
},
{
"hours": "09:00",
"wea": "多云",
"wea_img": "yun",
"tem": "14",
"win": "西北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "40"
},
{
"hours": "10:00",
"wea": "晴",
"wea_img": "qing",
"tem": "16",
"win": "西北风",
"win_speed": "3级",
"aqi": "优",
"aqinum": "40"
},
{
"hours": "11:00",
"wea": "晴",
"wea_img": "qing",
"tem": "19",
"win": "西北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "37"
},
{
"hours": "12:00",
"wea": "晴",
"wea_img": "qing",
"tem": "20",
"win": "西北风",
"win_speed": "2级",
"aqi": "优",
"aqinum": "34"
}
],
"aqi": {
"update_time": "12:57",
"air": "63",
"air_level": "良",
"air_tips": "空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!",
"pm25": "45",
"pm25_desc": "良",
"pm10": "64",
"pm10_desc": "良",
"o3": "59",
"o3_desc": "优",
"no2": "15",
"no2_desc": "优",
"so2": "3",
"so2_desc": "优",
"co": "-",
"co_desc": "-",
"kouzhao": "不用佩戴口罩",
"yundong": "适宜运动",
"waichu": "适宜外出",
"kaichuang": "适宜开窗",
"jinghuaqi": "关闭净化器"
},
"zhishu": {
"chuanyi": {
"level": "较冷",
"tips": "建议着厚外套加毛衣等服装。"
},
"daisan": {
"level": "带伞",
"tips": "有降水,带雨伞,短期外出可收起雨伞。"
},
"ganmao": {
"level": "易发",
"tips": "大幅度降温,湿度较大,注意防护。"
},
"chenlian": {
"level": "不宜",
"tips": "有较强降水,建议在室内做适当锻炼。"
},
"ziwaixian": {
"level": "最弱",
"tips": "辐射弱,涂擦SPF8-12防晒护肤品。"
},
"liangshai": {
"level": "不宜",
"tips": "降水可能会淋湿衣物,请选择在室内晾晒。"
},
"kaiche": {
"level": "",
"tips": ""
},
"xiche": {
"level": "不宜",
"tips": "有雨,雨水和泥水会弄脏爱车。"
},
"lvyou": {
"level": "适宜",
"tips": "较弱降水和微风将伴您共赴旅程。"
},
"diaoyu": {
"level": "不宜",
"tips": "天气不好,有风,不适合垂钓。"
}
}
}
描述:用户自主选择城市时,确认后会调用这个api查询该城市的天气,目前存在两个问题,见问题5。 请求类型:POST 请求参数:
{
"province": "浙江",
"city": "杭州"
}
{
"ip": "113.200.174.6",
"city": "西安",
"province": "陕西",
"aqi": 53,
"fut_10_hour": [
"现在",
"05/11",
"01:00",
"02:00",
"03:00",
"04:00",
"05:00",
"06:00",
"07:00",
"08:00"
],
"fut_10_temp": [
15,
17,
17,
16,
15,
15,
15,
15,
16,
16
],
"fut_10_aqi": [
50,
44,
44,
44,
44,
44,
44,
44,
46,
46
]
}
This app can be installed on your PC or mobile device. This will allow this web app to look and behave like any other installed app. You will find it in your app lists and be able to pin it to your home screen, start menus or task bars. This installed web app will also be able to safely interact with other apps and your operating system.
If you shed tears when you miss the sun, you also miss the stars.