|
@@ -12,69 +12,121 @@
|
|
|
* @ jason.lu
|
|
|
* */
|
|
|
|
|
|
+import 'whatwg-fetch';
|
|
|
|
|
|
-var BasicFunction = new (function() {
|
|
|
+var BasicFunction = new (function () {
|
|
|
|
|
|
this.Queue = {
|
|
|
THRESHOLD: 1000,
|
|
|
IS_LOADED: false,
|
|
|
- nowuse: 0, SVR_URL: "http://localhost:8803/server/",
|
|
|
+ nowuse: 0, SVR_URL: "/server/",
|
|
|
groupsCount: 0, groups: [],
|
|
|
shouldStop: false,
|
|
|
- backup: ["http://localhost:8803/server/",
|
|
|
- "/server/",
|
|
|
- "http://172.30.84.3:8803/server/", "https://1.niimei.com/server/"],
|
|
|
+ backup: ["/server/",
|
|
|
+ "http://127.0.0.1:8866/server/",
|
|
|
+ "http://south.niimei.com:8866/server/",
|
|
|
+ "https://4.niimei.com/server/"],
|
|
|
list: [], temporary: 0, errorCount: 0
|
|
|
};
|
|
|
|
|
|
+ this.Users = {list: []};
|
|
|
+ this.Sectors = {list: []};
|
|
|
+ this.AlertClosingTimeout = 0;
|
|
|
+
|
|
|
+ this.loglog = function (a) {
|
|
|
+ console.log(a);
|
|
|
+ };
|
|
|
+
|
|
|
+ this.logwarn = function (obj) {
|
|
|
+ console.warn(obj);
|
|
|
+ };
|
|
|
+
|
|
|
+ this.logerror = function (obj) {
|
|
|
+ console.warn(obj);
|
|
|
+ };
|
|
|
+
|
|
|
+ this.logtrace = function () {
|
|
|
+ console.trace();
|
|
|
+ };
|
|
|
+
|
|
|
+ this.logverbose = function () {
|
|
|
+ // Not Echoing
|
|
|
+ };
|
|
|
+
|
|
|
+ this.asserThat = function(cond, why) {
|
|
|
+ console.assert(cond, why);
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ this.goajax = function (jqObject) {
|
|
|
+ return fetch(jqObject.url, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ //'x-doiby-authenticate' : 'CISICMIEINAOQPMDPWIDNENU'
|
|
|
+ },
|
|
|
+ body: jqObject.data
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
this.utils_get_param = function (name) {
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
|
|
var r = window.location.search.substr(1).match(reg);
|
|
|
if (r != null) return unescape(r[2]);
|
|
|
return null;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
this.reloadPage = function () {
|
|
|
location.reload()
|
|
|
- }
|
|
|
-
|
|
|
- let Users = {list: []};
|
|
|
- let Sectors = {list: []};
|
|
|
+ };
|
|
|
|
|
|
this.get_server_url = function () {
|
|
|
- this.output = $.ajax({url: BasicFunction.Queue.SVR_URL + "/fcFlow/list", timeout: 1000}).fail(this.on_check_fail).done(this.onDataArrive);
|
|
|
+ // AJAX
|
|
|
+ this.output = this.goajax({url: this.Queue.SVR_URL + "fcFlow/list", timeout: 1000})
|
|
|
+ .then(this.checkStatus)
|
|
|
+ .then(this.parseJson)
|
|
|
+ .then(this.onReachServer)
|
|
|
+ .catch(this.onCheckFail);
|
|
|
+ // .then(BasicFunction.onCheckFail);
|
|
|
};
|
|
|
|
|
|
- this.onDataArrive = function(obj) {
|
|
|
+ this.onReachServer = function (checkResponse) {
|
|
|
BasicFunction.Queue.IS_LOADED = true;
|
|
|
- console.warn("Using SERVER : ");
|
|
|
- console.warn(BasicFunction.Queue.SVR_URL);
|
|
|
- setTimeout(this.parse_queue, 50);
|
|
|
+ BasicFunction.logwarn("Using SERVER : ");
|
|
|
+ BasicFunction.logwarn(BasicFunction.Queue.SVR_URL);
|
|
|
+ setTimeout(BasicFunction.parse_queue, 50, BasicFunction);
|
|
|
};
|
|
|
|
|
|
- this.on_check_fail = function () {
|
|
|
+ this.onCheckFail = function (errmsg) {
|
|
|
if (BasicFunction.Queue.nowuse === BasicFunction.Queue.backup.length - 1) {
|
|
|
- console.warn("Backup Failed : " + BasicFunction.Queue.backup[BasicFunction.Queue.nowuse]);
|
|
|
- console.warn(this);
|
|
|
+ BasicFunction.logwarn("Backup Failed : " + BasicFunction.Queue.backup[BasicFunction.Queue.nowuse]);
|
|
|
+ BasicFunction.logwarn(this);
|
|
|
var out = "";
|
|
|
BasicFunction.Queue.backup.forEach(function (val, index, arr) {
|
|
|
- out += val + "\n";
|
|
|
+ out += index + ":[" +val +"] \n";
|
|
|
});
|
|
|
- BasicFunction.send_alert("抱歉, 服务器连接失败! \n 请确认 " + out + "其中之一可用");
|
|
|
+ BasicFunction.logerror("抱歉, 服务器连接失败! \n 请确认 "+ out +" 其中之一可用");
|
|
|
} else {
|
|
|
+ BasicFunction.loglog(errmsg);
|
|
|
BasicFunction.Queue.nowuse++;
|
|
|
BasicFunction.Queue.SVR_URL = BasicFunction.Queue.backup[BasicFunction.Queue.nowuse];
|
|
|
- this.ajax({url: BasicFunction.Queue.SVR_URL + "/fcFlow/list", timeout: 1000}).fail(on_check_fail).done(this.onDataArrive);
|
|
|
+ // AJAX
|
|
|
+ BasicFunction.goajax({url: BasicFunction.Queue.SVR_URL + "fcFlow/list", timeout: 1000})
|
|
|
+ .then(BasicFunction.checkStatus)
|
|
|
+ .then(BasicFunction.parseJson)
|
|
|
+ .then(BasicFunction.onReachServer)
|
|
|
+ .catch(BasicFunction.onCheckFail);
|
|
|
+ //.fail(BasicFunction.onCheckFail).done(BasicFunction.onReachServer);
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
this.get_data = function (url, callback, scope) {
|
|
|
BasicFunction.Queue.list.push({url: url, callback: callback, gid: -1, scope: scope});
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
this.new_data_group = function (groupName, callback) {
|
|
|
var gid = -1;
|
|
|
- BasicFunction.Queue.groups.forEach(function (val, index, arr) {
|
|
|
+ BasicFunction.Queue.groups.forEach(function (val) {
|
|
|
if (val.groupName === groupName) {
|
|
|
gid = val.gid;
|
|
|
}
|
|
@@ -87,26 +139,26 @@ var BasicFunction = new (function() {
|
|
|
});
|
|
|
}
|
|
|
return gid;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.group_get_data = function(groupName, url, callback) {
|
|
|
+ this.group_get_data = function (groupName, url, callback) {
|
|
|
var gid = -1;
|
|
|
- BasicFunction.Queue.groups.forEach(function (val, index, arr) {
|
|
|
+ BasicFunction.Queue.groups.forEach(function (val) {
|
|
|
if (val.groupName === groupName) {
|
|
|
gid = val.gid;
|
|
|
}
|
|
|
});
|
|
|
if (gid === -1) {
|
|
|
- send_alert("Group 方法使用错误!!!")
|
|
|
+ BasicFunction.send_alert("Group 方法使用错误!!!")
|
|
|
}
|
|
|
BasicFunction.Queue.list.push({url: url, callback: callback, gid: gid});
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.parse_queue = function() {
|
|
|
- console.log("Queue Length : " + BasicFunction.Queue.list.length);
|
|
|
+ this.parse_queue = function () {
|
|
|
+ BasicFunction.logverbose("Queue Length : " + BasicFunction.Queue.list.length);
|
|
|
|
|
|
if (BasicFunction.Queue.temporary > new Date().getTime()) {
|
|
|
- for (i = 0; i < BasicFunction.Queue.list.length; i++) {
|
|
|
+ for (let i = 0; i < BasicFunction.Queue.list.length; i++) {
|
|
|
BasicFunction.Queue.list.pop();
|
|
|
}
|
|
|
}
|
|
@@ -121,56 +173,83 @@ var BasicFunction = new (function() {
|
|
|
g_request_data(one.url, one.callback, one.gid, one.scope);
|
|
|
}
|
|
|
}
|
|
|
- if (BasicFunction.Queue.shouldStop == false) {
|
|
|
- setTimeout(parse_queue, 50);
|
|
|
+ if (BasicFunction.Queue.shouldStop === false) {
|
|
|
+ setTimeout(BasicFunction.parse_queue, 50);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ this.parseJSON = function(response) {
|
|
|
+ return response.json();
|
|
|
+ };
|
|
|
+
|
|
|
+ this.checkStatus = function(response) {
|
|
|
+ if (response.status >= 200 && response.status < 300) {
|
|
|
+ return response;
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ const error = new Error(response.statusText);
|
|
|
+ error.response = response;
|
|
|
+ throw error;
|
|
|
+ };
|
|
|
|
|
|
function request_data(url, callback, scope) {
|
|
|
- $.ajax({
|
|
|
+ BasicFunction.goajax({
|
|
|
url: BasicFunction.Queue.SVR_URL + url,
|
|
|
apiName: url,
|
|
|
- sendTime: new Date(),
|
|
|
- callme: callback,
|
|
|
- callerThis: scope
|
|
|
- }).done(on_dat_success).fail(on_fail);
|
|
|
+ sendTime: new Date()
|
|
|
+ }).then(BasicFunction.checkStatus)
|
|
|
+ .then(BasicFunction.parseJson)
|
|
|
+ .then(BasicFunction.on_dat_success)
|
|
|
+ .catch(BasicFunction.on_fail);
|
|
|
}
|
|
|
|
|
|
function g_request_data(url, callback, gid) {
|
|
|
- $.ajax({
|
|
|
+ BasicFunction.goajax({
|
|
|
url: BasicFunction.Queue.SVR_URL + url,
|
|
|
apiName: url,
|
|
|
sendTime: new Date(),
|
|
|
gid: gid,
|
|
|
callme: callback
|
|
|
- }).done(on_gp_success).fail(on_fail);
|
|
|
+ }).then(res => {
|
|
|
+ return res.json()
|
|
|
+ })
|
|
|
+ .then(BasicFunction.on_gp_success)
|
|
|
+ .then(callback)
|
|
|
+ .catch(BasicFunction.on_fail);
|
|
|
}
|
|
|
|
|
|
- function on_gp_success(a, b) {
|
|
|
- var gid = BasicFunction.gid;
|
|
|
- if (check_if_success(a, b)) {
|
|
|
- this.callme(a, b);
|
|
|
- BasicFunction.Queue.groups.forEach(function (v, i, a) {
|
|
|
+ this.on_gp_success = function(response) {
|
|
|
+ var obj = response.json();
|
|
|
+ var b = respose.status;
|
|
|
+ var gid = obj.gid;
|
|
|
+ if (BasicFunction.check_if_success(obj, b)) {
|
|
|
+ obj.callme(obj, b);
|
|
|
+ BasicFunction.Queue.groups.forEach(function (v) {
|
|
|
if (v.gid === gid) {
|
|
|
v.counter++;
|
|
|
- v.callme(v);
|
|
|
+ return v;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
+ return null;
|
|
|
+ };
|
|
|
|
|
|
- function on_dat_success(a, b) {
|
|
|
- if (check_if_authfail(a, b)) {
|
|
|
- setCookieWithTimeout("doibyUser", "", -10);
|
|
|
+ this.on_dat_success = function(responseJson) {
|
|
|
+
|
|
|
+ var a = response;
|
|
|
+ if (BasicFunction.check_if_authfail(a, {})) {
|
|
|
+ BasicFunction.setCookieWithTimeout("doibyUser", "", -10);
|
|
|
location.href = "sign-in1.html?from=entrance-5&msg=server-redirect-detected";
|
|
|
return;
|
|
|
}
|
|
|
- if (check_if_success(a, b)) {
|
|
|
- BasicFunction.callme(a, b);
|
|
|
+ if (BasicFunction.check_if_success(a, {})) {
|
|
|
+ return a;
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- function check_if_authfail(a) {
|
|
|
+ this.check_if_authfail = function (errormsg) {
|
|
|
+ BasicFunction.logerror(errormsg);
|
|
|
+ var a = errormsg;
|
|
|
if (a == null || typeof a !== "string") {
|
|
|
return false;
|
|
|
} else {
|
|
@@ -179,45 +258,56 @@ var BasicFunction = new (function() {
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- function check_if_success(a, b) {
|
|
|
+ this.check_if_success = function (response) {
|
|
|
+ // this == BasicFunction
|
|
|
+ BasicFunction.loglog("---------------Check-If-Success----------------");
|
|
|
+ var a = response.json();
|
|
|
+ var b = response.status;
|
|
|
if (typeof a === "string") {
|
|
|
try {
|
|
|
a = JSON.parse(a);
|
|
|
} catch (e) {
|
|
|
- console.warn("=---------- 异常 -----------=");
|
|
|
- console.warn(a);
|
|
|
- console.warn("=----------------------------=");
|
|
|
- send_alert("信息失败 : " + e);
|
|
|
+ BasicFunction.logwarn("=---------- 异常 -----------=");
|
|
|
+ BasicFunction.logwarn(a);
|
|
|
+ BasicFunction.logwarn("=----------------------------=");
|
|
|
+ BasicFunction.send_alert("信息失败 : 1 : " + e);
|
|
|
return;
|
|
|
}
|
|
|
} else if (typeof a === "undefined") {
|
|
|
- console.warn("=---------- 异常 -----------=");
|
|
|
- console.warn(a);
|
|
|
- console.warn("=------------------------------=");
|
|
|
- send_alert("信息失败 : " + e);
|
|
|
+ BasicFunction.logwarn("=---------- 异常 -----------=");
|
|
|
+ BasicFunction.logwarn(a);
|
|
|
+ BasicFunction.logwarn("=------------------------------=");
|
|
|
+ BasicFunction.logwarn(b);
|
|
|
+ BasicFunction.logwarn("=------------------------------=");
|
|
|
+ BasicFunction.send_alert("信息失败 - 2 " );
|
|
|
return;
|
|
|
}
|
|
|
if (a.ret === "10000") {
|
|
|
return true;
|
|
|
} else {
|
|
|
- console.trace();
|
|
|
- console.error(b);
|
|
|
- console.error(JSON.stringify(a));
|
|
|
- send_alert("查询失败 : 请参阅控制台输出! ");
|
|
|
+ BasicFunction.logtrace();
|
|
|
+ BasicFunction.logerror(b);
|
|
|
+ BasicFunction.logerror(JSON.stringify(a));
|
|
|
+ BasicFunction.send_alert("查询失败 : 请参阅控制台输出! ");
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- function on_fail(msg, sta, obj) {
|
|
|
+ this.on_fail = function (msg, sta, obj) {
|
|
|
+ try{
|
|
|
+ var vvurl =""
|
|
|
+ }catch (e) {
|
|
|
+ console.log(msg);
|
|
|
+ }
|
|
|
BasicFunction.Queue.errorCount += 1;
|
|
|
if (BasicFunction.Queue.errorCount >= 10) {
|
|
|
BasicFunction.Queue.errorCount = 0;
|
|
|
BasicFunction.Queue.temporary = new Date().getTime() + 30 * 1000;
|
|
|
BasicFunction.Queue.shouldStop = true;
|
|
|
- console.warn("----- Too many failure, temporary stop HTTP ------");
|
|
|
+ BasicFunction.logwarn("----- Too many failure, temporary stop HTTP ------");
|
|
|
BasicFunction.send_alert("很抱歉,网络错误数量过多,暂时终止HTTP功能30s");
|
|
|
}
|
|
|
let vurl = "";
|
|
@@ -227,186 +317,92 @@ var BasicFunction = new (function() {
|
|
|
vurl = "";
|
|
|
}
|
|
|
BasicFunction.send_alert("很抱歉,网络错误,请查看 Console" + vurl);
|
|
|
- console.warn("----- 网络请求失败 ---------");
|
|
|
+ BasicFunction.logwarn("----- 网络请求失败 ---------");
|
|
|
try {
|
|
|
- console.warn(JSON.stringify(this));
|
|
|
+ BasicFunction.logwarn(JSON.stringify(this));
|
|
|
} catch (e) {
|
|
|
- console.warn(JSON.stringify(obj.url));
|
|
|
- console.warn(JSON.stringify(obj.responseText));
|
|
|
- }
|
|
|
- console.warn("-----------msg-------------");
|
|
|
- console.warn(JSON.stringify(msg));
|
|
|
- console.warn("-----------sta--------------");
|
|
|
- console.warn(JSON.stringify(sta));
|
|
|
- console.warn("----------------------------");
|
|
|
- }
|
|
|
+ BasicFunction.logwarn(JSON.stringify(obj.url));
|
|
|
+ BasicFunction.logwarn(JSON.stringify(obj.responseText));
|
|
|
+ }
|
|
|
+ BasicFunction.logwarn("-----------msg-------------");
|
|
|
+ BasicFunction.logwarn(JSON.stringify(msg));
|
|
|
+ BasicFunction.logwarn("-----------sta--------------");
|
|
|
+ BasicFunction.logwarn(JSON.stringify(sta));
|
|
|
+ BasicFunction.logwarn("----------------------------");
|
|
|
+ };
|
|
|
|
|
|
- var first_parse = function(ajax, obj) {
|
|
|
+ this.first_parse = function (ajax, obj) {
|
|
|
if (typeof obj === "string") {
|
|
|
obj = JSON.parse(obj);
|
|
|
}
|
|
|
|
|
|
if (typeof obj !== "object") {
|
|
|
- console.warn(ajax);
|
|
|
+ BasicFunction.logwarn(ajax);
|
|
|
throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
|
|
|
}
|
|
|
|
|
|
if (obj.ret === "10000") {
|
|
|
return obj.model;
|
|
|
} else {
|
|
|
- console.warn(ajax);
|
|
|
+ BasicFunction.logwarn(ajax);
|
|
|
throw "Error ! Server returned error." + JSON.stringify(obj);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- this.on_document_load = function() {
|
|
|
- if (typeof (page_document_load) !== "undefined") {
|
|
|
- this.page_document_load();
|
|
|
- }
|
|
|
- if (typeof (resizeAll) !== "undefined") {
|
|
|
- this.resizeAll();
|
|
|
- }
|
|
|
};
|
|
|
|
|
|
- this.AlertClosingTimeout = 0;
|
|
|
+ this.send_alert = function (a, b) {
|
|
|
|
|
|
- this.send_alert = function(a, b) {
|
|
|
|
|
|
if (BasicFunction.Queue.shouldStop) return;
|
|
|
- $("#mpAlert").html(a);
|
|
|
- $("#mpAlert").show();
|
|
|
|
|
|
- if (AlertClosingTimeout > 0) {
|
|
|
- clearTimeout(AlertClosingTimeout);
|
|
|
+ if (BasicFunction.AlertClosingTimeout > 0) {
|
|
|
+ clearTimeout(BasicFunction.AlertClosingTimeout);
|
|
|
}
|
|
|
|
|
|
- BasicFunction.AlertClosingTimeout = setTimeout(function () {
|
|
|
- if ($("#mpAlert").html().indexOf("<") >= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- $("#mpAlert").hide();
|
|
|
- }, 10000);
|
|
|
-
|
|
|
- return;
|
|
|
+ BasicFunction.logwarn(a);
|
|
|
+ BasicFunction.logwarn(b);
|
|
|
|
|
|
- //var q = "<!-- Modal 部分开始 -->\n<div class=\"modal fade\" id=\"alertModal\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\" role=\"document\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h5 class=\"modal-title\" id=\"alertModalLabel\">New message</h5>\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n <span aria-hidden=\"true\">×</span>\n </button>\n </div>\n <div class=\"modal-body\">\n <form>\n <div class=\"form-group\">\n <label for=\"recipient-name\" class=\"col-form-label\">Recipient:</label>\n <input type=\"text\" class=\"form-control\" id=\"recipient-name\">\n </div>\n <div class=\"form-group\">\n <label for=\"message-text\" class=\"col-form-label\">Message:</label>\n <textarea class=\"form-control\" id=\"message-text\"></textarea>\n </div>\n </form>\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close</button>\n <button type=\"button\" class=\"btn btn-primary\">Send message</button>\n </div>\n </div>\n </div>\n</div>";
|
|
|
- //var model = document.createElement("div");
|
|
|
- //if ($("#modalContainer").length <= 0) {
|
|
|
- alert(a);
|
|
|
- return;
|
|
|
- //}
|
|
|
+ // alert(a +"\n"+ b);
|
|
|
|
|
|
- $("#modalContainer").html(q);
|
|
|
- var modalO = $("alertModal");
|
|
|
- if (modalO.length === 0) {
|
|
|
- alert(a);
|
|
|
- } else {
|
|
|
- $("#alertModelLabel").text(b);
|
|
|
- $("#message-text").text(b);
|
|
|
- modalO.modal('show');
|
|
|
- }
|
|
|
+ BasicFunction.AlertClosingTimeout = setTimeout(function () {
|
|
|
+ //$("#mpAlert").hide();
|
|
|
+ }, 10000);
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- function getUserName(uid) {
|
|
|
+ this.getUserName = function (uid) {
|
|
|
var uname = null;
|
|
|
- Users.list.forEach(function (val, aid, arr) {
|
|
|
+ BasicFunction.Users.list.forEach(function (val, aid) {
|
|
|
+ BasicFunction.loglog(aid);
|
|
|
if (val.worker.staffId === uid) {
|
|
|
uname = val.worker.staffName;
|
|
|
}
|
|
|
});
|
|
|
if (uname == null) {
|
|
|
- if (uid != 0) {
|
|
|
- get_data("oaStaff/list?staffId=" + uid, on_username_retn);
|
|
|
+ if (uid !== 0) {
|
|
|
+ BasicFunction.get_data("oaStaff/list?staffId=" + uid, BasicFunction.on_username_retn);
|
|
|
return "[用户:" + uid + "]";
|
|
|
} else return "[用户:" + uid + "]";
|
|
|
} else {
|
|
|
return uname;
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.on_username_retn = function (obj, sta) {
|
|
|
+ this.on_username_retn = function (obj) {
|
|
|
var uid = this.url.substring(this.url.indexOf("staffId=") + 8);
|
|
|
let ruid = parseInt(uid);
|
|
|
- var out = first_parse(this, obj);
|
|
|
+ var out = BasicFunction.first_parse(this, obj);
|
|
|
if (out.list.length > 0) {
|
|
|
- Users.list.push({
|
|
|
+ BasicFunction.Users.list.push({
|
|
|
uid: ruid, worker: out.list[0]
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- this.getSectorName = function(sectorId) {
|
|
|
- var secName = null;
|
|
|
- Sectors.list.forEach(function (val, aid, arr) {
|
|
|
- if (val.sector.sectorId === sectorId) {
|
|
|
- secName = val.sector.sectorName;
|
|
|
- }
|
|
|
- });
|
|
|
- if (secName == null) {
|
|
|
- get_data("fcSector/list?sectorId=" + sectorId, on_secname_retn);
|
|
|
- return "[工位:" + sectorId + "]";
|
|
|
- } else {
|
|
|
- return secName;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.on_secname_retn = function(obj, sta) {
|
|
|
- var secid = this.url.substring(this.url.indexOf("sectorId=") + 9);
|
|
|
- let rsecid = parseInt(secid);
|
|
|
- var out = first_parse(this, obj);
|
|
|
- if (out.list.length > 0) {
|
|
|
- Sectors.list.push({
|
|
|
- secid: rsecid, sector: out.list[0]
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.getSectorId = function(spotId) {
|
|
|
- var secId = null;
|
|
|
- Sectors.list.forEach(function (val, aid, arr) {
|
|
|
- if (val.sector.spotId === spotId) {
|
|
|
- secId = val.sector.sectorId;
|
|
|
- }
|
|
|
- });
|
|
|
- if (secId == null) {
|
|
|
- get_data("fcSectorSpot/list?spotId=" + spotId, on_secid_retn);
|
|
|
- return -1;
|
|
|
- } else {
|
|
|
- return secId;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- this.on_secid_retn = function(obj, sta) {
|
|
|
- var spotId = this.url.substring(this.url.indexOf("spotId=") + 7);
|
|
|
- let rsecid = parseInt(spotId);
|
|
|
- var out = first_parse(this, obj);
|
|
|
- if (out.list.length > 0) {
|
|
|
- Sectors.list.push({
|
|
|
- secid: rsecid, sector: out.list[0]
|
|
|
- });
|
|
|
- }
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * Calc b/a+b * 100(precision = 2), when b is zero, return zero
|
|
|
- * @param a (pass)
|
|
|
- * @param b (fail)
|
|
|
- */
|
|
|
- this.get_factor = function(a, b) {
|
|
|
- if (a + b === 0) {
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- return Math.floor(10000 * b / (a + b)) / 100;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.setCookieWithTimeout = function(name, value, liveMinutes) {
|
|
|
- if (liveMinutes == undefined || liveMinutes == null) {
|
|
|
+ this.setCookieWithTimeout = function (name, value, liveMinutes) {
|
|
|
+ if (liveMinutes === undefined || liveMinutes == null) {
|
|
|
liveMinutes = 60 * 2;
|
|
|
}
|
|
|
- if (typeof (liveMinutes) != 'number') {
|
|
|
+ if (typeof (liveMinutes) !== 'number') {
|
|
|
liveMinutes = 60 * 2;//默认120分钟
|
|
|
}
|
|
|
var minutes = liveMinutes * 60 * 1000;
|
|
@@ -414,59 +410,57 @@ var BasicFunction = new (function() {
|
|
|
exp.setTime(exp.getTime() + minutes + 8 * 3600 * 1000);
|
|
|
//path=/表示全站有效,而不是当前页
|
|
|
document.cookie = name + "=" + value + ";path=/;expires=" + exp.toUTCString();
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.setCookie = function(c_name, value, expiredays) {
|
|
|
- var exdate = new Date()
|
|
|
- exdate.setDate(exdate.getDate() + expiredays)
|
|
|
+ this.setCookie = function (c_name, value, expiredays) {
|
|
|
+ var exdate = new Date();
|
|
|
+ exdate.setDate(exdate.getDate() + expiredays);
|
|
|
document.cookie = c_name + "=" + escape(value) +
|
|
|
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.getCookie = function(c_name) {
|
|
|
+ this.getCookie = function (c_name) {
|
|
|
if (document.cookie.length > 0) {
|
|
|
- var c_start = document.cookie.indexOf(c_name + "=")
|
|
|
- if (c_start != -1) {
|
|
|
- c_start = c_start + c_name.length + 1
|
|
|
- var c_end = document.cookie.indexOf(";", c_start)
|
|
|
- if (c_end == -1) c_end = document.cookie.length
|
|
|
+ var c_start = document.cookie.indexOf(c_name + "=");
|
|
|
+ if (c_start !== -1) {
|
|
|
+ c_start = c_start + c_name.length + 1;
|
|
|
+ var c_end = document.cookie.indexOf(";", c_start);
|
|
|
+ if (c_end === -1) c_end = document.cookie.length;
|
|
|
return unescape(document.cookie.substring(c_start, c_end))
|
|
|
}
|
|
|
}
|
|
|
return "";
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- var userId = utils_get_param("userId");
|
|
|
+ /*this.userId = utils_get_param("userId");
|
|
|
|
|
|
this.getUserId = function() {
|
|
|
- console.log("Original USERID : " + userId);
|
|
|
+ BasicFunction.loglog("Original USERID : " + userId);
|
|
|
var use = getCookie("doibyUser");
|
|
|
if (use == null || use === undefined || use.length <= 0) {
|
|
|
location.href = "sign-in1.html?from=entrance-1&msg=nologin-mustauth";
|
|
|
return;
|
|
|
}
|
|
|
- console.log("Got UID From COOKIE : " + use);
|
|
|
+ BasicFunction.loglog("Got UID From COOKIE : " + use);
|
|
|
try {
|
|
|
var mm = parseInt(use);
|
|
|
- if (mm <= 0) {
|
|
|
- } else {
|
|
|
- userId = mm;
|
|
|
+ if (mm > 0) {
|
|
|
+ BasicFunction.userId = mm;
|
|
|
}
|
|
|
} catch (e) {
|
|
|
location.href = "sign-in1.html?from=entrance-1&msg=cookie-wrong-format";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log("Got UserId Eventually : " + userId);
|
|
|
- }
|
|
|
-
|
|
|
+ BasicFunction.loglog("Got UserId Eventually : " + userId);
|
|
|
+ };*/
|
|
|
|
|
|
- //$(document).ready(on_document_load);
|
|
|
this.get_server_url();
|
|
|
- this.on_document_load();
|
|
|
+ //this.on_document_load();
|
|
|
})();
|
|
|
|
|
|
+window.BasicFunction = BasicFunction;
|
|
|
|
|
|
export {
|
|
|
BasicFunction
|
|
|
-}
|
|
|
+};
|