上传文件至「templates/admin」

This commit is contained in:
admin committed 2026-04-28 10:46:08 +00:00
1 parent d4926b4fdd
commit c636cc60d9
5 files changed
+244

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>管理后台 - Modern Navigator</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body { margin: 0; font-family: sans-serif; background: #f4f7f6; display: flex; }
.sidebar { width: 250px; height: 100vh; background: #2c3e50; color: white; padding-top: 20px; position: fixed; }
.sidebar a { display: block; padding: 15px 25px; color: #bdc3c7; text-decoration: none; transition: 0.3s; }
.sidebar a:hover, .sidebar a.active { background: #34495e; color: white; }
.main-content { margin-left: 250px; padding: 40px; width: 100%; }
.admin-card { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-bottom: 20px; }
.btn { padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; font-weight: bold; }
.btn-primary { background: #3498db; color: white; }
.btn-danger { background: #e74c3c; color: white; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #eee; }
.badge { padding: 4px 8px; border-radius: 4px; font-size: 12px; }
.badge-enabled { background: #2ecc71; color: white; }
.badge-disabled { background: #95a5a6; color: white; }
.badge-construction { background: #f1c40f; color: black; }
.badge-offline { background: #e74c3c; color: white; }
input, select, textarea { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 6px; box-sizing: border-box; }
</style>
</head>
<body>
<div class="sidebar">
<h2 style="text-align: center; margin-bottom: 30px;">Admin Panel</h2>
<a href="{{ url_for('admin_dashboard') }}"><i class="fas fa-home"></i> 仪表盘</a>
<a href="{{ url_for('admin_items') }}"><i class="fas fa-list"></i> 条目管理</a>
<a href="{{ url_for('admin_users') }}"><i class="fas fa-users"></i> 用户管理</a>
<a href="{{ url_for('admin_settings') }}"><i class="fas fa-cog"></i> 全局配置</a>
<a href="{{ url_for('index') }}" target="_blank"><i class="fas fa-external-link-alt"></i> 查看前台</a>
<a href="{{ url_for('logout') }}" style="margin-top: 50px; color: #e74c3c;"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
</div>
<div class="main-content">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div style="padding: 15px; margin-bottom: 20px; border-radius: 8px; background: {% if category=='success' %}#d4edda{% else %}#f8d7da{% endif %}; color: {% if category=='success' %}#155724{% else %}#721c24{% endif %};">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
{% block content %}{% endblock %}
</div>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
{% extends 'admin/base.html' %}
{% block content %}
<h1>系统概览</h1>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;">
<div class="admin-card">
<h3>导航条目</h3>
<p style="font-size: 2rem; font-weight: bold;">{{ item_count }}</p>
</div>
<div class="admin-card">
<h3>管理员人数</h3>
<p style="font-size: 2rem; font-weight: bold;">{{ user_count }}</p>
</div>
<div class="admin-card">
<h3>系统状态</h3>
<p style="font-size: 2rem; font-weight: bold; color: #2ecc71;">运行中</p>
</div>
</div>
{% endblock %}
+120
View File
@@ -0,0 +1,120 @@
{% extends 'admin/base.html' %}
{% block content %}
<div style="display: flex; justify-content: space-between; align-items: center;">
<h1>条目管理</h1>
<button class="btn btn-primary" onclick="document.getElementById('add-modal').style.display='block'">新增条目</button>
</div>
<!-- 新增条目弹窗 -->
<div id="add-modal" class="admin-card" style="display:none; margin-top: 20px;">
<h3>添加新导航</h3>
<form action="{{ url_for('admin_items') }}" method="POST" enctype="multipart/form-data">
<input type="text" name="title" placeholder="网站名称" required>
<input type="text" name="url" placeholder="跳转链接 (URL)">
<textarea name="description" placeholder="网站描述"></textarea>
<!-- 图片上传字段 -->
<div style="display: flex; gap: 10px; margin-top: 10px;">
<div style="flex: 1;">
<label for="file_large">大图上传:</label><br>
<input type="file" name="file_large" id="file_large" accept="image/*">
<input type="text" name="image_large" placeholder="或输入大图 URL">
</div>
<div style="flex: 1;">
<label for="file_thumb">缩略图上传:</label><br>
<input type="file" name="file_thumb" id="file_thumb" accept="image/*">
<input type="text" name="image_thumb" placeholder="或输入缩略图 URL">
</div>
</div>
<select name="status" style="margin-top: 10px;">
{% for s in status_enum %}
<option value="{{ s.value }}">{{ s.name }}</option>
{% endfor %}
</select>
<input type="number" name="sort_weight" value="0" placeholder="排序权重 (越大越靠前)">
<button type="submit" class="btn btn-primary">提交保存</button>
<button type="button" class="btn" onclick="document.getElementById('add-modal').style.display='none'">取消</button>
</form>
</div>
<!-- 条目列表 -->
<div class="admin-card">
<table>
<thead>
<tr>
<th>权重</th>
<th>标题</th>
<th>状态</th>
<th>预览图</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>{{ item.sort_weight }}</td>
<td>{{ item.title }}</td>
<td><span class="badge badge-{{ item.status.value }}">{{ item.status.value }}</span></td>
<td><img src="{{ item.image_thumb }}" style="height: 30px; border-radius: 4px;"></td>
<td>
<button class="btn btn-primary" style="font-size: 12px; text-decoration: none; margin-right: 5px;"
onclick="openEditModal('{{ item.id }}', '{{ item.title }}', '{{ item.url or '' }}', '{{ item.description or '' }}', '{{ item.image_large or '' }}', '{{ item.image_thumb or '' }}', '{{ item.status.value }}', '{{ item.sort_weight }}')">编辑</button>
<a href="{{ url_for('delete_item', id=item.id) }}" class="btn btn-danger" style="font-size: 12px; text-decoration: none;" onclick="return confirm('确定删除吗?')">删除</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- 编辑条目弹窗 -->
<div id="edit-modal" class="admin-card" style="display:none; margin-top: 20px; position: fixed; top: 10%; left: 50%; transform: translateX(-50%); z-index: 1000; width: 90%; max-width: 600px;">
<h3>编辑导航条目</h3>
<form id="edit-form" action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" id="edit-id">
<input type="text" name="title" id="edit-title" placeholder="网站名称" required>
<input type="text" name="url" id="edit-url" placeholder="跳转链接 (URL)">
<textarea name="description" id="edit-description" placeholder="网站描述"></textarea>
<!-- 图片上传字段 -->
<div style="display: flex; gap: 10px; margin-top: 10px;">
<div style="flex: 1;">
<label for="edit_file_large">大图上传:</label><br>
<input type="file" name="file_large" id="edit_file_large" accept="image/*">
<input type="text" name="image_large" id="edit-image_large" placeholder="或输入大图 URL">
</div>
<div style="flex: 1;">
<label for="edit_file_thumb">缩略图上传:</label><br>
<input type="file" name="file_thumb" id="edit-file_thumb" accept="image/*">
<input type="text" name="image_thumb" id="edit-image_thumb" placeholder="或输入缩略图 URL">
</div>
</div>
<select name="status" id="edit-status" style="margin-top: 10px;">
{% for s in status_enum %}
<option value="{{ s.value }}">{{ s.name }}</option>
{% endfor %}
</select>
<input type="number" name="sort_weight" id="edit-sort_weight" placeholder="排序权重 (越大越靠前)">
<button type="submit" class="btn btn-primary">更新条目</button>
<button type="button" class="btn" onclick="document.getElementById('edit-modal').style.display='none'">取消</button>
</form>
</div>
<script>
function openEditModal(id, title, url, description, image_large, image_thumb, status, sort_weight) {
document.getElementById('edit-form').action = '/admin/items/edit/' + id;
document.getElementById('edit-id').value = id;
document.getElementById('edit-title').value = title;
document.getElementById('edit-url').value = url;
document.getElementById('edit-description').value = description;
// 注意:此处不设置 file input 的值,因为文件是无法通过 JS 设置的,用户需要手动选择
document.getElementById('edit-image_large').value = image_large;
document.getElementById('edit-image_thumb').value = image_thumb;
document.getElementById('edit-status').value = status;
document.getElementById('edit-sort_weight').value = sort_weight;
document.getElementById('edit-modal').style.display = 'block';
}
</script>
{% endblock %}
+20
View File
@@ -0,0 +1,20 @@
{% extends 'admin/base.html' %}
{% block content %}
<h1>全局配置</h1>
<div class="admin-card">
<form method="POST">
<h3>前台启动弹窗</h3>
<div style="margin-bottom: 20px;">
<label>
<input type="checkbox" name="is_enabled" style="width: auto;" {% if setting and setting.is_enabled %}checked{% endif %}> 启用启动弹窗
</label>
</div>
<h3>弹窗内容 (支持 HTML)</h3>
<textarea name="config_value" style="height: 200px;">{{ setting.config_value if setting else '' }}</textarea>
<button type="submit" class="btn btn-primary">保存全局设置</button>
</form>
</div>
{% endblock %}
+36
View File
@@ -0,0 +1,36 @@
{% extends 'admin/base.html' %}
{% block content %}
<h1>用户管理</h1>
<div class="admin-card">
<h3>新增管理员</h3>
<form method="POST">
<div style="display: flex; gap: 10px;">
<input type="text" name="username" placeholder="用户名" required>
<input type="password" name="password" placeholder="密码" required>
<button type="submit" class="btn btn-primary" style="margin-top: 10px;">创建用户</button>
</div>
</form>
</div>
<div class="admin-card">
<table>
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>创建时间</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.id }}</td>
<td>{{ user.username }}</td>
<td>{{ user.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}