下載違規資料

This commit is contained in:
威勝 張 2024-03-25 10:02:44 +08:00
parent 3b2edaab43
commit a7aedcd924
3 changed files with 140 additions and 3 deletions

View File

@ -9,6 +9,8 @@
<h1 >校園總違規區域</h1> <h1 >校園總違規區域</h1>
<div class="size2"> <div class="size2">
<button class="btn btn-primary" onclick="add_violation_view.showModal();map_show_1()" id="add_violation_id">新增違規區域</button> <button class="btn btn-primary" onclick="add_violation_view.showModal();map_show_1()" id="add_violation_id">新增違規區域</button>
<!--<button class="btn btn-primary" onclick="add_park_space_view.showModal();map_show()" id="add_park_space_id">新增停車區</button> <!--<button class="btn btn-primary" onclick="add_park_space_view.showModal();map_show()" id="add_park_space_id">新增停車區</button>
@ -21,9 +23,11 @@
<th> <th>
總違規區域 總違規區域
</th> </th>
<th> <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> </th>
</tr> </tr>
</thead> </thead>
@ -362,7 +366,45 @@
</script> </script>
<!--輸出EXCEL-->
<script>
function export_excel() {
// 發送HTTP GET請求到Web API動作方法
fetch('http://140.125.20.183:7700/api/Violation_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>

View File

@ -12,7 +12,16 @@
起始時間 : <input type="date" id="start_date_id"> 起始時間 : <input type="date" id="start_date_id">
結束時間 : <input type="date" id="end_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; " class="btn btn-outline-secondary" onclick="serch_date_click()">搜尋</button>
<button class="btn btn-outline-info" onclick="date_export_excel()" style="position: relative;height:30px">
<img class="img-profile rounded-circle" style="height:30px;width=10%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" src="~/image/icon/724933.png">
<span style="visibility: hidden;">下載</span>
</button>
<button class="btn btn-outline-info" onclick="plate_export_excel()" style="position: relative;height:30px;float:right">
<img class="img-profile rounded-circle" style="height:30px;width=10%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" src="~/image/icon/724933.png">
<span style="visibility: hidden;">下載</span>
</button>
<button style="height:30px;float:right " class="btn btn-outline-secondary" onclick="serch_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" /> <input type="text" style="float:right" placeholder="請輸入車牌 ex:ABC4321" id="serch_text_id" />
<table class="table"> <table class="table">
@ -304,6 +313,92 @@
} }
</script> </script>
<!--透過日期下載EXCEL-->
<script>
function date_export_excel(){
var name = document.getElementById("parking_spaces_name_id").value
var start_date = document.getElementById("start_date_id").value
var end_date = document.getElementById("end_date_id").value
// 發送HTTP GET請求到Web API動作方法
fetch('http://140.125.20.183:7700/api/Violation_car_table/export-excel_location_name_1_-' + name + "-start_time-" + start_date + "-end_time-" + end_date, {
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 plate_export_excel() {
var license_plate_number = document.getElementById("serch_text_id").value
// 發送HTTP GET請求到Web API動作方法
fetch('http://140.125.20.183:7700/api/Violation_car_table/export-excel_license_plate_number-'+license_plate_number, {
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 = `${license_plate_number}-${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>
<!--刪除資料--> <!--刪除資料-->
<script> <script>
function delet_data(location_name , name , time) { function delet_data(location_name , name , time) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB