初始提交: LiteAdmin 社区平台

This commit is contained in:
张志挺
2026-08-07 14:18:18 +08:00
commit f39008193f
37 changed files with 5447 additions and 0 deletions
+545
View File
@@ -0,0 +1,545 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}LiteAdmin 管理后台{% endblock %}</title>
<style>
:root {
--primary: #2563eb;
--primary-dark: #1d4ed8;
--primary-light: #dbeafe;
--sidebar-bg: #1e293b;
--sidebar-text: #94a3b8;
--sidebar-active: #2563eb;
--bg: #f1f5f9;
--card-bg: #ffffff;
--text: #1e293b;
--text-light: #64748b;
--border: #e2e8f0;
--success: #22c55e;
--warning: #f59e0b;
--danger: #ef4444;
--info: #3b82f6;
--radius: 8px;
--shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
--shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 10px 15px rgba(0,0,0,0.1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
color: var(--text);
background: var(--bg);
display: flex;
min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
/* 侧边栏 */
.sidebar {
width: 240px;
background: var(--sidebar-bg);
color: var(--sidebar-text);
display: flex;
flex-direction: column;
flex-shrink: 0;
position: fixed;
top: 0;
left: 0;
height: 100vh;
z-index: 100;
overflow-y: auto;
}
.sidebar-header {
padding: 20px;
border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-header h1 {
font-size: 18px;
color: #fff;
font-weight: 600;
}
.sidebar-header .subtitle {
font-size: 12px;
color: var(--sidebar-text);
margin-top: 4px;
}
.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section { margin-bottom: 8px; }
.nav-section-title {
padding: 8px 20px 4px;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: #475569;
font-weight: 600;
}
.nav-item {
display: flex;
align-items: center;
padding: 10px 20px;
color: var(--sidebar-text);
transition: all 0.15s;
cursor: pointer;
border-left: 3px solid transparent;
font-size: 14px;
}
.nav-item:hover {
background: rgba(255,255,255,0.05);
color: #e2e8f0;
text-decoration: none;
}
.nav-item.active {
background: rgba(37,99,235,0.15);
color: #60a5fa;
border-left-color: var(--sidebar-active);
}
.nav-item .icon {
margin-right: 10px;
font-size: 16px;
width: 20px;
text-align: center;
}
.sidebar-footer {
padding: 16px 20px;
border-top: 1px solid rgba(255,255,255,0.06);
font-size: 13px;
}
.sidebar-footer .user-info {
color: #e2e8f0;
margin-bottom: 8px;
}
/* 主区域 */
.main {
margin-left: 240px;
flex: 1;
display: flex;
flex-direction: column;
min-height: 100vh;
}
.topbar {
background: var(--card-bg);
border-bottom: 1px solid var(--border);
padding: 12px 28px;
display: flex;
align-items: center;
justify-content: space-between;
position: sticky;
top: 0;
z-index: 50;
}
.topbar .breadcrumb {
font-size: 14px;
color: var(--text-light);
}
.topbar .breadcrumb a { color: var(--text-light); }
.topbar .breadcrumb span { color: var(--text); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.content {
padding: 24px 28px;
flex: 1;
}
/* 页面标题 */
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24px;
}
.page-header h2 {
font-size: 22px;
font-weight: 600;
color: var(--text);
}
/* 卡片 */
.card {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
border: 1px solid var(--border);
margin-bottom: 20px;
}
.card-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
}
.card-header h3 {
font-size: 16px;
font-weight: 600;
}
.card-body { padding: 20px; }
/* 按钮 */
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 16px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
border: 1px solid var(--border);
background: var(--card-bg);
color: var(--text);
transition: all 0.15s;
text-decoration: none;
line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger:hover { background: #dc2626; }
/* 表单 */
.form-group { margin-bottom: 16px; }
.form-group label {
display: block;
font-size: 13px;
font-weight: 500;
color: var(--text);
margin-bottom: 6px;
}
.form-control {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 6px;
font-size: 14px;
color: var(--text);
background: var(--card-bg);
transition: border-color 0.15s;
outline: none;
font-family: inherit;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 100px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }
/* 表格 */
.table-wrap { overflow-x: auto; }
table {
width: 100%;
border-collapse: collapse;
}
table th, table td {
padding: 10px 14px;
text-align: left;
border-bottom: 1px solid var(--border);
font-size: 14px;
}
table th {
background: #f8fafc;
font-weight: 600;
color: var(--text-light);
font-size: 12px;
text-transform: uppercase;
letter-spacing: 0.3px;
}
table tr:hover td { background: #f8fafc; }
table tr:last-child td { border-bottom: none; }
/* 搜索框 */
.search-box {
display: flex;
gap: 8px;
margin-bottom: 16px;
}
.search-box input { flex: 1; max-width: 320px; }
/* 分页 */
.pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
margin-top: 16px;
}
.pagination a, .pagination span {
padding: 6px 12px;
border: 1px solid var(--border);
border-radius: 4px;
font-size: 13px;
color: var(--text);
text-decoration: none;
}
.pagination a:hover { background: var(--primary-light); border-color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: var(--text-light); cursor: not-allowed; }
/* 标签 / Badge */
.badge {
display: inline-block;
padding: 2px 8px;
border-radius: 10px;
font-size: 12px;
font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fce4ec; color: #c62828; }
.badge-info { background: var(--primary-light); color: var(--primary-dark); }
/* 统计卡片 */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: var(--card-bg);
border-radius: var(--radius);
border: 1px solid var(--border);
padding: 20px;
box-shadow: var(--shadow);
}
.stat-card .stat-label {
font-size: 13px;
color: var(--text-light);
margin-bottom: 8px;
}
.stat-card .stat-value {
font-size: 28px;
font-weight: 700;
color: var(--text);
}
.stat-card .stat-icon {
float: right;
font-size: 32px;
opacity: 0.15;
}
/* Toast 消息 */
.toast-container {
position: fixed;
top: 16px;
right: 16px;
z-index: 9999;
}
.toast {
padding: 12px 20px;
border-radius: 6px;
color: #fff;
font-size: 14px;
margin-bottom: 8px;
box-shadow: var(--shadow-lg);
animation: slideIn 0.25s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: var(--warning); }
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
/* 空状态 */
.empty-state {
text-align: center;
padding: 40px;
color: var(--text-light);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
/* 确认对话框 */
.modal-overlay {
display: none;
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 1000;
align-items: center;
justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
background: var(--card-bg);
border-radius: var(--radius);
padding: 24px;
max-width: 400px;
width: 90%;
box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 12px; }
.modal .actions { margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end; }
/* 文件管理 */
.file-list .file-item {
display: flex;
align-items: center;
padding: 8px 12px;
border-bottom: 1px solid var(--border);
}
.file-list .file-item:last-child { border-bottom: none; }
.file-list .file-item .name { flex: 1; }
.file-list .file-item .size { color: var(--text-light); font-size: 13px; margin-right: 12px; }
.file-list .file-item .date { color: var(--text-light); font-size: 13px; margin-right: 12px; }
/* 日志查看器 */
.log-viewer {
background: #1e293b;
color: #e2e8f0;
border-radius: var(--radius);
padding: 16px;
font-family: "SF Mono", "Fira Code", "Consolas", monospace;
font-size: 13px;
line-height: 1.6;
max-height: 500px;
overflow-y: auto;
}
.log-entry { padding: 2px 0; white-space: pre-wrap; word-break: break-all; }
.log-DEBUG { color: #94a3b8; }
.log-INFO { color: #60a5fa; }
.log-WARNING { color: #fbbf24; }
.log-ERROR { color: #f87171; }
.log-CRITICAL { color: #ef4444; font-weight: bold; }
/* 响应式 */
@media (max-width: 768px) {
.sidebar { width: 60px; }
.sidebar-header h1, .sidebar-header .subtitle,
.nav-item span, .nav-section-title, .sidebar-footer { display: none; }
.main { margin-left: 60px; }
.content { padding: 16px; }
.stats-grid { grid-template-columns: 1fr 1fr; }
}
</style>
</head>
<body>
<!-- 侧边栏 -->
<div class="sidebar">
<div class="sidebar-header">
<h1>LiteAdmin</h1>
<div class="subtitle">管理后台</div>
</div>
<nav class="sidebar-nav">
<div class="nav-section">
<div class="nav-section-title">概览</div>
<a href="/admin/" class="nav-item {% if request.path == '/admin/' %}active{% endif %}">
<span class="icon">&#9751;</span><span>控制台</span>
</a>
</div>
{% if admin_models %}
<div class="nav-section">
<div class="nav-section-title">数据管理</div>
{% for model_name, model_info in admin_models.items() %}
<a href="/admin/{{ model_name }}/" class="nav-item {% if request.path.startswith('/admin/' + model_name) %}active{% endif %}">
<span class="icon">&#9776;</span><span>{{ model_info.verbose_name or model_name }}</span>
</a>
{% endfor %}
</div>
{% endif %}
<div class="nav-section">
<div class="nav-section-title">系统</div>
<a href="/admin/logs/" class="nav-item {% if request.path == '/admin/logs/' %}active{% endif %}">
<span class="icon">&#9881;</span><span>运行日志</span>
</a>
<a href="/admin/files/" class="nav-item {% if request.path == '/admin/files/' %}active{% endif %}">
<span class="icon">&#128193;</span><span>文件管理</span>
</a>
</div>
</nav>
<div class="sidebar-footer">
<div class="user-info">{{ current_user.username }}</div>
<a href="/admin/logout/" style="color: var(--danger); font-size: 13px;">退出登录</a>
</div>
</div>
<!-- 主区域 -->
<div class="main">
<div class="topbar">
<div class="breadcrumb">
{% block breadcrumb %}
<a href="/admin/">控制台</a>
{% endblock %}
</div>
<div class="topbar-right">
<span style="font-size:13px;color:var(--text-light);">{{ current_user.username }}</span>
</div>
</div>
<div class="content">
{% if flash_message %}
<div class="toast-container">
<div class="toast toast-{{ flash_type or 'info' }}">{{ flash_message }}</div>
</div>
{% endif %}
{% block content %}{% endblock %}
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Toast 自动消失
var toasts = document.querySelectorAll('.toast');
toasts.forEach(function(t) {
setTimeout(function() { t.style.opacity = '0'; t.style.transition = 'opacity 0.3s'; }, 3000);
setTimeout(function() { t.remove(); }, 3300);
});
});
</script>
</body>
</html>
+68
View File
@@ -0,0 +1,68 @@
{% extends "admin/base.html" %}
{% block title %}控制台 - LiteAdmin{% endblock %}
{% block breadcrumb %}<span>控制台</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>控制台</h2>
</div>
<div class="stats-grid">
{% for stat in stats %}
<div class="stat-card">
<div class="stat-icon">{{ stat.icon }}</div>
<div class="stat-label">{{ stat.label }}</div>
<div class="stat-value">{{ stat.value }}</div>
</div>
{% endfor %}
</div>
{% if recent_items %}
<div class="card">
<div class="card-header">
<h3>最近更新</h3>
</div>
<div class="card-body">
<div class="table-wrap">
<table>
<thead>
<tr>
<th>模型</th>
<th>ID</th>
<th>标题</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
{% for item in recent_items %}
<tr>
<td><span class="badge badge-info">{{ item.model_verbose }}</span></td>
<td>{{ item.id }}</td>
<td><a href="/admin/{{ item.model_name }}/{{ item.id }}/">{{ item.title }}</a></td>
<td>{{ item.updated_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endif %}
<div class="card">
<div class="card-header">
<h3>系统信息</h3>
</div>
<div class="card-body">
<table>
<tbody>
<tr><td style="width:200px;font-weight:500;">LiteAdmin 版本</td><td>v1.0.0</td></tr>
<tr><td style="font-weight:500;">Python 版本</td><td>{{ system_info.python_version }}</td></tr>
<tr><td style="font-weight:500;">数据库</td><td>SQLite</td></tr>
<tr><td style="font-weight:500;">数据目录</td><td>{{ system_info.db_path }}</td></tr>
<tr><td style="font-weight:500;">上传目录</td><td>{{ system_info.upload_dir }}</td></tr>
<tr><td style="font-weight:500;">运行时间</td><td>{{ system_info.uptime }}</td></tr>
</tbody>
</table>
</div>
</div>
{% endblock %}
+54
View File
@@ -0,0 +1,54 @@
{% extends "admin/base.html" %}
{% block title %}文件管理 - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <span>文件管理</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>文件管理</h2>
<div>
<form method="post" enctype="multipart/form-data" style="display:flex;gap:8px;align-items:center;">
<input type="file" name="file" class="form-control" style="width:auto;" required>
<button type="submit" class="btn btn-primary btn-sm">上传</button>
</form>
</div>
</div>
<div class="card">
<div class="card-header">
<h3>当前目录: {{ current_path or '/' }}</h3>
</div>
<div class="card-body">
{% if files %}
<div class="file-list">
{% if parent_path %}
<div class="file-item">
<span class="icon" style="margin-right:10px;">&#128193;</span>
<span class="name"><a href="/admin/files/?path={{ parent_path }}">..</a></span>
</div>
{% endif %}
{% for file in files %}
<div class="file-item">
<span class="icon" style="margin-right:10px;">{% if file.is_dir %}&#128193;{% else %}&#128196;{% endif %}</span>
<span class="name">
{% if file.is_dir %}
<a href="/admin/files/?path={{ file.path }}">{{ file.name }}</a>
{% else %}
<a href="/admin/files/download/?path={{ file.path }}" target="_blank">{{ file.name }}</a>
{% endif %}
</span>
{% if not file.is_dir %}
<span class="size">{{ file.size }}</span>
{% endif %}
<span class="date">{{ file.modified }}</span>
<a href="/admin/files/delete/?path={{ file.path }}" class="btn btn-sm btn-danger" onclick="return confirm('确定删除 {{ file.name }} 吗?')">删除</a>
</div>
{% endfor %}
</div>
{% else %}
<div class="empty-state">
<div class="icon">&#128193;</div>
<p>此目录为空</p>
</div>
{% endif %}
</div>
</div>
{% endblock %}
+145
View File
@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录 - LiteAdmin</title>
<style>
:root {
--primary: #2563eb;
--primary-dark: #1d4ed8;
--bg: #f1f5f9;
--card-bg: #ffffff;
--text: #1e293b;
--text-light: #64748b;
--border: #e2e8f0;
--radius: 8px;
--shadow: 0 4px 6px rgba(0,0,0,0.07), 0 10px 15px rgba(0,0,0,0.1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
color: var(--text);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-wrapper {
width: 100%;
max-width: 400px;
padding: 20px;
}
.login-card {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 40px;
}
.login-card h1 {
font-size: 24px;
text-align: center;
margin-bottom: 8px;
color: var(--text);
}
.login-card .subtitle {
text-align: center;
color: var(--text-light);
margin-bottom: 28px;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
font-size: 13px;
font-weight: 500;
margin-bottom: 6px;
color: var(--text);
}
.form-control {
width: 100%;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 6px;
font-size: 14px;
color: var(--text);
outline: none;
transition: border-color 0.15s;
font-family: inherit;
}
.form-control:focus {
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.btn {
width: 100%;
padding: 10px 16px;
border: none;
border-radius: 6px;
font-size: 15px;
font-weight: 500;
cursor: pointer;
background: var(--primary);
color: #fff;
transition: background 0.15s;
}
.btn:hover { background: var(--primary-dark); }
.error-msg {
background: #fce4ec;
color: #c62828;
padding: 10px 14px;
border-radius: 6px;
margin-bottom: 16px;
font-size: 13px;
text-align: center;
}
.copyright {
text-align: center;
margin-top: 20px;
color: rgba(255,255,255,0.6);
font-size: 13px;
}
</style>
</head>
<body>
<div class="login-wrapper">
<div class="login-card">
<h1>LiteAdmin</h1>
<div class="subtitle">管理后台登录</div>
{% if error %}
<div class="error-msg">{{ error }}</div>
{% endif %}
<form method="post" action="/admin/login/">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required>
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required>
</div>
<button type="submit" class="btn">登 录</button>
</form>
</div>
<div class="copyright">LiteAdmin v1.0 &copy; 2026</div>
</div>
</body>
</html>
+65
View File
@@ -0,0 +1,65 @@
{% extends "admin/base.html" %}
{% block title %}运行日志 - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <span>运行日志</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>运行日志</h2>
<div>
<form method="get" style="display:flex;gap:8px;align-items:center;">
<select name="level" class="form-control" style="width:auto;" onchange="this.form.submit()">
<option value="">全部级别</option>
<option value="DEBUG" {% if level == 'DEBUG' %}selected{% endif %}>DEBUG</option>
<option value="INFO" {% if level == 'INFO' %}selected{% endif %}>INFO</option>
<option value="WARNING" {% if level == 'WARNING' %}selected{% endif %}>WARNING</option>
<option value="ERROR" {% if level == 'ERROR' %}selected{% endif %}>ERROR</option>
<option value="CRITICAL" {% if level == 'CRITICAL' %}selected{% endif %}>CRITICAL</option>
</select>
<input type="text" name="search" class="form-control" style="width:200px;" placeholder="搜索日志..." value="{{ search or '' }}">
<button type="submit" class="btn btn-primary btn-sm">筛选</button>
<a href="/admin/logs/" class="btn btn-sm">重置</a>
</form>
</div>
</div>
<div class="card">
<div class="card-header">
<h3>日志列表</h3>
<span style="font-size:13px;color:var(--text-light);">自动刷新中</span>
</div>
<div class="card-body">
<div class="log-viewer" id="logViewer">
{% if logs %}
{% for log in logs %}
<div class="log-entry log-{{ log.level }}">[{{ log.time }}] [{{ log.level }}] [{{ log.module }}] {{ log.message }}</div>
{% endfor %}
{% else %}
<div class="log-entry" style="color:#94a3b8;">暂无日志记录</div>
{% endif %}
</div>
</div>
</div>
<script>
function refreshLogs() {
var level = document.querySelector('select[name="level"]').value || '';
var search = document.querySelector('input[name="search"]').value || '';
var url = '/admin/api/logs/?level=' + encodeURIComponent(level) + '&search=' + encodeURIComponent(search);
fetch(url)
.then(function(r) { return r.json(); })
.then(function(data) {
var viewer = document.getElementById('logViewer');
var html = '';
data.logs.forEach(function(log) {
html += '<div class="log-entry log-' + log.level + '">[' + log.time + '] [' + log.level + '] [' + log.module + '] ' + log.message + '</div>';
});
if (!html) {
html = '<div class="log-entry" style="color:#94a3b8;">暂无日志记录</div>';
}
viewer.innerHTML = html;
viewer.scrollTop = viewer.scrollHeight;
});
}
setInterval(refreshLogs, 3000);
</script>
{% endblock %}
+46
View File
@@ -0,0 +1,46 @@
{% extends "admin/base.html" %}
{% block title %}{{ verbose_name }}详情 - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <a href="/admin/{{ model_name }}/">{{ verbose_name }}管理</a> / <span>详情 #{{ obj.id }}</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>{{ verbose_name }} #{{ obj.id }}</h2>
<div>
{% if can_edit %}
<a href="/admin/{{ model_name }}/{{ obj.id }}/edit/" class="btn btn-primary">编辑</a>
{% endif %}
<a href="/admin/{{ model_name }}/" class="btn">返回列表</a>
</div>
</div>
<div class="card">
<div class="card-header">
<h3>基本信息</h3>
</div>
<div class="card-body">
<table>
<tbody>
{% for field in detail_fields %}
<tr>
<td style="width:200px;font-weight:500;padding:10px 14px;border-bottom:1px solid var(--border);">{{ field.verbose_name or field.name }}</td>
<td style="padding:10px 14px;border-bottom:1px solid var(--border);">{{ field.render(obj) }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% if can_delete %}
<div class="card" style="border-color: var(--danger);">
<div class="card-header" style="color: var(--danger);">
<h3>危险操作</h3>
</div>
<div class="card-body">
<p style="margin-bottom:12px;color:var(--text-light);">删除后将无法恢复,请谨慎操作。</p>
<form method="post" action="/admin/{{ model_name }}/{{ obj.id }}/delete/" onsubmit="return confirm('确定要删除这个{{ verbose_name }}吗?');">
<button type="submit" class="btn btn-danger">删除此{{ verbose_name }}</button>
</form>
</div>
</div>
{% endif %}
{% endblock %}
+47
View File
@@ -0,0 +1,47 @@
{% extends "admin/base.html" %}
{% block title %}{{ title }} - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <a href="/admin/{{ model_name }}/">{{ verbose_name }}管理</a> / <span>{{ title }}</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>{{ title }}</h2>
<div>
<a href="/admin/{{ model_name }}/" class="btn">返回列表</a>
</div>
</div>
<div class="card">
<div class="card-body">
<form method="post" {% if has_file %}enctype="multipart/form-data"{% endif %}>
{% for field in fields %}
<div class="form-group">
<label for="{{ field.name }}">{{ field.verbose_name or field.name }}</label>
{% if field.type == 'textarea' %}
<textarea id="{{ field.name }}" name="{{ field.name }}" class="form-control" {% if field.required %}required{% endif %}>{{ field.value or '' }}</textarea>
{% elif field.type == 'select' %}
<select id="{{ field.name }}" name="{{ field.name }}" class="form-control">
{% for opt in field.options %}
<option value="{{ opt.value }}" {% if field.value == opt.value %}selected{% endif %}>{{ opt.label }}</option>
{% endfor %}
</select>
{% elif field.type == 'file' %}
<input type="file" id="{{ field.name }}" name="{{ field.name }}" class="form-control">
{% if field.value %}<div class="form-hint">当前文件: {{ field.value }}</div>{% endif %}
{% elif field.type == 'boolean' %}
<select id="{{ field.name }}" name="{{ field.name }}" class="form-control">
<option value="1" {% if field.value %}selected{% endif %}>是</option>
<option value="0" {% if not field.value %}selected{% endif %}>否</option>
</select>
{% else %}
<input type="{{ field.input_type or 'text' }}" id="{{ field.name }}" name="{{ field.name }}" class="form-control" value="{{ field.value or '' }}" {% if field.required %}required{% endif %}>
{% endif %}
{% if field.hint %}<div class="form-hint">{{ field.hint }}</div>{% endif %}
</div>
{% endfor %}
<div style="margin-top:24px;display:flex;gap:8px;">
<button type="submit" class="btn btn-primary">保存</button>
<a href="/admin/{{ model_name }}/" class="btn">取消</a>
</div>
</form>
</div>
</div>
{% endblock %}
+102
View File
@@ -0,0 +1,102 @@
{% extends "admin/base.html" %}
{% block title %}{{ verbose_name }} - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <span>{{ verbose_name }}</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>{{ verbose_name }}</h2>
<div>
{% if can_add %}
<a href="/admin/{{ model_name }}/add/" class="btn btn-primary">+ 新增</a>
{% endif %}
{% if can_import %}
<a href="/admin/user/import/" class="btn">&#128229; 批量导入</a>
{% endif %}
</div>
</div>
<div class="card">
{% if search_fields %}
<div class="card-body" style="padding-bottom: 0;">
<form method="get" class="search-box">
<input type="text" name="q" class="form-control" placeholder="搜索..." value="{{ search_query or '' }}">
<button type="submit" class="btn btn-primary">搜索</button>
{% if search_query %}<a href="/admin/{{ model_name }}/" class="btn">清除</a>{% endif %}
</form>
</div>
{% endif %}
<div class="card-body">
{% if items %}
<div class="table-wrap">
<table>
<thead>
<tr>
{% for field in list_fields %}
<th>{{ field.verbose_name or field.name }}</th>
{% endfor %}
<th style="width:120px;">操作</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
{% for field in list_fields %}
<td>
{% if loop.first %}
<a href="/admin/{{ model_name }}/{{ item.id }}/">{{ field.render(item) }}</a>
{% else %}
{{ field.render(item) }}
{% endif %}
</td>
{% endfor %}
<td>
<a href="/admin/{{ model_name }}/{{ item.id }}/" class="btn btn-sm">查看</a>
{% if can_edit %}
<a href="/admin/{{ model_name }}/{{ item.id }}/edit/" class="btn btn-sm">编辑</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if pagination.total_pages > 1 %}
<div class="pagination">
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}{% if search_query %}&q={{ search_query }}{% endif %}">&laquo; 上一页</a>
{% else %}
<span class="disabled">&laquo; 上一页</span>
{% endif %}
{% for p in range(1, pagination.total_pages + 1) %}
{% if p == pagination.page %}
<span class="active">{{ p }}</span>
{% elif p <= 5 or p > pagination.total_pages - 2 or (p >= pagination.page - 2 and p <= pagination.page + 2) %}
<a href="?page={{ p }}{% if search_query %}&q={{ search_query }}{% endif %}">{{ p }}</a>
{% elif loop.index == 6 or p == pagination.total_pages - 2 %}
<span>...</span>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}{% if search_query %}&q={{ search_query }}{% endif %}">下一页 &raquo;</a>
{% else %}
<span class="disabled">下一页 &raquo;</span>
{% endif %}
</div>
<div style="text-align:center;margin-top:8px;font-size:13px;color:var(--text-light);">
共 {{ pagination.total }} 条,第 {{ pagination.page }}/{{ pagination.total_pages }} 页
</div>
{% endif %}
{% else %}
<div class="empty-state">
<div class="icon">&#128196;</div>
<p>暂无 {{ verbose_name }} 数据</p>
{% if can_add %}
<a href="/admin/{{ model_name }}/add/" class="btn btn-primary" style="margin-top:12px;">新增{{ verbose_name }}</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
{% endblock %}
+56
View File
@@ -0,0 +1,56 @@
{% extends "admin/base.html" %}
{% block title %}批量导入用户 - LiteAdmin{% endblock %}
{% block breadcrumb %}<a href="/admin/">控制台</a> / <a href="/admin/user/">用户管理</a> / <span>批量导入</span>{% endblock %}
{% block content %}
<div class="page-header">
<h2>批量导入用户</h2>
</div>
<div class="card">
<div class="card-body">
{% if message %}
<div class="alert alert-success">{{ message }}</div>
{% endif %}
{% if error %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label>上传 Excel 或 CSV 文件</label>
<input type="file" name="file" accept=".xlsx,.xls,.csv" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">导入</button>
<a href="/admin/user/" class="btn">返回用户列表</a>
</form>
</div>
</div>
<div class="card">
<div class="card-header">文件格式说明</div>
<div class="card-body">
<p>支持 <code>.xlsx</code>、<code>.xls</code> 和 <code>.csv</code> 格式。</p>
<p>第一行必须为列标题,支持以下列:</p>
<table>
<thead>
<tr>
<th>列名</th>
<th>必填</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr><td>username</td><td>是</td><td>用户名(唯一)</td></tr>
<tr><td>password</td><td>是</td><td>登录密码</td></tr>
<tr><td>email</td><td>否</td><td>邮箱地址</td></tr>
<tr><td>role</td><td>否</td><td>角色:admin / editor / viewer(默认 viewer)</td></tr>
<tr><td>level</td><td>否</td><td>等级:lv0~lv5(默认 lv1)</td></tr>
</tbody>
</table>
<p style="margin-top:12px;">示例 CSV:</p>
<pre><code>username,password,email,role,level
张三,abc123,zhangsan@test.com,viewer,lv1
李四,def456,lisi@test.com,viewer,lv2</code></pre>
</div>
</div>
{% endblock %}
+16
View File
@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}{{ announcement.title }} - 公告{% endblock %}
{% block content %}
<div class="page-title">
<h1>{{ announcement.title }}</h1>
<p>发布于 {{ announcement.created_at.strftime('%Y-%m-%d %H:%M') }}</p>
</div>
<div class="card">
<div class="card-body">
<div class="prose">{{ content_html }}</div>
</div>
</div>
<a href="/announcements/" class="btn">&larr; 返回公告列表</a>
{% endblock %}
+53
View File
@@ -0,0 +1,53 @@
{% extends "base.html" %}
{% block title %}公告 - 社区平台{% endblock %}
{% block content %}
<div class="page-title">
<h1>公告</h1>
<p>平台最新通知与动态</p>
</div>
<div class="card">
<div class="card-body" style="padding:12px 20px;">
{% if announcements %}
{% for item in announcements %}
<div class="list-item">
<div class="main-info">
<a href="/announcements/{{ item.id }}/" class="title">
{% if item.is_pinned %}<span class="badge badge-warning">置顶</span> {% endif %}
{{ item.title }}
</a>
<div class="meta">
<span>{{ item.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
<span>发布者 #{{ item.created_by }}</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无公告</p></div>
{% endif %}
</div>
</div>
{% if pagination.total_pages > 1 %}
<div class="pagination">
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}">&laquo; 上一页</a>
{% else %}
<span class="disabled">&laquo; 上一页</span>
{% endif %}
{% for p in range(1, pagination.total_pages + 1) %}
{% if p == pagination.page %}
<span class="active">{{ p }}</span>
{% else %}
<a href="?page={{ p }}">{{ p }}</a>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}">下一页 &raquo;</a>
{% else %}
<span class="disabled">下一页 &raquo;</span>
{% endif %}
</div>
{% endif %}
{% endblock %}
+334
View File
@@ -0,0 +1,334 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}社区平台{% endblock %}</title>
<style>
:root {
--primary: #2563eb;
--primary-dark: #1d4ed8;
--primary-light: #dbeafe;
--bg: #f8fafc;
--card-bg: #ffffff;
--text: #1e293b;
--text-light: #64748b;
--border: #e2e8f0;
--success: #22c55e;
--warning: #f59e0b;
--danger: #ef4444;
--radius: 8px;
--shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
--header-bg: #1e293b;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
color: var(--text);
background: var(--bg);
min-height: 100vh;
display: flex;
flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
/* 顶部导航 */
.header {
background: var(--header-bg);
color: #fff;
position: sticky;
top: 0;
z-index: 100;
}
.header-inner {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
display: flex;
align-items: center;
height: 56px;
}
.header .logo {
font-size: 18px;
font-weight: 700;
color: #fff;
margin-right: 32px;
}
.header .logo:hover { text-decoration: none; }
.header nav { display: flex; gap: 4px; flex: 1; }
.header nav a {
color: #94a3b8;
padding: 8px 14px;
border-radius: 6px;
font-size: 14px;
transition: all 0.15s;
}
.header nav a:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }
.header nav a.active { color: #fff; background: var(--primary); }
.header .search-box { position: relative; margin: 0 8px; }
.header .search-box input {
background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
color: #fff; padding: 6px 12px 6px 32px; border-radius: 20px; font-size: 13px;
width: 180px; outline: none; transition: all 0.2s; font-family: inherit;
}
.header .search-box input:focus { background: rgba(255,255,255,0.15); border-color: var(--primary); width: 220px; }
.header .search-box input::placeholder { color: #64748b; }
.header .search-icon {
position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
color: #64748b; font-size: 14px; pointer-events: none;
}
.header .user-area { display: flex; align-items: center; gap: 12px; }
.header .user-area a { color: #94a3b8; font-size: 14px; }
.header .user-area a:hover { color: #fff; }
.header .user-area .username { color: #e2e8f0; font-size: 13px; }
/* 主内容 */
.main { flex: 1; }
.page-content { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }
/* 页面标题 */
.page-title { margin-bottom: 24px; }
.page-title h1 { font-size: 24px; font-weight: 700; }
.page-title p { color: var(--text-light); margin-top: 6px; font-size: 14px; }
/* 卡片 */
.card {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
border: 1px solid var(--border);
margin-bottom: 16px;
}
.card-header {
padding: 14px 20px;
border-bottom: 1px solid var(--border);
font-weight: 600;
font-size: 15px;
display: flex;
align-items: center;
justify-content: space-between;
}
.card-body { padding: 20px; }
/* 按钮 */
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 16px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
border: 1px solid var(--border);
background: var(--card-bg);
color: var(--text);
transition: all 0.15s;
text-decoration: none;
line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
/* 表单 */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-control {
width: 100%; padding: 8px 12px; border: 1px solid var(--border);
border-radius: 6px; font-size: 14px; color: var(--text);
background: var(--card-bg); outline: none; transition: border-color 0.15s;
font-family: inherit;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
textarea.form-control { min-height: 120px; resize: vertical; }
select.form-control { cursor: pointer; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
/* 列表项 */
.list-item {
display: flex;
padding: 14px 0;
border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .main-info { flex: 1; }
.list-item .title { font-size: 15px; font-weight: 500; }
.list-item .meta { font-size: 13px; color: var(--text-light); margin-top: 6px; display: flex; gap: 16px; flex-wrap: wrap; }
.list-item .side-info { text-align: right; color: var(--text-light); font-size: 13px; white-space: nowrap; }
.badge {
display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 500;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #0369a1; }
/* 公告横幅 */
.announcement-banner {
background: linear-gradient(135deg, #1e40af, #3b82f6);
color: #fff;
border-radius: var(--radius);
padding: 16px 20px;
margin-bottom: 16px;
}
.announcement-banner a { color: #bfdbfe; }
.announcement-banner .item { padding: 6px 0; display: flex; gap: 8px; }
.announcement-banner .item .tag { flex-shrink: 0; }
/* 标签 */
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tag {
display: inline-block; padding: 4px 10px; border-radius: 4px;
font-size: 12px; background: #f1f5f9; color: var(--text-light); cursor: pointer;
}
.tag:hover { background: var(--primary-light); color: var(--primary); }
.tag.active { background: var(--primary); color: #fff; }
/* 回复 */
.reply-item {
padding: 14px 0;
border-bottom: 1px solid var(--border);
}
.reply-item:last-child { border-bottom: none; }
.reply-item .meta { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.reply-item .content { line-height: 1.7; }
/* 内容渲染 */
.prose { line-height: 1.8; font-size: 15px; }
.prose p { margin-bottom: 12px; }
.prose h2 { font-size: 20px; margin: 24px 0 12px; }
.prose h3 { font-size: 17px; margin: 20px 0 10px; }
.prose ul, .prose ol { padding-left: 20px; margin-bottom: 12px; }
.prose li { margin-bottom: 4px; }
.prose code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.prose pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: var(--radius); overflow-x: auto; margin-bottom: 12px; }
/* 空状态 */
.empty-state { text-align: center; padding: 40px; color: var(--text-light); }
/* 分页 */
.pagination {
display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 16px;
}
.pagination a, .pagination span {
padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px;
color: var(--text); text-decoration: none;
}
.pagination a:hover { background: var(--primary-light); border-color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: var(--text-light); cursor: not-allowed; }
/* Markdown 表格样式 */
.prose table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.prose th { background: #f8fafc; font-weight: 600; }
.prose tr:nth-child(even) { background: #fafbfc; }
.prose pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: var(--radius); overflow-x: auto; margin-bottom: 12px; }
.prose code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.prose pre code { background: transparent; padding: 0; border-radius: 0; font-size: 13px; }
.prose blockquote { border-left: 4px solid var(--primary); padding: 8px 16px; margin: 12px 0; background: #f8fafc; color: var(--text-light); }
.prose img { max-width: 100%; border-radius: var(--radius); margin: 12px 0; }
/* 搜索 */
.search-preview { font-size: 13px; color: var(--text-light); margin-top: 6px; line-height: 1.6; max-height: 48px; overflow: hidden; }
.search-form { margin-bottom: 0; }
/* 统计统计 */
.stats-bar { display: flex; gap: 24px; margin-bottom: 24px; }
.stat-item { text-align: center; }
.stat-item .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-item .label { font-size: 13px; color: var(--text-light); margin-top: 2px; }
/* 底部 */
.footer {
background: var(--header-bg);
color: #94a3b8;
text-align: center;
padding: 20px;
font-size: 13px;
margin-top: auto;
}
.footer a { color: #60a5fa; }
@media (max-width: 768px) {
.header-inner { flex-wrap: wrap; height: auto; padding: 8px 12px; }
.header nav { order: 3; width: 100%; margin-top: 8px; overflow-x: auto; }
.stats-bar { flex-wrap: wrap; gap: 16px; }
}
</style>
</head>
<body>
<div class="header">
<div class="header-inner">
<a href="/" class="logo">社区平台</a>
<nav>
<a href="/" class="{% if request.path == '/' %}active{% endif %}">首页</a>
<a href="/announcements/" class="{% if request.path.startswith('/announcements') %}active{% endif %}">公告</a>
<a href="/forum/" class="{% if request.path.startswith('/forum') %}active{% endif %}">论坛</a>
<a href="/knowledge/" class="{% if request.path.startswith('/knowledge') %}active{% endif %}">知识库</a>
</nav>
<div class="search-box">
<span class="search-icon">&#128269;</span>
<form method="get" action="/search/" style="display:inline;">
<input type="text" name="q" placeholder="搜索...">
</form>
</div>
<div class="user-area">
{% if current_user %}
<span class="username">{{ current_user.username }}</span>
<span class="badge badge-primary">{{ current_user.get_level_name() }}</span>
<a href="/admin/">管理</a>
<a href="/admin/logout/">退出</a>
{% else %}
<a href="/login/">登录</a>
{% endif %}
</div>
</div>
</div>
<div class="main">
<div class="page-content">
{% block content %}{% endblock %}
</div>
</div>
<div class="footer">
<p>社区平台 &copy; 2026 Powered by LiteAdmin</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.prose table').forEach(function(t) {
if (!t.parentElement.classList.contains('table-wrap')) {
var wrap = document.createElement('div');
wrap.className = 'table-wrap';
wrap.style.overflowX = 'auto';
t.parentNode.insertBefore(wrap, t);
wrap.appendChild(t);
}
});
});
</script>
</body>
</html>
+63
View File
@@ -0,0 +1,63 @@
{% extends "base.html" %}
{% block title %}{{ topic.title }} - 论坛{% endblock %}
{% block content %}
<div class="page-title">
<h1>{{ topic.title }}</h1>
<p>
<span class="badge badge-info">{{ topic.category }}</span>
由 {{ topic.author_name }} 发布于 {{ topic.created_at.strftime('%Y-%m-%d %H:%M') }}
&middot; {{ topic.view_count }} 次浏览 &middot; {{ topic.reply_count }} 条回复
</p>
</div>
<div class="card">
<div class="card-body">
<div class="prose">{{ content_html }}</div>
</div>
</div>
<div class="card">
<div class="card-header">
<span>全部回复 ({{ replies|length }})</span>
</div>
<div class="card-body" style="padding:12px 20px;">
{% if replies %}
{% for reply in replies %}
<div class="reply-item">
<div class="meta">
<strong>{{ reply.author_name }}</strong>
<span>#{{ loop.index }}</span>
<span>{{ reply.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
</div>
<div class="content">{{ reply.content_html }}</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无回复,来抢沙发吧</p></div>
{% endif %}
</div>
</div>
{% if current_user %}
<div class="card">
<div class="card-header"><span>发表回复</span></div>
<div class="card-body">
<p style="font-size:13px;color:var(--text-light);margin-bottom:12px;">支持 Markdown 语法</p>
<form method="post" action="/forum/{{ topic.id }}/reply/">
<div class="form-group">
<textarea name="content" class="form-control" placeholder="写下你的回复...(支持 Markdown 语法)" required></textarea>
</div>
<button type="submit" class="btn btn-primary">发表回复</button>
</form>
</div>
</div>
{% else %}
<div class="card">
<div class="card-body" style="text-align:center;">
<p style="color:var(--text-light);">请<a href="/login/">登录</a>后发表回复</p>
</div>
</div>
{% endif %}
<a href="/forum/" class="btn">&larr; 返回论坛</a>
{% endblock %}
+68
View File
@@ -0,0 +1,68 @@
{% extends "base.html" %}
{% block title %}论坛 - 社区平台{% endblock %}
{% block content %}
<div class="page-title" style="display:flex;align-items:center;justify-content:space-between;">
<div>
<h1>论坛</h1>
<p>自由交流、答疑解惑</p>
</div>
{% if current_user %}
<a href="/forum/new/" class="btn btn-primary">+ 发布话题</a>
{% endif %}
</div>
<div class="tags">
<a href="/forum/" class="tag {% if not category %}active{% endif %}">全部</a>
<a href="/forum/?category=general" class="tag {% if category == 'general' %}active{% endif %}">综合</a>
<a href="/forum/?category=tech" class="tag {% if category == 'tech' %}active{% endif %}">技术</a>
<a href="/forum/?category=life" class="tag {% if category == 'life' %}active{% endif %}">生活</a>
<a href="/forum/?category=study" class="tag {% if category == 'study' %}active{% endif %}">学习</a>
</div>
<div class="card">
<div class="card-body" style="padding:12px 20px;">
{% if topics %}
{% for topic in topics %}
<div class="list-item">
<div class="main-info">
<a href="/forum/{{ topic.id }}/" class="title">{{ topic.title }}</a>
<div class="meta">
<span class="badge badge-info">{{ topic.category }}</span>
<span>{{ topic.author_name }}</span>
<span>{{ topic.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
</div>
</div>
<div class="side-info">
<div>{{ topic.reply_count }}</div>
<div>回复</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无话题</p></div>
{% endif %}
</div>
</div>
{% if pagination.total_pages > 1 %}
<div class="pagination">
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}{% if category %}&category={{ category }}{% endif %}">&laquo; 上一页</a>
{% else %}
<span class="disabled">&laquo; 上一页</span>
{% endif %}
{% for p in range(1, pagination.total_pages + 1) %}
{% if p == pagination.page %}
<span class="active">{{ p }}</span>
{% else %}
<a href="?page={{ p }}{% if category %}&category={{ category }}{% endif %}">{{ p }}</a>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}{% if category %}&category={{ category }}{% endif %}">下一页 &raquo;</a>
{% else %}
<span class="disabled">下一页 &raquo;</span>
{% endif %}
</div>
{% endif %}
{% endblock %}
+37
View File
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block title %}发布话题 - 论坛{% endblock %}
{% block content %}
<div class="page-title">
<h1>发布新话题</h1>
<p>支持 Markdown 语法(表格、代码块、图片等)</p>
</div>
<div class="card">
<div class="card-body">
{% if error %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}
<form method="post">
<div class="form-group">
<label for="title">标题</label>
<input type="text" id="title" name="title" class="form-control" required placeholder="请输入话题标题">
</div>
<div class="form-group">
<label for="category">分类</label>
<select id="category" name="category" class="form-control">
<option value="general">综合</option>
<option value="tech">技术</option>
<option value="life">生活</option>
<option value="study">学习</option>
</select>
</div>
<div class="form-group">
<label for="content">内容(支持 Markdown)</label>
<textarea id="content" name="content" class="form-control" rows="12" required placeholder="支持 Markdown 语法:标题、表格、代码块、图片、链接..."></textarea>
</div>
<button type="submit" class="btn btn-primary">发布话题</button>
<a href="/forum/" class="btn">取消</a>
</form>
</div>
</div>
{% endblock %}
+97
View File
@@ -0,0 +1,97 @@
{% extends "base.html" %}
{% block title %}首页 - 社区平台{% endblock %}
{% block content %}
<div class="page-title">
<h1>欢迎来到社区平台</h1>
<p>交流学习、分享知识、共同成长</p>
</div>
<div class="stats-bar">
<div class="stat-item">
<div class="num">{{ total_users }}</div>
<div class="label">注册用户</div>
</div>
<div class="stat-item">
<div class="num">{{ total_topics }}</div>
<div class="label">论坛主题</div>
</div>
<div class="stat-item">
<div class="num">{{ total_articles }}</div>
<div class="label">知识文章</div>
</div>
</div>
{% if announcements %}
<div class="card">
<div class="card-header">
<span>最新公告</span>
<a href="/announcements/" style="font-size:13px;font-weight:400;">查看全部 &rarr;</a>
</div>
<div class="card-body" style="padding:12px 20px;">
{% for item in announcements %}
<div class="list-item">
<div class="main-info">
<a href="/announcements/{{ item.id }}/" class="title">
{% if item.is_pinned %}<span class="badge badge-warning">置顶</span> {% endif %}
{{ item.title }}
</a>
<div class="meta">{{ item.created_at.strftime('%Y-%m-%d %H:%M') }}</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;">
<div class="card">
<div class="card-header">
<span>最新论坛话题</span>
<a href="/forum/" style="font-size:13px;font-weight:400;">进入论坛 &rarr;</a>
</div>
<div class="card-body" style="padding:12px 20px;">
{% if recent_topics %}
{% for topic in recent_topics %}
<div class="list-item">
<div class="main-info">
<a href="/forum/{{ topic.id }}/" class="title">{{ topic.title }}</a>
<div class="meta">
<span>{{ topic.author_name }}</span>
<span>{{ topic.reply_count }} 回复</span>
<span>{{ topic.created_at.strftime('%m-%d %H:%M') }}</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无话题</p></div>
{% endif %}
</div>
</div>
<div class="card">
<div class="card-header">
<span>最新知识文章</span>
<a href="/knowledge/" style="font-size:13px;font-weight:400;">进入知识库 &rarr;</a>
</div>
<div class="card-body" style="padding:12px 20px;">
{% if recent_articles %}
{% for article in recent_articles %}
<div class="list-item">
<div class="main-info">
<a href="/knowledge/{{ article.id }}/" class="title">{{ article.title }}</a>
<div class="meta">
<span class="badge badge-info">{{ article.category }}</span>
<span>{{ article.author_name }}</span>
<span>{{ article.created_at.strftime('%m-%d %H:%M') }}</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无文章</p></div>
{% endif %}
</div>
</div>
</div>
{% endblock %}
+20
View File
@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}{{ article.title }} - 知识库{% endblock %}
{% block content %}
<div class="page-title">
<h1>{{ article.title }}</h1>
<p>
<span class="badge badge-info">{{ article.category }}</span>
由 {{ article.author_name }} 发布于 {{ article.created_at.strftime('%Y-%m-%d %H:%M') }}
&middot; {{ article.view_count }} 次阅读
</p>
</div>
<div class="card">
<div class="card-body">
<div class="prose">{{ content_html }}</div>
</div>
</div>
<a href="/knowledge/" class="btn">&larr; 返回知识库</a>
{% endblock %}
+60
View File
@@ -0,0 +1,60 @@
{% extends "base.html" %}
{% block title %}知识库 - 社区平台{% endblock %}
{% block content %}
<div class="page-title">
<h1>知识库</h1>
<p>规范文档、知识沉淀</p>
</div>
<div class="tags">
<a href="/knowledge/" class="tag {% if not category %}active{% endif %}">全部</a>
<a href="/knowledge/?category=general" class="tag {% if category == 'general' %}active{% endif %}">综合</a>
<a href="/knowledge/?category=tech" class="tag {% if category == 'tech' %}active{% endif %}">技术</a>
<a href="/knowledge/?category=study" class="tag {% if category == 'study' %}active{% endif %}">学习</a>
<a href="/knowledge/?category=life" class="tag {% if category == 'life' %}active{% endif %}">生活</a>
</div>
<div class="card">
<div class="card-body" style="padding:12px 20px;">
{% if articles %}
{% for article in articles %}
<div class="list-item">
<div class="main-info">
<a href="/knowledge/{{ article.id }}/" class="title">{{ article.title }}</a>
<div class="meta">
<span class="badge badge-info">{{ article.category }}</span>
<span>{{ article.author_name }}</span>
<span>{{ article.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
<span>{{ article.view_count }} 次阅读</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state"><p>暂无知识文章</p></div>
{% endif %}
</div>
</div>
{% if pagination.total_pages > 1 %}
<div class="pagination">
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}{% if category %}&category={{ category }}{% endif %}">&laquo; 上一页</a>
{% else %}
<span class="disabled">&laquo; 上一页</span>
{% endif %}
{% for p in range(1, pagination.total_pages + 1) %}
{% if p == pagination.page %}
<span class="active">{{ p }}</span>
{% else %}
<a href="?page={{ p }}{% if category %}&category={{ category }}{% endif %}">{{ p }}</a>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}{% if category %}&category={{ category }}{% endif %}">下一页 &raquo;</a>
{% else %}
<span class="disabled">下一页 &raquo;</span>
{% endif %}
</div>
{% endif %}
{% endblock %}
+1
View File
@@ -0,0 +1 @@
{% extends "base.html" %}{% block title %}{{ title }}{% endblock %}{% block content %}<h1>{{ heading }}</h1><p>{{ content }}</p><ul>{% for item in items %}<li>{{ item|upper }}</li>{% endfor %}</ul>{% endblock %}
+98
View File
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>注册 - 社区平台</title>
<style>
:root {
--primary: #2563eb;
--bg: #f1f5f9;
--card-bg: #ffffff;
--text: #1e293b;
--text-light: #64748b;
--border: #e2e8f0;
--radius: 8px;
--shadow: 0 4px 6px rgba(0,0,0,0.07);
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
color: var(--text);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.wrap { width:100%; max-width:420px; padding:20px; }
.card {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 36px;
}
.card h1 { font-size:22px; text-align:center; margin-bottom:6px; }
.card .subtitle { text-align:center; color:var(--text-light); margin-bottom:24px; font-size:14px; }
.form-group { margin-bottom:18px; }
.form-group label { display:block; font-size:13px; font-weight:500; margin-bottom:6px; }
.form-control {
width:100%; padding:10px 14px; border:1px solid var(--border); border-radius:6px;
font-size:14px; color:var(--text); outline:none; transition:border-color 0.15s;
font-family:inherit;
}
.form-control:focus { border-color:var(--primary); box-shadow:0 0 0 3px rgba(37,99,235,0.1); }
.btn {
width:100%; padding:10px 16px; border:none; border-radius:6px; font-size:15px;
font-weight:500; cursor:pointer; background:var(--primary); color:#fff; transition:background 0.15s;
}
.btn:hover { background:#1d4ed8; }
.alert {
background:#fce4ec; color:#c62828; padding:10px 14px; border-radius:6px;
margin-bottom:16px; font-size:13px;
}
.alert-success { background:#dcfce7; color:#166534; }
.footer-link { text-align:center; margin-top:16px; font-size:13px; }
.footer-link a { color:var(--primary); }
.copyright { text-align:center; margin-top:20px; color:rgba(255,255,255,0.6); font-size:13px; }
</style>
</head>
<body>
<div class="wrap">
<div class="card">
<h1>注册账号</h1>
<div class="subtitle">加入社区,参与讨论</div>
{% if message %}
<div class="alert alert-success">{{ message }}</div>
{% endif %}
{% if error %}
<div class="alert">{{ error }}</div>
{% endif %}
<form method="post" action="/register/">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required>
</div>
<div class="form-group">
<label for="email">邮箱(选填)</label>
<input type="email" id="email" name="email" class="form-control" placeholder="请输入邮箱">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required>
</div>
<div class="form-group">
<label for="confirm">确认密码</label>
<input type="password" id="confirm" name="confirm" class="form-control" placeholder="再次输入密码" required>
</div>
<button type="submit" class="btn">注册</button>
</form>
<div class="footer-link">
已有账号?<a href="/login/">登录</a>
</div>
</div>
<div class="copyright">社区平台 &copy; 2026</div>
</div>
</body>
</html>
+49
View File
@@ -0,0 +1,49 @@
{% extends "base.html" %}
{% block title %}搜索 - 社区平台{% endblock %}
{% block content %}
<div class="page-title">
<h1>搜索</h1>
</div>
<div class="card">
<div class="card-body">
<form method="get" action="/search/" class="search-form">
<div style="display:flex;gap:8px;">
<input type="text" name="q" class="form-control" placeholder="输入关键字搜索公告、论坛、知识库..." value="{{ query }}" style="flex:1;">
<button type="submit" class="btn btn-primary">搜索</button>
</div>
</form>
</div>
</div>
{% if query %}
<div class="card">
<div class="card-header">
<span>搜索结果:共找到 {{ result_count }} 条</span>
</div>
<div class="card-body" style="padding:12px 20px;">
{% if results %}
{% for item in results %}
<div class="list-item">
<div class="main-info">
<a href="{{ item.url }}" class="title">{{ item.title }}</a>
<div class="meta">
<span class="badge badge-info">{{ item.type_verbose }}</span>
<span>{{ item.author_name }}</span>
<span>匹配度: {{ item.score }}</span>
</div>
<div class="search-preview">{{ item.content_preview }}</div>
</div>
</div>
{% endfor %}
{% endif %}
{% if not results %}
<div class="empty-state">
<p>未找到与 "{{ query }}" 相关的内容</p>
<p style="margin-top:8px;font-size:13px;">建议:尝试不同的关键字或使用更少的词语</p>
</div>
{% endif %}
</div>
</div>
{% endif %}
{% endblock %}