Light12306/RwTicketAssistantV2/app/air/js/util/WeatherRetriever.js
iFish addcafcdf8 + 集成扩展的源码
+ 增加相关TypedScript的导入
2014-08-08 14:33:43 +08:00

90 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var WeatherRetriever = {
map: {
"\u6674":14,
"\u591a\u4e91":1,
"\u9634":4,
"\u96fe":11,
"\u7279\u5927\u66b4\u96e8":9,
"\u5927\u66b4\u96e8":9,
"\u66b4\u96e8":9,
"\u96f7\u9635\u96e8":3,
"\u9635\u96e8":10,
"\u5927\u96e8":9,
"\u4e2d\u96e8":9,
"\u5c0f\u96e8":9,
"\u96e8\u5939\u96ea":13,
"\u66b4\u96ea":15,
"\u9635\u96ea":15,
"\u5927\u96ea":15,
"\u4e2d\u96ea":15,
"\u5c0f\u96ea":6,
"\u5f3a\u6c99\u5c18\u66b4":2,
"\u6c99\u5c18\u66b4":2,
"\u6c99\u5c18":2,
"\u626c\u6c99":5,
"\u51b0\u96f9":8,
"\u6d6e\u5c18":1,
"\u973e":12
},
imageMap: {
"0": "14", "1": "1", "2": "4", "3": "10", "4": "3", "5": "3", "6": "13", "7": "9",
"8": "9", "9": "9", "10": "9", "11": "9", "12": "9", "13": "15", "14": "6", "15": "15",
"16": "15", "17": "15", "18": "11", "19": "9", "20": "2", "21": "9", "22": "9", "23": "9",
"24": "9", "25": "9", "26": "6", "27": "15", "28": "15", "29": "2", "30": "5", "31": "2",
"32": "12", "33": "4", "34": "4", "35": "4"
},
retrieve: function(city, date, time, callback) {
var days = (Util.date.parse(date) - Util.date.floor()) / 86400000,
code = CityMap.name2weather[city];
if (!code) {
return ;
}
if (days < 0 || days > 6) {
return ;
}
var currentTime = Util.date.formatTime(),
offset = days * 2;
if (currentTime < '18:00') {
offset += 1;
}
//假设不存在起落在同日8:00前的航班起飞时间在8:00前天气认为是白天天气
if (time >= '20:00') {
offset += 1;
}
$.getJSON(config.urls.weather + code, function(data) {
var img = data.yb[days ? 'img' + offset : 'img_single'],
title = data.yb[days ? 'img_title' + offset : 'img_title_single'];
if (img === '99') {
img = 'img' + (offset - 1);
}
callback && callback(img, title);
});
},
fill: function(element, date) {
for (i=0; i<=15; i++) {
$('.weather .icon', element).removeClass('weatherIcon' + i);
}
$('.weather .icon', element).addClass('weatherIcon0');
$('.weather .text', element).text('无法获取').addClass('noText');
this.retrieve($('.point', element).text(), date, $('.time',element).text(), function(weatherImg, weatherTitle) {
var i;
if (WeatherRetriever.imageMap[weatherImg] !== undefined) {
$('.weather .icon', element).removeClass('weatherIcon0').addClass('weatherIcon' + WeatherRetriever.imageMap[weatherImg]);
$('.weather .text', element).text(weatherTitle).removeClass('noText');
$('.weather .text,.icon', element).hide().fadeIn('slow');
}
});
}
};