351 lines
9.9 KiB
JavaScript
351 lines
9.9 KiB
JavaScript
define(function (require, exports, module) {
|
||
var citydata = require("./station/station_data.js");
|
||
var utility = require("./utility.js");
|
||
var local = self.location.host === "test.fishlee.net";
|
||
|
||
var errorMessages = { randCodeError: "验证码错误!", randCodeExpired: "验证码失效", randCodeLentgh: "验证码长度为4位!", randCodeFormat: "验证码只能由数字或字母组成!", randCodeEmpty: "验证码不能为空!", userNameEmpty: "登录名必须填写!", userNameFormat: "登录名格式不正确,请重新输入!", passwordEmpty: "密码必须填写,且不少于6位!", passwordLength: "密码长度不能少于6位!", pleaseClickCaptcha: "请点击验证码", pleaseClickLeftCaptcha: "请点击左侧验证码", pleaseClickCaptchaRight: "请正确点击验证码", loginError: "当前访问用户过多,请稍候重试!" };
|
||
exports.parseErrorMessage = function (msg) {
|
||
return errorMessages[msg] || msg;
|
||
};
|
||
|
||
exports.debug = function () {
|
||
if (!local)
|
||
return;
|
||
console.log.apply(console, arguments);
|
||
};
|
||
exports.stationReportApi = "http://srv.12306.liebao.cn/tt/ls2";
|
||
exports.trainSuggestApi = "http://srv.12306.liebao.cn/ts";
|
||
exports.onceTransitApi = "http://srv.12306.liebao.cn/tt/tor";
|
||
exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey";
|
||
exports.chatReportUrl = "http://12306.liebao.cn/index.php?r=Api/AbuseReport";
|
||
exports.sysNoticeUrl = "http://12306.liebao.cn/index.php?r=Api/GetNotificationList";
|
||
|
||
if (local) {
|
||
exports.trainSuggestApi = "/ts.axd";
|
||
exports.onceTransitApi = "/tt/tor";
|
||
exports.sysNoticeUrl = "http://chatdev.fishlee.net/announcement/list";
|
||
exports.chatReportUrl = "http://chatdev.fishlee.net/api/users/report";
|
||
}
|
||
|
||
exports.sysNoticeLoadInterval = 30 * 60 * 1800;
|
||
exports.sysNoticeMaxShowCount = 3;
|
||
|
||
exports.citydata = citydata;
|
||
exports.cities = _(_.flatten(_.map(_.values(citydata.data), function (e) { return _.values(e); }))).mapObject(function (e) { return e.c; });;
|
||
exports.citynameMap = _.mapObject(exports.cities, function (c) {
|
||
return c.n;
|
||
});
|
||
exports.getCityName = function (code) {
|
||
var city = null;
|
||
return (city = exports.cities[code]) && city.n;
|
||
};
|
||
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;
|
||
};
|
||
|
||
exports.identityCardTypes = {
|
||
|
||
};
|
||
exports.passengerTypes = {
|
||
"1": "成人",
|
||
"2": "儿童",
|
||
"3": "学生",
|
||
"4": "残军"
|
||
};
|
||
exports.seatNameMap = {
|
||
'A': "高级动卧",
|
||
'F': "动卧",
|
||
'9': "商务座",
|
||
'E': "特等软座",
|
||
'P': "特等座",
|
||
'M': "一等座",
|
||
'O': "二等座",
|
||
'7': "一等软座",
|
||
'8': "二等软座",
|
||
'6': "高级软卧",
|
||
'5': "包厢硬卧",
|
||
'4': "软卧",
|
||
'3': "硬卧",
|
||
'2': "软座",
|
||
'1': "硬座",
|
||
'0': "无座",
|
||
'S': "一等包座",
|
||
'B': "混编硬座",
|
||
'Q': "观光座",
|
||
'H': "一人软包",
|
||
'*': "其它"
|
||
};
|
||
exports.tagMap = {
|
||
"动车或高铁或城铁": "[DGC].*",
|
||
"特快或直达": "[TZ].*",
|
||
"快车": "K.*",
|
||
"高铁": "G.*",
|
||
"动车": "D.*",
|
||
"城铁": "C.*",
|
||
"直达": "Z.*",
|
||
"特快": "T.*",
|
||
"任意车次": ".*"
|
||
};
|
||
exports.translateTrain = function (array) {
|
||
/// <summary>将列车编号翻译为实际的检查序列</summary>
|
||
return array.map(function (e) {
|
||
return exports.tagMap[e] || e;
|
||
});
|
||
};
|
||
exports.baseUri = "https://kyfw.12306.cn/otn/";
|
||
exports.queryBaseUri = "https://dynamic.12306.cn/otsquery/";
|
||
exports.toSeatTypeName = function (code) {
|
||
return exports.seatNameMap[code] || code;
|
||
};
|
||
exports.seatDisplayOrder = 'O219PM6430'.split('');
|
||
//席别映射选择
|
||
exports.displayMap = {
|
||
"M": ["7"],
|
||
"P": ["E"],
|
||
"O": ["8"],
|
||
"6": ["A"],
|
||
"4": ["F"],
|
||
"9": ["H"],
|
||
"3": ["5"]
|
||
};
|
||
exports.emptySeatCodeArray = ['O', '8', '1', '2'];
|
||
exports.getEmptySeatCode = function (ticketMap) {
|
||
/// <summary>获得站票的席别代码</summary>
|
||
|
||
for (var code in exports.emptySeatCodeArray) {
|
||
if(!exports.emptySeatCodeArray.hasOwnProperty(code)||!ticketMap[exports.emptySeatCodeArray[code]])
|
||
continue;
|
||
|
||
return exports.emptySeatCodeArray[code];
|
||
}
|
||
};
|
||
exports.findSeatData = function(ticketMap, code) {
|
||
return ticketMap[code] || (function() {
|
||
var codemap = exports.displayMap[code];
|
||
if (!codemap)
|
||
return null;
|
||
for (var index in codemap) {
|
||
if (ticketMap[codemap[index]]) {
|
||
return ticketMap[codemap[index]];
|
||
}
|
||
}
|
||
return null;
|
||
}()) || null;
|
||
};
|
||
|
||
exports.isDebug = ((function () { return false; }) + '').indexOf("false;") != -1;
|
||
exports.log = function () {
|
||
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)]
|
||
];
|
||
|
||
exports.startTrainStationSuggestQueryLimit = 1;
|
||
exports.maxSuggestStationTimeRange = {
|
||
"": 300,
|
||
"G": 180,
|
||
"D": 180
|
||
}
|
||
exports.maxSellDays = 59;
|
||
exports.minDate = utility.trimToDay(new Date());
|
||
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;
|
||
|
||
if (year > 2015 || (year === 2015 && (month > 2 || (month === 2 && day >= 3)))) {
|
||
startDate = utility.addDays(date, -59);
|
||
}
|
||
else if (year === 2015) {
|
||
if (month === 2 || (month === 1 && day >= 28))
|
||
startDate = new Date(2014, 11, 6);
|
||
else if (day >= 21)
|
||
startDate = new Date(2014, 11, 5);
|
||
else if (day >= 14)
|
||
startDate = new Date(2014, 11, 4);
|
||
else if (day >= 7)
|
||
startDate = new Date(2014, 11, 3);
|
||
else
|
||
startDate = new Date(2014, 11, 2);
|
||
}
|
||
else if (year === 2014 && day == 31)
|
||
startDate = new Date(2014, 11, 2);
|
||
else if (year === 2014 && day >= 20)
|
||
startDate = new Date(2014, 11, 1);
|
||
else
|
||
startDate = utility.addDays(date, -19);
|
||
|
||
return startDate;
|
||
};
|
||
exports.isStudentTicketEnabled = function (date) {
|
||
/// <summary>判断指定的日期学生票是否可以买</summary>
|
||
date = utility.toDate(date);
|
||
|
||
var tag = (date.getMonth() + 1) * 10 + date.getDate();
|
||
return _.any(exports.stuDate, function (e) {
|
||
return tag >= e[0] && tag <= e[1];
|
||
});
|
||
};
|
||
exports.stuDate = [
|
||
[101, 331],
|
||
[601, 930],
|
||
[1201, 1231]
|
||
];
|
||
exports.isValidDate = function (date) {
|
||
date = utility.trimToDay(date);
|
||
return date >= exports.minDate;
|
||
};
|
||
exports.isAutoBookEnabled = function (profile) {
|
||
return (profile.selectedTrain && profile.selectedTrain.length)
|
||
|| (profile.selectedSeatType && profile.selectedSeatType.length);
|
||
};
|
||
//查找默认的日期
|
||
//(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 = "";
|
||
exports.trackTypes = {
|
||
//打开首页
|
||
OPEN_PAGE_INDEX: 100,
|
||
//登录
|
||
LOGIN: 101,
|
||
//查票
|
||
QUERY_TICKET: 102,
|
||
//显示购票提示
|
||
QUERY_SUGGESTION: 103,
|
||
//显示预售提示
|
||
SELLTIME_SUGGEST: 104,
|
||
//提交订单
|
||
SUBMIT_ORDER: 105,
|
||
//提交订单失败
|
||
SUBMIT_ORDER_FAILED: 106,
|
||
//提交订单失败
|
||
SUBMIT_ORDER_SUCCESS: 107,
|
||
//主动退出登录
|
||
LOGOUT: 108,
|
||
//显示停靠站
|
||
SHOW_TRAIN_STOP: 109,
|
||
//由自动刷新发起的提交订单
|
||
SUBMIT_AUTO: 110,
|
||
//开始刷票
|
||
START_AUTOREFRESH: 111,
|
||
//停止刷票
|
||
STOP_AUTOREFRESH: 112,
|
||
//刷到票了
|
||
VALID_AUTOREFRESH: 113,
|
||
//加入聊天
|
||
JOIN_CHAT: 114,
|
||
//退出聊天
|
||
EXIT_CHAT: 115,
|
||
//extar
|
||
OPEN_SYS_NOTICE: 116,
|
||
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,
|
||
PROFILE_DATEBAR: 137,
|
||
//----------------------------
|
||
TRANSIT_SHOWTRANSIT: 150,
|
||
TRANSIT_MANUALLYREQUIRE: 151
|
||
};
|
||
exports.chatSendMsgDelay = 5000;
|
||
exports.maxRecentCity = 18;
|
||
exports.suggestRefreshInterval = 60000;
|
||
Object.defineProperty(exports, "fastSubmitOrderSkipVc", {
|
||
get: function() {
|
||
return false;
|
||
}
|
||
});
|
||
|
||
Object.defineProperty(exports, "moreOptDefault", {
|
||
get: function () {
|
||
return true;
|
||
var d = exports.minDate;
|
||
|
||
return _.any(exports.showMoreOptRange, function (v) {
|
||
return v[0] <= d && d <= v[1];
|
||
});
|
||
}
|
||
});
|
||
|
||
}); |