初始化项目:基础设施 + 用户认证 + 后台管理系统 + AGPL 3.0 许可
This commit is contained in:
29
templates/MetaLab-2026/guidelines.html
Normal file
29
templates/MetaLab-2026/guidelines.html
Normal file
@ -0,0 +1,29 @@
|
||||
<p><b>致开发者:</b></p>
|
||||
<p>欢迎来到 MetaLab,一个为构建者准备的纯粹空间。为维护高质量的技术讨论环境,请您在参与前阅读本准则。我们的核心非常简单:<b>平等交流、专注技术、开放分享</b>。任何破坏这些基础的行为都将被处理。</p>
|
||||
<h4>第一章 社区共识</h4>
|
||||
<p>我们希望通过遵循以下共识,共同塑造理想的开发者家园:</p>
|
||||
<p><b>平等:</b>这里没有特权,每个成员在发言和受尊重上权利平等。</p>
|
||||
<p><b>纯粹:</b>讨论应围绕技术本身——代码、架构、逻辑与可验证的事实。</p>
|
||||
<p><b>开放:</b>鼓励开源、协作与知识共享,相信开放是进步的动力。</p>
|
||||
<h4>第二章 基本行为规范</h4>
|
||||
<p><b>【核心要求】</b></p>
|
||||
<p><b>保持尊重,专注技术:</b>可以就技术观点进行激烈辩论,但<span class="red">禁止任何形式的人身攻击、嘲讽、歧视、骚扰及引战行为</span>。讨论应聚焦于软件开发、系统架构、技术原理等实质性内容。</p>
|
||||
<p><span class="red">禁止广告与推广:</span>严禁任何形式的广告、引流、软文、诱导私信、招募、付费服务推广等。分享个人或团队的非商业开源项目不在此限。</p>
|
||||
<p><b>保证内容质量与相关性:</b>请发布对社区有建设性的内容。禁止发布与开发者社区主题无关、无意义的灌水、测试性内容,或令人不适的信息。</p>
|
||||
<p><b>【具体细则】</b></p>
|
||||
<p><b>善于提问与分享:</b>提问前请先尝试搜索;提问时,请清晰描述问题、已尝试的方案及错误信息。鼓励分享高质量、有深度的原创内容或经过授权的转载(需明确标注来源)。</p>
|
||||
<p><span class="red">遵守法律法规:</span>严禁发布任何违反法律法规的内容,包括但不限于恶意代码、侵权盗版信息、违禁品交易信息等。</p>
|
||||
<p><b>鼓励理性讨论:</b>表达不同意见时,应提供基于技术事实或逻辑的依据。</p>
|
||||
<h4>第三章 内容发布与授权</h4>
|
||||
<p><b>内容归属:</b>您发布的原创内容,著作权归您本人所有。发布非原创内容(如翻译、转载)时,必须明确标注原作者及来源,并确保您的发布行为符合原内容的授权协议。</p>
|
||||
<p><span class="highlight">默认授权(重要):</span></p>
|
||||
<p><span class="highlight">为践行开源共享原则,您在本社区公开发布的原创内容,即视为默认同意按照知识共享 署名-相同方式共享 4.0 国际协议 (CC BY-SA 4.0) 进行授权。这意味着他人可以在标明您署名并以相同方式共享的前提下,使用、修改和再发布您的内容。</span></p>
|
||||
<p><b>质量倡议:</b>我们强烈鼓励经过思考、调研的高质量内容。请避免发布过于随意、未经基本搜索或与社区主题完全无关的内容。</p>
|
||||
<h4>第四章 社区治理</h4>
|
||||
<p><b>治理原则:</b>社区管理以本准则为依据,力求公开、公正。</p>
|
||||
<p><span class="red">处理措施:</span>对于违规行为,社区运营方可能采取 <b>内容处置</b>(修改、屏蔽、删除)或 <b>账号处置</b>(警告、临时或永久封禁)。具体尺度由运营方根据违规性质、情节及影响判断。</p>
|
||||
<p><b>申诉流程:</b>如您认为处理有误,有权在决定作出后的 7 个工作日内,通过邮件(metazone@foxmail.com)向元域管理组提交申诉,邮件主题请注明"账号申诉",正文需附上详细理由及相关证据。</p>
|
||||
<h4>第五章 其他</h4>
|
||||
<p><b>免责声明:</b>您应对在社区内的言行独立负责。用户发布的内容仅代表其个人观点,社区运营方无法实时审查,在法律允许的最大范围内不承担责任。</p>
|
||||
<p><b>准则修改:</b>我们可能根据需要对准则进行修订。修订内容将在社区内显著位置公告。若您在新规生效后继续使用社区,即视为同意接受更新后的准则约束。</p>
|
||||
<p><b>遵守法律:</b>您使用社区服务的行为必须遵守您所在地的法律法规;此外,本社区服务器位于中华人民共和国香港特别行政区,您还需遵守当地相关法律。</p>
|
||||
48
templates/MetaLab-2026/html/auth/login.html
Normal file
48
templates/MetaLab-2026/html/auth/login.html
Normal file
@ -0,0 +1,48 @@
|
||||
{{template "layout/header.html" .}}
|
||||
<body>
|
||||
|
||||
{{template "layout/nav.html" .}}
|
||||
|
||||
<main class="auth-page">
|
||||
<div class="auth-card">
|
||||
<h2>登录 MetaLab</h2>
|
||||
<p class="auth-subtitle">回到开发者社区</p>
|
||||
<form id="loginForm" novalidate>
|
||||
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
|
||||
<div class="form-group">
|
||||
<label for="email">邮箱地址</label>
|
||||
<input type="email" id="email" placeholder="your@email.com" required>
|
||||
<span class="form-error" id="emailError">请输入有效的邮箱地址</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input type="password" id="password" placeholder="输入密码" required>
|
||||
<span class="form-error" id="passwordError">请输入密码</span>
|
||||
</div>
|
||||
<div class="form-group remember-group">
|
||||
<label class="remember-label">
|
||||
<input type="checkbox" id="rememberMe">
|
||||
保持登录 30 天
|
||||
</label>
|
||||
<span class="remember-hint">非共享设备推荐</span>
|
||||
</div>
|
||||
<button type="submit" class="submit-btn" id="submitBtn">登 录</button>
|
||||
</form>
|
||||
<div class="auth-footer">
|
||||
还没有账号?<a href="/auth/register">立即注册</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
{{template "layout/footer.html" .}}
|
||||
|
||||
<button class="scroll-top-btn" id="scrollTopBtn">
|
||||
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>
|
||||
</button>
|
||||
|
||||
<script src="/static/js/common.js"></script>
|
||||
<script src="/static/js/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
80
templates/MetaLab-2026/html/auth/register.html
Normal file
80
templates/MetaLab-2026/html/auth/register.html
Normal file
@ -0,0 +1,80 @@
|
||||
{{template "layout/header.html" .}}
|
||||
<body>
|
||||
|
||||
{{template "layout/nav.html" .}}
|
||||
|
||||
<main class="auth-page">
|
||||
<div class="auth-card">
|
||||
<h2>创建账号</h2>
|
||||
<p class="auth-subtitle">加入 MetaLab 开发者社区</p>
|
||||
<form id="registerForm" novalidate>
|
||||
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
|
||||
<div class="form-group">
|
||||
<label for="email">邮箱地址</label>
|
||||
<input type="email" id="email" placeholder="your@email.com" required>
|
||||
<span class="form-error" id="emailError">请输入有效的邮箱地址</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input type="password" id="password" placeholder="至少 8 位,包含字母与数字" required minlength="8">
|
||||
<span class="form-error" id="passwordError">密码至少 8 位,需包含字母与数字</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="confirmPassword">确认密码</label>
|
||||
<input type="password" id="confirmPassword" placeholder="请再次输入密码" required>
|
||||
<span class="form-error" id="confirmPasswordError">两次输入的密码不一致</span>
|
||||
</div>
|
||||
<div class="form-group remember-group">
|
||||
<label class="remember-label">
|
||||
<input type="checkbox" id="rememberMe">
|
||||
保持登录 30 天
|
||||
</label>
|
||||
<span class="remember-hint">非共享设备推荐</span>
|
||||
</div>
|
||||
<p class="guidelines-link">点击注册即表示同意 <a href="javascript:void(0)" id="openGuidelines">《MetaLab 社区用户准则》</a></p>
|
||||
<button type="submit" class="submit-btn" id="submitBtn">注 册</button>
|
||||
</form>
|
||||
<div class="auth-footer">
|
||||
已有账号?<a href="/auth/login">立即登录</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- 社区准则模态框 -->
|
||||
<div class="modal-overlay" id="modalOverlay">
|
||||
<div class="modal">
|
||||
<div class="modal-header">
|
||||
<h3>MetaLab 社区用户准则</h3>
|
||||
<button class="modal-close" id="modalClose">×</button>
|
||||
</div>
|
||||
<div class="modal-body" id="modalBody">
|
||||
{{.Guidelines}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div id="modalEnforce">
|
||||
<div class="timer" id="timer">
|
||||
<span id="timerLabel">剩余阅读时间</span>
|
||||
<span class="count" id="timerCount">60</span>
|
||||
<span id="timerUnit">秒</span>
|
||||
<span id="timerDone" style="display:none">✓ 阅读时间已满足</span>
|
||||
</div>
|
||||
<span class="scroll-hint" id="scrollHint">▼ 请滚动至底部完成阅读</span>
|
||||
</div>
|
||||
<button class="confirm-btn" id="confirmBtn" disabled>我已完整阅读并同意</button>
|
||||
<button class="confirm-btn" id="previewCloseBtn" style="display:none">关 闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
{{template "layout/footer.html" .}}
|
||||
|
||||
<button class="scroll-top-btn" id="scrollTopBtn">
|
||||
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>
|
||||
</button>
|
||||
|
||||
<script src="/static/js/common.js"></script>
|
||||
<script src="/static/js/register.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
22
templates/MetaLab-2026/html/home/index.html
Normal file
22
templates/MetaLab-2026/html/home/index.html
Normal file
@ -0,0 +1,22 @@
|
||||
{{template "layout/header.html" .}}
|
||||
<body>
|
||||
|
||||
{{template "layout/nav.html" .}}
|
||||
|
||||
<main class="hero">
|
||||
<div class="container">
|
||||
<h1>Meta<span>Lab</span></h1>
|
||||
<p class="hero-tagline">下一代开发者社区</p>
|
||||
{{if .IsLoggedIn}}
|
||||
<p class="hero-desc">欢迎回来,{{.Username}}</p>
|
||||
{{else}}
|
||||
<p class="hero-desc">一个为构建者准备的纯粹空间</p>
|
||||
{{end}}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{{template "layout/footer.html" .}}
|
||||
|
||||
<script src="/static/js/common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
5
templates/MetaLab-2026/html/layout/footer.html
Normal file
5
templates/MetaLab-2026/html/layout/footer.html
Normal file
@ -0,0 +1,5 @@
|
||||
<footer>
|
||||
<div class="container footer-content">
|
||||
<p class="copyright">© 2024-2026 MetaLab | Framework: MetaZone</p>
|
||||
</div>
|
||||
</footer>
|
||||
12
templates/MetaLab-2026/html/layout/header.html
Normal file
12
templates/MetaLab-2026/html/layout/header.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{{if .CSRFToken}}<meta name="csrf-token" content="{{.CSRFToken}}">{{end}}
|
||||
<title>{{.Title}} - MetaLab</title>
|
||||
<link rel="stylesheet" href="/static/css/common.css">
|
||||
{{if .ExtraCSS}}
|
||||
<link rel="stylesheet" href="{{.ExtraCSS}}">
|
||||
{{end}}
|
||||
</head>
|
||||
17
templates/MetaLab-2026/html/layout/nav.html
Normal file
17
templates/MetaLab-2026/html/layout/nav.html
Normal file
@ -0,0 +1,17 @@
|
||||
<header>
|
||||
<div class="container nav-container">
|
||||
<a href="/" class="logo">Meta<span>Lab</span></a>
|
||||
<button class="mobile-menu-btn" id="mobileMenuBtn">
|
||||
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
|
||||
</button>
|
||||
<ul class="nav-links" id="navLinks">
|
||||
<li><a href="/">首页</a></li>
|
||||
{{if .IsLoggedIn}}
|
||||
<li><a href="/settings" class="nav-user">{{.Username}}</a></li>
|
||||
<li><a href="javascript:void(0)" class="nav-logout" id="logoutBtn">退出</a></li>
|
||||
{{else}}
|
||||
<li><a href="/auth/login" class="nav-login">登录</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
351
templates/MetaLab-2026/static/css/auth.css
Normal file
351
templates/MetaLab-2026/static/css/auth.css
Normal file
@ -0,0 +1,351 @@
|
||||
/* ============================================================
|
||||
MetaLab Auth Styles — 注册/登录页面专属样式
|
||||
============================================================ */
|
||||
|
||||
/* ---------- Auth Page Layout ---------- */
|
||||
.auth-page {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem 20px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 2.5rem;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.auth-card h2 {
|
||||
font-size: 1.6rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
text-align: center;
|
||||
margin-bottom: .4rem;
|
||||
}
|
||||
|
||||
.auth-card .auth-subtitle {
|
||||
text-align: center;
|
||||
color: var(--color-secondary);
|
||||
font-size: .95rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
/* ---------- Form ---------- */
|
||||
.form-group {
|
||||
margin-bottom: 1.2rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: .9rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: .4rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: .75rem 1rem;
|
||||
border: 1.5px solid var(--color-border);
|
||||
border-radius: var(--radius);
|
||||
font-size: 1rem;
|
||||
transition: var(--transition);
|
||||
outline: none;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
border-color: var(--color-accent);
|
||||
box-shadow: 0 0 0 3px rgba(52,152,219,.15);
|
||||
}
|
||||
|
||||
.form-group input.error {
|
||||
border-color: var(--color-danger);
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: var(--color-danger);
|
||||
font-size: .8rem;
|
||||
margin-top: .3rem;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.guidelines-link {
|
||||
font-size: .85rem;
|
||||
color: var(--color-text-light);
|
||||
text-align: center;
|
||||
margin: 1.2rem 0;
|
||||
}
|
||||
|
||||
.guidelines-link a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 500;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.guidelines-link a:hover {
|
||||
color: #2980b9;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
padding: .85rem;
|
||||
background: var(--color-accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.submit-btn:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
.submit-btn:disabled {
|
||||
background: #b0bec5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* ---------- Remember Me ---------- */
|
||||
.remember-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.remember-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
font-size: .9rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.remember-label input[type="checkbox"] {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
accent-color: var(--color-accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
.remember-hint {
|
||||
display: block;
|
||||
font-size: .78rem;
|
||||
color: var(--color-secondary);
|
||||
margin-top: .3rem;
|
||||
margin-left: 24px;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
text-align: center;
|
||||
margin-top: 1.5rem;
|
||||
font-size: .9rem;
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 500;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.auth-footer a:hover {
|
||||
color: #2980b9;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* ---------- Modal ---------- */
|
||||
.modal-overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,.5);
|
||||
z-index: 2000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.modal-overlay.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius);
|
||||
width: 100%;
|
||||
max-width: 700px;
|
||||
max-height: 85vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 10px 40px rgba(0,0,0,.2);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.2rem 1.5rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
font-size: 1.2rem;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.4rem;
|
||||
color: var(--color-secondary);
|
||||
cursor: pointer;
|
||||
padding: .2rem;
|
||||
line-height: 1;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1.5rem 1.5rem 1rem;
|
||||
font-size: .92rem;
|
||||
line-height: 1.8;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.modal-body h4 {
|
||||
font-size: 1.05rem;
|
||||
color: var(--color-primary);
|
||||
margin: 1.2rem 0 .5rem;
|
||||
}
|
||||
|
||||
.modal-body h4:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.modal-body p {
|
||||
margin-bottom: .8rem;
|
||||
}
|
||||
|
||||
.modal-body .red {
|
||||
color: var(--color-danger);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.modal-body .highlight {
|
||||
color: var(--color-danger);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 1rem 1.5rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
flex-wrap: wrap;
|
||||
gap: .6rem;
|
||||
}
|
||||
|
||||
.timer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .4rem;
|
||||
color: var(--color-secondary);
|
||||
font-size: .9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.timer .count {
|
||||
color: var(--color-accent);
|
||||
font-weight: 700;
|
||||
min-width: 1.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.timer.done .count {
|
||||
color: #27ae60;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
padding: .6rem 1.8rem;
|
||||
background: var(--color-accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-size: .95rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.confirm-btn:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
.confirm-btn:disabled {
|
||||
background: #b0bec5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.scroll-hint {
|
||||
color: var(--color-danger);
|
||||
font-size: .82rem;
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .3rem;
|
||||
}
|
||||
|
||||
/* ---------- Toast ---------- */
|
||||
.toast {
|
||||
position: fixed;
|
||||
top: 1.5rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-120px);
|
||||
background: #27ae60;
|
||||
color: #fff;
|
||||
padding: .85rem 2rem;
|
||||
border-radius: var(--radius);
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
z-index: 3000;
|
||||
box-shadow: 0 6px 20px rgba(39,174,96,.35);
|
||||
transition: transform .4s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
background: var(--color-danger);
|
||||
box-shadow: 0 6px 20px rgba(231,76,60,.35);
|
||||
}
|
||||
|
||||
/* ---------- Responsive ---------- */
|
||||
@media (max-width: 768px) {
|
||||
.auth-card {
|
||||
padding: 1.8rem;
|
||||
}
|
||||
.modal {
|
||||
max-height: 90vh;
|
||||
}
|
||||
.modal-body {
|
||||
font-size: .85rem;
|
||||
}
|
||||
}
|
||||
240
templates/MetaLab-2026/static/css/common.css
Normal file
240
templates/MetaLab-2026/static/css/common.css
Normal file
@ -0,0 +1,240 @@
|
||||
/* ============================================================
|
||||
MetaLab Common Styles — 全站共享样式(Reset / 变量 / 导航 / 页脚)
|
||||
每个页面加载此文件后,按需加载页面专属 CSS
|
||||
============================================================ */
|
||||
|
||||
:root {
|
||||
--color-bg: #f8f9fa;
|
||||
--color-surface: #fff;
|
||||
--color-primary: #2c3e50;
|
||||
--color-secondary: #7f8c8d;
|
||||
--color-accent: #3498db;
|
||||
--color-danger: #e74c3c;
|
||||
--color-border: #e0e0e0;
|
||||
--color-text: #333;
|
||||
--color-text-light: #666;
|
||||
--shadow: 0 4px 12px rgba(0,0,0,.08);
|
||||
--radius: 8px;
|
||||
--transition: all .3s ease;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* ---------- Reset ---------- */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
scroll-snap-type: y mandatory;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
line-height: 1.6;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ---------- Layout ---------- */
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
vertical-align: -.125em;
|
||||
display: inline-block;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ---------- Header / Nav ---------- */
|
||||
header {
|
||||
background: var(--color-surface);
|
||||
box-shadow: var(--shadow);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.nav-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: .6rem 0;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.logo span {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
list-style: none;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.nav-links a {
|
||||
font-weight: 500;
|
||||
padding: .5rem 0;
|
||||
position: relative;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.nav-links a:hover,
|
||||
.nav-links a.nav-active {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.nav-links a::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 0;
|
||||
height: 2px;
|
||||
background: var(--color-accent);
|
||||
transition: width .3s ease;
|
||||
}
|
||||
|
||||
.nav-links a:hover::after,
|
||||
.nav-links a.nav-active::after {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-login {
|
||||
color: var(--color-accent) !important;
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
|
||||
.nav-user {
|
||||
color: var(--color-accent) !important;
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
|
||||
.nav-logout {
|
||||
color: var(--color-secondary) !important;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: none;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* ---------- Contact / Footer ---------- */
|
||||
.contact-bar {
|
||||
text-align: center;
|
||||
padding: .6rem 0;
|
||||
background: #e8f0f8;
|
||||
border-top: 1px solid var(--color-border);
|
||||
font-size: .95rem;
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
|
||||
.contact-bar a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.contact-bar a:hover {
|
||||
color: #2980b9;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
footer {
|
||||
background: var(--color-primary);
|
||||
color: #bdc3c7;
|
||||
padding: .8rem 0;
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
font-size: .9rem;
|
||||
color: #95a5a6;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* ---------- Scroll-to-top ---------- */
|
||||
.scroll-top-btn {
|
||||
position: fixed;
|
||||
bottom: 1.5rem;
|
||||
right: 1.5rem;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
box-shadow: 0 4px 12px rgba(52,152,219,.35);
|
||||
cursor: pointer;
|
||||
font-size: 1.1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 999;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transform: translateY(10px);
|
||||
transition: opacity .3s ease, visibility .3s ease, transform .3s ease;
|
||||
}
|
||||
|
||||
.scroll-top-btn.visible {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.scroll-top-btn:hover {
|
||||
background: #2980b9;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 16px rgba(52,152,219,.45);
|
||||
}
|
||||
|
||||
/* ---------- Responsive (共享:导航) ---------- */
|
||||
@media (max-width: 768px) {
|
||||
.nav-links {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background: var(--color-surface);
|
||||
flex-direction: column;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 10px 15px rgba(0,0,0,.1);
|
||||
text-align: center;
|
||||
}
|
||||
.nav-links.active {
|
||||
display: flex;
|
||||
}
|
||||
.mobile-menu-btn {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
354
templates/MetaLab-2026/static/css/home.css
Normal file
354
templates/MetaLab-2026/static/css/home.css
Normal file
@ -0,0 +1,354 @@
|
||||
/* ============================================================
|
||||
MetaLab Home Styles — 首页专属样式(Hero / Plans / Features / Timeline)
|
||||
仅在首页加载,通过 ExtraCSS 注入
|
||||
============================================================ */
|
||||
|
||||
/* ---------- Hero ---------- */
|
||||
.hero {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 4rem 0;
|
||||
text-align: center;
|
||||
background: linear-gradient(180deg, #fff 0%, #f0f4f8 100%);
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: 4rem;
|
||||
font-weight: 800;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: .6rem;
|
||||
line-height: 1.1;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
|
||||
.hero h1 span {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.hero-tagline {
|
||||
font-size: 1.5rem;
|
||||
color: var(--color-secondary);
|
||||
margin-bottom: 1.5rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.hero-desc {
|
||||
font-size: 1.15rem;
|
||||
color: var(--color-text-light);
|
||||
max-width: 500px;
|
||||
margin: 0 auto 2.2rem;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.cta-button,
|
||||
.secondary-button {
|
||||
display: inline-block;
|
||||
padding: .9rem 2.2rem;
|
||||
border-radius: var(--radius);
|
||||
font-weight: 600;
|
||||
font-size: 1.1rem;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.cta-button {
|
||||
background: var(--color-accent);
|
||||
color: #fff;
|
||||
border: 2px solid var(--color-accent);
|
||||
}
|
||||
|
||||
.cta-button:hover {
|
||||
background: transparent;
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.secondary-button {
|
||||
background: transparent;
|
||||
color: var(--color-accent);
|
||||
border: 2px solid var(--color-accent);
|
||||
}
|
||||
|
||||
.secondary-button:hover {
|
||||
background: var(--color-accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* ---------- Shared section headings ---------- */
|
||||
.section-title {
|
||||
text-align: center;
|
||||
font-size: 2.2rem;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: .8rem;
|
||||
}
|
||||
|
||||
.section-subtitle {
|
||||
text-align: center;
|
||||
color: var(--color-secondary);
|
||||
font-size: 1.1rem;
|
||||
max-width: 600px;
|
||||
margin: 0 auto 3.5rem;
|
||||
}
|
||||
|
||||
/* ---------- Plans ---------- */
|
||||
.plans {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 1.5rem 0;
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
.plans .section-title {
|
||||
font-size: 2rem;
|
||||
margin-bottom: .4rem;
|
||||
}
|
||||
|
||||
.plans .section-subtitle {
|
||||
margin-bottom: 1.2rem;
|
||||
}
|
||||
|
||||
.plans-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.plan-card {
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
box-shadow: var(--shadow);
|
||||
transition: var(--transition);
|
||||
border: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.plan-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,.12);
|
||||
}
|
||||
|
||||
.plan-icon {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background: rgba(52,152,219,.1);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--color-accent);
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
.plan-card h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.plan-card p {
|
||||
color: var(--color-text-light);
|
||||
margin-bottom: 1rem;
|
||||
flex-grow: 1;
|
||||
font-size: .95rem;
|
||||
}
|
||||
|
||||
.plan-status {
|
||||
display: inline-block;
|
||||
background: #e8f4fc;
|
||||
color: var(--color-accent);
|
||||
padding: .3rem .9rem;
|
||||
border-radius: 20px;
|
||||
font-size: .85rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* ---------- Features ---------- */
|
||||
.features {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 4rem 0;
|
||||
background: var(--color-surface);
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
.features-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 2.5rem;
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
.feature {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.feature .icon {
|
||||
font-size: 2.5rem;
|
||||
color: var(--color-accent);
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.feature h3 {
|
||||
font-size: 1.3rem;
|
||||
margin-bottom: .8rem;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.feature p {
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
|
||||
/* ---------- Timeline ---------- */
|
||||
.section-group {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
.timeline-vision {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 1.5rem 0 1rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.timeline-vision .section-title {
|
||||
margin-bottom: .3rem;
|
||||
}
|
||||
|
||||
.timeline-vision .section-subtitle {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.timeline {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 2rem;
|
||||
padding: 2rem 0 1rem;
|
||||
overflow-x: auto;
|
||||
overflow-y: visible;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior-y: contain;
|
||||
}
|
||||
|
||||
.timeline::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 4%;
|
||||
top: 1.9rem;
|
||||
width: 92%;
|
||||
height: 3px;
|
||||
background: var(--color-accent);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.timeline-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
min-width: 200px;
|
||||
max-width: 240px;
|
||||
padding: 0 .5rem;
|
||||
}
|
||||
|
||||
.timeline-marker {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background: var(--color-accent);
|
||||
border-radius: 50%;
|
||||
border: 4px solid var(--color-surface);
|
||||
box-shadow: var(--shadow);
|
||||
margin-bottom: 1.5rem;
|
||||
z-index: 1;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem 1.2rem;
|
||||
box-shadow: var(--shadow);
|
||||
border: 1px solid var(--color-border);
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.timeline-item:hover .timeline-content {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,.12);
|
||||
}
|
||||
|
||||
.timeline-title {
|
||||
font-size: 1.15rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.timeline-desc {
|
||||
color: var(--color-text-light);
|
||||
font-size: .95rem;
|
||||
}
|
||||
|
||||
/* ---------- Responsive (首页专属) ---------- */
|
||||
@media (max-width: 768px) {
|
||||
.hero h1 {
|
||||
font-size: 3rem;
|
||||
}
|
||||
.hero-tagline {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
.hero-desc {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
.timeline {
|
||||
justify-content: flex-start;
|
||||
gap: 1.5rem;
|
||||
padding: 2rem 20px 1.5rem;
|
||||
scroll-snap-type: x mandatory;
|
||||
}
|
||||
.timeline-item {
|
||||
min-width: 240px;
|
||||
max-width: 280px;
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
.timeline::before {
|
||||
left: 20px;
|
||||
width: calc(240px * 4 + 1.5rem * 3 + 20px);
|
||||
}
|
||||
.cta-button,
|
||||
.secondary-button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin: .5rem 0;
|
||||
}
|
||||
.secondary-button {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
194
templates/MetaLab-2026/static/js/common.js
Normal file
194
templates/MetaLab-2026/static/js/common.js
Normal file
@ -0,0 +1,194 @@
|
||||
/* ============================================================
|
||||
MetaLab Common JS — 全站共享脚本
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ---- Shared utils (exposed to other scripts via window.MetaLab) ----
|
||||
window.MetaLab = window.MetaLab || {};
|
||||
var toastTimer = null;
|
||||
window.MetaLab.toast = function (el, msg, isError) {
|
||||
if (!el) return;
|
||||
clearTimeout(toastTimer);
|
||||
el.textContent = msg;
|
||||
el.className = 'toast' + (isError ? ' error' : '');
|
||||
void el.offsetWidth;
|
||||
el.classList.add('show');
|
||||
toastTimer = setTimeout(function () {
|
||||
el.classList.remove('show');
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
// ---- CSRF token helper (reads from <meta> tag rendered by server) ----
|
||||
window.MetaLab.csrfToken = function () {
|
||||
var meta = document.querySelector('meta[name="csrf-token"]');
|
||||
return meta ? meta.getAttribute('content') : '';
|
||||
};
|
||||
|
||||
// ---- Auto-attach X-CSRF-Token to all state-changing requests ----
|
||||
// Monkey-patch XMLHttpRequest and fetch to inject CSRF header
|
||||
(function () {
|
||||
var token = window.MetaLab.csrfToken();
|
||||
if (!token) return;
|
||||
|
||||
// Patch XMLHttpRequest (used by register.js / login.js / common.js)
|
||||
var origXHROpen = XMLHttpRequest.prototype.open;
|
||||
var origXHRSend = XMLHttpRequest.prototype.send;
|
||||
XMLHttpRequest.prototype.open = function (method, url) {
|
||||
this._method = method;
|
||||
this._url = url;
|
||||
return origXHROpen.apply(this, arguments);
|
||||
};
|
||||
var SAME_ORIGIN = /^\/(?!\/)/;
|
||||
XMLHttpRequest.prototype.send = function () {
|
||||
if (SAME_ORIGIN.test(this._url) &&
|
||||
this._method && !/^(GET|HEAD|OPTIONS)$/i.test(this._method)) {
|
||||
this.setRequestHeader('X-CSRF-Token', token);
|
||||
}
|
||||
return origXHRSend.apply(this, arguments);
|
||||
};
|
||||
|
||||
// Patch fetch (used by auto-refresh)
|
||||
var origFetch = window.fetch;
|
||||
window.fetch = function (url, options) {
|
||||
options = options || {};
|
||||
var headers = options.headers || {};
|
||||
var method = (options.method || 'GET').toUpperCase();
|
||||
var urlStr = (typeof url === 'string') ? url : '';
|
||||
if (SAME_ORIGIN.test(urlStr) && !/^(GET|HEAD|OPTIONS)$/i.test(method)) {
|
||||
if (headers instanceof Headers) {
|
||||
headers.set('X-CSRF-Token', token);
|
||||
} else {
|
||||
headers['X-CSRF-Token'] = token;
|
||||
}
|
||||
options.headers = headers;
|
||||
}
|
||||
return origFetch(url, options);
|
||||
};
|
||||
})();
|
||||
|
||||
var menuBtn = document.getElementById('mobileMenuBtn');
|
||||
var navLinks = document.getElementById('navLinks');
|
||||
var scrollBtn = document.getElementById('scrollTopBtn');
|
||||
|
||||
var menuIcon = '<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>';
|
||||
var closeIcon = '<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
||||
|
||||
// ---- Mobile menu toggle ----
|
||||
if (menuBtn && navLinks) {
|
||||
menuBtn.addEventListener('click', function () {
|
||||
navLinks.classList.toggle('active');
|
||||
menuBtn.innerHTML = navLinks.classList.contains('active') ? closeIcon : menuIcon;
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Close mobile menu on nav click ----
|
||||
var links = document.querySelectorAll('.nav-links a');
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
links[i].addEventListener('click', function () {
|
||||
if (navLinks) {
|
||||
navLinks.classList.remove('active');
|
||||
}
|
||||
if (menuBtn) {
|
||||
menuBtn.innerHTML = menuIcon;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Smooth scroll for anchor links ----
|
||||
var anchors = document.querySelectorAll('a[href^="#"]');
|
||||
for (var j = 0; j < anchors.length; j++) {
|
||||
anchors[j].addEventListener('click', function (e) {
|
||||
var href = this.getAttribute('href');
|
||||
if (href === '#') return;
|
||||
var target = document.querySelector(href);
|
||||
if (target) {
|
||||
e.preventDefault();
|
||||
window.scrollTo({ top: target.offsetTop - 55, behavior: 'smooth' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Scroll-to-top button ----
|
||||
if (scrollBtn) {
|
||||
window.addEventListener('scroll', function () {
|
||||
scrollBtn.classList.toggle('visible', window.scrollY > window.innerHeight * 0.5);
|
||||
});
|
||||
scrollBtn.addEventListener('click', function () {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Dev greeting ----
|
||||
console.log('%c🔨 嘿,开发者朋友!', 'color:#2ecc71;font-size:18px;font-weight:bold');
|
||||
console.log('%c欢迎来到 MetaLab 的蓝图页。', 'color:#34495e');
|
||||
console.log('%c我们正在搭建一个纯净、友好的下一代开发者社区。', 'color:#34495e');
|
||||
console.log('%c有任何想法或愿意参与早期测试?欢迎联系我们:metazone@foxmail.com', 'color:#e74c3c;font-style:italic');
|
||||
|
||||
// ---- Logout ----
|
||||
var logoutBtn = document.getElementById('logoutBtn');
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener('click', function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/api/auth/logout', true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
window.location.href = '/';
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Auto-refresh token (silent) ----
|
||||
// 场景 A:页面开着时,每 10 分钟静默续期(保持 access token 不过期)
|
||||
// 场景 B:关浏览器 15+ min 后回来,access token 过期但 refresh 仍有效
|
||||
// → 页面先渲染为未登录 → 刷新成功后 reload 一次获得登录态
|
||||
// 不在认证页面执行刷新(登录/注册页无需续期)
|
||||
var onAuthPage = /^\/auth\//.test(window.location.pathname);
|
||||
if (!onAuthPage) {
|
||||
|
||||
var REFRESH_INTERVAL = 10 * 60 * 1000; // 10 minutes
|
||||
var refreshTimer = null;
|
||||
|
||||
function tryRefresh(callback) {
|
||||
fetch('/api/auth/refresh', { method: 'POST' })
|
||||
.then(function (res) {
|
||||
if (res.ok) {
|
||||
if (callback) callback();
|
||||
} else {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer);
|
||||
refreshTimer = null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer);
|
||||
refreshTimer = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 仅当存在"记住我"标记 Cookie 时才尝试刷新(避免无需刷新时产生 401 控制台报错)
|
||||
function hasCookie(name) {
|
||||
return document.cookie.split(';').some(function (c) {
|
||||
return c.trim().startsWith(name + '=');
|
||||
});
|
||||
}
|
||||
|
||||
if (hasCookie('mlb_rm')) {
|
||||
tryRefresh(function () {
|
||||
refreshTimer = setInterval(function () { tryRefresh(null); }, REFRESH_INTERVAL);
|
||||
|
||||
if (!document.getElementById('logoutBtn') && !sessionStorage.getItem('mlb_refreshed')) {
|
||||
sessionStorage.setItem('mlb_refreshed', '1');
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
sessionStorage.removeItem('mlb_refreshed');
|
||||
}
|
||||
|
||||
} // end if (!onAuthPage)
|
||||
})();
|
||||
80
templates/MetaLab-2026/static/js/login.js
Normal file
80
templates/MetaLab-2026/static/js/login.js
Normal file
@ -0,0 +1,80 @@
|
||||
/* ============================================================
|
||||
MetaLab Login JS — 登录页面专属脚本
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var loginForm = document.getElementById('loginForm');
|
||||
var emailInput = document.getElementById('email');
|
||||
var passwordInput = document.getElementById('password');
|
||||
var rememberMeCheckbox = document.getElementById('rememberMe');
|
||||
var emailError = document.getElementById('emailError');
|
||||
var passwordError = document.getElementById('passwordError');
|
||||
var submitBtn = document.getElementById('submitBtn');
|
||||
var toast = document.getElementById('toast');
|
||||
|
||||
if (!loginForm) return;
|
||||
|
||||
function checkFormValidity() {
|
||||
var email = emailInput.value.trim();
|
||||
var password = passwordInput.value;
|
||||
submitBtn.disabled = !(email && password);
|
||||
}
|
||||
|
||||
emailInput.addEventListener('input', function () {
|
||||
var v = emailInput.value.trim();
|
||||
if (v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v)) {
|
||||
emailInput.classList.add('error');
|
||||
emailError.style.display = 'block';
|
||||
} else {
|
||||
emailInput.classList.remove('error');
|
||||
emailError.style.display = 'none';
|
||||
}
|
||||
checkFormValidity();
|
||||
});
|
||||
|
||||
passwordInput.addEventListener('input', checkFormValidity);
|
||||
|
||||
loginForm.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var email = emailInput.value.trim();
|
||||
var password = passwordInput.value;
|
||||
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
emailInput.classList.add('error');
|
||||
emailError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
if (!password) {
|
||||
passwordInput.classList.add('error');
|
||||
passwordError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
doLogin(email, password);
|
||||
});
|
||||
|
||||
function doLogin(email, password) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/api/auth/login', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
var resp;
|
||||
try { resp = JSON.parse(xhr.responseText); } catch (err) { resp = null; }
|
||||
|
||||
if (xhr.status === 200 && resp && resp.success) {
|
||||
window.MetaLab.toast(toast, '登录成功', false);
|
||||
setTimeout(function () {
|
||||
window.location.href = '/';
|
||||
}, 800);
|
||||
} else {
|
||||
var msg = (resp && resp.message) ? resp.message : '登录失败,请稍后重试';
|
||||
window.MetaLab.toast(toast, msg, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(JSON.stringify({ email: email, password: password, remember_me: rememberMeCheckbox.checked }));
|
||||
}
|
||||
})();
|
||||
305
templates/MetaLab-2026/static/js/register.js
Normal file
305
templates/MetaLab-2026/static/js/register.js
Normal file
@ -0,0 +1,305 @@
|
||||
/* ============================================================
|
||||
MetaLab Register JS — 注册页面专属脚本
|
||||
============================================================ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ---- DOM refs ----
|
||||
var openGuidelines = document.getElementById('openGuidelines');
|
||||
var modalOverlay = document.getElementById('modalOverlay');
|
||||
var modalBody = document.getElementById('modalBody');
|
||||
var modalClose = document.getElementById('modalClose');
|
||||
var modalEnforce = document.getElementById('modalEnforce');
|
||||
var confirmBtn = document.getElementById('confirmBtn');
|
||||
var previewCloseBtn = document.getElementById('previewCloseBtn');
|
||||
var timerCount = document.getElementById('timerCount');
|
||||
var timerLabel = document.getElementById('timerLabel');
|
||||
var timerUnit = document.getElementById('timerUnit');
|
||||
var timerDone = document.getElementById('timerDone');
|
||||
var timer = document.getElementById('timer');
|
||||
var scrollHint = document.getElementById('scrollHint');
|
||||
var submitBtn = document.getElementById('submitBtn');
|
||||
var registerForm = document.getElementById('registerForm');
|
||||
var toast = document.getElementById('toast');
|
||||
var emailInput = document.getElementById('email');
|
||||
var passwordInput = document.getElementById('password');
|
||||
var confirmPasswordInput = document.getElementById('confirmPassword');
|
||||
var rememberMeCheckbox = document.getElementById('rememberMe');
|
||||
var emailError = document.getElementById('emailError');
|
||||
var passwordError = document.getElementById('passwordError');
|
||||
var confirmPasswordError = document.getElementById('confirmPasswordError');
|
||||
|
||||
// Guard: exit if not on auth page
|
||||
if (!registerForm) return;
|
||||
|
||||
var countdown = 60;
|
||||
var timerInterval = null;
|
||||
var reachedBottom = false;
|
||||
var agreed = false;
|
||||
var isRegistrationMode = false;
|
||||
var countdownPaused = false;
|
||||
|
||||
// ---- Modal Open ----
|
||||
function openModal(onAgreed) {
|
||||
isRegistrationMode = typeof onAgreed === 'function';
|
||||
clearInterval(timerInterval);
|
||||
countdown = 60;
|
||||
reachedBottom = false;
|
||||
agreed = false;
|
||||
modalBody.scrollTop = 0;
|
||||
modalOverlay.classList.add('active');
|
||||
modalOverlay._onAgreed = isRegistrationMode ? onAgreed : null;
|
||||
|
||||
if (isRegistrationMode) {
|
||||
modalEnforce.style.display = '';
|
||||
confirmBtn.style.display = '';
|
||||
previewCloseBtn.style.display = 'none';
|
||||
timerCount.textContent = '60';
|
||||
timerLabel.style.display = '';
|
||||
timerCount.style.display = '';
|
||||
timerUnit.style.display = '';
|
||||
timerDone.style.display = 'none';
|
||||
timer.classList.remove('done');
|
||||
countdownPaused = false;
|
||||
confirmBtn.disabled = true;
|
||||
scrollHint.style.display = 'flex';
|
||||
scrollHint.textContent = '▼ 请滚动至底部完成阅读';
|
||||
scrollHint.style.color = 'var(--color-danger)';
|
||||
startCountdown();
|
||||
} else {
|
||||
modalEnforce.style.display = 'none';
|
||||
confirmBtn.style.display = 'none';
|
||||
previewCloseBtn.style.display = '';
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Countdown ----
|
||||
function startCountdown() {
|
||||
timerInterval = setInterval(function () {
|
||||
if (countdownPaused) return;
|
||||
countdown--;
|
||||
timerCount.textContent = countdown;
|
||||
if (countdown <= 0) {
|
||||
clearInterval(timerInterval);
|
||||
timerLabel.style.display = 'none';
|
||||
timerCount.style.display = 'none';
|
||||
timerUnit.style.display = 'none';
|
||||
timerDone.style.display = '';
|
||||
timer.classList.add('done');
|
||||
scrollHint.textContent = '▼ 请滚动至底部完成阅读';
|
||||
updateConfirmState();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// ---- Scroll Detection ----
|
||||
modalBody.addEventListener('scroll', function () {
|
||||
if (reachedBottom) return;
|
||||
if (modalBody.scrollTop + modalBody.clientHeight >= modalBody.scrollHeight - 5) {
|
||||
reachedBottom = true;
|
||||
scrollHint.textContent = '✓ 已阅读至底部';
|
||||
scrollHint.style.color = '#27ae60';
|
||||
updateConfirmState();
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Pause countdown on tab/window inactive ----
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (!isRegistrationMode) return;
|
||||
countdownPaused = document.hidden;
|
||||
});
|
||||
window.addEventListener('blur', function () {
|
||||
if (isRegistrationMode) countdownPaused = true;
|
||||
});
|
||||
window.addEventListener('focus', function () {
|
||||
if (isRegistrationMode) countdownPaused = false;
|
||||
});
|
||||
|
||||
// ---- Update Confirm Button ----
|
||||
function updateConfirmState() {
|
||||
if (countdown <= 0 && reachedBottom) {
|
||||
confirmBtn.disabled = false;
|
||||
scrollHint.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Confirm (agree to guidelines) ----
|
||||
confirmBtn.addEventListener('click', function () {
|
||||
agreed = true;
|
||||
modalOverlay.classList.remove('active');
|
||||
if (modalOverlay._onAgreed) {
|
||||
modalOverlay._onAgreed();
|
||||
modalOverlay._onAgreed = null;
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Close Modal ----
|
||||
modalClose.addEventListener('click', function () {
|
||||
modalOverlay.classList.remove('active');
|
||||
});
|
||||
previewCloseBtn.addEventListener('click', function () {
|
||||
modalOverlay.classList.remove('active');
|
||||
});
|
||||
modalOverlay.addEventListener('click', function (e) {
|
||||
if (e.target === modalOverlay) {
|
||||
modalOverlay.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Open Guidelines Link (preview only) ----
|
||||
openGuidelines.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
openModal(null);
|
||||
});
|
||||
|
||||
// ---- Form Validation ----
|
||||
function checkFormValidity() {
|
||||
var email = emailInput.value.trim();
|
||||
var password = passwordInput.value;
|
||||
var confirm = confirmPasswordInput.value;
|
||||
var emailValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||
var passwordValid = password.length >= 8 && /[a-zA-Z]/.test(password) && /\d/.test(password);
|
||||
var confirmValid = passwordValid && confirm === password;
|
||||
submitBtn.disabled = !(emailValid && passwordValid && confirmValid);
|
||||
}
|
||||
|
||||
emailInput.addEventListener('input', function () {
|
||||
var v = emailInput.value.trim();
|
||||
if (v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v)) {
|
||||
emailInput.classList.add('error');
|
||||
emailError.style.display = 'block';
|
||||
} else {
|
||||
emailInput.classList.remove('error');
|
||||
emailError.style.display = 'none';
|
||||
}
|
||||
checkFormValidity();
|
||||
});
|
||||
|
||||
passwordInput.addEventListener('input', function () {
|
||||
var v = passwordInput.value;
|
||||
if (v && (v.length < 8 || !/[a-zA-Z]/.test(v) || !/\d/.test(v))) {
|
||||
passwordInput.classList.add('error');
|
||||
passwordError.style.display = 'block';
|
||||
} else {
|
||||
passwordInput.classList.remove('error');
|
||||
passwordError.style.display = 'none';
|
||||
}
|
||||
if (confirmPasswordInput.value) {
|
||||
validateConfirmPassword();
|
||||
}
|
||||
checkFormValidity();
|
||||
});
|
||||
|
||||
confirmPasswordInput.addEventListener('input', function () {
|
||||
validateConfirmPassword();
|
||||
checkFormValidity();
|
||||
});
|
||||
|
||||
function validateConfirmPassword() {
|
||||
var confirm = confirmPasswordInput.value;
|
||||
var password = passwordInput.value;
|
||||
if (confirm && confirm !== password) {
|
||||
confirmPasswordInput.classList.add('error');
|
||||
confirmPasswordError.style.display = 'block';
|
||||
} else {
|
||||
confirmPasswordInput.classList.remove('error');
|
||||
confirmPasswordError.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Form Submit: validate → check email → open guidelines → on agree → submit ----
|
||||
registerForm.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var email = emailInput.value.trim();
|
||||
var password = passwordInput.value;
|
||||
var confirm = confirmPasswordInput.value;
|
||||
|
||||
// Client-side validation
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
emailInput.classList.add('error');
|
||||
emailError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
if (password.length < 8 || !/[a-zA-Z]/.test(password) || !/\d/.test(password)) {
|
||||
passwordInput.classList.add('error');
|
||||
passwordError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
if (confirm !== password) {
|
||||
confirmPasswordInput.classList.add('error');
|
||||
confirmPasswordError.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable submit to prevent double-click
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = '检查中...';
|
||||
|
||||
// Step 1: Check if email already registered (before showing 60s guidelines)
|
||||
var checkXhr = new XMLHttpRequest();
|
||||
checkXhr.open('POST', '/api/auth/check-email', true);
|
||||
checkXhr.setRequestHeader('Content-Type', 'application/json');
|
||||
checkXhr.onreadystatechange = function () {
|
||||
if (checkXhr.readyState !== 4) return;
|
||||
|
||||
submitBtn.disabled = true; // will be re-enabled by checkFormValidity if needed
|
||||
|
||||
var resp;
|
||||
try { resp = JSON.parse(checkXhr.responseText); } catch (err) { resp = null; }
|
||||
|
||||
if (checkXhr.status === 200 && resp && resp.success) {
|
||||
if (resp.data && resp.data.exists) {
|
||||
// Already registered → notify user immediately, skip guidelines
|
||||
window.MetaLab.toast(toast, '该邮箱已注册,请直接登录', true);
|
||||
submitBtn.textContent = '注 册';
|
||||
submitBtn.disabled = false;
|
||||
} else {
|
||||
// Not registered → proceed to guidelines modal
|
||||
submitBtn.textContent = '注 册';
|
||||
openModal(function () {
|
||||
doRegister(email, password, confirm);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// API error → show message, don't block
|
||||
var msg = (resp && resp.message) ? resp.message : '网络异常,请稍后重试';
|
||||
window.MetaLab.toast(toast, msg, true);
|
||||
submitBtn.textContent = '注 册';
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
};
|
||||
checkXhr.send(JSON.stringify({ email: email }));
|
||||
});
|
||||
|
||||
// ---- AJAX Register ----
|
||||
function doRegister(email, password, confirmPassword) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/api/auth/register', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
var resp;
|
||||
try { resp = JSON.parse(xhr.responseText); } catch (err) { resp = null; }
|
||||
|
||||
if (xhr.status === 200 && resp && resp.success) {
|
||||
window.MetaLab.toast(toast, '🎉 注册成功!欢迎加入 MetaLab', false);
|
||||
// Token 已通过 HttpOnly Cookie 自动设置,JS 无需处理
|
||||
// 注册即登录,跳转首页
|
||||
setTimeout(function () {
|
||||
window.location.href = '/';
|
||||
}, 1500);
|
||||
} else {
|
||||
var msg = (resp && resp.message) ? resp.message : '注册失败,请稍后重试';
|
||||
window.MetaLab.toast(toast, msg, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(JSON.stringify({
|
||||
email: email,
|
||||
password: password,
|
||||
confirm_password: confirmPassword,
|
||||
remember_me: rememberMeCheckbox.checked
|
||||
}));
|
||||
}
|
||||
})();
|
||||
9
templates/MetaLab-2026/theme.json
Normal file
9
templates/MetaLab-2026/theme.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "MetaLab-2026",
|
||||
"display_name": "MetaLab 2026 标准主题",
|
||||
"version": "1.0.0",
|
||||
"author": "MetaZone",
|
||||
"description": "默认社区主题,清爽简约",
|
||||
"preview": "preview.png",
|
||||
"compatible_version": ">=1.0.0"
|
||||
}
|
||||
30
templates/admin/html/dashboard/index.html
Normal file
30
templates/admin/html/dashboard/index.html
Normal file
@ -0,0 +1,30 @@
|
||||
{{template "admin/layout/base.html" .}}
|
||||
<div class="page-header">
|
||||
<h1>欢迎,{{.Username}}</h1>
|
||||
<p class="page-desc">MetaLab 管理控制面板</p>
|
||||
</div>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-blue"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 4-7 8-7s8 3 8 7"/></svg></div>
|
||||
<div class="stat-info"><div class="stat-label">用户总数</div><div class="stat-value">—</div></div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-green"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18"/><line x1="9" y1="9" x2="15" y2="9"/><line x1="9" y1="13" x2="15" y2="13"/></svg></div>
|
||||
<div class="stat-info"><div class="stat-label">帖子总数</div><div class="stat-value">—</div></div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon stat-orange"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg></div>
|
||||
<div class="stat-info"><div class="stat-label">当前角色</div><div class="stat-value">{{.Role}}</div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<h3>快速开始</h3>
|
||||
<ul>
|
||||
<li>在左侧导航选择管理模块</li>
|
||||
<li>使用「用户管理」查看、搜索和封禁用户</li>
|
||||
<li>使用「返回前台」链接回到主站</li>
|
||||
</ul>
|
||||
</div>
|
||||
{{template "admin/layout/footer.html" .}}
|
||||
38
templates/admin/html/layout/base.html
Normal file
38
templates/admin/html/layout/base.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{{if .CSRFToken}}<meta name="csrf-token" content="{{.CSRFToken}}">{{end}}
|
||||
<title>{{.Title}} - MetaLab CP</title>
|
||||
<link rel="stylesheet" href="/admin/static/css/common.css">
|
||||
{{if .ExtraCSS}}
|
||||
<link rel="stylesheet" href="{{.ExtraCSS}}">
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<header class="admin-header">
|
||||
<div class="admin-header-inner">
|
||||
<a href="/admin" class="admin-logo">MetaLab <span>管理面板</span></a>
|
||||
<div class="admin-header-right">
|
||||
<span class="admin-user">{{.Username}}</span>
|
||||
<a href="/" class="admin-back-btn">← 返回前台</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-container">
|
||||
<aside class="admin-sidebar">
|
||||
<nav>
|
||||
<a href="/admin" class="sidebar-item {{if eq .CurrentPath "/admin"}}active{{end}}">
|
||||
<span class="sidebar-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg></span>
|
||||
管理首页
|
||||
</a>
|
||||
{{if .CanManageUsers}}
|
||||
<a href="/admin/users" class="sidebar-item {{if eq .CurrentPath "/admin/users"}}active{{end}}">
|
||||
<span class="sidebar-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 4-7 8-7s8 3 8 7"/></svg></span>
|
||||
用户管理
|
||||
</a>
|
||||
{{end}}
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="admin-main">
|
||||
8
templates/admin/html/layout/footer.html
Normal file
8
templates/admin/html/layout/footer.html
Normal file
@ -0,0 +1,8 @@
|
||||
</main>
|
||||
</div>
|
||||
<script src="/admin/static/js/common.js"></script>
|
||||
{{if .ExtraJS}}
|
||||
<script src="{{.ExtraJS}}"></script>
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
||||
50
templates/admin/html/users/index.html
Normal file
50
templates/admin/html/users/index.html
Normal file
@ -0,0 +1,50 @@
|
||||
{{template "admin/layout/base.html" .}}
|
||||
<div class="page-header">
|
||||
<h1>用户管理</h1>
|
||||
<p class="page-desc">搜索、查看和管理本站用户</p>
|
||||
</div>
|
||||
|
||||
<!-- 搜索与筛选 -->
|
||||
<div class="filter-bar">
|
||||
<input type="text" id="searchInput" class="filter-input" placeholder="搜索邮箱或用户名..." autocomplete="off">
|
||||
<select id="roleFilter" class="filter-select">
|
||||
<option value="">全部角色</option>
|
||||
<option value="user">普通用户</option>
|
||||
<option value="moderator">版主</option>
|
||||
<option value="admin">管理员</option>
|
||||
<option value="owner">站长</option>
|
||||
</select>
|
||||
<select id="statusFilter" class="filter-select">
|
||||
<option value="">全部状态</option>
|
||||
<option value="active">正常</option>
|
||||
<option value="banned">已封禁</option>
|
||||
<option value="deleted">已注销</option>
|
||||
<option value="locked">已锁定</option>
|
||||
</select>
|
||||
<button id="searchBtn" class="btn btn-primary">搜索</button>
|
||||
</div>
|
||||
|
||||
<!-- 用户表格 -->
|
||||
<div class="table-container">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>UID</th>
|
||||
<th>用户名</th>
|
||||
<th>邮箱</th>
|
||||
<th>角色</th>
|
||||
<th>状态</th>
|
||||
<th>注册时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="userTableBody">
|
||||
<tr class="table-loading"><td colspan="7">加载中...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-bar" id="paginationBar"></div>
|
||||
<script>window.__currentUid = {{.UID}}; window.__isOwner = {{if .IsOwner}}true{{else}}false{{end}};</script>
|
||||
{{template "admin/layout/footer.html" .}}
|
||||
295
templates/admin/static/css/common.css
Normal file
295
templates/admin/static/css/common.css
Normal file
@ -0,0 +1,295 @@
|
||||
/* =====================================================
|
||||
MetaLab 管理面板 - 通用样式
|
||||
单一职责:布局、导航、通用组件(按钮/表格/卡片/弹窗等)
|
||||
不包含任何页面特有样式
|
||||
===================================================== */
|
||||
|
||||
/* --- 变量 --- */
|
||||
:root {
|
||||
--bg: #f5f6fa;
|
||||
--bg-card: #ffffff;
|
||||
--text: #2d3436;
|
||||
--text-muted: #636e72;
|
||||
--border: #e0e0e0;
|
||||
--primary: #0984e3;
|
||||
--primary-hover: #0773c5;
|
||||
--danger: #d63031;
|
||||
--danger-hover: #c0392b;
|
||||
--success: #00b894;
|
||||
--warning: #e17055;
|
||||
--sidebar-bg: #1e272e;
|
||||
--sidebar-text: #b2bec3;
|
||||
--sidebar-active: #0984e3;
|
||||
--header-bg: #2d3436;
|
||||
--radius: 6px;
|
||||
--shadow: 0 1px 3px rgba(0,0,0,0.08);
|
||||
}
|
||||
|
||||
/* --- 重置 --- */
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
line-height: 1.6;
|
||||
}
|
||||
a { color: var(--primary); text-decoration: none; }
|
||||
a:hover { color: var(--primary-hover); }
|
||||
|
||||
/* --- 顶部导航 --- */
|
||||
.admin-header {
|
||||
background: var(--header-bg);
|
||||
color: #fff;
|
||||
height: 52px;
|
||||
position: fixed; top: 0; left: 0; right: 0;
|
||||
z-index: 100;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
||||
}
|
||||
.admin-header-inner {
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
padding: 0 20px;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
}
|
||||
.admin-logo {
|
||||
font-size: 18px; font-weight: 700;
|
||||
color: #fff; letter-spacing: 0.5px;
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
}
|
||||
.admin-logo span {
|
||||
font-weight: 400; font-size: 14px;
|
||||
color: var(--sidebar-text);
|
||||
}
|
||||
.admin-logo:hover { color: #fff; }
|
||||
.admin-header-right {
|
||||
display: flex; align-items: center; gap: 16px;
|
||||
}
|
||||
.admin-user { color: #dfe6e9; font-size: 13px; }
|
||||
.admin-back-btn {
|
||||
font-size: 12px; color: #b2bec3;
|
||||
padding: 4px 10px; border: 1px solid #636e72;
|
||||
border-radius: 4px; transition: all 0.2s;
|
||||
}
|
||||
.admin-back-btn:hover { color: #fff; border-color: #fff; }
|
||||
|
||||
/* --- 整体布局 --- */
|
||||
.admin-container {
|
||||
display: flex;
|
||||
margin-top: 52px;
|
||||
min-height: calc(100vh - 52px);
|
||||
}
|
||||
|
||||
/* --- 侧边栏 --- */
|
||||
.admin-sidebar {
|
||||
width: 200px; min-width: 200px;
|
||||
background: var(--sidebar-bg);
|
||||
padding: 16px 0;
|
||||
position: sticky; top: 52px;
|
||||
height: calc(100vh - 52px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.sidebar-item {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 10px 20px;
|
||||
color: var(--sidebar-text);
|
||||
font-size: 13px;
|
||||
transition: all 0.15s;
|
||||
border-left: 3px solid transparent;
|
||||
}
|
||||
.sidebar-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
|
||||
.sidebar-item.active {
|
||||
color: #fff; background: rgba(9,132,227,0.2);
|
||||
border-left-color: var(--sidebar-active);
|
||||
}
|
||||
.sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; }
|
||||
.sidebar-icon svg { width: 100%; height: 100%; }
|
||||
|
||||
/* --- 主内容区 --- */
|
||||
.admin-main {
|
||||
flex: 1; padding: 28px 32px;
|
||||
max-width: 1200px; min-width: 0;
|
||||
}
|
||||
|
||||
/* --- 页面标题 --- */
|
||||
.page-header { margin-bottom: 24px; }
|
||||
.page-header h1 { font-size: 22px; font-weight: 600; color: var(--text); }
|
||||
.page-desc { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
|
||||
|
||||
/* --- 统计卡片 --- */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.stat-card {
|
||||
background: var(--bg-card);
|
||||
border-radius: var(--radius);
|
||||
padding: 20px;
|
||||
box-shadow: var(--shadow);
|
||||
display: flex; align-items: center; gap: 16px;
|
||||
}
|
||||
.stat-icon {
|
||||
width: 44px; height: 44px; border-radius: 10px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.stat-icon svg { width: 24px; height: 24px; }
|
||||
.stat-blue { background: #e3f2fd; color: var(--primary); }
|
||||
.stat-green { background: #e8f5e9; color: var(--success); }
|
||||
.stat-orange { background: #fff3e0; color: var(--warning); }
|
||||
.stat-label { font-size: 12px; color: var(--text-muted); }
|
||||
.stat-value { font-size: 22px; font-weight: 600; color: var(--text); }
|
||||
|
||||
/* --- 信息卡片 --- */
|
||||
.info-card {
|
||||
background: var(--bg-card);
|
||||
border-radius: var(--radius);
|
||||
padding: 20px 24px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.info-card h3 { font-size: 16px; margin-bottom: 12px; }
|
||||
.info-card ul { padding-left: 20px; color: var(--text-muted); font-size: 13px; line-height: 2; }
|
||||
|
||||
/* --- 筛选栏 --- */
|
||||
.filter-bar {
|
||||
display: flex; gap: 10px; margin-bottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.filter-input {
|
||||
flex: 1; min-width: 180px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
.filter-input:focus { border-color: var(--primary); }
|
||||
.filter-select {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.filter-select:focus { border-color: var(--primary); }
|
||||
|
||||
/* --- 按钮 --- */
|
||||
.btn {
|
||||
padding: 8px 18px; border: none; border-radius: var(--radius);
|
||||
font-size: 13px; cursor: pointer; transition: all 0.2s;
|
||||
font-weight: 500;
|
||||
}
|
||||
.btn-primary { background: var(--primary); color: #fff; }
|
||||
.btn-primary:hover { background: var(--primary-hover); }
|
||||
.btn-danger { background: var(--danger); color: #fff; }
|
||||
.btn-danger:hover { background: var(--danger-hover); }
|
||||
.btn-sm { padding: 5px 12px; font-size: 12px; }
|
||||
.btn-outline {
|
||||
background: transparent; border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
}
|
||||
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
/* --- 表格容器 --- */
|
||||
.table-container {
|
||||
background: var(--bg-card);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/* --- 数据表格 --- */
|
||||
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
.data-table th {
|
||||
text-align: left; padding: 12px 16px;
|
||||
background: #fafafa; color: var(--text-muted);
|
||||
font-weight: 600; font-size: 12px; text-transform: uppercase;
|
||||
letter-spacing: 0.5px; border-bottom: 2px solid var(--border);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.data-table td {
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.data-table tbody tr:hover { background: #f8f9ff; }
|
||||
.table-loading td { text-align: center; padding: 40px; color: var(--text-muted); }
|
||||
|
||||
/* --- 状态标签 --- */
|
||||
.badge {
|
||||
display: inline-block; padding: 2px 8px;
|
||||
border-radius: 12px; font-size: 11px; font-weight: 600;
|
||||
}
|
||||
.badge-active { background: #e8f5e9; color: var(--success); }
|
||||
.badge-banned { background: #ffebee; color: var(--danger); }
|
||||
.badge-deleted { background: #fff3e0; color: var(--warning); }
|
||||
.badge-locked { background: #eceff1; color: #546e7a; }
|
||||
|
||||
/* --- 角色标签 --- */
|
||||
.role-tag {
|
||||
display: inline-block; padding: 2px 8px;
|
||||
border-radius: 4px; font-size: 11px; font-weight: 600;
|
||||
}
|
||||
.role-user { background: #e3f2fd; color: #1976d2; }
|
||||
.role-moderator { background: #e8f5e9; color: #2e7d32; }
|
||||
.role-admin { background: #fce4ec; color: #c62828; }
|
||||
.role-owner { background: #fff3e0; color: #e65100; }
|
||||
|
||||
/* --- 操作按钮组 --- */
|
||||
.action-group { display: flex; gap: 6px; }
|
||||
|
||||
/* --- 分页 --- */
|
||||
.pagination-bar {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
gap: 8px; margin-top: 20px;
|
||||
}
|
||||
.pagination-bar button {
|
||||
padding: 6px 14px; border: 1px solid var(--border);
|
||||
background: #fff; border-radius: 4px; font-size: 13px;
|
||||
cursor: pointer; transition: all 0.15s;
|
||||
}
|
||||
.pagination-bar button:hover:not(:disabled) {
|
||||
border-color: var(--primary); color: var(--primary);
|
||||
}
|
||||
.pagination-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.pagination-bar .page-current {
|
||||
padding: 6px 14px; font-size: 13px; color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* --- 确认弹窗 --- */
|
||||
.modal-overlay {
|
||||
display: none; position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.4); z-index: 200;
|
||||
align-items: center; justify-content: center;
|
||||
}
|
||||
.modal-overlay.show { display: flex; }
|
||||
.modal-box {
|
||||
background: #fff; border-radius: 8px;
|
||||
padding: 28px 32px; min-width: 340px;
|
||||
box-shadow: 0 8px 30px rgba(0,0,0,0.15);
|
||||
}
|
||||
.modal-box h3 { margin-bottom: 12px; font-size: 17px; }
|
||||
.modal-box p { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
|
||||
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
|
||||
|
||||
/* --- Toast 通知 --- */
|
||||
.toast-container {
|
||||
position: fixed; top: 64px; right: 20px;
|
||||
z-index: 300; display: flex; flex-direction: column; gap: 8px;
|
||||
}
|
||||
.toast {
|
||||
padding: 12px 20px; border-radius: 6px;
|
||||
font-size: 13px; color: #fff; font-weight: 500;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
||||
animation: toastIn 0.3s ease;
|
||||
max-width: 360px;
|
||||
}
|
||||
.toast-success { background: var(--success); }
|
||||
.toast-error { background: var(--danger); }
|
||||
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
|
||||
12
templates/admin/static/css/users.css
Normal file
12
templates/admin/static/css/users.css
Normal file
@ -0,0 +1,12 @@
|
||||
/* =====================================================
|
||||
MetaLab 管理面板 - 用户管理页样式
|
||||
单一职责:仅用户管理页面特有样式
|
||||
===================================================== */
|
||||
|
||||
.data-table .col-uid { width: 60px; }
|
||||
.data-table .col-username { width: 120px; }
|
||||
.data-table .col-email { min-width: 180px; }
|
||||
.data-table .col-role { width: 90px; }
|
||||
.data-table .col-status { width: 90px; }
|
||||
.data-table .col-time { width: 140px; }
|
||||
.data-table .col-actions { width: 160px; }
|
||||
122
templates/admin/static/js/common.js
Normal file
122
templates/admin/static/js/common.js
Normal file
@ -0,0 +1,122 @@
|
||||
/* =====================================================
|
||||
MetaLab 管理面板 - 通用 JS
|
||||
单一职责:AJAX 封装、Toast 通知、确认弹窗
|
||||
不包含任何页面特有逻辑
|
||||
===================================================== */
|
||||
|
||||
// --- AJAX 封装 ---
|
||||
const api = {
|
||||
async get(url) {
|
||||
const res = await fetch(url, {
|
||||
headers: { 'Accept': 'application/json' }
|
||||
});
|
||||
return res.json();
|
||||
},
|
||||
async put(url, body) {
|
||||
const res = await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': getCSRFToken()
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
return res.json();
|
||||
},
|
||||
async post(url, body) {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': getCSRFToken()
|
||||
},
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
};
|
||||
|
||||
function getCSRFToken() {
|
||||
const meta = document.querySelector('meta[name="csrf-token"]');
|
||||
return meta ? meta.getAttribute('content') : '';
|
||||
}
|
||||
|
||||
// --- Toast 通知 ---
|
||||
function showToast(message, type) {
|
||||
const container = document.querySelector('.toast-container') || createToastContainer();
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
toast.textContent = message;
|
||||
container.appendChild(toast);
|
||||
setTimeout(() => {
|
||||
toast.style.opacity = '0';
|
||||
toast.style.transition = 'opacity 0.3s';
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function createToastContainer() {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'toast-container';
|
||||
document.body.appendChild(el);
|
||||
return el;
|
||||
}
|
||||
|
||||
// --- 确认弹窗 ---
|
||||
function showConfirm(title, message) {
|
||||
return new Promise((resolve) => {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay show';
|
||||
overlay.innerHTML = `
|
||||
<div class="modal-box">
|
||||
<h3>${escapeHtml(title)}</h3>
|
||||
<p>${escapeHtml(message)}</p>
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-outline" id="modalCancel">取消</button>
|
||||
<button class="btn btn-danger" id="modalConfirm">确认</button>
|
||||
</div>
|
||||
</div>`;
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
overlay.querySelector('#modalCancel').onclick = () => {
|
||||
overlay.remove();
|
||||
resolve(false);
|
||||
};
|
||||
overlay.querySelector('#modalConfirm').onclick = () => {
|
||||
overlay.remove();
|
||||
resolve(true);
|
||||
};
|
||||
overlay.addEventListener('click', (e) => {
|
||||
if (e.target === overlay) { overlay.remove(); resolve(false); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// --- 时间格式化 ---
|
||||
function formatTime(isoStr) {
|
||||
if (!isoStr) return '—';
|
||||
const d = new Date(isoStr);
|
||||
return d.getFullYear() + '-' +
|
||||
String(d.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(d.getDate()).padStart(2, '0') + ' ' +
|
||||
String(d.getHours()).padStart(2, '0') + ':' +
|
||||
String(d.getMinutes()).padStart(2, '0');
|
||||
}
|
||||
|
||||
// --- 角色标签 ---
|
||||
function roleLabel(role) {
|
||||
const map = { user: '普通用户', moderator: '版主', admin: '管理员', owner: '站长' };
|
||||
return `<span class="role-tag role-${role}">${map[role] || role}</span>`;
|
||||
}
|
||||
|
||||
// --- 状态标签 ---
|
||||
function statusLabel(status) {
|
||||
const map = { active: '正常', banned: '已封禁', deleted: '已注销', locked: '已锁定' };
|
||||
return `<span class="badge badge-${status}">${map[status] || status}</span>`;
|
||||
}
|
||||
156
templates/admin/static/js/users.js
Normal file
156
templates/admin/static/js/users.js
Normal file
@ -0,0 +1,156 @@
|
||||
/* =====================================================
|
||||
MetaLab 管理面板 - 用户管理 JS
|
||||
单一职责:用户列表渲染、搜索筛选、封禁/解封、强制下线
|
||||
===================================================== */
|
||||
|
||||
let currentPage = 1;
|
||||
const pageSize = 20;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadUsers();
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', () => {
|
||||
currentPage = 1;
|
||||
loadUsers();
|
||||
});
|
||||
document.getElementById('searchInput').addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') { currentPage = 1; loadUsers(); }
|
||||
});
|
||||
document.getElementById('roleFilter').addEventListener('change', () => {
|
||||
currentPage = 1; loadUsers();
|
||||
});
|
||||
document.getElementById('statusFilter').addEventListener('change', () => {
|
||||
currentPage = 1; loadUsers();
|
||||
});
|
||||
});
|
||||
|
||||
async function loadUsers() {
|
||||
const keyword = document.getElementById('searchInput').value.trim();
|
||||
const role = document.getElementById('roleFilter').value;
|
||||
const status = document.getElementById('statusFilter').value;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
page: currentPage,
|
||||
page_size: pageSize,
|
||||
keyword, role, status
|
||||
});
|
||||
|
||||
try {
|
||||
const res = await api.get('/api/admin/users?' + params);
|
||||
if (res.success) {
|
||||
renderTable(res.data.users);
|
||||
renderPagination(res.data.total, res.data.page);
|
||||
} else {
|
||||
showToast(res.message || '加载失败', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showToast('网络错误', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function renderTable(users) {
|
||||
const tbody = document.getElementById('userTableBody');
|
||||
if (!users || users.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;padding:40px;color:#636e72;">没有找到用户</td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = users.map(u => `
|
||||
<tr>
|
||||
<td class="col-uid">${u.uid}</td>
|
||||
<td class="col-username">${escapeHtml(u.username)}</td>
|
||||
<td class="col-email">${escapeHtml(u.email)}</td>
|
||||
<td class="col-role">${roleLabel(u.role)}</td>
|
||||
<td class="col-status">${statusLabel(u.status)}</td>
|
||||
<td class="col-time">${formatTime(u.created_at)}</td>
|
||||
<td class="col-actions">
|
||||
<div class="action-group">
|
||||
${renderActions(u)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function renderActions(u) {
|
||||
// 不可操作自己
|
||||
if (u.uid === window.__currentUid) return '—';
|
||||
|
||||
let btns = '';
|
||||
const isOwner = window.__isOwner || false;
|
||||
// 封禁/解封按钮
|
||||
if (u.status === 'active') {
|
||||
btns += `<button class="btn btn-danger btn-sm" onclick="banUser(${u.uid}, '${escapeHtml(u.username)}')">封禁</button>`;
|
||||
} else if (u.status === 'banned') {
|
||||
btns += `<button class="btn btn-outline btn-sm" onclick="unbanUser(${u.uid}, '${escapeHtml(u.username)}')">解封</button>`;
|
||||
}
|
||||
// 强制下线按钮
|
||||
if (u.status === 'active' || u.status === 'banned') {
|
||||
btns += `<button class="btn btn-outline btn-sm" onclick="resetToken(${u.uid}, '${escapeHtml(u.username)}')">踢下线</button>`;
|
||||
}
|
||||
// 删除按钮(仅 owner 可见,且目标不是 locked/deleted)
|
||||
if (isOwner && u.status !== 'locked' && u.status !== 'deleted') {
|
||||
btns += `<button class="btn btn-danger btn-sm" onclick="deleteUser(${u.uid}, '${escapeHtml(u.username)}')">删除</button>`;
|
||||
}
|
||||
// 解锁按钮(仅 owner 可见,状态为 locked)
|
||||
if (isOwner && u.status === 'locked') {
|
||||
btns += `<button class="btn btn-outline btn-sm" onclick="unlockUser(${u.uid}, '${escapeHtml(u.username)}')">解锁</button>`;
|
||||
}
|
||||
return btns || '—';
|
||||
}
|
||||
|
||||
async function banUser(uid, username) {
|
||||
const ok = await showConfirm('封禁用户', `确定要封禁用户「${username}」吗?封禁后该用户将无法登录。`);
|
||||
if (!ok) return;
|
||||
const res = await api.put(`/api/admin/users/${uid}/status`, { status: 'banned' });
|
||||
if (res.success) { showToast(res.message, 'success'); loadUsers(); }
|
||||
else { showToast(res.message || '操作失败', 'error'); }
|
||||
}
|
||||
|
||||
async function unbanUser(uid, username) {
|
||||
const ok = await showConfirm('解封用户', `确定要解封用户「${username}」吗?`);
|
||||
if (!ok) return;
|
||||
const res = await api.put(`/api/admin/users/${uid}/status`, { status: 'active' });
|
||||
if (res.success) { showToast(res.message, 'success'); loadUsers(); }
|
||||
else { showToast(res.message || '操作失败', 'error'); }
|
||||
}
|
||||
|
||||
async function deleteUser(uid, username) {
|
||||
const ok = await showConfirm('删除用户', `确定要永久删除用户「${username}」吗?此操作不可撤销,该账号将被立即锁定。`);
|
||||
if (!ok) return;
|
||||
const res = await api.put(`/api/admin/users/${uid}/status`, { status: 'locked' });
|
||||
if (res.success) { showToast(res.message, 'success'); loadUsers(); }
|
||||
else { showToast(res.message || '操作失败', 'error'); }
|
||||
}
|
||||
|
||||
async function unlockUser(uid, username) {
|
||||
const ok = await showConfirm('解锁用户', `确定要解锁用户「${username}」吗?该账号将恢复为正常状态。`);
|
||||
if (!ok) return;
|
||||
const res = await api.put(`/api/admin/users/${uid}/status`, { status: 'active' });
|
||||
if (res.success) { showToast(res.message, 'success'); loadUsers(); }
|
||||
else { showToast(res.message || '操作失败', 'error'); }
|
||||
}
|
||||
|
||||
async function resetToken(uid, username) {
|
||||
const ok = await showConfirm('强制下线', `确定要强制「${username}」下线吗?该用户需要重新登录。`);
|
||||
if (!ok) return;
|
||||
const res = await api.post(`/api/admin/users/${uid}/reset-token`);
|
||||
if (res.success) { showToast(res.message, 'success'); }
|
||||
else { showToast(res.message || '操作失败', 'error'); }
|
||||
}
|
||||
|
||||
function renderPagination(total, page) {
|
||||
const totalPages = Math.ceil(total / pageSize);
|
||||
const bar = document.getElementById('paginationBar');
|
||||
if (totalPages <= 1) { bar.innerHTML = ''; return; }
|
||||
|
||||
let html = `<button onclick="goPage(${page - 1})" ${page <= 1 ? 'disabled' : ''}>上一页</button>`;
|
||||
html += `<span class="page-current">第 ${page} / ${totalPages} 页(共 ${total} 条)</span>`;
|
||||
html += `<button onclick="goPage(${page + 1})" ${page >= totalPages ? 'disabled' : ''}>下一页</button>`;
|
||||
bar.innerHTML = html;
|
||||
}
|
||||
|
||||
function goPage(p) {
|
||||
currentPage = p;
|
||||
loadUsers();
|
||||
window.scrollTo({ top: 0 });
|
||||
}
|
||||
Reference in New Issue
Block a user