123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>系统设置 - 后台管理系统</title>
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
- <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
- <style>
- .sidebar {
- position: fixed;
- top: 60px;
- bottom: 0;
- left: 0;
- z-index: 100;
- padding: 0;
- box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
- background-color: #f8f9fa;
- }
- .sidebar-sticky {
- position: relative;
- top: 0;
- height: calc(100vh - 60px);
- padding-top: .5rem;
- overflow-x: hidden;
- overflow-y: auto;
- }
- .navbar {
- box-shadow: 0 2px 4px rgba(0,0,0,.1);
- height: 60px;
- }
- .main-content {
- margin-left: 240px;
- padding: 20px;
- margin-top: 60px;
- }
- .nav-link {
- color: #333;
- padding: 10px 20px;
- }
- .nav-link:hover {
- background-color: #e9ecef;
- }
- .nav-link.active {
- color: #0d6efd;
- background-color: #e9ecef;
- }
- .card {
- margin-bottom: 20px;
- box-shadow: 0 0 10px rgba(0,0,0,0.1);
- }
- </style>
- </head>
- <body>
- <nav class="navbar navbar-expand-lg navbar-light bg-white fixed-top">
- <div class="container-fluid">
- <a class="navbar-brand" href="#">后台管理系统</a>
- <div class="d-flex">
- <button class="btn btn-outline-danger" id="logoutBtn">退出登录</button>
- </div>
- </div>
- </nav>
- <div class="container-fluid">
- <div class="row">
- <nav class="col-md-3 col-lg-2 d-md-block sidebar">
- <div class="sidebar-sticky">
- <ul class="nav flex-column">
- <li class="nav-item">
- <a class="nav-link" href="/admin/views/dashboard.html" data-page="dashboard">
- <i class="bi bi-speedometer2"></i> 仪表板
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="/admin/views/groups.html" data-page="groups">
- <i class="bi bi-people"></i> 群组管理
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="/admin/views/transactions.html" data-page="transactions">
- <i class="bi bi-cash-stack"></i> 交易记录
- </a>
- </li>
- <!-- <li class="nav-item">
- <a class="nav-link" href="/admin/views/statistics.html" data-page="statistics">
- <i class="bi bi-graph-up"></i> 统计报表
- </a>
- </li> -->
- <li class="nav-item">
- <a class="nav-link active" href="/admin/views/settings.html" data-page="settings">
- <i class="bi bi-gear"></i> 系统设置
- </a>
- </li>
- </ul>
- </div>
- </nav>
- <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
- <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
- <h1 class="h2">系统设置</h1>
- </div>
- <div class="row">
- <div class="col-md-6">
- <div class="card">
- <div class="card-body">
- <h5 class="card-title">基本设置</h5>
- <form id="basicSettingsForm">
- <div class="mb-3">
- <label for="siteName" class="form-label">站点名称</label>
- <input type="text" class="form-control" id="siteName">
- </div>
- <div class="mb-3">
- <label for="adminEmail" class="form-label">管理员邮箱</label>
- <input type="email" class="form-control" id="adminEmail">
- </div>
- <div class="mb-3">
- <label for="adminTG" class="form-label">商务对接链接</label>
- <input type="text" class="form-control" id="adminTG">
- </div>
- <button type="submit" class="btn btn-primary">保存设置</button>
- </form>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="card">
- <div class="card-body">
- <h5 class="card-title">安全设置</h5>
- <form id="securitySettingsForm">
- <div class="mb-3">
- <label for="currentPassword" class="form-label">当前密码</label>
- <input type="password" class="form-control" id="currentPassword">
- </div>
- <div class="mb-3">
- <label for="newPassword" class="form-label">新密码</label>
- <input type="password" class="form-control" id="newPassword">
- </div>
- <div class="mb-3">
- <label for="confirmPassword" class="form-label">确认新密码</label>
- <input type="password" class="form-control" id="confirmPassword">
- </div>
- <button type="submit" class="btn btn-primary">修改密码</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </main>
- </div>
- </div>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
- <script>
- // 检查登录状态
- function checkAuth() {
- const token = localStorage.getItem('token');
- console.log('检查登录状态,token:', token ? '存在' : '不存在');
-
- if (!token) {
- console.log('未找到token,跳转到登录页');
- window.location.href = '/admin/views/login.html';
- return;
- }
- // 验证token是否有效
- fetch('/api/users/profile', {
- headers: {
- 'Authorization': `Bearer ${token}`
- }
- })
- .then(response => {
- if (!response.ok) {
- throw new Error('Token无效');
- }
- return response.json();
- })
- .then(data => {
- console.log('用户信息:', data);
- // 可以在这里保存用户信息到全局变量
- window.currentUser = data;
- })
- .catch(error => {
- console.error('验证token时出错:', error);
- localStorage.removeItem('token');
- window.location.href = '/admin/views/login.html';
- });
- }
- // 加载设置
- async function loadSettings() {
- try {
- const token = localStorage.getItem('token');
- const response = await fetch('/api/settings', {
- headers: {
- 'Authorization': `Bearer ${token}`
- }
- });
- if (response.ok) {
- const settings = await response.json();
- document.getElementById('siteName').value = settings.site_name;
- document.getElementById('adminEmail').value = settings.admin_email;
- document.getElementById('adminTG').value = settings.admin_tg;
- } else if (response.status === 401) {
- window.location.href = '/';
- }
- } catch (error) {
- console.error('加载设置失败:', error);
- }
- }
- // 保存基本设置
- document.getElementById('basicSettingsForm').addEventListener('submit', async (e) => {
- e.preventDefault();
- try {
- const token = localStorage.getItem('token');
- const response = await fetch('/api/settings', {
- method: 'PUT',
- headers: {
- 'Authorization': `Bearer ${token}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- siteName: document.getElementById('siteName').value,
- adminEmail: document.getElementById('adminEmail').value,
- adminTG: document.getElementById('adminTG').value
- })
- });
- if (response.ok) {
- alert('设置已保存');
- } else {
- const data = await response.json();
- alert(data.message || '保存设置失败');
- }
- } catch (error) {
- console.error('保存设置失败:', error);
- alert('保存设置失败,请稍后重试');
- }
- });
- // 修改密码
- document.getElementById('securitySettingsForm').addEventListener('submit', async (e) => {
- e.preventDefault();
- const newPassword = document.getElementById('newPassword').value;
- const confirmPassword = document.getElementById('confirmPassword').value;
- if (newPassword !== confirmPassword) {
- alert('两次输入的密码不一致');
- return;
- }
- try {
- const token = localStorage.getItem('token');
- const response = await fetch('/api/settings/password', {
- method: 'PUT',
- headers: {
- 'Authorization': `Bearer ${token}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- currentPassword: document.getElementById('currentPassword').value,
- newPassword: newPassword
- })
- });
- if (response.ok) {
- alert('密码修改成功');
- document.getElementById('securitySettingsForm').reset();
- } else {
- const data = await response.json();
- alert(data.message || '修改密码失败');
- }
- } catch (error) {
- console.error('修改密码失败:', error);
- alert('修改密码失败,请稍后重试');
- }
- });
- // 退出登录
- document.getElementById('logoutBtn').addEventListener('click', () => {
- localStorage.removeItem('token');
- window.location.href = '/';
- });
- // 页面加载时检查登录状态并加载数据
- checkAuth();
- loadSettings();
- </script>
- </body>
- </html>
|