settings.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>系统设置 - 后台管理系统</title>
  7. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  8. <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
  9. <style>
  10. .sidebar {
  11. position: fixed;
  12. top: 0;
  13. bottom: 0;
  14. left: 0;
  15. z-index: 100;
  16. padding: 48px 0 0;
  17. box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
  18. background-color: #f8f9fa;
  19. }
  20. .sidebar-sticky {
  21. position: relative;
  22. top: 0;
  23. height: calc(100vh - 48px);
  24. padding-top: .5rem;
  25. overflow-x: hidden;
  26. overflow-y: auto;
  27. }
  28. .navbar {
  29. box-shadow: 0 2px 4px rgba(0,0,0,.1);
  30. }
  31. .main-content {
  32. margin-left: 240px;
  33. padding: 20px;
  34. }
  35. .nav-link {
  36. color: #333;
  37. padding: 10px 20px;
  38. }
  39. .nav-link:hover {
  40. background-color: #e9ecef;
  41. }
  42. .nav-link.active {
  43. color: #0d6efd;
  44. background-color: #e9ecef;
  45. }
  46. .card {
  47. margin-bottom: 20px;
  48. box-shadow: 0 0 10px rgba(0,0,0,0.1);
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <nav class="navbar navbar-expand-lg navbar-light bg-white fixed-top">
  54. <div class="container-fluid">
  55. <a class="navbar-brand" href="#">后台管理系统</a>
  56. <div class="d-flex">
  57. <button class="btn btn-outline-danger" id="logoutBtn">退出登录</button>
  58. </div>
  59. </div>
  60. </nav>
  61. <div class="container-fluid">
  62. <div class="row">
  63. <nav class="col-md-3 col-lg-2 d-md-block sidebar">
  64. <div class="sidebar-sticky">
  65. <ul class="nav flex-column">
  66. <li class="nav-item">
  67. <a class="nav-link" href="/dashboard.html" data-page="dashboard">
  68. <i class="bi bi-speedometer2"></i> 仪表板
  69. </a>
  70. </li>
  71. <li class="nav-item">
  72. <a class="nav-link" href="/groups.html" data-page="groups">
  73. <i class="bi bi-people"></i> 群组管理
  74. </a>
  75. </li>
  76. <li class="nav-item">
  77. <a class="nav-link" href="/transactions.html" data-page="transactions">
  78. <i class="bi bi-cash-stack"></i> 交易记录
  79. </a>
  80. </li>
  81. <li class="nav-item">
  82. <a class="nav-link" href="/statistics.html" data-page="statistics">
  83. <i class="bi bi-graph-up"></i> 统计报表
  84. </a>
  85. </li>
  86. <li class="nav-item">
  87. <a class="nav-link active" href="/settings.html" data-page="settings">
  88. <i class="bi bi-gear"></i> 系统设置
  89. </a>
  90. </li>
  91. </ul>
  92. </div>
  93. </nav>
  94. <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
  95. <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  96. <h1 class="h2">系统设置</h1>
  97. </div>
  98. <div class="row">
  99. <div class="col-md-6">
  100. <div class="card">
  101. <div class="card-body">
  102. <h5 class="card-title">基本设置</h5>
  103. <form id="basicSettingsForm">
  104. <div class="mb-3">
  105. <label for="siteName" class="form-label">站点名称</label>
  106. <input type="text" class="form-control" id="siteName">
  107. </div>
  108. <div class="mb-3">
  109. <label for="adminEmail" class="form-label">管理员邮箱</label>
  110. <input type="email" class="form-control" id="adminEmail">
  111. </div>
  112. <button type="submit" class="btn btn-primary">保存设置</button>
  113. </form>
  114. </div>
  115. </div>
  116. </div>
  117. <div class="col-md-6">
  118. <div class="card">
  119. <div class="card-body">
  120. <h5 class="card-title">安全设置</h5>
  121. <form id="securitySettingsForm">
  122. <div class="mb-3">
  123. <label for="currentPassword" class="form-label">当前密码</label>
  124. <input type="password" class="form-control" id="currentPassword">
  125. </div>
  126. <div class="mb-3">
  127. <label for="newPassword" class="form-label">新密码</label>
  128. <input type="password" class="form-control" id="newPassword">
  129. </div>
  130. <div class="mb-3">
  131. <label for="confirmPassword" class="form-label">确认新密码</label>
  132. <input type="password" class="form-control" id="confirmPassword">
  133. </div>
  134. <button type="submit" class="btn btn-primary">修改密码</button>
  135. </form>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </main>
  141. </div>
  142. </div>
  143. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
  144. <script>
  145. // 检查登录状态
  146. function checkAuth() {
  147. const token = localStorage.getItem('token');
  148. if (!token) {
  149. window.location.href = '/';
  150. }
  151. }
  152. // 加载设置
  153. async function loadSettings() {
  154. try {
  155. const token = localStorage.getItem('token');
  156. const response = await fetch('/admin/api/settings', {
  157. headers: {
  158. 'Authorization': `Bearer ${token}`
  159. }
  160. });
  161. if (response.ok) {
  162. const settings = await response.json();
  163. document.getElementById('siteName').value = settings.siteName;
  164. document.getElementById('adminEmail').value = settings.adminEmail;
  165. } else if (response.status === 401) {
  166. window.location.href = '/';
  167. }
  168. } catch (error) {
  169. console.error('加载设置失败:', error);
  170. }
  171. }
  172. // 保存基本设置
  173. document.getElementById('basicSettingsForm').addEventListener('submit', async (e) => {
  174. e.preventDefault();
  175. try {
  176. const token = localStorage.getItem('token');
  177. const response = await fetch('/admin/api/settings', {
  178. method: 'PUT',
  179. headers: {
  180. 'Authorization': `Bearer ${token}`,
  181. 'Content-Type': 'application/json'
  182. },
  183. body: JSON.stringify({
  184. siteName: document.getElementById('siteName').value,
  185. adminEmail: document.getElementById('adminEmail').value
  186. })
  187. });
  188. if (response.ok) {
  189. alert('设置已保存');
  190. } else {
  191. const data = await response.json();
  192. alert(data.message || '保存设置失败');
  193. }
  194. } catch (error) {
  195. console.error('保存设置失败:', error);
  196. alert('保存设置失败,请稍后重试');
  197. }
  198. });
  199. // 修改密码
  200. document.getElementById('securitySettingsForm').addEventListener('submit', async (e) => {
  201. e.preventDefault();
  202. const newPassword = document.getElementById('newPassword').value;
  203. const confirmPassword = document.getElementById('confirmPassword').value;
  204. if (newPassword !== confirmPassword) {
  205. alert('两次输入的密码不一致');
  206. return;
  207. }
  208. try {
  209. const token = localStorage.getItem('token');
  210. const response = await fetch('/admin/api/settings/password', {
  211. method: 'PUT',
  212. headers: {
  213. 'Authorization': `Bearer ${token}`,
  214. 'Content-Type': 'application/json'
  215. },
  216. body: JSON.stringify({
  217. currentPassword: document.getElementById('currentPassword').value,
  218. newPassword: newPassword
  219. })
  220. });
  221. if (response.ok) {
  222. alert('密码修改成功');
  223. document.getElementById('securitySettingsForm').reset();
  224. } else {
  225. const data = await response.json();
  226. alert(data.message || '修改密码失败');
  227. }
  228. } catch (error) {
  229. console.error('修改密码失败:', error);
  230. alert('修改密码失败,请稍后重试');
  231. }
  232. });
  233. // 退出登录
  234. document.getElementById('logoutBtn').addEventListener('click', () => {
  235. localStorage.removeItem('token');
  236. window.location.href = '/';
  237. });
  238. // 页面加载时检查登录状态并加载数据
  239. checkAuth();
  240. loadSettings();
  241. </script>
  242. </body>
  243. </html>