636 lines
22 KiB
Plaintext
636 lines
22 KiB
Plaintext
|
||
@{
|
||
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>
|
||
|
||
<!--下載時間段進入車輛excel檔按鍵-->
|
||
時間段內進入車輛 :
|
||
<th>
|
||
<button class="btn btn-outline-info" onclick="export_excel_1()" style="position: relative;">
|
||
<img class="img-profile rounded-circle" style="width:20%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" src="~/image/icon/724933.png">
|
||
<span style="visibility: hidden;">下載</span>
|
||
</button>
|
||
</th>
|
||
|
||
<!--下載進入車輛excel檔按鍵-->
|
||
總進入車輛 :
|
||
<th>
|
||
<button class="btn btn-outline-info" onclick="export_excel()" style="position: relative;">
|
||
<img class="img-profile rounded-circle" style="width:20%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" src="~/image/icon/724933.png">
|
||
<span style="visibility: hidden;">下載</span>
|
||
</button>
|
||
</th>
|
||
|
||
<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>
|
||
<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 id="lastPageButton" 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 id="nextPageButton" class="btn btn-outline-secondary" onclick="fetchData_Down()">下一頁</button>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
</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
|
||
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,
|
||
data: {},
|
||
headers: {
|
||
'Authorization': token
|
||
},
|
||
contentType: "application/json",
|
||
headers: {
|
||
'Authorization': token
|
||
},
|
||
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);
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
// 定義抓取資料的函式
|
||
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)
|
||
}
|
||
});
|
||
}
|
||
|
||
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)
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
</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) {
|
||
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>
|
||
|
||
|
||
|
||
<!--下一筆資料-->
|
||
<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) {
|
||
// 設定車輛序列號
|
||
serial_number = car_serial_number
|
||
|
||
// 發送AJAX GET請求
|
||
$.ajax({
|
||
type: "GET",
|
||
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name-" + location_name + "-time-" + time,
|
||
data: {},
|
||
contentType: "application/json",
|
||
headers: {
|
||
'Authorization': token
|
||
},
|
||
success: function (Model) {
|
||
// 在控制台列印返回的模型資料
|
||
console.log(Model)
|
||
|
||
// 設定固定車輛圖片
|
||
//let fixed_car_img = "<img style='width:100%' src='~/bootstrap_1/img/Yuntech.png'>";
|
||
|
||
// 檢查是否有離開時間
|
||
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>";
|
||
// 添加固定車輛圖片
|
||
if (Model.car_img == null || Model.car_img == "") {
|
||
table += "<td>" + "<img src='" + "/bootstrap_1/img/maxresdefault.jpg" + "' style='width:80%' />" + "</td>";
|
||
} else {
|
||
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>";
|
||
|
||
// 添加固定車輛圖片
|
||
if (Model.car_img == null || Model.car_img == "") {
|
||
table += "<td>" + "<img src='" + "/bootstrap_1/img/maxresdefault.jpg" + "' style='width:40%' />" + "<img src='" + "/bootstrap_1/img/maxresdefault.jpg" + "' style='width:40%' />" + "</td>";
|
||
} else {
|
||
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;
|
||
}
|
||
}
|
||
});
|
||
// 顯示詳細資料的對話框
|
||
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",
|
||
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/license_plate_number-" + license_plate_number,
|
||
data: {},
|
||
contentType: "application/json",
|
||
headers: {
|
||
'Authorization': token
|
||
},
|
||
success: function (Model) {
|
||
console.log(Model)
|
||
All_Model = Model
|
||
|
||
set_data(Model)
|
||
|
||
}
|
||
});
|
||
}
|
||
</script>
|
||
|
||
<!--透過日期搜尋紀錄-->
|
||
<script>
|
||
function serch_date_click() {
|
||
var name = document.getElementById("location_select_id").value
|
||
var start_date = document.getElementById("start_date_id").value
|
||
var end_date = document.getElementById("end_date_id").value
|
||
console.log(start_date)
|
||
|
||
// 隱藏上一頁按鈕
|
||
document.getElementById("lastPageButton").style.display = "none"
|
||
|
||
// 隱藏下一頁按鈕
|
||
document.getElementById("nextPageButton").style.display = "none"
|
||
|
||
$.ajax({
|
||
type: "GET",
|
||
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name_1_-" + name + "-start_time-" + start_date + "-end_time-" + end_date,
|
||
data: {},
|
||
contentType: "application/json",
|
||
headers: {
|
||
'Authorization': token
|
||
},
|
||
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>
|
||
|
||
<!--輸出時間段內EXCEL-->
|
||
<script>
|
||
function export_excel_1() {
|
||
var name = document.getElementById("location_select_id").value;
|
||
var start_date = document.getElementById("start_date_id").value;
|
||
var end_date = document.getElementById("end_date_id").value;
|
||
|
||
// 將日期格式轉換為後端期望的格式(如 'YYYY-MM-DDTHH:MM:SS')
|
||
var start_time = new Date(start_date).toISOString();
|
||
var end_time = new Date(end_date).toISOString();
|
||
|
||
// 構建請求URL
|
||
var url = "http://140.125.20.183:7700/api/Yuntech_in_car_table/location_name_2_-" + name + "-start_time-" + start_date + "-end_time-" + end_date + "-export_excel";
|
||
|
||
// 發送HTTP GET請求到Web API動作方法
|
||
fetch(url, {
|
||
method: 'GET',
|
||
headers: {
|
||
'Authorization': token
|
||
}
|
||
})
|
||
.then(response => {
|
||
// 確認響應的狀態碼是否為200(成功)
|
||
if (!response.ok) {
|
||
throw new Error('Network response was not ok');
|
||
}
|
||
// 將響應的數據轉換為Blob對象
|
||
return response.blob();
|
||
})
|
||
.then(blob => {
|
||
// 創建URL對象
|
||
const url = window.URL.createObjectURL(blob);
|
||
// 創建當前時間
|
||
const currentTime = new Date().toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/g, "");
|
||
// 構建檔案名稱
|
||
const filename = `時間段內進入車輛-${currentTime}.xlsx`;
|
||
// 創建<a>元素
|
||
const a = document.createElement('a');
|
||
a.href = url;
|
||
a.download = filename; // 下載時的文件名稱
|
||
// 模擬單擊<a>元素
|
||
a.click();
|
||
// 釋放URL對象
|
||
window.URL.revokeObjectURL(url);
|
||
})
|
||
.catch(error => {
|
||
console.error('There was a problem with your fetch operation:', error);
|
||
});
|
||
}
|
||
</script>
|
||
|
||
<!--輸出總EXCEL-->
|
||
<script>
|
||
function export_excel() {
|
||
// 發送HTTP GET請求到Web API動作方法
|
||
fetch('http://140.125.20.183:7700/api/Yuntech_in_car_table/export-all_excel', {
|
||
method: 'GET',
|
||
headers: {
|
||
'Authorization': token
|
||
}
|
||
})
|
||
.then(response => {
|
||
// 確認響應的狀態碼是否為200(成功)
|
||
if (!response.ok) {
|
||
throw new Error('Network response was not ok');
|
||
}
|
||
// 將響應的數據轉換為Blob對象
|
||
return response.blob();
|
||
})
|
||
.then(blob => {
|
||
// 創建URL對象
|
||
const url = window.URL.createObjectURL(blob);
|
||
// 創建當前時間
|
||
const currentTime = new Date().toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/g, "");
|
||
// 構建檔案名稱
|
||
const filename = `進入車輛-${currentTime}.xlsx`;
|
||
// 創建<a>元素
|
||
const a = document.createElement('a');
|
||
a.href = url;
|
||
a.download = filename; // 下載時的文件名稱
|
||
// 模擬單擊<a>元素
|
||
a.click();
|
||
// 釋放URL對象
|
||
window.URL.revokeObjectURL(url);
|
||
})
|
||
.catch(error => {
|
||
console.error('There was a problem with your fetch operation:', error);
|
||
});
|
||
}
|
||
</script>
|
||
|
||
|
||
<!--檢查token-->
|
||
<script>
|
||
var token
|
||
function token_check() {
|
||
// 检查本地存储中是否存在JWT令牌
|
||
token = localStorage.getItem('token_park_space');
|
||
console.log(token)
|
||
$.ajax({
|
||
type: "GET",
|
||
url: 'http://140.125.20.183: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://140.125.20.183: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://140.125.20.183:7700/Users/user_id-' + id,
|
||
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>
|