Light12306/Web12306/js/data.js

139 lines
3.5 KiB
JavaScript
Raw Normal View History

2014-05-16 20:10:45 +08:00
define(function (require, exports, module) {
2014-07-04 20:57:57 +08:00
var citydata = require("./station/station_data.js");
exports.trimToDay = function (d) {
d = d || new Date();
if (!(d instanceof Date)) {
d = new Date(d + '');
}
var x = new Date();
x.setTime(d.getTime() - d.getTime() % (1000 * 3600 * 24));
return x;
};
exports.addDays = function (date, days) {
var x = new Date();
x.setTime(date.getTime() - date.getTime() % (1000 * 3600 * 24) + 1000 * 3600 * 24 * days);
return x;
};
2014-07-04 20:57:57 +08:00
exports.citydata = citydata;
2014-07-08 20:11:31 +08:00
exports.cities = _(_.flatten(_.map(_.values(citydata.data), function (e) { return _.values(e); }))).mapObject(function (e) { return e.c; });;
2014-07-31 21:30:48 +08:00
exports.citynameMap = _.mapObject(exports.cities, function (c) {
return c.n;
});
2014-05-16 20:10:45 +08:00
exports.identityCardTypes = {
};
exports.passengerTypes = {
"1": "成人",
"2": "儿童",
"3": "学生",
"4": "残军"
2014-05-16 20:10:45 +08:00
};
exports.tagOtnMap = {
"9": "SWZ",
"P": "TZ",
"M": "ZY",
"O": "ZE",
"6": "GR",
"4": "RW",
"3": "YW",
"2": "RZ",
"1": "YZ",
"0": "WZ",
2014-06-26 22:24:54 +08:00
"*": "QT",
"B": "HB"
2014-05-16 20:10:45 +08:00
};
exports.tagRevMap = _.invert(exports.tagOtnMap);
exports.seatNameMap = {
"商务座": "SWZ",
"特等座": "TZ",
"一等座": "ZY",
"二等座": "ZE",
"高级软卧": "GR",
"软卧": "RW",
"硬卧": "YW",
"软座": "RZ",
"硬座": "YZ",
2014-06-26 22:24:54 +08:00
"无座": "WZ",
"混编硬座": "HB"
2014-05-16 20:10:45 +08:00
};
2014-07-29 21:19:06 +08:00
exports.tagMap = {
"动车或高铁或城铁": "[DGC].*",
"特快或直达": "[TZ].*",
"快车": "K.*",
"高铁": "G.*",
"动车": "D.*",
"城铁": "C.*",
"直达": "Z.*",
"特快": "T.*",
"任意车次": ".*"
};
exports.translateTrain = function (array) {
/// <summary>将列车编号翻译为实际的检查序列</summary>
2014-07-31 21:30:48 +08:00
return array.map(function (e) {
2014-07-29 21:19:06 +08:00
return exports.tagMap[e] || e;
});
};
2014-05-16 20:10:45 +08:00
exports.seatNameInvMap = _.invert(exports.seatNameMap);
exports.baseUri = "https://kyfw.12306.cn/otn/";
exports.queryBaseUri = "https://dynamic.12306.cn/otsquery/";
2014-06-26 22:24:54 +08:00
exports.toSeatTypeName = function (code) {
2014-06-20 20:55:14 +08:00
return exports.seatNameInvMap[exports.tagOtnMap[code]];
};
exports.seatDisplayOrder = 'O219PM6430'.split('');
2014-07-11 18:34:59 +08:00
exports.isDebug = ((function () { return false; }) + '').indexOf("false;") != -1;
exports.log = function () {
2014-07-11 18:34:59 +08:00
if (!exports.isDebug)
return;
console.log.apply(console, Array.prototype.slice.call(arguments));
};
exports.showMoreOptRange = [
[new Date(2014, 9, 5), new Date(2014, 9, 20)],
[new Date(2015, 1, 20), new Date(2014, 2, 18)]
];
2014-07-31 21:30:48 +08:00
exports.startTrainStationSuggestQueryLimit = 10;
exports.maxSuggestStationTimeRange = {
"": 240,
"G": 120,
"D": 120
}
exports.maxSellDays = 19;
exports.minDate = exports.trimToDay(new Date());
exports.maxDate = exports.addDays(exports.minDate, exports.maxSellDays);
2014-07-31 21:30:48 +08:00
exports.isValidDate = function (date) {
date = exports.trimToDay(date);
return date >= exports.minDate;
};
2014-07-31 21:30:48 +08:00
exports.isAutoBookEnabled = function (profile) {
return profile.selectedTrain && profile.selectedTrain.length
&& profile.selectedSeatType && profile.selectedSeatType.length;
};
2014-07-25 22:28:51 +08:00
//查找默认的日期
2014-07-31 21:30:48 +08:00
(function () {
2014-07-25 22:28:51 +08:00
var d = exports.minDate;
var day = d.getDay();
if (day < 5) {
//星期1-5则取星期五
exports.defaultDate = exports.addDays(d, 5 - day);
} else if (day > 0) {
//取周日
exports.defaultDate = exports.addDays(d, 7 - day);
}
})();
Object.defineProperty(exports, "moreOptDefault", {
get: function () {
var d = exports.minDate;
2014-07-31 21:30:48 +08:00
return _.any(exports.showMoreOptRange, function (v) {
return v[0] <= d && d <= v[1];
});
}
});
2014-04-30 19:20:58 +08:00
});