mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-28 20:45:05 +08:00
值班表新前端
This commit is contained in:
83
FrontEnd/renderTable.js
Normal file
83
FrontEnd/renderTable.js
Normal file
@@ -0,0 +1,83 @@
|
||||
document.getElementById('getAssignment').addEventListener('click', function () {
|
||||
dateInput = document.getElementById('calendar').value;
|
||||
|
||||
if (!dateInput) {
|
||||
dateInput = getToday()
|
||||
}
|
||||
|
||||
const url = `/api/getAssignment?date=${dateInput}`;
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('网络响应失败');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
const responseDiv = document.getElementById('response');
|
||||
responseDiv.innerHTML = ''; // 清除旧内容
|
||||
|
||||
const table = document.createElement('table');
|
||||
|
||||
data.forEach(subArray => {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
subArray.forEach(item => {
|
||||
const cell = document.createElement('td');
|
||||
cell.textContent = item.Name || item.ID;
|
||||
|
||||
// 优先判断 Access 条件
|
||||
if (item.Access < 5) {
|
||||
cell.classList.add('cell_Moderator');
|
||||
} else if (item.Note === 1) {
|
||||
cell.classList.add('cell_SwitchOrRepay');
|
||||
} else if (item.Note === 2) {
|
||||
cell.classList.add('cell_Volunteering');
|
||||
}
|
||||
|
||||
row.appendChild(cell);
|
||||
});
|
||||
|
||||
table.appendChild(row);
|
||||
});
|
||||
const title =`<i><h5 align=center >${dateInput}网维值班表</h5></i>`
|
||||
const titleContainer = document.createElement('div');
|
||||
titleContainer.innerHTML = title
|
||||
responseDiv.appendChild(titleContainer)
|
||||
// 插入表格
|
||||
responseDiv.appendChild(table);
|
||||
|
||||
// 添加图例说明
|
||||
const legendHTML = `
|
||||
<i class="table_notes"><span class="ZoneHead"></span>片区负责人<br></i>
|
||||
<i class="table_notes"><span class="Moderator"></span>管理层<br></i>
|
||||
<i class="table_notes"><span class="SwitchOrRepay"></span>换班/补班<br></i>
|
||||
<i class="table_notes"><span class="Volunteering"></span>蹭班<br></i>
|
||||
`;
|
||||
const legendContainer = document.createElement('div');
|
||||
legendContainer.innerHTML = legendHTML;
|
||||
responseDiv.appendChild(legendContainer);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('请求失败:', error);
|
||||
document.getElementById('response').innerHTML = '获取任务失败,请重试。';
|
||||
});
|
||||
});
|
||||
|
||||
function getToday() {
|
||||
const today = new Date();
|
||||
|
||||
const year = today.getFullYear();
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1
|
||||
const day = String(today.getDate()).padStart(2, '0');
|
||||
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
128
FrontEnd/testAssignment.html
Normal file
128
FrontEnd/testAssignment.html
Normal file
@@ -0,0 +1,128 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>值班表生成</title>
|
||||
<style>body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
/* display: flex;*/
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
background-color: #fff;
|
||||
padding: 30px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input[type="date"] {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
#response {
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background-color: #e9ecef;
|
||||
border-radius: 4px;
|
||||
text-align: left;
|
||||
}</style>
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin:auto
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid black;
|
||||
padding: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
td:first-child, th:first-child {
|
||||
background-color: #b3d9f7;
|
||||
font-weight: bold;
|
||||
}
|
||||
td:nth-child(2), th:nth-child(2) {
|
||||
background-color: #55ffaa
|
||||
}
|
||||
.ZoneHead {
|
||||
display: inline-block; /* 让颜色块和文字在同一行显示 */
|
||||
width: 1em; /* 设置颜色块的宽度为1个字的宽度 */
|
||||
height: 1em; /* 设置颜色块的高度为1个字的高度 */
|
||||
background-color: #55ffaa; /* 设置颜色块的背景颜色 */
|
||||
vertical-align: middle; /* 让颜色块垂直居中 */
|
||||
align-self: left;
|
||||
}
|
||||
.Moderator {
|
||||
display: inline-block; /* 让颜色块和文字在同一行显示 */
|
||||
width: 1em; /* 设置颜色块的宽度为1个字的宽度 */
|
||||
height: 1em; /* 设置颜色块的高度为1个字的高度 */
|
||||
background-color: #ffa0c9; /* 设置颜色块的背景颜色 */
|
||||
vertical-align: middle; /* 让颜色块垂直居中 */
|
||||
}
|
||||
.SwitchOrRepay{
|
||||
display: inline-block; /* 让颜色块和文字在同一行显示 */
|
||||
width: 1em; /* 设置颜色块的宽度为1个字的宽度 */
|
||||
height: 1em; /* 设置颜色块的高度为1个字的高度 */
|
||||
background-color: #fff6b5; /* 设置颜色块的背景颜色 */
|
||||
vertical-align: middle; /* 让颜色块垂直居中 */
|
||||
}
|
||||
.Volunteering{
|
||||
display: inline-block; /* 让颜色块和文字在同一行显示 */
|
||||
width: 1em; /* 设置颜色块的宽度为1个字的宽度 */
|
||||
height: 1em; /* 设置颜色块的高度为1个字的高度 */
|
||||
background-color: #c0ff85; /* 设置颜色块的背景颜色 */
|
||||
vertical-align: middle; /* 让颜色块垂直居中 */
|
||||
}
|
||||
.cell_ZoneHead {
|
||||
background-color: #55ffaa; /* 设置颜色块的背景颜色 */
|
||||
}
|
||||
.cell_Moderator {
|
||||
background-color: #ffa0c9 !important; /* 设置颜色块的背景颜色 */
|
||||
}
|
||||
.cell_SwitchOrRepay{
|
||||
background-color: #fff6b5; /* 设置颜色块的背景颜色 */
|
||||
}
|
||||
.cell_Volunteering{
|
||||
background-color: #c0ff85; /* 设置颜色块的背景颜色 */
|
||||
}
|
||||
.table_notes{
|
||||
align-items:left
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>选择日期</h1>
|
||||
<i>如果不选择的日期的话,则自动获取今天的值班表</i><br></br>
|
||||
<input type="date" id="calendar">
|
||||
<button id="getAssignment">获取值班表</button>
|
||||
<div id="response"></div>
|
||||
</div>
|
||||
|
||||
<script src="renderTable.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user