Kaynağa Gözat

添加天气图标

klzhangweiya 2 yıl önce
ebeveyn
işleme
da4814bb8d

+ 1 - 1
VbdsmUI_V2.1.1/src/pc/manage/classic.html

@@ -26,7 +26,7 @@
 				width: 0px;
 			}
 		</style>
-
+		<script src="./plugin/weather/index.js" type="text/javascript"></script>
 		<script charset="UTF-8" type="text/javascript"></script>
 	</head>
 

+ 2 - 1
VbdsmUI_V2.1.1/src/pc/manage/js/classic.util.js

@@ -8,7 +8,8 @@ $(function () {
 	window.document.domain = AUTH.site.domain || "vbdsm.com"
 
 	loadData()
-	getWinXin()
+	//getWinXin()
+	getGdWeather("classic");
 	$("#basicBtn").click(function () {
 		var tabTitle = $(this).text()
 		var url = $(this).attr("src")

BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/多云.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/晴.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/阴.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/雨.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/雨夹雪.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/雪.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/雾.png


BIN
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/images/weather_icon/风.png


+ 3 - 2
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/index.html

@@ -16,7 +16,7 @@
 				margin-left: -6px;
 			}
 		</style>
-
+         <script src="./index.js"></script>
 		<script charset="UTF-8" type="text/javascript"></script>
 	</head>
 	<body>
@@ -35,7 +35,8 @@
 				'<script src="/system/lang/desktop/config.json?script=1&auth_cid=' + cid + '"><\/script>'
 			)
 			$(function () {
-				getWinXin()
+				//getWinXin()
+				getGdWeather();
 			})
 
 			function getWinXin() {

+ 75 - 0
VbdsmUI_V2.1.1/src/pc/manage/plugin/weather/index.js

@@ -157,4 +157,79 @@ function createUrl(cname) {
     }
     var urls = 'https://sapi.k780.com/?app=weather.future&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json&jsoncallback=getWeather&weaid=' + encodeURI(cityName);
     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
+            }
+        }
+    }
 }