|
@@ -159,77 +159,3 @@ function createUrl(cname) {
|
|
|
return urls;
|
|
return urls;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//高德地图获取天气
|
|
|
|
|
-function getAdcode(){
|
|
|
|
|
- return new Promise((resolve, reject)=>{
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- url: "https://restapi.amap.com/v3/ip?key=ee001a52e68437f9a030eaa01c3a9646",
|
|
|
|
|
- type: 'get',
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- success: function (data) {
|
|
|
|
|
- resolve(data);
|
|
|
|
|
- },
|
|
|
|
|
- error: function (data) {
|
|
|
|
|
- reject(data);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-function getGdWeather(mode) {
|
|
|
|
|
- getAdcode().then((adcode)=>{
|
|
|
|
|
- if(adcode && adcode.status == "1"){
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- url: `https://restapi.amap.com/v3/weather/weatherInfo?key=ee001a52e68437f9a030eaa01c3a9646&city=${adcode.adcode}&extensions=base`,
|
|
|
|
|
- type: 'get',
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- success: function (data) {
|
|
|
|
|
- if(data && data.status == "1"){
|
|
|
|
|
- var weather = data.lives[0];
|
|
|
|
|
- let nowText = new Date(weather.reporttime).toLocaleDateString('zh').replaceAll('/', '-')
|
|
|
|
|
- if(mode=="classic"){
|
|
|
|
|
- var name = weather.city + ' ' + nowText + ' ' +
|
|
|
|
|
- weather.temperature + "°C" + ' ' + weather.winddirection+ ' ' + weather.windpower+ '级';
|
|
|
|
|
- $("#weatherWX").html(name);
|
|
|
|
|
- }else{
|
|
|
|
|
- var oSpan = document.getElementsByClassName('info');
|
|
|
|
|
- oSpan[0].innerHTML = weather.city;
|
|
|
|
|
- oSpan[1].innerHTML = nowText;
|
|
|
|
|
- oSpan[2].innerHTML = weather.temperature+ "°C";
|
|
|
|
|
- oSpan[3].innerHTML = weather.winddirection + " " + weather.windpower + "级";
|
|
|
|
|
- var firstImg = document.getElementsByTagName("img")[0];
|
|
|
|
|
- var code = getWeatherImage(weather.weather);
|
|
|
|
|
- firstImg.src = "./images/weather_icon/" + encodeURI(code) + ".png"
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- error: function (data) {
|
|
|
|
|
- console.error(data)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-const iconWeatherMap = {
|
|
|
|
|
- '风': ['有风', '平静', '微风', '和风', '清风', '强风/劲风', '疾风', '大风', '烈风', '风暴', '狂爆风', '飓风', '热带风暴', '龙卷风'],
|
|
|
|
|
- '多云': ['少云', '晴间多云', '多云'],
|
|
|
|
|
- '雪': ['雪', '阵雪', '小雪', '中雪', '大雪', '暴雪', '小雪-中雪', '中雪-大雪', '大雪-暴雪', '冷'],
|
|
|
|
|
- '雾': ['浮尘', '扬沙', '沙尘暴', '强沙尘暴', '雾', '浓雾', '强浓雾', '轻雾', '大雾', '特强浓雾'],
|
|
|
|
|
- '晴': ['晴', '热'],
|
|
|
|
|
- '雨夹雪': ['雨雪天气', '雨夹雪', '阵雨夹雪'],
|
|
|
|
|
- '雨': ['阵雨', '雷阵雨', '雷阵雨并伴有冰雹', '小雨', '中雨', '大雨', '暴雨', '大暴雨', '特大暴雨', '强阵雨', '强雷阵雨', '极端降雨', '毛毛雨/细雨', '雨', '小雨-中雨', '中雨-大雨', '大雨-暴雨', '暴雨-大暴雨', '大暴雨-特大暴雨', '冻雨'],
|
|
|
|
|
- '阴': ['阴', '霾', '中度霾', '重度霾', '严重霾', '未知']
|
|
|
|
|
-}
|
|
|
|
|
-function getWeatherImage(weather) {
|
|
|
|
|
- for (const weatherKey in iconWeatherMap) {
|
|
|
|
|
- if (Object.hasOwnProperty.call(iconWeatherMap, weatherKey)) {
|
|
|
|
|
- const weatherNames = iconWeatherMap[weatherKey]
|
|
|
|
|
- const findWeatherItem = weatherNames.find(name => weather === name)
|
|
|
|
|
- // 如果找了某一类的图标了,那重新赋值url
|
|
|
|
|
- if (findWeatherItem) {
|
|
|
|
|
- return weatherKey
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|