parking-html/Parking_spaces/Views/Engineering/Engineering_Index_.cshtml
2024-10-01 02:34:26 +08:00

224 lines
5.7 KiB
Plaintext

@{
ViewData["Title"] = "Engineering_Index";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
}
<h1>工程模式</h1>
<div>
<table class="table">
<thead>
<tr>
<th>
演算法名稱
</th>
<th>
狀態
</th>
<th>
啟動時間
</th>
<th>
</th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
</div>
<!--獲取資料-->
<script>
var token = localStorage.getItem('token_park_space');
var token_ckeck //確認token
var position //職位
function get_data(){
$.ajax({
type: "GET",
url: "http://localhost:7700/api/Parking_space_algorithm",
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
put_data(Model)
}
});
}
function get_data_1() {
$.ajax({
type: "GET",
url: "http://localhost:7700/api/Parking_space_algorithm",
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
set_data(Model)
}
});
}
</script>
<!--編輯資料-->
<script>
function put_data(Model){
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].algorithm_name != null) {
data_1 = {
"algorithm_name": Model[i].algorithm_name,
"state": "False",
"run_time": Model[i].run_time,
"algorithm_serial_num": Model[i].algorithm_serial_num
}
var stringify_obj = JSON.stringify(data_1);
$.ajax({
type: "PUT",
url: "http://localhost:7700/api/Parking_space_algorithm/" + Model[i].algorithm_serial_num,
data: stringify_obj,
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
setTimeout('get_data_1()', 1000);
//console.log(Model)
//window.location.reload();
}
});
}
}
}
}
</script>
<!--放置資料-->
<script>
var c=0
function set_data(Model) {
table = "<tr>";
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].algorithm_name != null) {
table += "<td>" + Model[i].algorithm_name + "</td>"
var state="未啟動"
if (Model[i].state=="True"){
state = "啟動"
}
table += "<td>" + state + "</td>"
table += "<td>" + Model[i].run_time + "</td>"
table += "<td>" + "</td>"
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
if (c<10){
setTimeout('get_data_1()', 1000);
c = c + 1
}
}
</script>
<!--檢查token-->
<script>
var token
function token_check() {
// 检查本地存储中是否存在JWT令牌
token = localStorage.getItem('token_park_space');
console.log(token)
$.ajax({
type: "GET",
url: 'http://localhost:7700/Users/token_check',
headers: {
'Authorization': token
},
success: function (response) {
console.log(response)
token_check = "true"
from_token_import_id()
},
error: function (xhr) {
token_check = "false"
window.location.href = '/';
// 处理错误响应,例如跳转到未授权页面
//window.location.href = 'https://example.com/unauthorized_page';
}
});
}
function from_token_import_id() {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://localhost:7700/Users/token-' + token,
headers: {
'Authorization': token
},
success: function (response) {
console.log(response)
from_id_import_user_data(response)
}
});
}
function from_id_import_user_data(id) {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://localhost:7700/Users/user_id-' + id,
headers: {
'Authorization': token
},
success: function (model) {
model = model.result
position = model.lastname
console.log(position)
if (position == "engineer") {
get_data()
}
else {
window.location.href = '/';
}
}
});
}
</script>
<!--開機自啟-->
<script>
window.onload = token_check;
</script>