<!DOCTYPE html>标签:console,log,tableContainer,制作,let,2.22,row,data,页面 From: https://www.cnblogs.com/dmx-03/p/18040275
<html lang="en">
<head>
<meta charset="UTF-8">
<title>浏览审批卡</title>
<style>
.reSet {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.form table tr td {
width: 100px;
height: 30px;
border: 1px solid #000;
text-align: center;
}
button {
display: block;
margin-top: 10px;
padding: 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<h1 style="text-align: center">浏览审批卡信息</h1>
<div class="centered-form">
<div class="bordered-form">
<div class="form">
<div id="container">
</div>
</div>
</div>
</div>
</body>
<script>
var urlParams = new URLSearchParams(window.location.search);
var username = urlParams.get('username');
console.log("用户名为:" + username);
const requestUrl = `http://localhost:8080/president/getCollege/${username}`;
fetch(requestUrl,
{
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
})
.then(response => response.json())
.then(data => {
if (data.msg === 'success') {
console.log(data.data.college);
getAll(data.data.college);
} else {
alert("找不到所对应的学院");
}
})
.catch(error => {
alert("请求失败,请重试");
console.error(error);
});
</script>
<script>
function getAll(pro) {
console.log("pro " + pro);
const requestUrl = `http://localhost:8080/president/getTest/${pro}`;
fetch(requestUrl,
{
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
})
.then(response => response.json())
.then(data => {
if (data.msg === 'success') {
console.log("555");
generateTable(data.data);
} else {
alert("当前不存在结果");
}
})
.catch(error => {
alert("请求失败2,请重试");
console.error(error);
});
}
</script>
<script>
function generateTable(data) {
const tableContainer = document.getElementById("container");
// 清空 tableContainer 中的所有子节点
while (tableContainer.hasChildNodes()) {
tableContainer.removeChild(tableContainer.firstChild);
}
const table = document.createElement("table");
const tableBody = document.createElement("tbody");
let row = document.createElement("tr");
row.innerHTML = '<td>试卷审批卡编号</td><td>申请日期</td><td>课程名称</td><td>任课教师</td><td>课程编号</td><td>课程性质</td><td>学分</td><td>授课班级</td><td>授课专业</td><td>考试方式</td><td>考试日期</td><td>考试人数</td><td>出题方式</td><td>成绩组成</td><td>考核与评价方式</td><td>考核内容合理性分析</td><td>专业审查意见</td><td>专业审查结论</td><td>合理性审查意见</td><td>合理性审查结果</td><td>审核状态</td>';
tableBody.appendChild(row);
// 查询方式是按姓名查询或多条查询
for (let i = 0; i < data.length; i++) {
let s;
if (data[i].auditStatus === 0) {
s = "待审核";
} else if (data[i].auditStatus === -1) {
s = "未通过";
} else if (data[i].auditStatus === 1) {
s = "已符合";
} else if (data[i].auditStatus === 2) {
s = "已通过";
}
row = document.createElement("tr");
let p1 = data[i].professional;
let p2 = data[i].professionalConclusion;
if (data[i].professional === null) {
p1 = "未进行";
p2 = "未进行";
}
let r1 = data[i].reasonable;
let r2 = data[i].reasonableConclusion;
if (data[i].reasonable === undefined || data[i].reasonable === null) {
r1 = "未进行";
r2 = "未进行";
}
console.log("9 " + data[i].auditStatus);
console.log(s);
row.innerHTML = `<td>${data[i].cardId}</td><td>${data[i].cardDate}</td><td>${data[i].courseName}</td><td>${data[i].courseTeacher}</td><td>${data[i].courseID}</td><td>${data[i].courseNature}</td><td>${data[i].credit}</td><td>${data[i].courseClass}</td><td>${data[i].courseMajor}</td><td>${data[i].testWay}</td><td>${data[i].testDate}</td><td>${data[i].testCount}</td><td>${data[i].testMethod}</td><td>${data[i].testGrade}</td><td>${data[i].testEvaluation}</td><td>${data[i].testAnalysis}</td><td>${p1}</td><td>${p2}</td><td>${r1}</td><td>${r2}</td><td>${s}</td>`;
tableBody.appendChild(row);
table.appendChild(tableBody);
tableContainer.appendChild(table);
}
}
</script>
</html>