| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>文件管理系统</title>
- <script>
- // Fetch categories from the backend
- async function fetchCategories() {
- const response = await fetch('/categories'); // Backend endpoint to get categories
- const categories = await response.json();
- const categoryList = document.getElementById('category-list');
- // Populate the left-side list with categories
- categoryList.innerHTML = '';
- categories.forEach(category => {
- const listItem = document.createElement('li');
- listItem.textContent = category.name;
- listItem.onclick = () => fetchTableData(category.table_name);
- categoryList.appendChild(listItem);
- });
- }
- // Fetch table data when a category is clicked
- async function fetchTableData(tableName) {
- const response = await fetch(`/table-data?table=${tableName}`); // Backend endpoint for table data
- const tableData = await response.json();
- const tableBody = document.getElementById('table-body');
- // Populate the right-side table with data
- tableBody.innerHTML = '';
- tableData.forEach(row => {
- const tableRow = document.createElement('tr');
- Object.values(row).forEach(value => {
- const cell = document.createElement('td');
- cell.textContent = value;
- tableRow.appendChild(cell);
- });
- tableBody.appendChild(tableRow);
- });
- }
- // Initial load
- document.addEventListener('DOMContentLoaded', fetchCategories);
- </script>
- <style>
- body {
- font-family: Arial, sans-serif;
- margin: 0;
- display: flex;
- }
- #sidebar {
- width: 20%;
- background-color: #f8f9fa;
- padding: 1em;
- border-right: 1px solid #ddd;
- }
- #content {
- flex-grow: 1;
- padding: 1em;
- }
- ul {
- list-style: none;
- padding: 0;
- }
- li {
- padding: 0.5em;
- cursor: pointer;
- border: 1px solid #ddd;
- margin-bottom: 0.5em;
- border-radius: 4px;
- text-align: center;
- }
- li:hover {
- background-color: #e9ecef;
- }
- table {
- width: 100%;
- border-collapse: collapse;
- }
- table, th, td {
- border: 1px solid #ddd;
- }
- th, td {
- padding: 0.5em;
- text-align: left;
- }
- th {
- background-color: #f1f1f1;
- }
- </style>
- </head>
- <body>
- <div id="sidebar">
- <h2>分类</h2>
- <ul id="category-list">
- <!-- Categories will be dynamically loaded here -->
- </ul>
- </div>
- <div id="content">
- <h2>数据</h2>
- <table>
- <thead>
- <tr>
- <th>ID</th>
- <th>名称</th>
- <th>URL</th>
- </tr>
- </thead>
- <tbody id="table-body">
- <!-- Table data will be dynamically loaded here -->
- </tbody>
- </table>
- </div>
- </body>
- </html>
|