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

171 lines
4.7 KiB
Plaintext
Raw Normal View History

2024-02-01 11:37:15 +08:00

@{
ViewData["Title"] = "Engineering_Violation";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
}
<h1 >校園總違規區域</h1>
<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_park_space_view.showModal();map_show()" id="add_park_space_id">新增停車區</button>
<button class="btn btn-primary" onclick="add_violation_view.showModal();map_show_1()" id="add_violation_id">新增違規區域</button>
<button style="height:30px;float:right " class="btn btn-outline-secondary" onclick="serch_click()">搜尋</button>
<input type="text" style="float:right" placeholder="請輸入您的車牌" id="serch_text_id" />-->
<table class="table">
<thead>
<tr>
<th>
總違規區域
</th>
<th>
</th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
</div>
<!--獲取資料-->
<script>
var token_ckeck //= document.getElementById("token_ckeck_id").value
var position //職位
function get_data() {
console.log("start")
//token_check = document.getElementById("token_check_id").value
console.log(token_check)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Parking_spaces_violation_total_table",
data: {},
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_violation_name != null) {
table += "<td>" + Model[i].parking_spaces_violation_name + "</td>"
table += "<td>"
if (token_check == "true") {
table += '<button class="btn btn-outline-success " onclick="detail_data(' + "'" + Model[i].parking_spaces_violation_name + "'" + ')">詳細</button>' + ' ' + ' '
}
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
}
</script>
<!--前往詳細頁面-->
<script>
function detail_data(name) {
window.location = "/Engineering/Single_violation_detail/" + name;
}
</script>
<!--檢查token-->
<script>
function token_check() {
// 检查本地存储中是否存在JWT令牌
var 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 == "engineer") {
get_data()
}
else {
window.location.href = '/';
}
}
});
}
</script>
<!--開機自啟-->
<script>
window.onload = token_check;
</script>