[Frontend] yourteam.ajax 判斷 401(token失效) 倒登入頁重新登入
This commit is contained in:
parent
64a86b841c
commit
e45ddb24dd
@ -1139,7 +1139,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
<a href="javascript:;" class="dropdown-toggle no-arrow text-center" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fal fa-tv fa-2x"></i><br>系統監控
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
<div class="dropdown-menu" id="sysMonBtnList">
|
||||
<button class="dropdown-item" type="button" name="sysMonBtn">電錶</button>
|
||||
<button class="dropdown-item" type="button" name="sysMonBtn">照明系統</button>
|
||||
<button class="dropdown-item" type="button" name="sysMonBtn">電梯系統</button>
|
||||
@ -2072,6 +2072,10 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
location.href = "login.html";
|
||||
}
|
||||
|
||||
$(function () {
|
||||
getSysMonBtnList();
|
||||
})
|
||||
|
||||
onEvent("click", "button[name^=sysMonBtn]", function () {
|
||||
$("#app").load("_systemMonitor.html", loadCallback);
|
||||
})
|
||||
@ -2083,6 +2087,15 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
initTabsByEle();
|
||||
resetYTTooltip();
|
||||
}
|
||||
|
||||
function getSysMonBtnList() {
|
||||
let url = baseApiUrl + "/api/Device/GetMainSub";
|
||||
ytAjax = new YourTeam.Ajax(url, null, function (data) {
|
||||
console.log(data)
|
||||
/*sysMonBtnList*/
|
||||
},null,"POST").send();
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
<!-- END Body -->
|
||||
|
@ -27,7 +27,7 @@ class Ajax {
|
||||
this.type = type;
|
||||
this.dataType = dataType;
|
||||
this.sendData = sendData;
|
||||
if (successFunction) this.successFunction = successFunction;
|
||||
/*if (successFunction) this.successFunction = successFunction;*/
|
||||
if (errorFunction) this.errorFunction = errorFunction;
|
||||
return this;
|
||||
}
|
||||
@ -45,8 +45,9 @@ class Ajax {
|
||||
* beforeSendFunction
|
||||
* @description beforeSendFunction
|
||||
*/
|
||||
beforeSendFunction = function () {
|
||||
|
||||
beforeSendFunction = function (xhr) {
|
||||
let token = localStorage.getItem("JWT-Authorization");
|
||||
xhr.setRequestHeader('Authorization', "Bearer " + token);
|
||||
}
|
||||
/**
|
||||
* successFunction
|
||||
@ -54,7 +55,13 @@ class Ajax {
|
||||
* @param {Object} data the data object from the api return
|
||||
* @return {Object} data
|
||||
*/
|
||||
successFunction = function (data) {
|
||||
successFunction = function (data,callback) {
|
||||
if (data && data.unauthorized == 401) {
|
||||
location.href = "login.html";
|
||||
}
|
||||
if (callback) {
|
||||
callback(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
@ -74,6 +81,7 @@ class Ajax {
|
||||
location.href = "~/Login/Login";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* completeFunction
|
||||
* @description completeFunction
|
||||
@ -120,9 +128,9 @@ class Ajax {
|
||||
if (sendData) {
|
||||
this.sendData = sendData;
|
||||
}
|
||||
if (successFunction) {
|
||||
this.successFunction = successFunction;
|
||||
}
|
||||
//if (successFunction) {
|
||||
// this.successFunction = successFunction;
|
||||
//}
|
||||
if (errorFunction) {
|
||||
this.errorFunction = errorFunction;
|
||||
}
|
||||
@ -140,11 +148,11 @@ class Ajax {
|
||||
//processData: false,
|
||||
|
||||
beforeSend: this.beforeSendFunction,
|
||||
success: this.successFunction,
|
||||
success:(data) => this.successFunction(data,successFunction),
|
||||
error: this.errorFunction,
|
||||
complete: this.completeFunction,
|
||||
statusCode: {
|
||||
201: this.successFunction
|
||||
201: (data) => this.successFunction(data,successFunction),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user