index.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>文件管理系统</title>
  7. <script>
  8. // Fetch categories from the backend
  9. async function fetchCategories() {
  10. const response = await fetch('/categories'); // Backend endpoint to get categories
  11. const categories = await response.json();
  12. const categoryList = document.getElementById('category-list');
  13. // Populate the left-side list with categories
  14. categoryList.innerHTML = '';
  15. categories.forEach(category => {
  16. const listItem = document.createElement('li');
  17. listItem.textContent = category.name;
  18. listItem.onclick = () => fetchTableData(category.table_name);
  19. categoryList.appendChild(listItem);
  20. });
  21. }
  22. // Fetch table data when a category is clicked
  23. async function fetchTableData(tableName) {
  24. const response = await fetch(`/table-data?table=${tableName}`); // Backend endpoint for table data
  25. const tableData = await response.json();
  26. const tableBody = document.getElementById('table-body');
  27. // Populate the right-side table with data
  28. tableBody.innerHTML = '';
  29. tableData.forEach(row => {
  30. const tableRow = document.createElement('tr');
  31. Object.values(row).forEach(value => {
  32. const cell = document.createElement('td');
  33. cell.textContent = value;
  34. tableRow.appendChild(cell);
  35. });
  36. tableBody.appendChild(tableRow);
  37. });
  38. }
  39. // Initial load
  40. document.addEventListener('DOMContentLoaded', fetchCategories);
  41. </script>
  42. <style>
  43. body {
  44. font-family: Arial, sans-serif;
  45. margin: 0;
  46. display: flex;
  47. }
  48. #sidebar {
  49. width: 20%;
  50. background-color: #f8f9fa;
  51. padding: 1em;
  52. border-right: 1px solid #ddd;
  53. }
  54. #content {
  55. flex-grow: 1;
  56. padding: 1em;
  57. }
  58. ul {
  59. list-style: none;
  60. padding: 0;
  61. }
  62. li {
  63. padding: 0.5em;
  64. cursor: pointer;
  65. border: 1px solid #ddd;
  66. margin-bottom: 0.5em;
  67. border-radius: 4px;
  68. text-align: center;
  69. }
  70. li:hover {
  71. background-color: #e9ecef;
  72. }
  73. table {
  74. width: 100%;
  75. border-collapse: collapse;
  76. }
  77. table, th, td {
  78. border: 1px solid #ddd;
  79. }
  80. th, td {
  81. padding: 0.5em;
  82. text-align: left;
  83. }
  84. th {
  85. background-color: #f1f1f1;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div id="sidebar">
  91. <h2>分类</h2>
  92. <ul id="category-list">
  93. <!-- Categories will be dynamically loaded here -->
  94. </ul>
  95. </div>
  96. <div id="content">
  97. <h2>数据</h2>
  98. <table>
  99. <thead>
  100. <tr>
  101. <th>ID</th>
  102. <th>名称</th>
  103. <th>URL</th>
  104. </tr>
  105. </thead>
  106. <tbody id="table-body">
  107. <!-- Table data will be dynamically loaded here -->
  108. </tbody>
  109. </table>
  110. </div>
  111. </body>
  112. </html>