parking-html/Parking_spaces/Views/Engineering/Engineering_LED_detail.cshtml
2024-11-18 16:41:34 +08:00

272 lines
7.4 KiB
Plaintext

@{
ViewData["Title"] = "Engineering_LED_detail";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
string parking_spaces_name = ViewBag.parking_spaces_name;
}
<input type="hidden" id="parking_spaces_name_id" value=@parking_spaces_name />
<h1>@parking_spaces_name 字幕機</h1>
<div>
<p>
設定LED字幕機參數 :</br>
預設密碼:26888</br>
網路參數高級設置:密碼需要與路由器的子網路遮罩一樣(例:255.255.255.0 , 密碼就為ffffff00)
</p>
<table class="table">
<thead>
<tr>
<th>
停車場位置
</th>
<th>
字幕機IP
</th>
<th>
字幕機 PORT
</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 //職位
var parking_spaces_name = document.getElementById("parking_spaces_name_id").value
function get_data() {
$.ajax({
type: "GET",
url: "http://localhost:7700/api/Parking_spaces_lcd_instand",
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
set_data(Model)
}
});
}
</script>
<!--放置資料-->
<script>
function set_data(Model) {
table = "<tr>";
console.log(Model.length)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].parking_spaces_name == parking_spaces_name) {
table += "<td>" + Model[i].parking_spaces_name + "</td>"
var NewArray = Model[i].lcd_ip.split(":");
table += "<td>" + NewArray[0] + "</td>"
table += "<td>" + NewArray[1] + "</td>"
table += "<td>" + '<input type="text" id = "parking_space_amount_id" value =' + Model[i].parking_space_amount + ' />' + "</td > "
table += "<td>" + '<button class="btn btn-outline-warning " onclick="Update_detail(' + "'" + Model[i].parking_spaces_name + "'" + ')">更新並上傳</button>'
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
}
</script>
<!--更新並上傳-->
<script>
function Update_detail(parking_spaces_name){
$.ajax({
type: "GET",
url: "http://localhost:7700/api/Parking_spaces_total_table/" + parking_spaces_name,
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
Update_detail_1(Model)
}
});
}
function Update_detail_1(Model){
var parking_spaces_now_num = document.getElementById("parking_space_amount_id").value
Model.parking_spaces_now_num = parking_spaces_now_num
var stringify_obj = JSON.stringify(Model);
$.ajax({
type: "PUT",
url: "http://localhost:7700/api/Parking_spaces_total_table/" + parking_spaces_name,
data: stringify_obj,
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
Update_detail_2()
//window.location.reload();
}
});
}
function Update_detail_2() {
$.ajax({
type: "GET",
url: "http://localhost:7700/api/Parking_spaces_lcd_instand/parking_space_area-" + parking_spaces_name,
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].parking_spaces_name == parking_spaces_name) {
Update_detail_3(Model[i])
}
}
}
//Update_detail_1(Model)
}
});
}
function Update_detail_3(Model) {
var parking_spaces_now_num = document.getElementById("parking_space_amount_id").value
Model.parking_space_amount = parking_spaces_now_num
var stringify_obj = JSON.stringify(Model);
$.ajax({
type: "PUT",
url: "http://localhost:7700/api/Parking_spaces_lcd_instand/" + Model.lcd_ip,
data: stringify_obj,
headers: {
'Authorization': token
},
contentType: "application/json",
success: function (Model) {
console.log(Model)
//Update_detail_1(Model)
window.location.reload();
}
});
}
</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>