parking-html/Parking_spaces/Views/Engineering/Engineering_Index_.cshtml

224 lines
5.7 KiB
Plaintext
Raw Normal View History

2024-02-04 14:04:14 +08:00

@{
2024-02-01 11:37:15 +08:00
ViewData["Title"] = "Engineering_Index";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
}
<h1>工程模式</h1>
2024-02-04 14:04:14 +08:00
<div>
<table class="table">
<thead>
<tr>
<th>
演算法名稱
</th>
<th>
狀態
</th>
<th>
啟動時間
</th>
<th>
</th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
2024-02-01 11:37:15 +08:00
</div>
2024-02-04 14:04:14 +08:00
<!--獲取資料-->
2024-02-04 11:58:46 +08:00
<script>
2024-02-04 14:04:14 +08:00
var token = localStorage.getItem('token_park_space');
var token_ckeck //確認token
var position //職位
function get_data(){
$.ajax({
type: "GET",
2024-02-14 21:39:44 +08:00
url: "http://localhost:5174/api/Parking_space_algorithm",
2024-02-04 14:04:14 +08:00
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
put_data(Model)
2024-02-04 11:58:46 +08:00
}
2024-02-04 14:04:14 +08:00
});
}
function get_data_1() {
$.ajax({
type: "GET",
2024-02-14 21:39:44 +08:00
url: "http://localhost:5174/api/Parking_space_algorithm",
2024-02-04 14:04:14 +08:00
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
set_data(Model)
}
});
}
</script>
2024-02-01 11:37:15 +08:00
2024-02-04 14:04:14 +08:00
<!--編輯資料-->
<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",
2024-02-14 21:39:44 +08:00
url: "http://localhost:5174/api/Parking_space_algorithm/" + Model[i].algorithm_serial_num,
2024-02-04 14:04:14 +08:00
data: stringify_obj,
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
setTimeout('get_data_1()', 1000);
//console.log(Model)
//window.location.reload();
}
});
}
}
}
}
2024-02-04 11:58:46 +08:00
</script>
2024-02-01 11:37:15 +08:00
2024-02-04 14:04:14 +08:00
<!--放置資料-->
2024-02-01 11:37:15 +08:00
<script>
2024-02-04 14:04:14 +08:00
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>"
2024-02-04 11:58:46 +08:00
}
2024-02-04 14:04:14 +08:00
table += "</tr>"
table += "<tr>"
2024-02-04 11:58:46 +08:00
}
}
2024-02-04 14:04:14 +08:00
document.getElementById("demo").innerHTML = table
if (c<10){
setTimeout('get_data_1()', 1000);
c = c + 1
}
}
2024-02-01 11:37:15 +08:00
</script>
2024-02-04 14:04:14 +08:00
2024-02-01 11:37:15 +08:00
<!--檢查token-->
<script>
2024-02-14 21:39:44 +08:00
var token
2024-02-01 11:37:15 +08:00
function token_check() {
// 检查本地存储中是否存在JWT令牌
2024-02-14 21:39:44 +08:00
token = localStorage.getItem('token_park_space');
2024-02-01 11:37:15 +08:00
console.log(token)
$.ajax({
type: "GET",
2024-02-14 21:39:44 +08:00
url: 'http://localhost:5174/Users/token_check',
2024-02-01 11:37:15 +08:00
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",
2024-02-14 21:39:44 +08:00
url: 'http://localhost:5174/Users/token-' + token,
2024-02-01 11:37:15 +08:00
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",
2024-02-14 21:39:44 +08:00
url: 'http://localhost:5174/Users/user_id-' + id,
2024-02-01 11:37:15 +08:00
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>