[Forntend] 登入 開發機與測試機程序判斷

This commit is contained in:
dev01 2022-11-30 12:26:46 +08:00
parent 730654dc66
commit d943fb3fc5

View File

@ -56,7 +56,7 @@
<label class="custom-control-label" for="rememberme"> 記住我</label> <label class="custom-control-label" for="rememberme"> 記住我</label>
</div> </div>
</div> </div>
<button type="submit" class="btn btn-default float-right" onclick="Login(event)">登入</button> <button type="submit" class="btn btn-default float-right" onclick="Login(null,event)">登入</button>
</form> </form>
</div> </div>
<div class="blankpage-footer text-center"> <div class="blankpage-footer text-center">
@ -78,7 +78,7 @@
<script src="lib/notifications/sweetalert2/sweetalert2.bundle.js"></script>--> <script src="lib/notifications/sweetalert2/sweetalert2.bundle.js"></script>-->
<script src="lib/notifications/toastr/toastr.min.js"></script> <script src="lib/notifications/toastr/toastr.min.js"></script>
<script src="js/toast.js"></script> <script src="js/toast.js"></script>
<!--Bajascript--> <!--Bajascript-->
<script src="js/bajascript/bscriptReq.js"></script> <script src="js/bajascript/bscriptReq.js"></script>
@ -118,18 +118,20 @@
[ [
"init", "init",
] ,loadedJsPack); ], loadedJsPack);
} }
function loadedJsPack() { function loadedJsPack() {
myBaja = new MyBaja(); if (location.href.indexOf("localhost:5966") == -1) {
myBaja.setMyUserAccount(Login) myBaja = new MyBaja();
myBaja.setMyUserAccount(Login)
}
if (localStorage.getItem('taipei-t') == 'true') { if (localStorage.getItem('mitsubishi-t') == 'true') {
document.getElementById("rememberme").checked = true; document.getElementById("rememberme").checked = true;
remember = true; remember = true;
$("#account").val(atob(localStorage.getItem('taipei-a'))); $("#account").val(atob(localStorage.getItem('mitsubishi-a')));
$("#password").val(atob(localStorage.getItem('taipei-p'))); $("#password").val(atob(localStorage.getItem('mitsubishi-p')));
} }
else { else {
document.getElementById("rememberme").checked = false; document.getElementById("rememberme").checked = false;
@ -167,81 +169,90 @@
$("#rememberme").click(function () { $("#rememberme").click(function () {
if (remember) { if (remember) {
localStorage.setItem('taipei-t', 'false'); localStorage.setItem('mitsubishi-t', 'false');
localStorage.removeItem('taipei-a'); localStorage.removeItem('mitsubishi-a');
localStorage.removeItem('taipei-p'); localStorage.removeItem('mitsubishi-p');
remember = false; remember = false;
} else { } else {
localStorage.setItem('taipei-t', 'true'); localStorage.setItem('mitsubishi-t', 'true');
localStorage.setItem('taipei-a', btoa($("#account").val())); localStorage.setItem('mitsubishi-a', btoa($("#account").val()));
localStorage.setItem('taipei-p', btoa($("#password").val())); localStorage.setItem('mitsubishi-p', btoa($("#password").val()));
remember = true; remember = true;
} }
}); });
$("#account").change(function () { $("#account").change(function () {
if (remember) { if (remember) {
localStorage.setItem('taipei-a', btoa($("#account").val())); localStorage.setItem('mitsubishi-a', btoa($("#account").val()));
} else { } else {
localStorage.removeItem('taipei-a'); localStorage.removeItem('mitsubishi-a');
} }
}); });
$("#password").change(function () { $("#password").change(function () {
if (remember) { if (remember) {
localStorage.setItem('taipei-p', btoa($("#password").val())); localStorage.setItem('mitsubishi-p', btoa($("#password").val()));
} else { } else {
localStorage.removeItem('taipei-p'); localStorage.removeItem('mitsubishi-p');
} }
}); });
function Login(account) { $("#login-form").on("submit", function (e) {
e.preventDefault();
console.log(account) })
/*if ($("#login-form").valid()) {*/
var url = baseApiUrl + "/api/Login/";
var send_data = {
account: account,
password: "rJ2T5Kkj"
}
$.ajax({
method: "post",
url: url,
data: JSON.stringify(send_data),
async: false,
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (rel) {
console.log(rel)
//rel = JSON.stringify(rel);
if (rel.code != "0000") { }
toast_error(rel.msg || "系統內部發生錯誤,請聯絡系統管理員"); function Login(account, e) {
return; e ? e.preventDefault() : "";
} /*if ($("#login-form").valid()) {*/
else { var url = baseApiUrl + "/api/Login/";
toast_ok(rel.msg); var send_data = {
localStorage.setItem('JWT-Authorization', rel.data.token); account: account,
location.href = "index.html"; password: "rJ2T5Kkj"
return;
}
},
error: function (xhr, textStatus, thrownError) {
alert(textStatus);
}
});
} }
if (location.href.indexOf("localhost:5966") != -1) {
send_data = {
account: $("#account").val(),
password: $("#password").val()
}
}
$.ajax({
method: "post",
url: url,
data: JSON.stringify(send_data),
async: false,
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (rel) {
console.log(rel)
//rel = JSON.stringify(rel);
if (rel.code != "0000") {
toast_error(rel.msg || "系統內部發生錯誤,請聯絡系統管理員");
return;
}
else {
toast_ok(rel.msg);
localStorage.setItem('JWT-Authorization', rel.data.token);
location.href = "index.html";
return;
}
},
error: function (xhr, textStatus, thrownError) {
alert(textStatus);
}
});
} }
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
//#region 登入表單驗證 //#region 登入表單驗證
//#endregion //#endregion
</script> </script>