55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
define(function (require, exports, module) {
|
|
var ajax = require("../platform/webRequest.js");
|
|
var interval = 5 * 60 * 1000;
|
|
var timer = null;
|
|
var started = false;
|
|
|
|
var checkUser = function () {
|
|
timer = null;
|
|
ajax.sendGet("index/initMy12306", "login/init", null, "text", function () {
|
|
//var m = this.model;
|
|
|
|
//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) {
|
|
if (started)
|
|
timer = setTimeout(checkUser, interval);
|
|
}else if (this.model.indexOf("<title>登录") !== -1) {
|
|
document.dispatchEvent(new CustomEvent("loginInvalid"));
|
|
} else {
|
|
if (started)
|
|
timer = setTimeout(checkUser, interval);
|
|
}
|
|
}, function () {
|
|
if (started)
|
|
timer = setTimeout(checkUser, interval);
|
|
});
|
|
};
|
|
|
|
//
|
|
exports.start = function () {
|
|
started = true;
|
|
if (!timer)
|
|
checkUser();
|
|
return true;
|
|
};
|
|
|
|
exports.stop = function () {
|
|
started = false;
|
|
if (timer)
|
|
clearTimeout(timer);
|
|
return true;
|
|
};
|
|
});
|