parking-html/Parking_spaces/Views/Manager/Yuntech_in_car.cshtml

502 lines
16 KiB
Plaintext
Raw Normal View History

2024-02-06 13:38:38 +08:00

@{
ViewData["Title"] = "Yuntech_in_car";
Layout = "~/Views/Shared/_Layout_Manager.cshtml";
}
<h1>進入車輛</h1>
<div class="size2">
起始時間 : <input type="date" id="start_date_id">
結束時間 : <input type="date" id="end_date_id">
<button style="height:30px; " class="btn btn-outline-secondary" onclick="serch_date_click()">搜尋</button>
<button style="height:30px;float:right " class="btn btn-outline-secondary" onclick="serch_click()">搜尋</button>
<input type="text" style="float:right" placeholder="請輸入車牌 ex:ABC4321" id="serch_text_id" />
<br />
<select style="width:10%" id="location_select_id" onchange="location_select()"></select>
2024-02-06 13:38:38 +08:00
<table class="table">
<thead>
<tr>
<th>
區域
</th>
<th>
車牌號碼
</th>
<!--<th>
進入圖片
</th>
<th>
違規圖片
</th>-->
<th>
時間
</th>
<th></th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
<div class="row">
<div class="col-xl-1 col-lg-1">
<div>
<button class="btn btn-outline-secondary" onclick="fetchData_Up()">上一頁</button>
</div>
</div>
<div class="col-xl-10 col-lg-10">
</div>
<div class="col-xl-1 col-lg-1">
<div>
<button class="btn btn-outline-secondary" onclick="fetchData_Down()">下一頁</button>
</div>
</div>
</div>
2024-02-06 13:38:38 +08:00
</div>
<!--車輛詳細-彈跳視窗-->
<div>
<dialog id="detail_car_data_view" style="width:100%;">
<table class="table">
<button class="btn btn-danger" style="float:right" onclick="detail_car_data_view.close();"> 關閉 </button>
<p></p>
<thead>
<tr>
<th>
區域
</th>
<th>
車牌號碼
</th>
<th>
進入圖片
</th>
<th>
時間
</th>
</tr>
</thead>
<tbody id="detail_car_data">
</tbody>
</table>
<button class="btn btn-outline-success" style="float:left" onclick="previous_detail_data()"> Previous</button>
<button class="btn btn-outline-success" style="float:right" onclick="next_detail_data()"> Next </button>
</dialog>
</div>
<!--獲取資料-->
<script>
var All_Model
var serial_number = 0
var car_table_num = 0
2024-02-06 13:38:38 +08:00
function get_data() {
var name = "大門口"
//console.log(name)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/Amount-" + car_table_num,
2024-02-06 13:38:38 +08:00
data: {},
headers: {
'Authorization': token
},
2024-02-06 13:38:38 +08:00
contentType: "application/json",
2024-02-14 21:39:44 +08:00
headers: {
'Authorization': token
},
2024-02-06 13:38:38 +08:00
success: function (Model) {
//console.log(Model)
All_Model = Model
set_data(Model)
}
});
/*
// 監聽捲動事件
window.addEventListener("scroll", function () {
// 判斷是否捲動到底部
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
// 執行抓取資料的函式
fetchData();
}
});
*/
var select = document.getElementById("location_select_id")
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name",
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (Model) {
console.log(Model)
// 清除现有的选项
select.innerHTML = "";
// 添加新的选项
Model.forEach(function (item) {
var option = document.createElement('option');
option.text = item.location_name;
select.add(option);
});
}
});
}
2024-02-06 13:38:38 +08:00
// 定義抓取資料的函式
function fetchData_Up() {
car_table_num = car_table_num - 100
if (car_table_num < 0) {
window.alert('無上一筆資料')
car_table_num = 0
return
}
var name = "大門口"
//console.log(name)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/Amount-" + car_table_num,
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (Model) {
//console.log(Model)
All_Model = Model
set_data(Model)
2024-02-06 13:38:38 +08:00
}
});
}
function fetchData_Down() {
car_table_num = car_table_num + 100
var name = "大門口"
//console.log(name)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/Amount-" + car_table_num,
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (Model) {
//console.log(Model)
All_Model = Model
set_data(Model)
}
});
}
2024-02-06 13:38:38 +08:00
</script>
<!--放置資料-->
<script>
function set_data(Model) {
document.getElementById("demo").innerHTML = ''
var table = "<tr>";
console.log(Model.length)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].location != null) {
table += "<td>" + Model[i].location + "</td>"
table += "<td>" + Model[i].license_plate_number + "</td>"
// 将字符串转换为 Date 对象
var timestampDt = new Date(Model[i].in_time);
// 转换为其他格式
var options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
var formattedDate = timestampDt.toLocaleDateString('en-US', options);
table += "<td>" + formattedDate + "</td>"
table += "<td>" + '<button class="btn btn-outline-success" onclick="detail_data(' + "'" + Model[i].location + "','" + i + "','" + Model[i].in_time + "'" + ')">詳細</button>'
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
// 移動到最上面
window.scrollTo(0, 0);
}
function set_data_license_plate_and_date(Model) {
2024-02-06 13:38:38 +08:00
table = "<tr>";
console.log(Model.length)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].location != null) {
table += "<td>" + Model[i].location + "</td>"
table += "<td>" + Model[i].license_plate_number + "</td>"
// 将字符串转换为 Date 对象
var timestampDt = new Date(Model[i].in_time);
// 转换为其他格式
var options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
var formattedDate = timestampDt.toLocaleDateString('en-US', options);
table += "<td>" + formattedDate + "</td>"
table += "<td>" + '<button class="btn btn-outline-success" onclick="detail_data(' + "'" + Model[i].location + "','" + i + "','" + Model[i].in_time + "'" + ')">詳細</button>'
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
}
</script>
2024-02-06 13:38:38 +08:00
<!--下一筆資料-->
<script>
function next_detail_data() {
serial_number = Number(serial_number) + 1
if (serial_number >= All_Model.length) {
window.alert('無下一筆資料')
serial_number = All_Model.length - 1
return
}
//console.log(serial_number)
//console.log(All_Model[serial_number])
detail_data(All_Model[serial_number]['location'], serial_number, All_Model[serial_number]['in_time'])
}
</script>
<!--上一筆資料-->
<script>
function previous_detail_data() {
serial_number = Number(serial_number) - 1
if (serial_number < 0) {
window.alert('無上一筆資料')
serial_number = 0
return
}
// console.log(serial_number)
//console.log(All_Model[serial_number])
detail_data(All_Model[serial_number]['location'], serial_number, All_Model[serial_number]['in_time'])
}
</script>
<!--車輛詳細-->
<script>
function detail_data(location_name, car_serial_number, time) {
//console.log(location_name)
//console.log(All_Model[car_serial_number])
//console.log(time)
serial_number = car_serial_number
$.ajax({
type: "GET",
2024-02-14 22:02:50 +08:00
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name-" + location_name + "-time-" + time,
2024-02-06 13:38:38 +08:00
data: {},
contentType: "application/json",
2024-02-14 21:39:44 +08:00
headers: {
'Authorization': token
},
2024-02-06 13:38:38 +08:00
success: function (Model) {
console.log(Model)
if (Model.out_time == null) {
table = "<tr>";
table += "<td>" + Model.location + "</td>"
table += "<td>" + '<input type="text" id = "license_plate_number_text_id" value="' + Model.license_plate_number + '"/>' + "</td>"
//table += "<td>" + "</td>"
//table += "<td>" + "</td>"
table += "<td>" + "<img src=" + Model.car_img + ' style="width:80%"' + ">" + "</td>"
table += "<td id = 'create_data_time_id' >" + Model.in_time + "</td>"
document.getElementById("detail_car_data").innerHTML = table
}
else {
table = "<tr>";
table += "<td>" + Model.location + "</td>"
table += "<td>" + '<input type="text" id = "license_plate_number_text_id" value="' + Model.license_plate_number + '"/>' + "</td>"
//table += "<td>" + "</td>"
//table += "<td>" + "</td>"
table += "<td>" + "<img src=" + Model.car_img + ' style="width:40%"' + ">" + " <img src=" + Model.out_car_img + ' style="width:40%"' + ">" + "</td>"
table += "<td id = 'create_data_time_id' >" + "進入時間:" + Model.in_time + "<br/>" + "<br/>" + "出去時間: " + Model.out_time + "</td>"
document.getElementById("detail_car_data").innerHTML = table
}
2024-02-06 13:38:38 +08:00
}
});
detail_car_data_view.showModal();
}
</script>
<!--透過車牌號碼搜尋-->
<script>
function serch_click() {
var license_plate_number = document.getElementById("serch_text_id").value
if (license_plate_number == "") {
get_data()
}
$.ajax({
type: "GET",
2024-02-14 22:02:50 +08:00
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/license_plate_number-" + license_plate_number,
2024-02-06 13:38:38 +08:00
data: {},
contentType: "application/json",
2024-02-14 21:39:44 +08:00
headers: {
'Authorization': token
},
2024-02-06 13:38:38 +08:00
success: function (Model) {
console.log(Model)
All_Model = Model
set_data(Model)
}
});
}
</script>
<!--透過日期搜尋紀錄-->
<script>
function serch_date_click() {
var name = "大門口"
var start_date = document.getElementById("start_date_id").value
var end_date = document.getElementById("end_date_id").value
console.log(start_date)
$.ajax({
type: "GET",
2024-02-14 22:02:50 +08:00
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name_1_-" + name + "-start_time-" + start_date + "-end_time-" + end_date,
2024-02-06 13:38:38 +08:00
data: {},
contentType: "application/json",
2024-02-14 21:39:44 +08:00
headers: {
'Authorization': token
},
2024-02-06 13:38:38 +08:00
success: function (Model) {
console.log(Model)
All_Model = Model
set_data(Model)
}
});
}
</script>
<!--透過進入位置搜尋-->
<script>
function location_select() {
var select_location = document.getElementById("location_select_id").value
console.log(select_location)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location-" + select_location,
data: {},
headers: {
'Authorization': token
},
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (Model) {
//console.log(Model)
All_Model = Model
set_data(Model)
}
});
}
</script>
2024-02-06 13:38:38 +08:00
<!--檢查token-->
<script>
2024-02-14 21:39:44 +08:00
var token
2024-02-06 13:38:38 +08:00
function token_check() {
// 检查本地存储中是否存在JWT令牌
2024-02-14 21:39:44 +08:00
token = localStorage.getItem('token_park_space');
2024-02-06 13:38:38 +08:00
console.log(token)
$.ajax({
type: "GET",
2024-02-14 22:02:50 +08:00
url: 'http://140.125.20.183:7700/Users/token_check',
2024-02-06 13:38:38 +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 22:02:50 +08:00
url: 'http://140.125.20.183:7700/Users/token-' + token,
2024-02-06 13:38:38 +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 22:02:50 +08:00
url: 'http://140.125.20.183:7700/Users/user_id-' + id,
2024-02-06 13:38:38 +08:00
headers: {
'Authorization': token
},
success: function (model) {
model = model.result
position = model.lastname
console.log(position)
if (position == "manager") {
get_data()
}
else {
window.location.href = '/';
}
}
});
}
</script>
<!--開機自啟-->
<script>
window.onload = token_check;
</script>