2024-10-01 02:34:26 +08:00
|
|
|
|
|
|
|
|
|
@{
|
|
|
|
|
ViewData["Title"] = "Engineering_EL125_car";
|
|
|
|
|
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<h1>Engineering_EL125_car</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="size2">
|
|
|
|
|
<button class="btn btn-primary" onclick="create_user()">新增成員</button>
|
|
|
|
|
<table class="table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>
|
|
|
|
|
車牌號碼
|
|
|
|
|
</th>
|
|
|
|
|
<th></th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
|
|
<tbody id="demo">
|
|
|
|
|
</tbody>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--新增使用者-->
|
|
|
|
|
<div>
|
|
|
|
|
<dialog id="add_user_view" style="width:80%">
|
|
|
|
|
<div class="container form-container">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-12 text-right">
|
|
|
|
|
<button class="btn btn-danger" onclick="add_user_view.close();">關閉</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="add_user_license_plate_number_text_id">車牌號碼:</label>
|
|
|
|
|
<input type="text" class="form-control" placeholder="請輸入車牌 ex:ABC4321" id="add_user_license_plate_number_text_id" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="row mt-3">
|
|
|
|
|
<div class="col-12 text-right">
|
|
|
|
|
<button class="btn btn-success" onclick="post_user()">上傳</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</dialog>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--新增成員-->
|
|
|
|
|
<script>
|
|
|
|
|
function create_user() {
|
|
|
|
|
//document.getElementById("add_user_name_text_id").value = "";
|
|
|
|
|
document.getElementById("add_user_license_plate_number_text_id").value = "";
|
|
|
|
|
add_user_view.showModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function post_user() {
|
|
|
|
|
var license_plate_number = document.getElementById("add_user_license_plate_number_text_id").value;
|
|
|
|
|
var user_state_check = 'True'
|
|
|
|
|
var obj = { license_plate_number: license_plate_number }
|
|
|
|
|
console.log(obj)
|
|
|
|
|
var stringify_obj = JSON.stringify(obj);
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
2024-11-18 16:41:34 +08:00
|
|
|
|
url: "http://localhost:7700/api/El125_car_table",
|
2024-10-01 02:34:26 +08:00
|
|
|
|
data: stringify_obj,
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
headers: {
|
|
|
|
|
'Authorization': token
|
|
|
|
|
},
|
|
|
|
|
success: function (msg) {
|
|
|
|
|
console.log(msg)
|
|
|
|
|
if (msg == 'ok') {
|
|
|
|
|
add_user_view.close()
|
|
|
|
|
alert("上傳完成");
|
|
|
|
|
get_data()
|
|
|
|
|
}
|
|
|
|
|
if (msg == '車牌重複') {
|
|
|
|
|
alert("車牌重複");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test_upload_bt_2()
|
|
|
|
|
//wait_view()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--設置資料-->
|
|
|
|
|
<script>
|
|
|
|
|
function set_data(Model) {
|
|
|
|
|
console.log(Model)
|
|
|
|
|
table = "<tr>";
|
|
|
|
|
//console.log(Model.length)
|
|
|
|
|
if (Model.length > 0) {
|
|
|
|
|
for (var i = 0; i < Model.length; i++) {
|
|
|
|
|
table += "<td id='" + Model[i].license_plate_number + "_total'>" + Model[i].license_plate_number + "</td>"
|
|
|
|
|
/*
|
|
|
|
|
if (Model[i].user_state_check == "True") {
|
|
|
|
|
table += "<td>" + "ok" + "</td>"
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
table += "<td>" + "Not ok" + "</td>"
|
|
|
|
|
}*/
|
|
|
|
|
table += "<td>" + '<button class="btn btn-danger" onclick="delet_data(' + "'" + Model[i].license_plate_number + "'" + ')">刪除</button>' + "</td>"
|
|
|
|
|
/*table += '<button class="btn btn-danger " onclick="delet_data(' + "'" + Model[i].user_license_plate_number +"'"+ ')">刪除</button>'*/
|
|
|
|
|
table += "</tr>"
|
|
|
|
|
table += "<tr>"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
document.getElementById("demo").innerHTML = table
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--獲取資料-->
|
|
|
|
|
<script>
|
|
|
|
|
function get_data() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
2024-11-18 16:41:34 +08:00
|
|
|
|
url: "http://localhost:7700/api/El125_car_table",
|
2024-10-01 02:34:26 +08:00
|
|
|
|
data: {},
|
|
|
|
|
headers: {
|
|
|
|
|
'Authorization': token
|
|
|
|
|
},
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
headers: {
|
|
|
|
|
'Authorization': token
|
|
|
|
|
},
|
|
|
|
|
success: function (Model) {
|
|
|
|
|
//console.log(Model)
|
|
|
|
|
set_data(Model)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--刪除資料-->
|
|
|
|
|
<script>
|
|
|
|
|
function delet_data(license_plate_number) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "DELETE",
|
2024-11-18 16:41:34 +08:00
|
|
|
|
url: "http://localhost:7700/api/El125_car_table/" + license_plate_number,
|
2024-10-01 02:34:26 +08:00
|
|
|
|
data: {},
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
headers: {
|
|
|
|
|
'Authorization': token
|
|
|
|
|
},
|
|
|
|
|
success: function (msg) {
|
|
|
|
|
console.log(msg)
|
|
|
|
|
get_data()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--檢查token-->
|
|
|
|
|
<script>
|
|
|
|
|
var token
|
|
|
|
|
function token_check() {
|
|
|
|
|
// 检查本地存储中是否存在JWT令牌
|
|
|
|
|
token = localStorage.getItem('token_park_space');
|
|
|
|
|
//console.log(token)
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
2024-11-18 16:41:34 +08:00
|
|
|
|
url: 'http://localhost:7700/Users/token_check',
|
2024-10-01 02:34:26 +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-11-18 16:41:34 +08:00
|
|
|
|
url: 'http://localhost:7700/Users/token-' + token,
|
2024-10-01 02:34:26 +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-11-18 16:41:34 +08:00
|
|
|
|
url: 'http://localhost:7700/Users/user_id-' + id,
|
2024-10-01 02:34:26 +08:00
|
|
|
|
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>
|