644 lines
19 KiB
Plaintext
644 lines
19 KiB
Plaintext
|
|
@{
|
|
ViewData["Title"] = "Manager_Index";
|
|
Layout = "~/Views/Shared/_Layout_Manager.cshtml";
|
|
}
|
|
|
|
<h1>管理員模式</h1>
|
|
|
|
|
|
|
|
<div class="row">
|
|
<!--每日違規數量-->
|
|
<div class="col-xl-8 col-lg-8">
|
|
<div class="card shadow mb-8">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
每日違規數量
|
|
<button class="btn btn-info btn-circle btn-sm" style="float:right; background-image: url('/image/icon/F5.png'); background-size: cover;" onclick="get_violation_data_1()"></button>
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="chart-bar">
|
|
<canvas id="violation_car_Bar"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--字幕機狀態-->
|
|
<div class="col-xl-4 col-lg-4">
|
|
<div class="card shadow mb-4">
|
|
<!-- Card Header - Dropdown -->
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
各停車場車位數量<button class="btn btn-info btn-circle btn-sm" style="float:right; background-image: url('/image/icon/F5.png'); background-size: cover;" onclick="get_LED_data()"></button>
|
|
</h6>
|
|
</div>
|
|
<!-- Card Body -->
|
|
<div>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>
|
|
停車場位置
|
|
</th>
|
|
|
|
<th>
|
|
剩餘車位
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="LED_table">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<br />
|
|
|
|
<div class="row">
|
|
<!--每日車流量-->
|
|
<div class="col-xl-8 col-lg-8">
|
|
<div class="card shadow mb-8">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
每日車流量<button class="btn btn-info btn-circle btn-sm" style="float:right; background-image: url('/image/icon/F5.png'); background-size: cover;" onclick="get_in_yuntech_data_1()"></button>
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="chart-area">
|
|
<canvas id="in_car_Bar"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--校園總車位數量-->
|
|
<div class="col-xl-4 col-lg-4">
|
|
<div class="card shadow mb-4">
|
|
<!-- Card Header - Dropdown -->
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
校園總車位數量<button class="btn btn-info btn-circle btn-sm" style="float:right; background-image: url('/image/icon/F5.png'); background-size: cover;" onclick="get_yuntech_parking_data()"></button>
|
|
</h6>
|
|
</div>
|
|
<!-- Card Body -->
|
|
<div>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>
|
|
總車位
|
|
</th>
|
|
<th>
|
|
剩餘車位
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody id="parking_all_table">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<br />
|
|
|
|
|
|
<script src="/bootstrap_1/vendor/chart.js/Chart.min.js"></script>
|
|
|
|
<div class="row">
|
|
<!-- 校園月租臨停數 -->
|
|
<div class="col-xl-8 col-lg-8">
|
|
<div class="card shadow mb-8">
|
|
<!-- Card Header - Dropdown -->
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
校園當前車流量
|
|
<button class="btn btn-info btn-circle btn-sm" style="float:right; background-image: url('/image/icon/F5.png'); background-size: cover;" onclick="get_monthly_rent_data()"></button>
|
|
</h6>
|
|
</div>
|
|
<!-- Card Body -->
|
|
<div>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>類別</th>
|
|
<th>數量</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="monthly_table"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!--設定數據圖數據-每日車流量-->
|
|
<script>
|
|
function set_in_yuntech_table(labels, dailyTrafficData) {
|
|
date = JSON.parse(JSON.stringify(labels));
|
|
values = JSON.parse(JSON.stringify(dailyTrafficData));
|
|
// 假設你有一些資料,例如每日車流量
|
|
var dailyTrafficData = dailyTrafficData
|
|
|
|
// 取得 canvas 元素
|
|
var ctx1 = document.getElementById('in_car_Bar')
|
|
|
|
|
|
// 使用 Chart.js 繪製長條圖
|
|
var myLineChart = new Chart(ctx1, {
|
|
type: 'line',
|
|
data: {
|
|
labels: date,
|
|
datasets: [{
|
|
label: '車流量',
|
|
data: values,
|
|
backgroundColor: 'rgba(75, 192, 192, 0.2)', // 設定背景色
|
|
borderColor: 'rgba(75, 192, 192, 1)', // 設定邊框色
|
|
pointHitRadius: 10,
|
|
pointBorderWidth: 2,
|
|
ineTension: 0.3,
|
|
pointRadius: 3,
|
|
pointHoverRadius: 3,
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true, // 啟用 responsive 設置
|
|
maintainAspectRatio: false, // 保持長寬比例
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true
|
|
},
|
|
xAxes: {
|
|
gridLines: {
|
|
display: false // 移除 x 軸的網格線
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
function set_in_yuntech_table_1(labels, dailyTrafficData) {
|
|
date = JSON.parse(JSON.stringify(labels));
|
|
values = JSON.parse(JSON.stringify(dailyTrafficData));
|
|
// 假設你有一些資料,例如每日車流量
|
|
var dailyTrafficData = dailyTrafficData
|
|
|
|
// 取得 canvas 元素
|
|
var ctx = document.getElementById('in_car_Bar')
|
|
|
|
|
|
// 使用 Chart.js 繪製長條圖
|
|
var myBarChart = new Chart(ctx, {
|
|
type: 'bar',
|
|
data: {
|
|
labels: date.reverse(),
|
|
datasets: [{
|
|
label: '車流量',
|
|
data: values.reverse(),
|
|
backgroundColor: 'rgba(75, 192, 192, 0.2)', // 設定背景色
|
|
borderColor: 'rgba(75, 192, 192, 1)', // 設定邊框色
|
|
borderWidth: 1
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true, // 啟用 responsive 設置
|
|
maintainAspectRatio: false, // 保持長寬比例
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
<!--設定數據圖數據-每日違規數量-->
|
|
<script>
|
|
function set_violation_table(labels, dailyTrafficData) {
|
|
|
|
date = JSON.parse(JSON.stringify(labels));
|
|
values = JSON.parse(JSON.stringify(dailyTrafficData));
|
|
// 假設你有一些資料,例如每日違規數量
|
|
var dailyTrafficData = dailyTrafficData;
|
|
|
|
// 取得 canvas 元素
|
|
var ctx = document.getElementById('violation_car_Bar')
|
|
|
|
|
|
|
|
// 使用 Chart.js 繪製長條圖
|
|
var myBarChart = new Chart(ctx, {
|
|
type: 'bar',
|
|
data: {
|
|
labels: date,
|
|
datasets: [{
|
|
label: '違規數量',
|
|
data: values,
|
|
backgroundColor: 'rgba(255, 0, 0, 0.5)', // 設定半透明的紅色背景
|
|
borderColor: 'rgba(255, 0, 0, 1)', // 設定不透明的紅色邊框
|
|
borderWidth: 1
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true, // 啟用 responsive 設置
|
|
maintainAspectRatio: false, // 保持長寬比例
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<!--獲取資料-->
|
|
<script>
|
|
function get_data(){
|
|
console.log("GET")
|
|
get_violation_data_1()
|
|
get_in_yuntech_data_1()
|
|
get_yuntech_parking_data()
|
|
get_LED_data()
|
|
get_monthly_rent_data()
|
|
|
|
}
|
|
</script>
|
|
|
|
<!--獲取違規資料-->
|
|
<script>
|
|
var token_ckeck //= document.getElementById("token_ckeck_id").value
|
|
var position //職位
|
|
function get_violation_data_1() {
|
|
day = 30
|
|
violation_car_list = []
|
|
//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/Violation_car_table/get_day_violation-" + day,
|
|
data: {},
|
|
contentType: "application/json",
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
success: function (Model) {
|
|
//get_violation_data_2(Model)
|
|
console.log(Model)
|
|
set_violation_data_1(Model)
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<!--設置違規資料-->
|
|
<script>
|
|
|
|
function set_violation_data_1(Model) {
|
|
var date_list = []
|
|
var violation_car_list = []
|
|
if (Model.length > 0) {
|
|
for (var i = 0; i < Model.length; i++) {
|
|
var D_1 = new Date(Model[i]['date']);
|
|
var MD = D_1.toLocaleDateString('en-US', { month: '2-digit', day: '2-digit' });
|
|
date_list.push(MD)
|
|
violation_car_list.push(Model[i]['occurrences'])
|
|
}
|
|
}
|
|
set_violation_table(date_list, violation_car_list)
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!--獲取進入雲科資料-->
|
|
<script>
|
|
function get_in_yuntech_data_1() {
|
|
day = 30
|
|
in_car_list = []
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_in_car_table/get_day_in_car-" + day,
|
|
data: {},
|
|
contentType: "application/json",
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
success: function (Model) {
|
|
set_in_yuntech_data_1(Model)
|
|
|
|
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<!--設置進入雲科資料-->
|
|
<script>
|
|
var in_car_list = []
|
|
function set_in_yuntech_data_1(Model) {
|
|
var date_list = []
|
|
var in_car_list = []
|
|
if (Model.length > 0) {
|
|
for (var i = 0; i < Model.length; i++) {
|
|
var D_1 = new Date(Model[i]['date']);
|
|
var MD = D_1.toLocaleDateString('en-US', { month: '2-digit', day: '2-digit' });
|
|
date_list.push(MD)
|
|
in_car_list.push(Model[i]['occurrences'])
|
|
}
|
|
}
|
|
set_in_yuntech_table(date_list, in_car_list)
|
|
|
|
}
|
|
</script>
|
|
|
|
<!--獲取字幕機資料-->
|
|
<script>
|
|
function get_LED_data() {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://140.125.20.183:7700/api/Parking_spaces_lcd_instand",
|
|
data: {},
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
//console.log(Model)
|
|
set_LED_data(Model)
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<!--放置字幕機資料-->
|
|
<script>
|
|
function set_LED_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_name != null) {
|
|
table += "<td>" + Model[i].parking_spaces_name + "</td>"
|
|
table += "<td>" + Model[i].parking_space_amount + "</td>"
|
|
|
|
|
|
|
|
}
|
|
table += "</tr>"
|
|
table += "<tr>"
|
|
}
|
|
}
|
|
document.getElementById("LED_table").innerHTML = table
|
|
}
|
|
</script>
|
|
|
|
<!--獲取月租臨停資料-->
|
|
<script>
|
|
function get_monthly_rent_data() {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_monthly_rent_number",
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
console.log(Model)
|
|
set_monthly_data(Model);
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error("獲取數據失敗:", error);
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
<!--放置月租臨停資料-->
|
|
<script>
|
|
function set_monthly_data(Model) {
|
|
var table = "<tr>";
|
|
if (Model.length > 0) {
|
|
for (var i = 0; i < Model.length; i++) {
|
|
if (Model[i].category != null) {
|
|
table += "<td>" + Model[i].category + "</td>"
|
|
|
|
table += "<td>" + '<input type="text" id = "parking_space_amount_id" value =' + Model[i].number + ' />' + "</td > "
|
|
table += "<td>" + '<button class="btn btn-outline-warning " onclick="Update_monthly_rent_number(' + "'" + i + "'" + ')">更新並上傳</button>'
|
|
}
|
|
table += "</tr>"
|
|
table += "<tr>"
|
|
}
|
|
}
|
|
document.getElementById("monthly_table").innerHTML = table;
|
|
}
|
|
</script>
|
|
|
|
<!--更新剩餘車位資料-->
|
|
<script>
|
|
function Update_monthly_rent_number(num) {
|
|
var Row = $('#monthly_table tr:eq(' + num + ')');
|
|
var category = Row.find('td:eq(0)').text();
|
|
var number = Row.find('td:eq(1) input').val();
|
|
console.log(category, number);
|
|
var data = {
|
|
"category": category,
|
|
"number": number
|
|
}
|
|
var stringify_obj = JSON.stringify(data);
|
|
$.ajax({
|
|
type: "PUT",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_monthly_rent_number/" + category,
|
|
data: stringify_obj,
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
window.alert("更新成功")
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<!--獲取總車位資料-->
|
|
<script>
|
|
function get_yuntech_parking_data() {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_parking",
|
|
data: {},
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
set_yuntech_parking_data(Model)
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<!--放置總車位資料-->
|
|
<script>
|
|
function set_yuntech_parking_data(Model) {
|
|
table = "<tr>";
|
|
if (Model.length > 0) {
|
|
for (var i = 0; i < Model.length; i++) {
|
|
if (Model[i].all_num != null) {
|
|
table += "<td>" + Model[i].all_num + "</td>"
|
|
|
|
table += "<td>" + '<input type="text" id = "parking_space_amount_id" value =' + Model[i].now_num + ' />' + "</td > "
|
|
table += "<td>" + '<button class="btn btn-outline-warning " onclick="Update_now_num(' + "'" + Model[i].all_num + "'" + ')">更新並上傳</button>'
|
|
}
|
|
table += "</tr>"
|
|
table += "<tr>"
|
|
}
|
|
}
|
|
document.getElementById("parking_all_table").innerHTML = table
|
|
}
|
|
</script>
|
|
|
|
<!--更新剩餘車位資料-->
|
|
<script>
|
|
function Update_now_num(all_num) {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_parking/" + all_num,
|
|
data: {},
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
console.log(Model)
|
|
Update_detail_1(Model)
|
|
}
|
|
});
|
|
}
|
|
function Update_detail_1(Model) {
|
|
var parking_spaces_now_num = document.getElementById("parking_space_amount_id").value
|
|
Model.now_num = parking_spaces_now_num
|
|
var stringify_obj = JSON.stringify(Model);
|
|
|
|
$.ajax({
|
|
type: "PUT",
|
|
url: "http://140.125.20.183:7700/api/Yuntech_parking/" + Model.all_num,
|
|
data: stringify_obj,
|
|
headers: {
|
|
'Authorization': token
|
|
},
|
|
contentType: "application/json",
|
|
success: function (Model) {
|
|
console.log(Model)
|
|
}
|
|
});
|
|
}
|
|
</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>
|
|
|
|
|