| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>知识点学习情况分析</title>
- <!-- 引入Chart.js -->
- <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- body {
- font-family: 'Microsoft YaHei', Arial, sans-serif;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- min-height: 100vh;
- padding: 20px;
- }
- .container {
- max-width: 1400px;
- margin: 0 auto;
- background: white;
- border-radius: 15px;
- box-shadow: 0 20px 40px rgba(0,0,0,0.1);
- overflow: hidden;
- }
- header {
- background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
- color: white;
- padding: 20px;
- text-align: center;
- }
- h1 {
- font-size: 28px;
- margin-bottom: 10px;
- }
- .subtitle {
- font-size: 16px;
- opacity: 0.9;
- }
- .content {
- display: flex;
- //height : 950px;
- //height: calc(100vh - 120px);
- }
- #chartContainer {
- flex: 1;
- padding: 30px;
- border-right: 1px solid #eee;
- }
- #listContainer {
- flex: 1;
- padding: 30px;
- display: flex;
- flex-direction: column;
- }
- .chart-title {
- font-size: 20px;
- color: #333;
- margin-bottom: 20px;
- text-align: center;
- }
- .list-title {
- font-size: 20px;
- color: #333;
- margin-bottom: 20px;
- text-align: center;
- }
- /* 修复柱形图容器,避免变形 */
- .chart-wrapper {
- position: relative;
- width: 100%;
- height: 400px;
- }
- canvas {
- width: 100% !important;
- height: 100% !important;
- max-width: 100%;
- }
- table {
- width: 100%;
- border-collapse: collapse;
- box-shadow: 0 5px 15px rgba(0,0,0,0.08);
- border-radius: 10px;
- overflow: hidden;
- }
- th {
- background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
- color: white;
- text-align: left;
- padding: 15px;
- font-weight: 600;
- font-size: 14px;
- text-transform: uppercase;
- letter-spacing: 0.5px;
- }
- td {
- padding: 12px 15px;
- border-bottom: 1px solid #eee;
- color: #555;
- }
- tr:hover {
- background-color: #f8f9ff;
- transform: translateY(-1px);
- transition: all 0.3s ease;
- }
- tbody tr:last-child td {
- border-bottom: none;
- }
- .no-data {
- text-align: center;
- padding: 40px;
- color: #999;
- font-style: italic;
- }
- .chartjs-tooltip {
- background: rgba(0, 0, 0, 0.8) !important;
- border: none !important;
- border-radius: 8px !important;
- padding: 10px !important;
- color: white !important;
- font-size: 14px !important;
- }
- .selected-knowledge {
- background: #f0f8ff;
- padding: 15px;
- border-radius: 10px;
- margin-bottom: 20px;
- text-align: center;
- font-weight: 600;
- color: #4facfe;
- border: 2px dashed #4facfe;
- }
- /* 分页样式 */
- .pagination {
- display: flex;
- justify-content: center;
- margin-top: 20px;
- gap: 5px;
- }
- .pagination button {
- background: white;
- border: 1px solid #ddd;
- color: #333;
- padding: 8px 12px;
- cursor: pointer;
- border-radius: 4px;
- font-size: 14px;
- transition: all 0.3s ease;
- }
- .pagination button:hover {
- background: #f0f0f0;
- border-color: #999;
- }
- .pagination button.active {
- background: #4facfe;
- color: white;
- border-color: #4facfe;
- }
- .pagination button:disabled {
- background: #f5f5f5;
- color: #ccc;
- cursor: not-allowed;
- }
- .pagination-info {
- text-align: center;
- margin-top: 10px;
- color: #666;
- font-size: 14px;
- }
- @media (max-width: 768px) {
- .content {
- flex-direction: column;
- }
- #chartContainer {
- border-right: none;
- border-bottom: 1px solid #eee;
- }
- #listContainer {
- height: 400px;
- }
- .pagination button {
- padding: 6px 10px;
- font-size: 12px;
- }
- }
- </style>
- </head>
- <body>
- <div class="container">
- <header>
- <h1>知识点学习情况分析</h1>
- <div class="subtitle">实时监控学员学习进度与参与情况</div>
- </header>
- <div class="content">
- <!-- 左侧柱形图 -->
- <div id="chartContainer">
- <div class="chart-title">各知识点学习人数统计</div>
- <div class="chart-wrapper">
- <canvas id="myChart"></canvas>
- </div>
- </div>
- <!-- 右侧列表 -->
- <div id="listContainer">
- <div class="list-title">学习人员名单</div>
- <div id="selectedKnowledge" class="selected-knowledge">
- 请选择左侧知识点查看学习人员
- </div>
- <div style="flex: 1; overflow-y: auto;">
- <table id="studentTable">
- <thead>
- <tr>
- <th>专业</th>
- <th>班级</th>
- <th>学号</th>
- <th>姓名</th>
- </tr>
- </thead>
- <tbody id="studentList">
- <tr><td colspan="4" class="no-data">暂无数据</td></tr>
- </tbody>
- </table>
- </div>
- <!-- 分页控件 -->
- <div class="pagination-container">
- <div class="pagination" id="pagination">
- <!-- 分页按钮将通过JavaScript动态生成 -->
- </div>
- <div class="pagination-info" id="paginationInfo">
- <!-- 分页信息将通过JavaScript动态生成 -->
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- // 示例数据
- const knowledgeData = {
- labels: ["电传操纵系统", "飞行控制律", "传感器技术", "故障诊断", "人机交互"],
- datasets: [{
- label: '学习人数',
- data: [32, 25, 41, 18, 29],
- backgroundColor: [
- 'rgba(255, 99, 132, 0.8)',
- 'rgba(54, 162, 235, 0.8)',
- 'rgba(255, 206, 86, 0.8)',
- 'rgba(75, 192, 192, 0.8)',
- 'rgba(153, 102, 255, 0.8)'
- ],
- borderColor: [
- 'rgba(255, 99, 132, 1)',
- 'rgba(54, 162, 235, 1)',
- 'rgba(255, 206, 86, 1)',
- 'rgba(75, 192, 192, 1)',
- 'rgba(153, 102, 255, 1)'
- ],
- borderWidth: 2,
- borderRadius: 8,
- borderSkipped: false
- }]
- };
- // 学员数据
- const studentData = [
- // 电传操纵系统
- [
- { major: "航空航天工程", class: "飞控1班", studentId: "2023001", name: "张三" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023002", name: "李四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023003", name: "王五" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023004", name: "赵六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023005", name: "钱七" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023006", name: "孙八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023007", name: "周九" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023008", name: "吴十" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023009", name: "郑一" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023010", name: "王二" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023011", name: "冯三" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023012", name: "陈四" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023013", name: "褚五" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023014", name: "卫六" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023015", name: "蒋七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023016", name: "沈八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023017", name: "韩九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023018", name: "杨十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023019", name: "朱一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023020", name: "秦二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023021", name: "尤三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023022", name: "许四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023023", name: "何五" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023024", name: "吕六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023025", name: "施七" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023026", name: "张八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023027", name: "孔九" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023028", name: "曹十" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023029", name: "严一" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023030", name: "华二" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023031", name: "金三" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023032", name: "魏四" }
- ],
- // 飞行控制律
- [
- { major: "航空航天工程", class: "飞控1班", studentId: "2023033", name: "郑一" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023034", name: "王二" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023035", name: "冯三" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023036", name: "陈四" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023037", name: "褚五" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023038", name: "卫六" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023039", name: "蒋七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023040", name: "沈八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023041", name: "韩九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023042", name: "杨十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023043", name: "朱一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023044", name: "秦二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023045", name: "尤三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023046", name: "许四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023047", name: "何五" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023048", name: "吕六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023049", name: "施七" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023050", name: "张八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023051", name: "孔九" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023052", name: "曹十" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023053", name: "严一" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023054", name: "华二" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023055", name: "金三" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023056", name: "魏四" }
- ],
- // 传感器技术
- [
- { major: "航空航天工程", class: "飞控1班", studentId: "2023057", name: "蒋七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023058", name: "沈八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023059", name: "韩九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023060", name: "杨十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023061", name: "朱一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023062", name: "秦二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023063", name: "尤三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023064", name: "许四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023065", name: "何五" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023066", name: "吕六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023067", name: "施七" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023068", name: "张八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023069", name: "孔九" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023070", name: "曹十" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023071", name: "严一" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023072", name: "华二" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023073", name: "金三" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023074", name: "魏四" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023075", name: "张三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023076", name: "李四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023077", name: "王五" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023078", name: "赵六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023079", name: "钱七" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023080", name: "孙八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023081", name: "周九" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023082", name: "吴十" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023083", name: "郑一" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023084", name: "王二" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023085", name: "冯三" }
- ],
- // 故障诊断
- [
- { major: "航空航天工程", class: "飞控2班", studentId: "2023086", name: "尤三" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023087", name: "许四" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023088", name: "何五" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023089", name: "吕六" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023090", name: "施七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023091", name: "张八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023092", name: "孔九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023093", name: "曹十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023094", name: "严一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023095", name: "华二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023096", name: "金三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023097", name: "魏四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023098", name: "张三" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023099", name: "李四" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023100", name: "王五" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023101", name: "赵六" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023102", name: "钱七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023103", name: "孙八" }
- ],
- // 人机交互
- [
- { major: "航空航天工程", class: "飞控1班", studentId: "2023104", name: "施七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023105", name: "张八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023106", name: "孔九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023107", name: "曹十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023108", name: "严一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023109", name: "华二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023110", name: "金三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023111", name: "魏四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023112", name: "张三" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023113", name: "李四" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023114", name: "王五" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023115", name: "赵六" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023116", name: "钱七" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023117", name: "孙八" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023118", name: "周九" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023119", name: "吴十" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023120", name: "郑一" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023121", name: "王二" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023122", name: "冯三" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023123", name: "陈四" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023124", name: "褚五" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023125", name: "卫六" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023126", name: "蒋七" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023127", name: "沈八" },
- { major: "航空航天工程", class: "飞控1班", studentId: "2023128", name: "韩九" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023129", name: "杨十" },
- { major: "航空航天工程", class: "飞控2班", studentId: "2023130", name: "朱一" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023131", name: "秦二" },
- { major: "航空航天工程", class: "飞控3班", studentId: "2023132", name: "尤三" }
- ]
- ];
- // 每页显示的项目数量
- const ITEMS_PER_PAGE = 10;
- // 当前分页信息
- let currentPage = 1;
- let totalPages = 1;
- let currentDataIndex = 0;
- // 创建柱形图
- const ctx = document.getElementById('myChart').getContext('2d');
- const myChart = new Chart(ctx, {
- type: 'bar',
- data: knowledgeData,
- options: {
- responsive: true,
- maintainAspectRatio: false,
- plugins: {
- legend: {
- display: false
- },
- tooltip: {
- backgroundColor: 'rgba(0, 0, 0, 0.8)',
- titleColor: 'white',
- bodyColor: 'white',
- borderColor: 'rgba(255, 255, 255, 0.3)',
- borderWidth: 1,
- cornerRadius: 8,
- displayColors: false,
- callbacks: {
- label: function(context) {
- return `学习人数: ${context.parsed.y}人`;
- }
- }
- }
- },
- scales: {
- y: {
- beginAtZero: true,
- ticks: {
- stepSize: 5,
- color: '#666',
- font: {
- size: 12,
- family: 'Microsoft YaHei, Arial, sans-serif'
- }
- },
- grid: {
- color: 'rgba(0, 0, 0, 0.1)'
- }
- },
- x: {
- ticks: {
- color: '#666',
- font: {
- size: 12,
- family: 'Microsoft YaHei, Arial, sans-serif'
- },
- maxRotation: 45,
- minRotation: 45
- },
- grid: {
- display: false
- }
- }
- },
- onClick: (event, elements) => {
- if (elements.length > 0) {
- const index = elements[0].index;
- currentDataIndex = index;
- currentPage = 1; // 重置为第一页
- updateStudentList(index, 1);
- // 更新选中知识点显示
- document.getElementById('selectedKnowledge').innerHTML =
- `<strong>当前查看:</strong> ${knowledgeData.labels[index]}
- <span style="color: #666; font-weight: normal;">(${knowledgeData.datasets[0].data[index]}人学习)</span>`;
- }
- },
- interaction: {
- intersect: false,
- mode: 'index'
- }
- }
- });
- // 更新右侧列表(带分页)
- function updateStudentList(index, page = 1) {
- const listContainer = document.getElementById('studentList');
- const students = studentData[index];
- const paginationContainer = document.getElementById('pagination');
- const paginationInfo = document.getElementById('paginationInfo');
- if (students && students.length > 0) {
- // 计算分页
- totalPages = Math.ceil(students.length / ITEMS_PER_PAGE);
- currentPage = page;
- // 计算当前页的数据
- const startIndex = (page - 1) * ITEMS_PER_PAGE;
- const endIndex = Math.min(startIndex + ITEMS_PER_PAGE, students.length);
- const currentPageData = students.slice(startIndex, endIndex);
- // 清空列表并添加当前页数据
- listContainer.innerHTML = '';
- currentPageData.forEach(student => {
- const tr = document.createElement('tr');
- tr.innerHTML = `
- <td>${student.major}</td>
- <td>${student.class}</td>
- <td>${student.studentId}</td>
- <td>${student.name}</td>
- `;
- listContainer.appendChild(tr);
- });
- // 更新分页信息
- paginationInfo.textContent = `共 ${students.length} 条记录,第 ${page} 页,共 ${totalPages} 页`;
- // 生成分页按钮
- generatePaginationButtons();
- } else {
- listContainer.innerHTML = '<tr><td colspan="4" class="no-data">暂无学习人员</td></tr>';
- paginationContainer.innerHTML = '';
- paginationInfo.textContent = '';
- }
- }
- // 生成分页按钮
- function generatePaginationButtons() {
- const paginationContainer = document.getElementById('pagination');
- paginationContainer.innerHTML = '';
- // 上一页按钮
- const prevButton = document.createElement('button');
- prevButton.innerHTML = '«';
- prevButton.disabled = currentPage === 1;
- prevButton.addEventListener('click', () => {
- if (currentPage > 1) {
- updateStudentList(currentDataIndex, currentPage - 1);
- }
- });
- paginationContainer.appendChild(prevButton);
- // 页码按钮(最多显示5个页码)
- const maxVisiblePages = 5;
- let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
- let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
- // 如果接近末尾,调整起始页
- if (endPage - startPage + 1 < maxVisiblePages) {
- startPage = Math.max(1, endPage - maxVisiblePages + 1);
- }
- for (let i = startPage; i <= endPage; i++) {
- const pageButton = document.createElement('button');
- pageButton.textContent = i;
- pageButton.classList.toggle('active', i === currentPage);
- pageButton.addEventListener('click', () => {
- updateStudentList(currentDataIndex, i);
- });
- paginationContainer.appendChild(pageButton);
- }
- // 下一页按钮
- const nextButton = document.createElement('button');
- nextButton.innerHTML = '»';
- nextButton.disabled = currentPage === totalPages;
- nextButton.addEventListener('click', () => {
- if (currentPage < totalPages) {
- updateStudentList(currentDataIndex, currentPage + 1);
- }
- });
- paginationContainer.appendChild(nextButton);
- }
- // 页面加载完成后,默认显示第一个知识点的人员列表
- window.addEventListener('load', function() {
- // 等待Chart.js完全渲染完成
- setTimeout(() => {
- // 默认选择第一个知识点
- const firstIndex = 0;
- currentDataIndex = firstIndex;
- currentPage = 1;
- updateStudentList(firstIndex, 1);
- // 更新选中知识点显示
- document.getElementById('selectedKnowledge').innerHTML =
- `<strong>当前查看:</strong> ${knowledgeData.labels[firstIndex]}
- <span style="color: #666; font-weight: normal;">(${knowledgeData.datasets[0].data[firstIndex]}人学习)</span>`;
- }, 100);
- });
- </script>
- </body>
- </html>
|