Light12306/Web12306/js/account/keepalive.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-06-12 21:36:05 +08:00
define(function (require, exports, module) {
var ajax = require("../platform/webRequest.js");
2014-12-08 22:24:07 +08:00
var interval = 5 * 60 * 1000;
2014-06-12 21:36:05 +08:00
var timer = null;
2014-07-29 21:19:06 +08:00
var started = false;
2014-06-12 21:36:05 +08:00
2014-07-29 21:19:06 +08:00
var checkUser = function () {
timer = null;
2014-12-08 22:24:07 +08:00
ajax.sendGet("index/initMy12306", "login/init", null, "text", function () {
//var m = this.model;
2014-06-12 21:36:05 +08:00
2014-12-08 22:24:07 +08:00
//if (!m || !m.status) {
// if (started)
// timer = setTimeout(checkUser, interval);
//}
//else if (!m.data || !m.data.flag) {
// //登录无效
// document.dispatchEvent(new CustomEvent("loginInvalid"));
//}
//else {
// ajax.userAtts = m.data.attributes;
// if (started)
// timer = setTimeout(checkUser, interval);
//}
if (!this.model) {
2014-07-29 21:19:06 +08:00
if (started)
timer = setTimeout(checkUser, interval);
2014-12-08 22:24:07 +08:00
}else if (this.model.indexOf("<title>登录") !== -1) {
2014-06-12 21:36:05 +08:00
document.dispatchEvent(new CustomEvent("loginInvalid"));
2014-12-08 22:24:07 +08:00
} else {
2014-07-29 21:19:06 +08:00
if (started)
timer = setTimeout(checkUser, interval);
2014-06-12 21:36:05 +08:00
}
}, function () {
2014-07-29 21:19:06 +08:00
if (started)
timer = setTimeout(checkUser, interval);
2014-06-12 21:36:05 +08:00
});
};
//
2014-07-29 21:19:06 +08:00
exports.start = function () {
started = true;
2014-06-12 21:36:05 +08:00
if (!timer)
checkUser();
return true;
};
2014-07-29 21:19:06 +08:00
exports.stop = function () {
started = false;
2014-06-12 21:36:05 +08:00
if (timer)
clearTimeout(timer);
return true;
};
});