Light12306/Web12306/js/data.js

294 lines
7.7 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");
2014-08-06 20:56:47 +08:00
var utility = require("./utility.js");
2014-07-04 20:57:57 +08:00
2014-08-30 01:32:27 +08:00
exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey";
exports.sysNoticeUrl = "http://12306.liebao.cn/index.php?r=Api/GetNotificationList";
2014-08-19 21:33:26 +08:00
exports.sysNoticeLoadInterval = 30 * 60 * 1800;
exports.sysNoticeMaxShowCount = 3;
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-12-05 23:32:41 +08:00
exports.getCityName = function (code) {
2014-12-04 23:31:06 +08:00
var city = null;
return (city = exports.cities[code]) && city.n;
};
2014-09-10 21:49:46 +08:00
exports.findSimilarStation = function (name) {
var extractname = null;
//查找最接近的站点
_.each(exports.citynameMap, function (c) {
if ((c.n.indexOf(name) === 0 || name.indexOf(c.n) === 0) && (extractname === null || extractname.length > c.n.length))
extractname = c.n;
});
if (!extractname)
return [name];
var result = [];
_.each(exports.citynameMap, function (c) {
if (c.n.indexOf(extractname) === 0)
result.push(c.n);
});
return result;
};
exports.findSimilarStationInfos = function (name) {
var extractname = null;
//查找最接近的站点
_.each(exports.citynameMap, function (c) {
if ((c.n.indexOf(name) === 0 || name.indexOf(c.n) === 0) && (extractname === null || extractname.length > c.n.length))
extractname = c.n;
});
if (!extractname) {
var code = exports.citynameMap[name];
return code ? [{ code: code.c, name: name }] : [];
}
var result = [];
_.each(exports.citynameMap, function (c) {
if (c.n.indexOf(extractname) === 0)
result.push({ code: c.c, name: c.n });
});
return result;
};
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-09-09 18:18:00 +08:00
exports.startTrainStationSuggestQueryLimit = 1;
2014-07-31 21:30:48 +08:00
exports.maxSuggestStationTimeRange = {
2014-08-14 21:33:47 +08:00
"": 300,
"G": 180,
"D": 180
2014-07-31 21:30:48 +08:00
}
2014-12-01 02:17:13 +08:00
exports.maxSellDays = 59;
2014-08-06 20:56:47 +08:00
exports.minDate = utility.trimToDay(new Date());
2014-12-01 02:17:13 +08:00
exports.maxDate = (function () {
var dt = new Date();
if (dt.getFullYear() >= 2015 || (dt.getFullYear() === 2014 && dt.getMonth() === 11 && dt.getDate() >= 6))
return utility.addDays(exports.minDate, 59);
var date = dt.getDate();
switch (date) {
case 1: return new Date(2014, 11, 30);
case 2: return new Date(2015, 0, 6);
case 3: return new Date(2015, 0, 13);
case 4: return new Date(2015, 0, 20);
case 5: return new Date(2015, 0, 27);
}
return utility.addDays(exports.minDate, 19);
})();
exports.getBeginSellDate = function (date) {
date = utility.toDate(date);
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var startDate;
2014-12-01 21:50:08 +08:00
2014-12-01 02:17:13 +08:00
if (year > 2015 || (year === 2015 && (month > 2 || (month === 2 && day >= 3)))) {
startDate = utility.addDays(date, -59);
}
else if (year === 2015) {
2014-12-01 21:50:08 +08:00
if (month === 2 || (month === 1 && day >= 28))
startDate = new Date(2014, 11, 6);
else if (day >= 21)
2014-12-01 02:17:13 +08:00
startDate = new Date(2014, 11, 5);
2014-12-01 21:50:08 +08:00
else if (day >= 14)
2014-12-01 02:17:13 +08:00
startDate = new Date(2014, 11, 4);
2014-12-01 21:50:08 +08:00
else if (day >= 7)
2014-12-01 02:17:13 +08:00
startDate = new Date(2014, 11, 3);
else
2014-12-01 21:50:08 +08:00
startDate = new Date(2014, 11, 2);
2014-12-01 02:17:13 +08:00
}
2014-12-01 21:50:08 +08:00
else if (year === 2014 && day == 31)
startDate = new Date(2014, 11, 2);
2014-12-01 02:17:13 +08:00
else if (year === 2014 && day >= 20)
startDate = new Date(2014, 11, 1);
else
startDate = utility.addDays(date, -19);
return startDate;
};
2014-08-08 20:46:37 +08:00
exports.isStudentTicketEnabled = function (date) {
2014-08-06 20:56:47 +08:00
/// <summary>判断指定的日期学生票是否可以买</summary>
date = utility.toDate(date);
var tag = (date.getMonth() + 1) * 10 + date.getDate();
2014-08-08 20:46:37 +08:00
return _.any(exports.stuDate, function (e) {
2014-08-06 20:56:47 +08:00
return tag >= e[0] && tag <= e[1];
});
};
exports.stuDate = [
[101, 331],
[601, 930],
[1201, 1231]
];
2014-07-31 21:30:48 +08:00
exports.isValidDate = function (date) {
2014-08-06 20:56:47 +08:00
date = utility.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-31 21:30:48 +08:00
};
2014-07-25 22:28:51 +08:00
//查找默认的日期
2014-12-12 23:28:35 +08:00
//(function () {
// var d = exports.minDate;
// var day = d.getDay();
// if (day < 5) {
// //星期1-5则取星期五
// exports.defaultDate = utility.addDays(d, 5 - day);
// } else if (day > 0) {
// //取周日
// exports.defaultDate = utility.addDays(d, 7 - day);
// }
//})();
exports.defaultDate = "";
2014-08-08 20:46:37 +08:00
exports.trackTypes = {
2014-08-30 01:32:27 +08:00
//打开首页
2014-08-08 20:46:37 +08:00
OPEN_PAGE_INDEX: 100,
2014-08-30 01:32:27 +08:00
//登录
2014-08-08 20:46:37 +08:00
LOGIN: 101,
2014-08-30 01:32:27 +08:00
//查票
2014-08-08 20:46:37 +08:00
QUERY_TICKET: 102,
2014-08-30 01:32:27 +08:00
//显示购票提示
2014-08-08 20:46:37 +08:00
QUERY_SUGGESTION: 103,
2014-08-30 01:32:27 +08:00
//显示预售提示
2014-08-08 20:46:37 +08:00
SELLTIME_SUGGEST: 104,
2014-08-30 01:32:27 +08:00
//提交订单
2014-08-08 20:46:37 +08:00
SUBMIT_ORDER: 105,
2014-08-30 01:32:27 +08:00
//提交订单失败
2014-08-08 20:46:37 +08:00
SUBMIT_ORDER_FAILED: 106,
2014-08-30 01:32:27 +08:00
//提交订单失败
2014-08-08 20:46:37 +08:00
SUBMIT_ORDER_SUCCESS: 107,
2014-08-30 01:32:27 +08:00
//主动退出登录
2014-08-08 20:46:37 +08:00
LOGOUT: 108,
2014-08-30 01:32:27 +08:00
//显示停靠站
2014-08-08 20:46:37 +08:00
SHOW_TRAIN_STOP: 109,
2014-08-30 01:32:27 +08:00
//由自动刷新发起的提交订单
2014-08-08 20:46:37 +08:00
SUBMIT_AUTO: 110,
2014-08-30 01:32:27 +08:00
//开始刷票
2014-08-08 20:46:37 +08:00
START_AUTOREFRESH: 111,
2014-08-30 01:32:27 +08:00
//停止刷票
2014-08-08 20:46:37 +08:00
STOP_AUTOREFRESH: 112,
2014-08-30 01:32:27 +08:00
//刷到票了
2014-08-08 20:46:37 +08:00
VALID_AUTOREFRESH: 113,
2014-08-30 01:32:27 +08:00
//加入聊天
2014-08-08 20:46:37 +08:00
JOIN_CHAT: 114,
2014-08-30 01:32:27 +08:00
//退出聊天
2014-08-19 23:29:14 +08:00
EXIT_CHAT: 115,
//extar
OPEN_SYS_NOTICE: 116,
2014-09-02 23:15:40 +08:00
LOAD_SYS_NOTICE: 117,
LOAD_SUGGESTION: 118,
SHOW_NOTIFICATION_SELECT: 119,
OPEN_SELL_NOTIFICATION: 120,
//----------------------------
SUBMIT_ORDER_BY_SUGGESTIONI: 121,
QUEUE_ORDER_SUCCESS: 122,
PROFILE_AUTO_SELECTSEAT: 130,
PROFILE_AUTO_ADDTRAIN: 131,
PROFILE_AUTO_ADDPAS: 132,
PROFILE_AUTO_ADDDL: 133,
PROFILE_AUTO_MOREOPT: 134,
PROFILE_AUTO_OPENTM: 135,
PROFILE_AUTO_RESET: 136,
2014-12-05 23:32:41 +08:00
PROFILE_DATEBAR: 137,
//----------------------------
TRANSIT_SHOWTRANSIT: 150,
TRANSIT_MANUALLYREQUIRE: 151
2014-09-09 20:16:02 +08:00
};
2014-08-14 21:33:47 +08:00
exports.chatSendMsgDelay = 5000;
2014-08-19 23:29:14 +08:00
exports.maxRecentCity = 18;
2014-08-30 01:32:27 +08:00
exports.suggestRefreshInterval = 60000;
Object.defineProperty(exports, "moreOptDefault", {
get: function () {
2014-08-30 01:32:27 +08:00
return true;
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-09-10 21:49:46 +08:00
2014-04-30 19:20:58 +08:00
});