3573 lines
201 KiB
HTML
3573 lines
201 KiB
HTML
{% extends "base_tailwind.html" %}
|
||
|
||
{% block title %}管理后台 - {{ brand_name }}{% endblock %}
|
||
|
||
{% block extra_css %}
|
||
<style>
|
||
/* 管理后台专用:覆盖 base 的动画时长,调慢到 0.45s */
|
||
.list-item-enter {
|
||
animation-duration: 0.45s !important;
|
||
}
|
||
/* tab 面板切换淡入 */
|
||
@keyframes tabPanelEnter {
|
||
from { opacity: 0; transform: translateY(10px); }
|
||
to { opacity: 1; transform: translateY(0); }
|
||
}
|
||
.tab-panel-enter {
|
||
animation: tabPanelEnter 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
|
||
}
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.tab-panel-enter { animation: none !important; opacity: 1 !important; }
|
||
}
|
||
</style>
|
||
{% endblock %}
|
||
|
||
{% block content %}
|
||
<div class="space-y-6">
|
||
<!-- 页面标题 -->
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 list-item-enter" style="animation-delay: 0ms;">
|
||
<div>
|
||
<h1 class="text-2xl md:text-3xl font-bold text-neutral-900 dark:text-white">管理后台</h1>
|
||
<p class="text-neutral-500 dark:text-neutral-400 mt-1">用户管理、系统监控和注册码管理</p>
|
||
</div>
|
||
<div class="flex gap-3 flex-wrap">
|
||
<button onclick="openCreateUserModal()" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
|
||
</svg>
|
||
添加用户
|
||
</button>
|
||
<button onclick="openCreateTicketModal()" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 5v2m0 4v2m0 4v2M5 5a2 2 0 00-2 2v3a2 2 0 110 4v3a2 2 0 002 2h14a2 2 0 002-2v-3a2 2 0 110-4V7a2 2 0 00-2-2H5z"></path>
|
||
</svg>
|
||
生成注册码
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 统计卡片 -->
|
||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 80ms;">
|
||
<div class="flex items-center justify-between">
|
||
<div>
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">总用户数</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statTotalUsers">-</p>
|
||
</div>
|
||
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center">
|
||
<svg class="w-5 h-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path>
|
||
</svg>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 140ms;">
|
||
<div class="flex items-center justify-between">
|
||
<div>
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statTotalTasks">-</p>
|
||
</div>
|
||
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center">
|
||
<svg class="w-5 h-5 text-amber-600 dark:text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
|
||
</svg>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 200ms;">
|
||
<div class="flex items-center justify-between">
|
||
<div>
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">运行中</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statRunningTasks">-</p>
|
||
</div>
|
||
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center">
|
||
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 260ms;">
|
||
<div class="flex items-center justify-between">
|
||
<div>
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">成功任务</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statSuccessTasks">-</p>
|
||
</div>
|
||
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center">
|
||
<svg class="w-5 h-5 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Session 状态和管理 -->
|
||
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 320ms;">
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
|
||
</svg>
|
||
Session 状态
|
||
</h3>
|
||
<div class="flex gap-4 mt-2 text-sm">
|
||
<span class="text-green-600 dark:text-green-400">
|
||
<span class="w-2 h-2 bg-green-500 rounded-full inline-block mr-1"></span>
|
||
有效: <strong id="sessionValid">-</strong>
|
||
</span>
|
||
<span class="text-red-600 dark:text-red-400">
|
||
<span class="w-2 h-2 bg-red-500 rounded-full inline-block mr-1"></span>
|
||
过期: <strong id="sessionInvalid">-</strong>
|
||
</span>
|
||
<span class="text-neutral-500 dark:text-neutral-400">
|
||
<span class="w-2 h-2 bg-neutral-400 rounded-full inline-block mr-1"></span>
|
||
未知: <strong id="sessionUnknown">-</strong>
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3">
|
||
<button onclick="batchCheckSession()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
|
||
</svg>
|
||
批量检查
|
||
</button>
|
||
<button onclick="showBatchRefreshModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
批量刷新
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 多线路 & 选课模式 -->
|
||
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 350ms;">
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||
d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
多线路 & 选课模式
|
||
</h3>
|
||
<div class="flex flex-wrap items-center gap-4 mt-2 text-sm">
|
||
<label class="flex items-center gap-2 text-neutral-500 dark:text-neutral-400">
|
||
学校:
|
||
<select id="mlSchool" onchange="mlRefreshStatus()" class="input-field !w-auto !py-1.5 text-sm"></select>
|
||
</label>
|
||
<span class="text-neutral-500 dark:text-neutral-400">
|
||
当前线路: <strong id="mlCurrentLine" class="text-neutral-900 dark:text-white">-</strong>
|
||
</span>
|
||
<span class="text-neutral-500 dark:text-neutral-400">
|
||
预热账号: <strong id="mlAccounts" class="text-neutral-900 dark:text-white">-</strong>
|
||
</span>
|
||
</div>
|
||
<div id="mlLinesBox" class="flex flex-wrap gap-2 mt-3 text-xs"></div>
|
||
</div>
|
||
<div class="flex flex-col gap-3 items-stretch md:items-end">
|
||
<label class="flex items-center gap-3 cursor-pointer select-none justify-between md:justify-end">
|
||
<span class="text-sm font-medium text-neutral-700 dark:text-neutral-200">多线路 Session 预热</span>
|
||
<span class="relative inline-block w-10 h-5 align-middle">
|
||
<input type="checkbox" id="mlToggle" onchange="mlSetEnabled(this.checked)" class="peer sr-only">
|
||
<span class="block w-10 h-5 rounded-full bg-neutral-300 dark:bg-neutral-600 peer-checked:bg-green-500 transition-colors"></span>
|
||
<span class="absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform peer-checked:translate-x-5 pointer-events-none"></span>
|
||
</span>
|
||
</label>
|
||
<label class="flex items-center gap-3 cursor-pointer select-none justify-between md:justify-end">
|
||
<span class="text-sm font-medium text-neutral-700 dark:text-neutral-200">选课模式(暂停其他服务)</span>
|
||
<span class="relative inline-block w-10 h-5 align-middle">
|
||
<input type="checkbox" id="xkModeToggle" onchange="xkModeSet(this.checked)" class="peer sr-only">
|
||
<span class="block w-10 h-5 rounded-full bg-neutral-300 dark:bg-neutral-600 peer-checked:bg-red-500 transition-colors"></span>
|
||
<span class="absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform peer-checked:translate-x-5 pointer-events-none"></span>
|
||
</span>
|
||
</label>
|
||
<div class="flex gap-2">
|
||
<button onclick="mlPrelogin()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
全量预热
|
||
</button>
|
||
<button onclick="mlRefreshStatus()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
|
||
刷新状态
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 标签页切换 -->
|
||
<div class="border-b border-neutral-200 dark:border-neutral-800 list-item-enter" style="animation-delay: 365ms;">
|
||
<nav class="flex gap-6">
|
||
<button onclick="switchTab('users')" id="tab-users" class="pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors">
|
||
用户管理
|
||
</button>
|
||
<button onclick="switchTab('ai')" id="tab-ai" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
AI 助手
|
||
</button>
|
||
<button onclick="switchTab('tickets')" id="tab-tickets" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
注册码管理
|
||
</button>
|
||
<button onclick="switchTab('schools')" id="tab-schools" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
学校管理
|
||
</button>
|
||
<button onclick="switchTab('affiliates')" id="tab-affiliates" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
推广码管理
|
||
</button>
|
||
<button onclick="switchTab('payments')" id="tab-payments" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
支付管理
|
||
</button>
|
||
<button onclick="switchTab('ip')" id="tab-ip" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
IP管理
|
||
</button>
|
||
<button onclick="switchTab('tasks')" id="tab-tasks" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
|
||
任务列表
|
||
</button>
|
||
</nav>
|
||
</div>
|
||
|
||
<div id="panel-schools" class="hidden space-y-4">
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">学校管理</h3>
|
||
<div id="schoolList" class="space-y-3 mb-6"></div>
|
||
<form id="schoolForm" onsubmit="saveSchool(event)" class="space-y-4">
|
||
<div><label class="input-label">学校标识(创建后不可修改)</label><input id="schoolId" class="input-field" required pattern="[A-Za-z0-9_-]+"></div>
|
||
<div><label class="input-label">学校名称</label><input id="schoolName" class="input-field" required></div>
|
||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||
<div><label class="input-label">品牌缩写(可选,默认取学校标识大写,用于标题/题头)</label><input id="schoolAbbr" class="input-field" maxlength="12" placeholder="如 SDMU / QCU"></div>
|
||
<div>
|
||
<label class="input-label">学校 ICO(可选,该校用户登录后浏览器标签图标)</label>
|
||
<div class="flex items-center gap-3 flex-wrap">
|
||
<img id="schoolFaviconPreview" class="w-9 h-9 rounded-lg border border-neutral-200 dark:border-neutral-700 object-cover hidden" alt="当前图标">
|
||
<input type="file" id="schoolFaviconFile" accept="image/png,image/jpeg,image/webp,image/gif,image/x-icon,image/svg+xml" class="hidden" onchange="uploadSchoolIcon(this)">
|
||
<button type="button" onclick="document.getElementById('schoolFaviconFile').click()" class="px-4 py-2 rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 text-sm hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">上传图片</button>
|
||
<button type="button" id="schoolFaviconClear" onclick="clearSchoolIcon()" class="px-4 py-2 rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 text-sm hover:bg-neutral-200 dark:hover:bg-neutral-700 transition hidden">清除</button>
|
||
<span id="schoolFaviconHint" class="text-xs text-neutral-500">PNG/JPG/WebP/GIF/ICO,≤1MB,建议正方形</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div><label class="input-label">线路地址(每行一个完整的教务系统基础 URL)</label><textarea id="schoolUrls" class="input-field font-mono text-sm" rows="4" required></textarea></div>
|
||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 items-center">
|
||
<label class="flex items-center gap-2 text-sm"><input id="schoolCaptcha" type="checkbox" checked>教务系统登录需要图片验证码</label>
|
||
<div>
|
||
<label class="input-label" for="schoolKbcxSource">课表来源</label>
|
||
<select id="schoolKbcxSource" class="input-field">
|
||
<option value="auto">自动(网页版优先,失败回退 Mobile)</option>
|
||
<option value="web">网页版接口(如青岛城市学院)</option>
|
||
<option value="mobile">Mobile 接口(正方 APP 接口)</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-2"><button type="submit" class="btn-primary px-5 py-2 rounded-full text-sm">保存学校</button><button type="button" onclick="newSchool()" class="px-5 py-2 rounded-full bg-neutral-100 dark:bg-neutral-800 text-sm">新增学校</button></div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 用户列表 -->
|
||
<div id="panel-users" class="space-y-4 tab-panel-enter" style="animation-delay: 430ms;">
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">用户列表</h3>
|
||
<button onclick="loadUsers()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<div id="usersLoading" class="text-center py-12">
|
||
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
|
||
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
|
||
</div>
|
||
|
||
<div id="usersEmpty" class="hidden text-center py-12">
|
||
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
|
||
</svg>
|
||
<p class="text-neutral-500">暂无用户</p>
|
||
</div>
|
||
|
||
<div id="usersTable" class="hidden overflow-x-auto">
|
||
<table class="data-table">
|
||
<thead>
|
||
<tr>
|
||
<th>ID</th>
|
||
<th>用户名</th>
|
||
<th>学校</th>
|
||
<th>学号</th>
|
||
<th>Session</th>
|
||
<th>角色</th>
|
||
<th>状态</th>
|
||
<th>创建时间</th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="usersTableBody">
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<!-- 分页 -->
|
||
<div id="usersPagination" class="hidden mt-4 flex justify-center gap-2">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 注册码列表 -->
|
||
<div id="panel-tickets" class="hidden space-y-4">
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">注册码列表</h3>
|
||
<p class="text-sm text-neutral-500 mt-1">
|
||
总计: <span id="ticketTotal">-</span> |
|
||
已使用: <span id="ticketUsed">-</span> |
|
||
可用: <span id="ticketAvailable">-</span>
|
||
</p>
|
||
</div>
|
||
<button onclick="loadTickets()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<div id="ticketsLoading" class="text-center py-12">
|
||
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
|
||
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
|
||
</div>
|
||
|
||
<div id="ticketsEmpty" class="hidden text-center py-12">
|
||
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 5v2m0 4v2m0 4v2M5 5a2 2 0 00-2 2v3a2 2 0 110 4v3a2 2 0 002 2h14a2 2 0 002-2v-3a2 2 0 110-4V7a2 2 0 00-2-2H5z"></path>
|
||
</svg>
|
||
<p class="text-neutral-500">暂无注册码</p>
|
||
</div>
|
||
|
||
<div id="ticketBatchBar" class="hidden flex items-center gap-2 mb-3 p-2 bg-neutral-100 dark:bg-neutral-800/60 rounded-xl">
|
||
<span class="text-sm text-neutral-600 dark:text-neutral-300 ml-1">已选 <span id="ticketSelectedCount">0</span> 项</span>
|
||
<div class="flex-1"></div>
|
||
<button onclick="batchTicketAction('disable')" class="px-3 py-1.5 rounded-lg bg-amber-500 text-white text-sm font-medium hover:opacity-90 transition">批量禁用</button>
|
||
<button onclick="batchTicketAction('enable')" class="px-3 py-1.5 rounded-lg bg-green-600 text-white text-sm font-medium hover:opacity-90 transition">批量启用</button>
|
||
<button onclick="batchTicketAction('delete')" class="px-3 py-1.5 rounded-lg bg-red-600 text-white text-sm font-medium hover:opacity-90 transition">批量删除</button>
|
||
<button onclick="copySelectedTickets()" class="px-3 py-1.5 rounded-lg bg-neutral-900 dark:bg-white text-white dark:text-black text-sm font-medium hover:shadow-lg transition">复制选中</button>
|
||
</div>
|
||
|
||
<div id="ticketsTable" class="hidden overflow-x-auto">
|
||
<table class="data-table">
|
||
<thead>
|
||
<tr>
|
||
<th><input type="checkbox" id="ticketSelectAll" class="w-4 h-4 rounded border-neutral-300" onchange="toggleSelectAllTickets(this.checked)"></th>
|
||
<th>注册码</th>
|
||
<th>适用学校</th>
|
||
<th>使用次数</th>
|
||
<th>已用/上限</th>
|
||
<th>状态</th>
|
||
<th>过期时间</th>
|
||
<th>创建时间</th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="ticketsTableBody">
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 推广码列表 -->
|
||
<div id="panel-affiliates" class="hidden space-y-4">
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">推广码列表</h3>
|
||
<p class="text-sm text-neutral-500 mt-1">
|
||
管理推广人、佣金比例和优惠金额
|
||
</p>
|
||
</div>
|
||
<div class="flex gap-2">
|
||
<button onclick="openCreateAffiliateModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
|
||
</svg>
|
||
添加推广人
|
||
</button>
|
||
<button onclick="loadAffiliates()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="affiliatesLoading" class="text-center py-12">
|
||
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
|
||
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
|
||
</div>
|
||
|
||
<div id="affiliatesEmpty" class="hidden text-center py-12">
|
||
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
|
||
</svg>
|
||
<p class="text-neutral-500">暂无推广人</p>
|
||
</div>
|
||
|
||
<div id="affiliatesTable" class="hidden overflow-x-auto">
|
||
<table class="data-table">
|
||
<thead>
|
||
<tr>
|
||
<th>推广码</th>
|
||
<th>推广人</th>
|
||
<th>佣金比例</th>
|
||
<th>优惠金额</th>
|
||
<th>创建时间</th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="affiliatesTableBody">
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 创建用户模态框 -->
|
||
<div id="createUserModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateUserModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">添加用户</h3>
|
||
<button onclick="closeCreateUserModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<form id="createUserForm" onsubmit="submitCreateUser(event)">
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="input-label">用户名(学号)</label>
|
||
<input type="text" id="newUsername" class="input-field" placeholder="请输入用户名" required>
|
||
</div>
|
||
<div>
|
||
<label class="input-label">密码</label>
|
||
<input type="password" id="newPassword" class="input-field" placeholder="请输入密码" required>
|
||
</div>
|
||
<div><label class="input-label">学校</label><select id="newUserSchool" class="input-field" required></select></div>
|
||
<div class="flex items-center gap-2">
|
||
<input type="checkbox" id="newIsAdmin" class="w-4 h-4 rounded border-neutral-300">
|
||
<label for="newIsAdmin" class="text-sm text-neutral-700 dark:text-neutral-300">设为管理员</label>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button type="button" onclick="closeCreateUserModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||
创建
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 创建注册码模态框 -->
|
||
<div id="createTicketModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateTicketModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">生成注册码</h3>
|
||
<button onclick="closeCreateTicketModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<form id="createTicketForm" onsubmit="submitCreateTicket(event)">
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="input-label">生成数量</label>
|
||
<input type="number" id="ticketCount" class="input-field" value="1" min="1" max="100" required>
|
||
</div>
|
||
<div>
|
||
<label class="input-label">使用次数限制</label>
|
||
<input type="number" id="ticketMaxUses" class="input-field" value="1" min="1" max="100" required>
|
||
</div>
|
||
<div>
|
||
<label class="input-label" for="ticketSchoolScope">适用学校</label>
|
||
<select id="ticketSchoolScope" class="input-field" onchange="toggleTicketSchoolScope()"><option value="all">全部学校</option><option value="selected">指定学校(可多选)</option></select>
|
||
<div id="ticketSchoolChoices" class="hidden mt-2 space-y-1"></div>
|
||
</div>
|
||
<div id="ticketExpiryGroup">
|
||
<label class="input-label">有效期(天)</label>
|
||
<input type="number" id="ticketExpiryDays" class="input-field" value="365" min="1" max="3650" required>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<input type="checkbox" id="ticketActivateOnUse" class="w-4 h-4 rounded border-neutral-300" onchange="toggleTicketActivateOnUse()">
|
||
<label for="ticketActivateOnUse" class="text-sm text-neutral-700 dark:text-neutral-300">激活后计时(首次使用后才开始计算有效期)</label>
|
||
</div>
|
||
<div id="ticketValidDaysGroup" class="hidden">
|
||
<label class="input-label">激活后有效天数</label>
|
||
<input type="number" id="ticketValidDays" class="input-field" value="365" min="1" max="3650" required>
|
||
</div>
|
||
<div id="ticketCreateResult" class="hidden">
|
||
<label class="input-label">生成的注册码</label>
|
||
<textarea id="ticketCreateCodes" class="input-field font-mono text-xs" rows="5" readonly></textarea>
|
||
<button type="button" onclick="copyGeneratedCodes()" class="mt-2 w-full py-2 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black text-sm font-medium hover:shadow-lg transition">
|
||
复制全部注册码
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button type="button" onclick="closeCreateTicketModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||
生成
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 批量刷新 Session 模态框 -->
|
||
<div id="batchRefreshModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeBatchRefreshModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-2xl p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate max-h-[80vh] overflow-y-auto">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">批量刷新 Session</h3>
|
||
<button onclick="closeBatchRefreshModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-100 dark:border-blue-800 rounded-xl p-4 mb-4">
|
||
<p class="text-sm text-blue-800 dark:text-blue-200">
|
||
系统会自动从 accounts.json 读取账号密码进行刷新。强制刷新会忽略当前有效的 session,重新登录所有账号。
|
||
</p>
|
||
</div>
|
||
|
||
<div class="flex items-center gap-2 mb-4">
|
||
<input type="checkbox" id="batchForceRefresh" class="w-4 h-4 rounded border-neutral-300">
|
||
<label for="batchForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">
|
||
<strong>强制刷新</strong>(即使 session 有效也重新登录)
|
||
</label>
|
||
</div>
|
||
|
||
<div id="batchRefreshResult" class="hidden mb-4">
|
||
<div class="border-t border-neutral-200 dark:border-neutral-700 pt-4">
|
||
<h4 class="font-bold mb-2">刷新结果</h4>
|
||
<div class="flex gap-4 mb-3 text-sm">
|
||
<span class="text-green-600">未过期: <strong id="resultValid">0</strong></span>
|
||
<span class="text-blue-600">刷新成功: <strong id="resultRefreshed">0</strong></span>
|
||
<span class="text-red-600">登录失败: <strong id="resultFailed">0</strong></span>
|
||
</div>
|
||
<div class="overflow-x-auto max-h-60">
|
||
<table class="data-table text-sm">
|
||
<thead>
|
||
<tr>
|
||
<th>用户</th>
|
||
<th>状态</th>
|
||
<th>消息</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="batchRefreshDetails"></tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex gap-3">
|
||
<button type="button" onclick="closeBatchRefreshModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
关闭
|
||
</button>
|
||
<button type="button" onclick="batchCheckOnly()" class="flex-1 py-3 rounded-xl bg-neutral-200 dark:bg-neutral-700 text-neutral-800 dark:text-neutral-200 font-medium hover:bg-neutral-300 dark:hover:bg-neutral-600 transition">
|
||
仅检查
|
||
</button>
|
||
<button type="button" onclick="doBatchRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||
开始刷新
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 单用户刷新 Session 模态框 -->
|
||
<div id="singleRefreshModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeSingleRefreshModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">刷新用户 Session</h3>
|
||
<button onclick="closeSingleRefreshModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="input-label">用户</label>
|
||
<input type="text" id="singleRefreshUsername" class="input-field bg-neutral-100 dark:bg-neutral-800" readonly>
|
||
<input type="hidden" id="singleRefreshUserId">
|
||
</div>
|
||
<div>
|
||
<label class="input-label">教务系统密码</label>
|
||
<input type="password" id="singleRefreshPassword" class="input-field" placeholder="请输入密码">
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<input type="checkbox" id="singleForceRefresh" class="w-4 h-4 rounded border-neutral-300">
|
||
<label for="singleForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">强制刷新(即使 session 有效)</label>
|
||
</div>
|
||
<div id="singleRefreshResult"></div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button type="button" onclick="closeSingleRefreshModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button type="button" onclick="doSingleRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||
刷新
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 创建推广人模态框 -->
|
||
<div id="createAffiliateModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateAffiliateModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">添加推广人</h3>
|
||
<button onclick="closeCreateAffiliateModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<form id="createAffiliateForm" onsubmit="submitCreateAffiliate(event)">
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="input-label">推广码</label>
|
||
<input type="text" id="affiliateCode" class="input-field" placeholder="如: WH, ZZY" required maxlength="10">
|
||
<p class="text-xs text-neutral-500 mt-1">推广码将自动转为大写</p>
|
||
</div>
|
||
<div>
|
||
<label class="input-label">推广人姓名</label>
|
||
<input type="text" id="affiliateName" class="input-field" placeholder="请输入推广人姓名" required>
|
||
</div>
|
||
<div>
|
||
<label class="input-label">佣金比例 (%)</label>
|
||
<input type="number" id="affiliateCommission" class="input-field" value="30" min="0" max="100" required>
|
||
<p class="text-xs text-neutral-500 mt-1">用户支付金额的百分比作为佣金</p>
|
||
</div>
|
||
<div>
|
||
<label class="input-label">优惠金额 (元/人)</label>
|
||
<input type="number" id="affiliateDiscount" class="input-field" value="2" min="0" max="20" required>
|
||
<p class="text-xs text-neutral-500 mt-1">用户使用此推广码每人减免的金额</p>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button type="button" onclick="closeCreateAffiliateModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||
创建
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 推广人详情模态框 -->
|
||
<div id="affiliateDetailModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeAffiliateDetailModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-2xl p-4 max-h-[90vh] overflow-y-auto">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<div>
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">推广人详情</h3>
|
||
<p class="text-sm text-neutral-500 mt-1" id="detailAffiliateCode"></p>
|
||
</div>
|
||
<button onclick="closeAffiliateDetailModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<!-- 统计卡片 -->
|
||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||
<div class="bg-blue-50 dark:bg-blue-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-blue-600 dark:text-blue-400">总订单数</p>
|
||
<p class="text-2xl font-bold text-blue-900 dark:text-blue-200 text-center" id="statTotalOrders">-</p>
|
||
</div>
|
||
<div class="bg-green-50 dark:bg-green-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-green-600 dark:text-green-400">已支付订单</p>
|
||
<p class="text-2xl font-bold text-green-900 dark:text-green-200 text-center" id="statPaidOrders">-</p>
|
||
</div>
|
||
<div class="bg-purple-50 dark:bg-purple-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-purple-600 dark:text-purple-400">总销售额</p>
|
||
<p class="text-2xl font-bold text-purple-900 dark:text-purple-200 text-center" id="statTotalSales">-</p>
|
||
</div>
|
||
<div class="bg-orange-50 dark:bg-orange-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-orange-600 dark:text-orange-400">总佣金</p>
|
||
<p class="text-2xl font-bold text-orange-900 dark:text-orange-200 text-center" id="statTotalCommission">-</p>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 结算信息卡片 -->
|
||
<div class="grid grid-cols-2 md:grid-cols-3 gap-4 mb-6">
|
||
<div class="bg-red-50 dark:bg-red-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-red-600 dark:text-red-400">待结佣金</p>
|
||
<p class="text-2xl font-bold text-red-900 dark:text-red-200 text-center" id="statPendingCommission">-</p>
|
||
</div>
|
||
<div class="bg-gray-50 dark:bg-gray-900/20 rounded-xl p-4">
|
||
<p class="text-xs text-gray-600 dark:text-gray-400">已结佣金</p>
|
||
<p class="text-2xl font-bold text-gray-900 dark:text-gray-200" id="statTotalSettled">-</p>
|
||
</div>
|
||
<div class="flex items-center justify-center">
|
||
<button onclick="openSettleAffiliateModal()" id="btnSettleAffiliate" class="w-full h-full px-4 py-3 bg-red-600 hover:bg-red-700 text-white rounded-xl text-sm font-bold transition shadow-lg hover:shadow-xl">
|
||
<svg class="w-5 h-5 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
结清佣金
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 推广信息 -->
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-4 mb-6">
|
||
<div class="grid grid-cols-2 gap-4">
|
||
<div>
|
||
<p class="text-xs text-neutral-500">推广人姓名</p>
|
||
<p class="font-medium text-neutral-900 dark:text-white" id="detailAffiliateName">-</p>
|
||
</div>
|
||
<div>
|
||
<p class="text-xs text-neutral-500">佣金比例</p>
|
||
<p class="font-medium text-neutral-900 dark:text-white" id="detailCommissionRate">-</p>
|
||
</div>
|
||
<div>
|
||
<p class="text-xs text-neutral-500">优惠金额</p>
|
||
<p class="font-medium text-neutral-900 dark:text-white" id="detailDiscountAmount">-</p>
|
||
</div>
|
||
<div>
|
||
<p class="text-xs text-neutral-500">创建时间</p>
|
||
<p class="font-medium text-neutral-900 dark:text-white" id="detailCreatedAt">-</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 推广链接 -->
|
||
<div class="mb-6">
|
||
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2 block">推广链接</label>
|
||
<div class="flex gap-2">
|
||
<input type="text" id="affiliateLink" class="input-field flex-1 text-sm" readonly>
|
||
<button onclick="copyAffiliateLink()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-xl text-sm font-medium hover:shadow-lg transition">
|
||
复制
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 最近订单 -->
|
||
<div>
|
||
<h4 class="font-bold text-neutral-900 dark:text-white mb-3">最近订单</h4>
|
||
<div id="recentOrdersLoading" class="text-center py-4">
|
||
<div class="inline-block w-6 h-6 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
|
||
</div>
|
||
<div id="recentOrdersEmpty" class="hidden text-center py-4 text-neutral-500">
|
||
暂无订单
|
||
</div>
|
||
<div id="recentOrdersList" class="hidden space-y-2 max-h-60 overflow-y-auto">
|
||
<!-- 订单列表将在这里渲染 -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 结清佣金模态框 -->
|
||
<div id="settleAffiliateModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeSettleAffiliateModal()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<div>
|
||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">结清佣金</h3>
|
||
<p class="text-sm text-neutral-500 mt-1" id="settleAffiliateCode"></p>
|
||
</div>
|
||
<button onclick="closeSettleAffiliateModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<form id="settleAffiliateForm" onsubmit="submitSettleAffiliate(event)">
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">待结佣金</label>
|
||
<p class="text-2xl font-bold text-red-600" id="settlePendingAmount">-</p>
|
||
</div>
|
||
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">结算金额 <span class="text-red-500">*</span></label>
|
||
<div class="relative">
|
||
<span class="absolute left-3 top-1/2 -translate-y-1/2 text-neutral-500">¥</span>
|
||
<input type="number" id="settleAmount" step="0.01" min="0.01" required class="input-field w-full pl-8" placeholder="输入结算金额">
|
||
</div>
|
||
</div>
|
||
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">备注</label>
|
||
<textarea id="settleNote" rows="2" class="input-field w-full" placeholder="可选:添加结算备注"></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex gap-3 mt-6">
|
||
<button type="button" onclick="closeSettleAffiliateModal()" class="flex-1 px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 rounded-xl text-sm font-medium hover:bg-neutral-50 dark:hover:bg-neutral-800 transition">
|
||
取消
|
||
</button>
|
||
<button type="submit" class="flex-1 px-4 py-2.5 bg-red-600 hover:bg-red-700 text-white rounded-xl text-sm font-bold transition">
|
||
确认结清
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- IP管理 -->
|
||
<div id="panel-ip" class="hidden space-y-4 mt-4">
|
||
<!-- 统计卡片 -->
|
||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">今日访问</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatTotal">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">独立IP</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatUnique">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">被拦截</p>
|
||
<p class="text-2xl font-bold text-red-500 mt-1" id="ipStatBlocked">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400">封禁规则</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatBans">-</p>
|
||
</div>
|
||
</div>
|
||
<!-- 快捷操作 -->
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
|
||
</svg>
|
||
IP访问控制
|
||
</h3>
|
||
<p class="text-sm text-neutral-500 dark:text-neutral-400 mt-1">封禁管理、访问日志、登录频率限制、邮件解封</p>
|
||
</div>
|
||
<div class="flex gap-3 flex-wrap">
|
||
<button onclick="openIpBanModal()" class="px-5 py-2.5 rounded-full text-sm font-bold bg-red-500 text-white hover:bg-red-600 transition-colors">
|
||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
|
||
</svg>
|
||
添加封禁
|
||
</button>
|
||
<button onclick="openIpConfigModal()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
频率设置
|
||
</button>
|
||
<a href="{{ url_for('main.admin_ip') }}" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition flex items-center gap-1.5">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
|
||
</svg>
|
||
完整页面 →
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- 访问统计图表 -->
|
||
<div class="grid md:grid-cols-2 gap-4">
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<div class="flex items-center justify-between mb-3">
|
||
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">访问时段分布</h3>
|
||
<select id="ipStatsHours" onchange="loadIpStats()" class="text-xs rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 px-2 py-1 text-neutral-700 dark:text-neutral-300">
|
||
<option value="1">1小时</option>
|
||
<option value="6">6小时</option>
|
||
<option value="24" selected>24小时</option>
|
||
<option value="72">3天</option>
|
||
</select>
|
||
</div>
|
||
<div id="chartIpHour" class="w-full h-48"></div>
|
||
</div>
|
||
<div class="glass rounded-2xl p-5 layer-2">
|
||
<div class="flex items-center justify-between mb-3">
|
||
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">来源省份 Top10</h3>
|
||
</div>
|
||
<div id="chartIpRegion" class="w-full h-48"></div>
|
||
</div>
|
||
</div>
|
||
<!-- 封禁列表预览 -->
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">封禁列表</h3>
|
||
<a href="{{ url_for('main.admin_ip') }}" class="text-sm text-blue-500 hover:text-blue-700">查看全部 →</a>
|
||
</div>
|
||
<div id="ipBansPreview" class="overflow-x-auto">
|
||
<div class="text-center text-neutral-400 py-4">加载中...</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ── 任务列表 Tab ── -->
|
||
<div id="panel-tasks" class="hidden space-y-4 mt-4">
|
||
<!-- 实时请求图表 (60秒) -->
|
||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300 mb-3">实时请求(最近60秒)</h3>
|
||
<div id="chartRealtime" style="height:200px;"></div>
|
||
</div>
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300 mb-3">请求速度(过去24小时)</h3>
|
||
<div id="chart24h" style="height:200px;"></div>
|
||
</div>
|
||
</div>
|
||
<!-- 全量任务列表 -->
|
||
<div class="glass rounded-2xl p-4 sm:p-6 layer-2">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">所有抢课任务</h3>
|
||
<div class="flex gap-2 items-center">
|
||
<select id="adminTaskStatusFilter" onchange="loadAdminTasks(1)" class="px-3 py-1.5 text-xs rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-black">
|
||
<option value="">全部状态</option>
|
||
<option value="pending">待执行</option>
|
||
<option value="running">执行中</option>
|
||
<option value="success">成功</option>
|
||
<option value="failed">失败</option>
|
||
<option value="cancelled">已取消</option>
|
||
</select>
|
||
<button onclick="loadAdminTasks(1)" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-4 h-4 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div id="adminTasksLoading" class="text-center py-8 hidden">
|
||
<div class="inline-block w-8 h-8 border-2 border-neutral-300 border-t-neutral-900 rounded-full animate-spin"></div>
|
||
</div>
|
||
<div id="adminTasksEmpty" class="text-center py-8 text-neutral-400 hidden">暂无任务</div>
|
||
<div id="adminTasksBatchBar" class="hidden flex items-center gap-2 mb-3 px-1">
|
||
<button onclick="toggleSelectAll()" class="text-xs px-3 py-1.5 rounded-lg border border-neutral-200 dark:border-neutral-700 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">全选</button>
|
||
<button onclick="batchCancelTasks()" id="adminBatchCancelBtn" disabled class="text-xs px-3 py-1.5 rounded-lg bg-red-500 text-white hover:bg-red-600 disabled:opacity-40 disabled:cursor-not-allowed transition-colors">批量取消 (<span id="adminBatchCount">0</span>)</button>
|
||
</div>
|
||
<div id="adminTasksTableWrap" class="overflow-x-auto hidden">
|
||
<table class="w-full text-xs">
|
||
<thead>
|
||
<tr class="text-left text-neutral-500 border-b border-neutral-200 dark:border-neutral-700">
|
||
<th class="pb-2 pr-2 w-8"><input type="checkbox" id="adminTaskSelectAll" onchange="toggleAllCheckboxes(this.checked)" class="rounded"></th>
|
||
<th class="pb-2 pr-2">ID</th>
|
||
<th class="pb-2 pr-2">用户</th>
|
||
<th class="pb-2 pr-2">课程</th>
|
||
<th class="pb-2 pr-2">状态</th>
|
||
<th class="pb-2 pr-2">重试</th>
|
||
<th class="pb-2 pr-2">创建时间</th>
|
||
<th class="pb-2">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="adminTasksBody"></tbody>
|
||
</table>
|
||
</div>
|
||
<nav id="adminTasksPagination" class="mt-4 hidden">
|
||
<div class="flex justify-center items-center gap-1"></div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="panel-payments" class="hidden space-y-4 mt-4">
|
||
<!-- 统计卡片 -->
|
||
<div class="grid grid-cols-2 md:grid-cols-5 gap-4">
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<p class="text-xs text-neutral-500">总订单数</p>
|
||
<p class="text-2xl font-bold text-neutral-900 dark:text-white" id="paymentStatTotal">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<p class="text-xs text-neutral-500">待支付</p>
|
||
<p class="text-2xl font-bold text-yellow-600" id="paymentStatPending">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<p class="text-xs text-neutral-500">已支付</p>
|
||
<p class="text-2xl font-bold text-green-600" id="paymentStatPaid">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<p class="text-xs text-neutral-500">已处理</p>
|
||
<p class="text-2xl font-bold text-blue-600" id="paymentStatProcessed">-</p>
|
||
</div>
|
||
<div class="glass rounded-2xl p-4 layer-2">
|
||
<p class="text-xs text-neutral-500">总收入</p>
|
||
<p class="text-2xl font-bold text-purple-600" id="paymentStatRevenue">-</p>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 筛选和搜索 -->
|
||
<div class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex flex-wrap gap-4 items-center">
|
||
<div class="flex items-center space-x-2">
|
||
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">状态:</label>
|
||
<select id="paymentFilterStatus" class="px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-sm">
|
||
<option value="all">全部</option>
|
||
<option value="pending">待支付</option>
|
||
<option value="paid">已支付</option>
|
||
<option value="processed">已处理</option>
|
||
<option value="failed">支付失败</option>
|
||
<option value="cancelled">已取消</option>
|
||
<option value="expired">已过期</option>
|
||
<option value="refunded">已退款</option>
|
||
</select>
|
||
</div>
|
||
<div class="flex items-center space-x-2">
|
||
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">搜索:</label>
|
||
<input type="text" id="paymentSearchInput" placeholder="订单号/邮箱/推广码"
|
||
class="px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-sm w-64">
|
||
</div>
|
||
<button onclick="loadPaymentOrders()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full hover:shadow-lg transition text-sm font-medium">
|
||
查询
|
||
</button>
|
||
<button onclick="refreshPaymentData()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 订单列表 -->
|
||
<div class="glass rounded-2xl overflow-hidden layer-2">
|
||
<div class="overflow-x-auto">
|
||
<table class="data-table">
|
||
<thead>
|
||
<tr>
|
||
<th>订单号</th>
|
||
<th>邮箱</th>
|
||
<th>数量</th>
|
||
<th>金额</th>
|
||
<th>优惠</th>
|
||
<th>实付</th>
|
||
<th>推广码</th>
|
||
<th>状态</th>
|
||
<th>创建时间</th>
|
||
<th>支付时间</th>
|
||
<th>操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="paymentOrdersTableBody">
|
||
<!-- 订单数据将在这里渲染 -->
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="paymentLoadingState" class="text-center py-12" style="display: block;">
|
||
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
|
||
<p class="text-neutral-500 mt-2">加载中...</p>
|
||
</div>
|
||
<div id="paymentEmptyState" class="hidden text-center py-12">
|
||
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
|
||
</svg>
|
||
<p class="text-neutral-500">暂无订单</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 确认支付模态框 -->
|
||
<div id="confirmPaymentModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeConfirmPayment()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">手动确认支付</h3>
|
||
<p class="text-neutral-600 dark:text-neutral-400 mb-4">
|
||
确认要将订单 <span id="confirmOrderId" class="font-mono font-bold"></span> 标记为已支付吗?
|
||
</p>
|
||
<div class="bg-yellow-50 dark:bg-yellow-900/20 rounded-xl p-3 mb-4">
|
||
<p class="text-sm text-yellow-800 dark:text-yellow-300">
|
||
<i class="fas fa-exclamation-triangle mr-1"></i>
|
||
此操作将生成注册码并发送邮件给用户
|
||
</p>
|
||
</div>
|
||
<div class="flex gap-3">
|
||
<button onclick="closeConfirmPayment()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button onclick="submitConfirmPayment()" class="flex-1 py-3 rounded-xl bg-green-600 text-white font-bold hover:bg-green-700 transition">
|
||
确认支付
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 拒绝订单模态框 -->
|
||
<div id="rejectOrderModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeRejectOrder()"></div>
|
||
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
|
||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">拒绝订单</h3>
|
||
<p class="text-neutral-600 dark:text-neutral-400 mb-4">
|
||
确定要拒绝订单 <span id="rejectOrderId" class="font-mono font-bold"></span> 吗?
|
||
</p>
|
||
<div class="mb-4">
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2">拒绝原因</label>
|
||
<textarea id="rejectReason" rows="3" class="w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-xl bg-white dark:bg-neutral-800 text-sm" placeholder="请输入拒绝原因(可选)"></textarea>
|
||
</div>
|
||
<div class="flex gap-3">
|
||
<button onclick="closeRejectOrder()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||
取消
|
||
</button>
|
||
<button onclick="submitRejectOrder()" class="flex-1 py-3 rounded-xl bg-red-600 text-white font-bold hover:bg-red-700 transition">
|
||
确认拒绝
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 订单详情模态框 -->
|
||
<div id="paymentOrderDetailModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closePaymentOrderDetail()"></div>
|
||
<div class="absolute right-0 top-0 h-full w-full max-w-lg bg-white dark:bg-neutral-900 shadow-xl overflow-y-auto">
|
||
<div class="p-6">
|
||
<div class="flex justify-between items-center mb-6">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">订单详情</h3>
|
||
<button onclick="closePaymentOrderDetail()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<div id="paymentOrderDetailContent">
|
||
<!-- 详情内容 -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- IP管理:添加封禁 Modal -->
|
||
<div id="ipBanModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('ipBanModal').classList.add('hidden')"></div>
|
||
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
|
||
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
|
||
<div class="p-6">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">添加封禁规则</h3>
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁类型</label>
|
||
<select id="ipBanType" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
<option value="ip">单个IP</option>
|
||
<option value="cidr">IP段 (CIDR,如 1.2.3.0/24)</option>
|
||
<option value="country">国家/地区代码 (如 US)</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁值</label>
|
||
<input id="ipBanValue" type="text" placeholder="IP / CIDR / 国家代码"
|
||
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
</div>
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁时长</label>
|
||
<select id="ipBanDuration" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
<option value="">永久封禁</option>
|
||
<option value="1h">1小时</option>
|
||
<option value="6h">6小时</option>
|
||
<option value="1d">1天</option>
|
||
<option value="3d">3天</option>
|
||
<option value="1w">1周</option>
|
||
<option value="1m">1个月</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁原因</label>
|
||
<input id="ipBanReason" type="text" placeholder="可选"
|
||
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button onclick="submitIpBan()" class="flex-1 bg-red-500 text-white px-4 py-2.5 rounded-xl text-sm font-bold hover:bg-red-600 transition-colors">确认封禁</button>
|
||
<button onclick="document.getElementById('ipBanModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- IP管理:频率限制配置 Modal -->
|
||
<div id="ipConfigModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('ipConfigModal').classList.add('hidden')"></div>
|
||
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
|
||
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
|
||
<div class="p-6">
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">登录频率限制设置</h3>
|
||
<div class="space-y-4">
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">统计时间窗口(分钟)</label>
|
||
<input id="ipCfgWindow" type="number" min="1" max="60"
|
||
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
<p class="text-xs text-neutral-400 mt-1">在此时间窗口内统计失败次数</p>
|
||
</div>
|
||
<div>
|
||
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">最大失败次数</label>
|
||
<input id="ipCfgMax" type="number" min="1" max="100"
|
||
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
|
||
<p class="text-xs text-neutral-400 mt-1">超过此次数自动封禁1小时</p>
|
||
</div>
|
||
<div class="flex items-center gap-3">
|
||
<input id="ipCfgChinaOnly" type="checkbox" class="w-4 h-4 rounded">
|
||
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">启用中国IP限制</label>
|
||
</div>
|
||
</div>
|
||
<div class="flex gap-3 mt-6">
|
||
<button onclick="submitIpConfig()" class="flex-1 btn-primary py-2.5 rounded-xl text-sm font-bold">保存配置</button>
|
||
<button onclick="document.getElementById('ipConfigModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- AI 助手面板 -->
|
||
<div id="panel-ai" class="hidden space-y-4 mt-4">
|
||
<!-- AI 配置 -->
|
||
<section class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex flex-col gap-5 lg:flex-row lg:items-start lg:justify-between">
|
||
<div class="max-w-xl">
|
||
<div class="flex items-center gap-2">
|
||
<div class="flex h-9 w-9 items-center justify-center rounded-xl bg-slate-900 text-white dark:bg-slate-100 dark:text-slate-900">
|
||
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m12 3-1.5 5.5L5 10l5.5 1.5L12 17l1.5-5.5L19 10l-5.5-1.5L12 3Z"/></svg>
|
||
</div>
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">教务系统 AI 助手</h3>
|
||
</div>
|
||
</div>
|
||
<p id="aiConfigStatus" class="mt-4 text-sm text-neutral-500 dark:text-neutral-400">正在读取配置…</p>
|
||
</div>
|
||
<form id="aiConfigForm" class="grid w-full max-w-2xl gap-3 sm:grid-cols-2">
|
||
<label class="block sm:col-span-2">
|
||
<span class="mb-1 block text-xs font-medium text-neutral-600 dark:text-neutral-300">API Key</span>
|
||
<input id="aiApiKey" type="password" autocomplete="new-password" placeholder="获取模型可直接使用;启用助手需保存" class="w-full rounded-xl border border-neutral-200 bg-white px-3 py-2.5 text-sm text-neutral-800 outline-none transition focus:border-slate-500 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:focus:border-neutral-400 dark:focus:ring-neutral-700">
|
||
</label>
|
||
<label class="block">
|
||
<div class="mb-1 flex items-center justify-between gap-2">
|
||
<span class="text-xs font-medium text-neutral-600 dark:text-neutral-300">模型</span>
|
||
<button id="aiLoadModels" type="button" class="text-xs font-medium text-slate-700 underline-offset-2 hover:underline dark:text-slate-300">获取模型</button>
|
||
</div>
|
||
<input id="aiModel" list="aiModelOptions" type="text" placeholder="gpt-5.2" class="w-full rounded-xl border border-neutral-200 bg-white px-3 py-2.5 text-sm text-neutral-800 outline-none transition focus:border-slate-500 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:focus:border-neutral-400 dark:focus:ring-neutral-700">
|
||
<datalist id="aiModelOptions"></datalist>
|
||
</label>
|
||
<label class="block">
|
||
<span class="mb-1 block text-xs font-medium text-neutral-600 dark:text-neutral-300">兼容 API 根地址(可选)</span>
|
||
<input id="aiBaseUrl" type="url" placeholder="https://api.openai.com/v1(不要填 /chat/completions)" class="w-full rounded-xl border border-neutral-200 bg-white px-3 py-2.5 text-sm text-neutral-800 outline-none transition focus:border-slate-500 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:focus:border-neutral-400 dark:focus:ring-neutral-700">
|
||
</label>
|
||
<label class="block">
|
||
<span class="mb-1 block text-xs font-medium text-neutral-600 dark:text-neutral-300">API 协议</span>
|
||
<select id="aiApiStyle" class="w-full rounded-xl border border-neutral-200 bg-white px-3 py-2.5 text-sm text-neutral-800 outline-none transition focus:border-slate-500 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:focus:border-neutral-400 dark:focus:ring-neutral-700">
|
||
<option value="auto">自动识别(不支持时自动降级)</option>
|
||
<option value="responses">Responses API(OpenAI 官方)</option>
|
||
<option value="chat">Chat Completions(DeepSeek / 通义 / 智谱等兼容服务)</option>
|
||
</select>
|
||
</label>
|
||
<label class="block">
|
||
<span class="mb-1 block text-xs font-medium text-neutral-600 dark:text-neutral-300">每日用量默认上限(tokens,0=不限制)</span>
|
||
<input id="aiDailyLimit" type="number" min="0" step="10000" placeholder="1000000" class="w-full rounded-xl border border-neutral-200 bg-white px-3 py-2.5 text-sm text-neutral-800 outline-none transition focus:border-slate-500 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:focus:border-neutral-400 dark:focus:ring-neutral-700">
|
||
<p class="text-xs text-neutral-400 mt-1">未单独设置的用户按此限额执行,北京时间零点重置</p>
|
||
</label>
|
||
<label class="flex min-h-11 items-center gap-3 text-sm font-medium text-neutral-700 dark:text-neutral-200">
|
||
<input id="aiEnabled" type="checkbox" class="h-4 w-4 rounded border-neutral-300 text-slate-900 focus:ring-slate-500">
|
||
启用选课页 AI 助手
|
||
</label>
|
||
<div class="flex items-center justify-end gap-3 sm:col-span-2">
|
||
<label class="flex items-center gap-2 text-xs text-red-600 dark:text-red-400"><input id="aiClearKey" type="checkbox" class="h-3.5 w-3.5 rounded"> 清除 Key</label>
|
||
<button type="submit" class="btn-primary rounded-xl px-4 py-2.5 text-sm font-bold">保存 AI 配置</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 实时用量统计 -->
|
||
<section class="glass rounded-2xl p-6 layer-2">
|
||
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
|
||
<div>
|
||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">今日实时用量</h3>
|
||
<p class="text-xs text-neutral-400 mt-1">按北京时间每天零点重置 · 每 30 秒自动刷新</p>
|
||
</div>
|
||
<div class="flex items-center gap-3">
|
||
<div id="aiUsageTotals" class="text-xs text-neutral-500 dark:text-neutral-400 font-mono"></div>
|
||
<button onclick="loadAiUsage()" class="px-3 py-1.5 rounded-lg text-xs font-medium border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">刷新</button>
|
||
</div>
|
||
</div>
|
||
<div class="overflow-x-auto">
|
||
<table class="w-full text-sm">
|
||
<thead>
|
||
<tr class="text-left text-xs text-neutral-400 border-b border-neutral-200 dark:border-neutral-700">
|
||
<th class="py-2 pr-3">用户</th>
|
||
<th class="py-2 pr-3">调用</th>
|
||
<th class="py-2 pr-3">输入 tokens</th>
|
||
<th class="py-2 pr-3">输出 tokens</th>
|
||
<th class="py-2 pr-3">合计</th>
|
||
<th class="py-2 pr-3">今日用量进度</th>
|
||
<th class="py-2 pr-3">每日上限</th>
|
||
<th class="py-2">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="aiUsageTable">
|
||
<tr><td colspan="8" class="py-8 text-center text-neutral-400">加载中…</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
{% endblock %}
|
||
|
||
{% block extra_js %}
|
||
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
|
||
<script>
|
||
let currentPage = 1;
|
||
let currentTab = 'users';
|
||
let currentPaymentOrders = [];
|
||
let currentPaymentOrderId = null;
|
||
let aiUsageTimer = null;
|
||
|
||
function fmtInt(n) { return Number(n || 0).toLocaleString('en-US'); }
|
||
|
||
async function loadAiUsage() {
|
||
const tbody = document.getElementById('aiUsageTable');
|
||
if (!tbody) return;
|
||
try {
|
||
const data = await apiRequest('/api/admin/ai/usage');
|
||
if (!data.success) throw new Error(data.message || '读取失败');
|
||
document.getElementById('aiUsageTotals').textContent =
|
||
`全站 ${fmtInt(data.totals.calls)} 次 · 输入 ${fmtInt(data.totals.input_tokens)} · 输出 ${fmtInt(data.totals.output_tokens)} · 合计 ${fmtInt(data.totals.total_tokens)}`;
|
||
const rows = data.users.map(u => {
|
||
const pct = u.daily_limit > 0 ? Math.min(100, Math.round(u.total_tokens * 100 / u.daily_limit)) : 0;
|
||
const pctColor = pct >= 100 ? 'bg-red-500' : pct >= 80 ? 'bg-orange-500' : 'bg-emerald-500';
|
||
const bar = u.daily_limit > 0
|
||
? `<div class="flex items-center gap-2"><div class="h-1.5 w-20 rounded-full bg-neutral-200 dark:bg-neutral-700 overflow-hidden"><div class="h-full ${pctColor}" style="width:${pct}%"></div></div><span class="text-xs text-neutral-400">${pct}%</span></div>`
|
||
: '<span class="text-xs text-neutral-400">—</span>';
|
||
const limitText = u.daily_limit === 0 ? '不限制' : fmtInt(u.daily_limit);
|
||
const limitSource = u.personal_limit === null ? '(默认)' : '';
|
||
return `<tr class="border-b border-neutral-100 dark:border-neutral-800">
|
||
<td class="py-2 pr-3"><div class="font-medium text-neutral-800 dark:text-neutral-200">${escapeHtml(u.username)}</div><div class="text-xs text-neutral-400">${escapeHtml(u.jwxt_name || '')}</div></td>
|
||
<td class="py-2 pr-3 font-mono">${fmtInt(u.calls)}</td>
|
||
<td class="py-2 pr-3 font-mono">${fmtInt(u.input_tokens)}</td>
|
||
<td class="py-2 pr-3 font-mono">${fmtInt(u.output_tokens)}</td>
|
||
<td class="py-2 pr-3 font-mono font-semibold">${fmtInt(u.total_tokens)}</td>
|
||
<td class="py-2 pr-3">${bar}</td>
|
||
<td class="py-2 pr-3 font-mono text-xs">${limitText}<span class="text-neutral-400">${limitSource}</span></td>
|
||
<td class="py-2">
|
||
<div class="flex items-center gap-1.5">
|
||
<input id="aiLimit-${u.user_id}" type="number" min="0" step="10000" placeholder="默认"
|
||
value="${u.personal_limit === null ? '' : u.personal_limit}"
|
||
class="w-28 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 px-2 py-1 text-xs text-neutral-700 dark:text-neutral-300">
|
||
<button onclick="saveAiLimit(${u.user_id})" class="px-2 py-1 rounded-lg text-xs font-medium bg-neutral-900 dark:bg-white text-white dark:text-black hover:opacity-80 transition">保存</button>
|
||
</div>
|
||
</td>
|
||
</tr>`;
|
||
}).join('');
|
||
tbody.innerHTML = rows || '<tr><td colspan="8" class="py-8 text-center text-neutral-400">暂无用户</td></tr>';
|
||
const dailyInput = document.getElementById('aiDailyLimit');
|
||
if (dailyInput && dailyInput.value === '') dailyInput.placeholder = String(data.default_limit);
|
||
} catch (error) {
|
||
tbody.innerHTML = `<tr><td colspan="8" class="py-8 text-center text-red-400">读取失败:${escapeHtml(error.message)}</td></tr>`;
|
||
}
|
||
}
|
||
|
||
async function saveAiLimit(userId) {
|
||
const input = document.getElementById('aiLimit-' + userId);
|
||
const raw = input ? input.value.trim() : '';
|
||
const limit = raw === '' ? null : Number(raw);
|
||
try {
|
||
const result = await apiRequest('/api/admin/ai/usage/limit', {
|
||
method: 'POST', body: JSON.stringify({ user_id: userId, limit }),
|
||
});
|
||
if (!result.success) throw new Error(result.message || '保存失败');
|
||
showToast(result.message || '已保存', 'success');
|
||
loadAiUsage();
|
||
} catch (error) {
|
||
showToast('保存失败:' + error.message, 'error');
|
||
}
|
||
}
|
||
|
||
// 初始化
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
// 将所有弹窗移到 body 直接子级,确保 fixed 定位基于视口
|
||
['createUserModal', 'createTicketModal', 'createAffiliateModal', 'affiliateDetailModal', 'settleAffiliateModal', 'batchRefreshModal', 'singleRefreshModal'].forEach(id => {
|
||
const el = document.getElementById(id);
|
||
if (el) document.body.appendChild(el);
|
||
});
|
||
|
||
loadStats();
|
||
loadUsers();
|
||
loadAiConfig();
|
||
document.getElementById('aiConfigForm').addEventListener('submit', saveAiConfig);
|
||
document.getElementById('aiLoadModels').addEventListener('click', loadAiModels);
|
||
});
|
||
|
||
async function loadAiConfig() {
|
||
const status = document.getElementById('aiConfigStatus');
|
||
try {
|
||
const data = await apiRequest('/api/admin/ai/config');
|
||
if (!data.success) throw new Error(data.message || '读取失败');
|
||
const cfg = data.config || {};
|
||
document.getElementById('aiEnabled').checked = !!cfg.enabled;
|
||
document.getElementById('aiModel').value = cfg.model || 'gpt-5.2';
|
||
document.getElementById('aiBaseUrl').value = cfg.base_url || '';
|
||
document.getElementById('aiApiStyle').value = cfg.api_style || 'auto';
|
||
const dailyInput = document.getElementById('aiDailyLimit');
|
||
if (dailyInput && document.activeElement !== dailyInput) {
|
||
dailyInput.value = cfg.daily_limit > 0 ? cfg.daily_limit : 0;
|
||
}
|
||
status.textContent = cfg.configured
|
||
? `API Key 已配置 · 当前模型:${cfg.model || '-'}`
|
||
: '尚未配置 API Key,选课页助手不可用';
|
||
} catch (error) {
|
||
status.textContent = 'AI 配置读取失败:' + error.message;
|
||
}
|
||
}
|
||
|
||
async function saveAiConfig(event) {
|
||
event.preventDefault();
|
||
const status = document.getElementById('aiConfigStatus');
|
||
const data = {
|
||
enabled: document.getElementById('aiEnabled').checked,
|
||
model: document.getElementById('aiModel').value.trim(),
|
||
base_url: document.getElementById('aiBaseUrl').value.trim(),
|
||
api_style: document.getElementById('aiApiStyle').value,
|
||
daily_limit: document.getElementById('aiDailyLimit').value.trim() || 0,
|
||
api_key: document.getElementById('aiApiKey').value.trim(),
|
||
clear_api_key: document.getElementById('aiClearKey').checked,
|
||
};
|
||
try {
|
||
const result = await apiRequest('/api/admin/ai/config', {
|
||
method: 'POST', body: JSON.stringify(data),
|
||
});
|
||
if (!result.success) throw new Error(result.message || '保存失败');
|
||
document.getElementById('aiApiKey').value = '';
|
||
document.getElementById('aiClearKey').checked = false;
|
||
showToast(result.message || 'AI 配置已保存', 'success');
|
||
status.textContent = result.config.configured
|
||
? `API Key 已配置 · 当前模型:${result.config.model || '-'}`
|
||
: '尚未配置 API Key,选课页助手不可用';
|
||
} catch (error) {
|
||
showToast('AI 配置保存失败:' + error.message, 'error');
|
||
}
|
||
}
|
||
|
||
async function loadAiModels() {
|
||
const button = document.getElementById('aiLoadModels');
|
||
const status = document.getElementById('aiConfigStatus');
|
||
button.disabled = true;
|
||
button.textContent = '获取中…';
|
||
try {
|
||
const result = await apiRequest('/api/admin/ai/models', {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
api_key: document.getElementById('aiApiKey').value.trim(),
|
||
base_url: document.getElementById('aiBaseUrl').value.trim(),
|
||
}),
|
||
});
|
||
if (!result.success) throw new Error(result.message || '获取失败');
|
||
const options = document.getElementById('aiModelOptions');
|
||
options.replaceChildren(...(result.models || []).map(model => {
|
||
const option = document.createElement('option');
|
||
option.value = model;
|
||
return option;
|
||
}));
|
||
status.textContent = `已从当前服务读取 ${result.models.length} 个模型,可在模型输入框中选择或手动填写。`;
|
||
} catch (error) {
|
||
showToast('模型获取失败:' + error.message, 'error');
|
||
} finally {
|
||
button.disabled = false;
|
||
button.textContent = '获取模型';
|
||
}
|
||
}
|
||
|
||
let schoolCache = [];
|
||
const KBCX_SOURCE_LABELS = {auto: '自动', web: '网页版接口', mobile: 'Mobile接口'};
|
||
async function loadSchools() {
|
||
const data = await apiRequest('/api/admin/schools');
|
||
if (!data.success) { showToast(data.message || '学校加载失败', 'error'); return; }
|
||
schoolCache = data.schools;
|
||
mlSyncSchoolSelect(schoolCache);
|
||
const box = document.getElementById('schoolList');
|
||
box.replaceChildren();
|
||
for (const school of schoolCache) {
|
||
const row = document.createElement('button');
|
||
row.type = 'button';
|
||
row.className = 'block w-full text-left p-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-sm';
|
||
const source = KBCX_SOURCE_LABELS[school.kbcx_source] || '自动';
|
||
const abbr = school.abbr || school.id.toUpperCase();
|
||
row.textContent = `${school.name}(${abbr}教务助手)· ${school.urls.length} 条线路 · ${school.requires_captcha ? '需要验证码' : '无需验证码'} · 课表${source}`;
|
||
row.onclick = () => editSchool(school.id);
|
||
box.appendChild(row);
|
||
}
|
||
const choices = document.getElementById('ticketSchoolChoices');
|
||
choices.replaceChildren();
|
||
for (const school of schoolCache) {
|
||
const label = document.createElement('label');
|
||
label.className = 'flex items-center gap-2 text-sm';
|
||
const checkbox = document.createElement('input');
|
||
checkbox.type = 'checkbox'; checkbox.value = school.id; checkbox.className = 'ticket-school-checkbox';
|
||
label.append(checkbox, document.createTextNode(school.name));
|
||
choices.appendChild(label);
|
||
}
|
||
}
|
||
function updateFaviconUI(school) {
|
||
const img = document.getElementById('schoolFaviconPreview');
|
||
const clearBtn = document.getElementById('schoolFaviconClear');
|
||
const hint = document.getElementById('schoolFaviconHint');
|
||
const url = school ? (school.favicon || '') : '';
|
||
if (url) {
|
||
img.src = url;
|
||
img.classList.remove('hidden');
|
||
clearBtn.classList.remove('hidden');
|
||
hint.classList.add('hidden');
|
||
} else {
|
||
img.removeAttribute('src');
|
||
img.classList.add('hidden');
|
||
clearBtn.classList.add('hidden');
|
||
hint.classList.remove('hidden');
|
||
}
|
||
}
|
||
async function uploadSchoolIcon(input) {
|
||
const file = input.files && input.files[0];
|
||
input.value = '';
|
||
if (!file) return;
|
||
const sid = document.getElementById('schoolId').value.trim();
|
||
const school = schoolCache.find(item => item.id === sid);
|
||
if (!school) { showToast('请先保存学校,再上传图标', 'error'); return; }
|
||
if (file.size > 1024 * 1024) { showToast('图片不能超过 1MB', 'error'); return; }
|
||
const fd = new FormData();
|
||
fd.append('file', file);
|
||
try {
|
||
const resp = await fetch('/api/admin/schools/' + encodeURIComponent(sid) + '/icon', {
|
||
method: 'POST', credentials: 'same-origin', body: fd,
|
||
});
|
||
const data = await resp.json();
|
||
if (!data.success) { showToast(data.message || '上传失败', 'error'); return; }
|
||
school.favicon = data.favicon;
|
||
updateFaviconUI(school);
|
||
showToast('图标已上传,该校用户登录后生效', 'success');
|
||
} catch (e) { showToast('上传失败', 'error'); }
|
||
}
|
||
async function clearSchoolIcon() {
|
||
const sid = document.getElementById('schoolId').value.trim();
|
||
const school = schoolCache.find(item => item.id === sid);
|
||
if (!school || !school.favicon) return;
|
||
if (!confirm('清除该校的自定义图标?')) return;
|
||
try {
|
||
const data = await apiRequest('/api/admin/schools/' + encodeURIComponent(sid) + '/icon', {method: 'DELETE'});
|
||
if (!data.success) { showToast(data.message || '操作失败', 'error'); return; }
|
||
school.favicon = '';
|
||
updateFaviconUI(school);
|
||
showToast('已清除图标', 'success');
|
||
} catch (e) { showToast('操作失败', 'error'); }
|
||
}
|
||
function editSchool(id) {
|
||
const school = schoolCache.find(item => item.id === id);
|
||
if (!school) return;
|
||
document.getElementById('schoolId').value = school.id;
|
||
document.getElementById('schoolId').readOnly = true;
|
||
document.getElementById('schoolName').value = school.name;
|
||
document.getElementById('schoolAbbr').value = school.abbr || '';
|
||
updateFaviconUI(school);
|
||
document.getElementById('schoolUrls').value = school.urls.join('\n');
|
||
document.getElementById('schoolCaptcha').checked = school.requires_captcha;
|
||
document.getElementById('schoolKbcxSource').value = school.kbcx_source || 'auto';
|
||
}
|
||
function newSchool() {
|
||
document.getElementById('schoolForm').reset();
|
||
document.getElementById('schoolId').readOnly = false;
|
||
document.getElementById('schoolKbcxSource').value = 'auto';
|
||
updateFaviconUI(null);
|
||
}
|
||
async function saveSchool(event) {
|
||
event.preventDefault();
|
||
const payload = {
|
||
id: document.getElementById('schoolId').value.trim(),
|
||
name: document.getElementById('schoolName').value.trim(),
|
||
abbr: document.getElementById('schoolAbbr').value.trim(),
|
||
urls: document.getElementById('schoolUrls').value.split(/\r?\n/).map(line => line.trim()).filter(Boolean),
|
||
requires_captcha: document.getElementById('schoolCaptcha').checked,
|
||
kbcx_source: document.getElementById('schoolKbcxSource').value
|
||
};
|
||
try {
|
||
const data = await apiRequest('/api/admin/schools', {method: 'POST', body: JSON.stringify(payload)});
|
||
if (!data.success) { showToast(data.message || '保存失败', 'error'); return; }
|
||
showToast('学校配置已保存', 'success');
|
||
await loadSchools(); editSchool(payload.id);
|
||
} catch (error) { showToast('保存失败', 'error'); }
|
||
}
|
||
function toggleTicketSchoolScope() {
|
||
document.getElementById('ticketSchoolChoices').classList.toggle('hidden', document.getElementById('ticketSchoolScope').value === 'all');
|
||
}
|
||
|
||
// 切换标签页
|
||
function switchTab(tab) {
|
||
currentTab = tab;
|
||
document.getElementById('tab-users').className = tab === 'users'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-ai').className = tab === 'ai'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-tickets').className = tab === 'tickets'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-schools').className = tab === 'schools'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-affiliates').className = tab === 'affiliates'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-payments').className = tab === 'payments'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-ip').className = tab === 'ip'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
document.getElementById('tab-tasks').className = tab === 'tasks'
|
||
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
|
||
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
|
||
|
||
const panels = ['panel-users', 'panel-ai', 'panel-tickets', 'panel-schools', 'panel-affiliates', 'panel-payments', 'panel-ip', 'panel-tasks'];
|
||
const targetPanel = 'panel-' + tab;
|
||
|
||
panels.forEach(panelId => {
|
||
const panel = document.getElementById(panelId);
|
||
if (panel) {
|
||
if (panelId === targetPanel) {
|
||
panel.classList.remove('hidden');
|
||
// 重置动画,让面板每次切换都触发淡入
|
||
panel.classList.remove('tab-panel-enter');
|
||
panel.offsetHeight; // 触发重排
|
||
panel.classList.add('tab-panel-enter');
|
||
} else {
|
||
panel.classList.add('hidden');
|
||
panel.classList.remove('tab-panel-enter');
|
||
}
|
||
}
|
||
});
|
||
|
||
if (tab === 'tickets') {
|
||
loadTickets();
|
||
} else if (tab === 'schools') {
|
||
loadSchools();
|
||
} else if (tab === 'ai') {
|
||
loadAiConfig();
|
||
loadAiUsage();
|
||
if (aiUsageTimer) { clearInterval(aiUsageTimer); }
|
||
aiUsageTimer = setInterval(loadAiUsage, 30000);
|
||
} else if (tab === 'affiliates') {
|
||
loadAffiliates();
|
||
} else if (tab === 'payments') {
|
||
loadPaymentOrders();
|
||
} else if (tab === 'ip') {
|
||
loadIpStats();
|
||
loadIpBansPreview();
|
||
} else if (tab === 'tasks') {
|
||
loadAdminTasks(1);
|
||
loadRequestStats();
|
||
if (realtimeTimer) { clearInterval(realtimeTimer); }
|
||
realtimeTimer = setInterval(loadRequestStats, 5000);
|
||
} else {
|
||
// 切到其他 tab 时停止实时刷新
|
||
if (realtimeTimer) { clearInterval(realtimeTimer); realtimeTimer = null; }
|
||
if (aiUsageTimer) { clearInterval(aiUsageTimer); aiUsageTimer = null; }
|
||
}
|
||
}
|
||
|
||
// 加载统计数据
|
||
async function loadStats() {
|
||
try {
|
||
const data = await apiRequest('/api/admin/stats');
|
||
if (data.success) {
|
||
document.getElementById('statTotalUsers').textContent = data.stats.total_users;
|
||
document.getElementById('statTotalTasks').textContent = data.stats.total_tasks;
|
||
document.getElementById('statRunningTasks').textContent = data.stats.running_tasks;
|
||
document.getElementById('statSuccessTasks').textContent = data.stats.success_tasks;
|
||
|
||
if (data.stats.session_stats) {
|
||
document.getElementById('sessionValid').textContent = data.stats.session_stats.valid || 0;
|
||
document.getElementById('sessionInvalid').textContent = data.stats.session_stats.invalid || 0;
|
||
document.getElementById('sessionUnknown').textContent = data.stats.session_stats.unknown || 0;
|
||
}
|
||
}
|
||
} catch (error) {
|
||
console.error('加载统计失败:', error);
|
||
}
|
||
}
|
||
|
||
|
||
// 加载用户列表
|
||
async function loadUsers(page = 1) {
|
||
if (!schoolCache.length) await loadSchools();
|
||
currentPage = page;
|
||
const loading = document.getElementById('usersLoading');
|
||
const empty = document.getElementById('usersEmpty');
|
||
const table = document.getElementById('usersTable');
|
||
const pagination = document.getElementById('usersPagination');
|
||
|
||
loading.classList.remove('hidden');
|
||
empty.classList.add('hidden');
|
||
table.classList.add('hidden');
|
||
pagination.classList.add('hidden');
|
||
|
||
try {
|
||
const data = await apiRequest(`/api/admin/users/list?page=${page}&per_page=20`);
|
||
loading.classList.add('hidden');
|
||
|
||
if (!data.success || !data.users || data.users.length === 0) {
|
||
empty.classList.remove('hidden');
|
||
return;
|
||
}
|
||
|
||
renderUsersTable(data.users);
|
||
renderPagination(data.total, data.pages, page);
|
||
table.classList.remove('hidden');
|
||
pagination.classList.remove('hidden');
|
||
} catch (error) {
|
||
loading.classList.add('hidden');
|
||
showToast('加载失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 渲染用户表格
|
||
function renderUsersTable(users) {
|
||
const tbody = document.getElementById('usersTableBody');
|
||
tbody.innerHTML = users.map((user, index) => `
|
||
<tr>
|
||
<td class="font-mono text-sm">${user.id}</td>
|
||
<td class="font-medium">${escapeHtml(user.username)}</td>
|
||
<td>${escapeHtml(schoolCache.find(school => school.id === user.school_id)?.name || user.school_id || '山东管理学院')}</td>
|
||
<td>${user.jwxt_username ? escapeHtml(user.jwxt_username) : '<span class="text-neutral-400">-</span>'}</td>
|
||
<td>
|
||
${user.session_status === 'valid'
|
||
? '<span class="status-badge status-success">有效</span>'
|
||
: user.session_status === 'invalid'
|
||
? '<span class="status-badge status-danger">过期</span>'
|
||
: '<span class="status-badge status-info">未知</span>'}
|
||
</td>
|
||
<td>
|
||
${user.is_admin
|
||
? '<span class="status-badge status-danger">管理员</span>'
|
||
: '<span class="status-badge" style="background: #f3f4f6; color: #6b7280;">普通用户</span>'}
|
||
</td>
|
||
<td>
|
||
${user.is_active
|
||
? '<span class="status-badge status-success">激活</span>'
|
||
: '<span class="status-badge status-warning">禁用</span>'}
|
||
</td>
|
||
<td class="text-sm text-neutral-500">${formatTime(user.created_at)}</td>
|
||
<td>
|
||
<div class="flex gap-2">
|
||
<button onclick="viewUserTasks(${user.id})" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition" title="查看任务">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
|
||
</svg>
|
||
</button>
|
||
<button onclick="refreshUserSession(${user.id}, "${user.jwxt_username || user.username}")" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition" title="刷新 Session">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||
</svg>
|
||
</button>
|
||
<button onclick="deleteUser(${user.id}, '${user.username}')" class="p-2 hover:bg-red-100 dark:hover:bg-red-900/30 text-red-600 dark:text-red-400 rounded-lg transition" title="删除用户">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
`).join('')};
|
||
|
||
|
||
// 渲染分页
|
||
function renderPagination(total, pages, current) {
|
||
const container = document.getElementById('usersPagination');
|
||
let html = '';
|
||
|
||
html += `<button onclick="loadUsers(${current - 1})" ${current === 1 ? 'disabled' : ''} class="px-3 py-1 rounded-lg bg-neutral-100 dark:bg-neutral-800 text-sm disabled:opacity-50">上一页</button>`;
|
||
|
||
for (let i = 1; i <= pages; i++) {
|
||
if (i === 1 || i === pages || (i >= current - 2 && i <= current + 2)) {
|
||
html += `<button onclick="loadUsers(${i})" class="px-3 py-1 rounded-lg text-sm ${i === current ? 'bg-neutral-900 dark:bg-white text-white dark:text-black' : 'bg-neutral-100 dark:bg-neutral-800'}">${i}</button>`;
|
||
} else if (i === current - 3 || i === current + 3) {
|
||
html += `<span class="px-2">...</span>`;
|
||
}
|
||
}
|
||
|
||
html += `<button onclick="loadUsers(${current + 1})" ${current === pages ? 'disabled' : ''} class="px-3 py-1 rounded-lg bg-neutral-100 dark:bg-neutral-800 text-sm disabled:opacity-50">下一页</button>`;
|
||
container.innerHTML = html;
|
||
}
|
||
|
||
|
||
|
||
// 加载注册码列表
|
||
async function loadTickets() {
|
||
if (!schoolCache.length) await loadSchools();
|
||
const loading = document.getElementById('ticketsLoading');
|
||
const empty = document.getElementById('ticketsEmpty');
|
||
const table = document.getElementById('ticketsTable');
|
||
|
||
loading.classList.remove('hidden');
|
||
empty.classList.add('hidden');
|
||
table.classList.add('hidden');
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/tickets/list');
|
||
loading.classList.add('hidden');
|
||
|
||
if (!data.success || !data.tickets || data.tickets.length === 0) {
|
||
empty.classList.remove('hidden');
|
||
return;
|
||
}
|
||
|
||
// 更新统计
|
||
if (data.stats) {
|
||
document.getElementById('ticketTotal').textContent = data.stats.total || 0;
|
||
document.getElementById('ticketUsed').textContent = data.stats.used || 0;
|
||
document.getElementById('ticketAvailable').textContent = data.stats.available || 0;
|
||
}
|
||
|
||
renderTicketsTable(data.tickets);
|
||
table.classList.remove('hidden');
|
||
} catch (error) {
|
||
loading.classList.add('hidden');
|
||
showToast('加载失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 渲染注册码表格
|
||
let ticketSelection = new Set();
|
||
|
||
function updateTicketBatchBar() {
|
||
const bar = document.getElementById('ticketBatchBar');
|
||
const count = document.getElementById('ticketSelectedCount');
|
||
const selectAll = document.getElementById('ticketSelectAll');
|
||
if (count) count.textContent = ticketSelection.size;
|
||
if (bar) bar.classList.toggle('hidden', ticketSelection.size === 0);
|
||
if (selectAll && window._ticketsCache) {
|
||
selectAll.checked = window._ticketsCache.length > 0 && ticketSelection.size === window._ticketsCache.length;
|
||
}
|
||
}
|
||
|
||
function toggleTicketSelection(code, checked) {
|
||
if (checked) {
|
||
ticketSelection.add(code);
|
||
} else {
|
||
ticketSelection.delete(code);
|
||
}
|
||
updateTicketBatchBar();
|
||
}
|
||
|
||
function toggleSelectAllTickets(checked) {
|
||
ticketSelection = new Set();
|
||
if (checked && window._ticketsCache) {
|
||
window._ticketsCache.forEach(t => ticketSelection.add(t.code));
|
||
}
|
||
document.querySelectorAll('.ticket-checkbox').forEach(cb => { cb.checked = checked; });
|
||
updateTicketBatchBar();
|
||
}
|
||
|
||
function copyTextToClipboard(text) {
|
||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||
return navigator.clipboard.writeText(text);
|
||
}
|
||
const textarea = document.createElement('textarea');
|
||
textarea.value = text;
|
||
document.body.appendChild(textarea);
|
||
textarea.select();
|
||
document.execCommand('copy');
|
||
document.body.removeChild(textarea);
|
||
return Promise.resolve();
|
||
}
|
||
|
||
function copyGeneratedCodes() {
|
||
const text = document.getElementById('ticketCreateCodes').value;
|
||
copyTextToClipboard(text).then(() => showToast('注册码已复制到剪贴板', 'success'));
|
||
}
|
||
|
||
function copySelectedTickets() {
|
||
if (ticketSelection.size === 0) return;
|
||
const text = Array.from(ticketSelection).join('\n');
|
||
copyTextToClipboard(text).then(() => showToast(`已复制 ${ticketSelection.size} 个注册码`, 'success'));
|
||
}
|
||
|
||
async function batchTicketAction(action) {
|
||
if (ticketSelection.size === 0) return;
|
||
const actionNames = { disable: '禁用', enable: '启用', delete: '删除' };
|
||
if (!confirm(`确定要${actionNames[action]}选中的 ${ticketSelection.size} 个注册码吗?${action === 'delete' ? '删除会同时删除使用这些注册码的用户,此操作不可恢复。' : ''}`)) return;
|
||
|
||
let successCount = 0;
|
||
for (const code of ticketSelection) {
|
||
try {
|
||
const data = await apiRequest(`/api/admin/tickets/${code}/${action}`, { method: 'POST' });
|
||
if (data.success) successCount++;
|
||
} catch (error) { /* 继续处理下一个 */ }
|
||
}
|
||
showToast(`成功${actionNames[action]} ${successCount} 个注册码`, successCount > 0 ? 'success' : 'error');
|
||
ticketSelection = new Set();
|
||
loadTickets();
|
||
}
|
||
|
||
function renderTicketsTable(tickets) {
|
||
window._ticketsCache = tickets;
|
||
ticketSelection = new Set(ticketSelection);
|
||
const tbody = document.getElementById('ticketsTableBody');
|
||
tbody.innerHTML = tickets.map((ticket, index) => {
|
||
const isExpired = ticket.expires_at && new Date(ticket.expires_at) < new Date();
|
||
const isFullyUsed = ticket.uses >= ticket.max_uses;
|
||
const expiryText = ticket.pending_activation
|
||
? (ticket.activated_at
|
||
? `<span class="text-blue-600 dark:text-blue-400">已激活·${formatDate(ticket.expires_at)}到期</span>`
|
||
: '<span class="text-neutral-400">待激活(使用后计时)</span>')
|
||
: formatDate(ticket.expires_at);
|
||
return `
|
||
<tr>
|
||
<td><input type="checkbox" class="ticket-checkbox w-4 h-4 rounded border-neutral-300" ${ticketSelection.has(ticket.code) ? 'checked' : ''} onchange="toggleTicketSelection('${ticket.code}', this.checked)"></td>
|
||
<td class="font-mono text-sm font-medium">${ticket.code}</td>
|
||
<td class="text-sm">${ticket.school_ids === null || ticket.school_ids === undefined ? '全部学校' : escapeHtml(ticket.school_ids.map(id => schoolCache.find(s => s.id === id)?.name || id).join('、'))}</td>
|
||
<td>${ticket.used_by.length > 0 ? ticket.used_by.join(', ') : '<span class="text-neutral-400">-</span>'}</td>
|
||
<td>${ticket.uses} / ${ticket.max_uses}</td>
|
||
<td>
|
||
${!ticket.enabled ? '<span class="status-badge status-warning">已禁用</span>' :
|
||
isExpired ? '<span class="status-badge status-danger">已过期</span>' :
|
||
isFullyUsed ? '<span class="status-badge status-info">已用完</span>' :
|
||
ticket.pending_activation ? '<span class="status-badge status-info">待激活</span>' :
|
||
'<span class="status-badge status-success">可用</span>'}
|
||
</td>
|
||
<td class="text-sm text-neutral-500">${expiryText}</td>
|
||
<td class="text-sm text-neutral-500">${formatDate(ticket.created_at)}</td>
|
||
<td>
|
||
<div class="flex gap-2">
|
||
${ticket.enabled ? `
|
||
<button onclick="disableTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-amber-600" title="禁用">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
|
||
</svg>
|
||
</button>
|
||
` : `
|
||
<button onclick="enableTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-green-600" title="启用">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
</button>
|
||
`}
|
||
<button onclick="deleteTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-red-600" title="删除">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
`;
|
||
}).join('');
|
||
}
|
||
|
||
// 模态框控制
|
||
function openModal(id) {
|
||
document.getElementById(id).classList.remove('hidden');
|
||
document.documentElement.style.overflow = 'hidden';
|
||
document.body.style.overflow = 'hidden';
|
||
}
|
||
function closeModal(id) {
|
||
document.getElementById(id).classList.add('hidden');
|
||
document.documentElement.style.overflow = '';
|
||
document.body.style.overflow = '';
|
||
}
|
||
function openCreateUserModal() {
|
||
document.getElementById('createUserForm').reset();
|
||
loadSchools().then(() => {
|
||
const select = document.getElementById('newUserSchool');
|
||
select.replaceChildren(...schoolCache.map(school => {
|
||
const option = document.createElement('option');
|
||
option.value = school.id; option.textContent = school.name;
|
||
return option;
|
||
}));
|
||
});
|
||
openModal('createUserModal');
|
||
}
|
||
function closeCreateUserModal() {
|
||
closeModal('createUserModal');
|
||
}
|
||
function openCreateTicketModal() {
|
||
document.getElementById('createTicketForm').reset();
|
||
document.getElementById('ticketCreateResult').classList.add('hidden');
|
||
toggleTicketActivateOnUse();
|
||
toggleTicketSchoolScope();
|
||
loadSchools();
|
||
openModal('createTicketModal');
|
||
}
|
||
function toggleTicketActivateOnUse() {
|
||
const onUse = document.getElementById('ticketActivateOnUse').checked;
|
||
document.getElementById('ticketExpiryGroup').classList.toggle('hidden', onUse);
|
||
document.getElementById('ticketValidDaysGroup').classList.toggle('hidden', !onUse);
|
||
document.getElementById('ticketExpiryDays').required = !onUse;
|
||
document.getElementById('ticketValidDays').required = onUse;
|
||
}
|
||
function closeCreateTicketModal() {
|
||
closeModal('createTicketModal');
|
||
}
|
||
function openCreateAffiliateModal() {
|
||
document.getElementById('createAffiliateForm').reset();
|
||
openModal('createAffiliateModal');
|
||
}
|
||
function closeCreateAffiliateModal() {
|
||
closeModal('createAffiliateModal');
|
||
}
|
||
|
||
// 推广人详情模态框
|
||
let currentAffiliateCode = null;
|
||
let currentPendingCommission = 0;
|
||
|
||
async function openAffiliateDetailModal(code) {
|
||
currentAffiliateCode = code;
|
||
currentPendingCommission = 0;
|
||
openModal('affiliateDetailModal');
|
||
|
||
// 重置显示
|
||
document.getElementById('statTotalOrders').textContent = '-';
|
||
document.getElementById('statPaidOrders').textContent = '-';
|
||
document.getElementById('statTotalSales').textContent = '-';
|
||
document.getElementById('statTotalCommission').textContent = '-';
|
||
document.getElementById('statPendingCommission').textContent = '-';
|
||
document.getElementById('statTotalSettled').textContent = '-';
|
||
document.getElementById('recentOrdersLoading').classList.remove('hidden');
|
||
document.getElementById('recentOrdersEmpty').classList.add('hidden');
|
||
document.getElementById('recentOrdersList').classList.add('hidden');
|
||
|
||
try {
|
||
const data = await apiRequest(`/api/admin/affiliates/${code}`);
|
||
|
||
if (data.success) {
|
||
const affiliate = data.affiliate;
|
||
const stats = affiliate.stats;
|
||
|
||
// 保存待结佣金
|
||
currentPendingCommission = stats.pending_commission || 0;
|
||
|
||
// 基本信息
|
||
document.getElementById('detailAffiliateCode').textContent = `推广码: ${affiliate.code}`;
|
||
document.getElementById('detailAffiliateName').textContent = affiliate.name;
|
||
document.getElementById('detailCommissionRate').textContent = `${affiliate.commission_rate}%`;
|
||
document.getElementById('detailDiscountAmount').textContent = `¥${affiliate.discount_amount}/人`;
|
||
document.getElementById('detailCreatedAt').textContent = formatDate(affiliate.created_at);
|
||
|
||
// 推广链接
|
||
const baseUrl = window.location.origin;
|
||
document.getElementById('affiliateLink').value = `${baseUrl}/buy?invitecode=${affiliate.code}`;
|
||
|
||
// 统计数据
|
||
document.getElementById('statTotalOrders').textContent = stats.total_orders;
|
||
document.getElementById('statPaidOrders').textContent = stats.paid_orders;
|
||
document.getElementById('statTotalSales').textContent = `¥${stats.total_sales}`;
|
||
document.getElementById('statTotalCommission').textContent = `¥${stats.total_commission.toFixed(2)}`;
|
||
document.getElementById('statPendingCommission').textContent = `¥${(stats.pending_commission || 0).toFixed(2)}`;
|
||
document.getElementById('statTotalSettled').textContent = `¥${(stats.total_settled || 0).toFixed(2)}`;
|
||
|
||
// 控制结清按钮显示
|
||
const btnSettle = document.getElementById('btnSettleAffiliate');
|
||
if (currentPendingCommission <= 0) {
|
||
btnSettle.classList.add('opacity-50', 'cursor-not-allowed');
|
||
btnSettle.disabled = true;
|
||
} else {
|
||
btnSettle.classList.remove('opacity-50', 'cursor-not-allowed');
|
||
btnSettle.disabled = false;
|
||
}
|
||
|
||
// 最近订单
|
||
document.getElementById('recentOrdersLoading').classList.add('hidden');
|
||
|
||
if (affiliate.recent_orders.length === 0) {
|
||
document.getElementById('recentOrdersEmpty').classList.remove('hidden');
|
||
} else {
|
||
document.getElementById('recentOrdersList').classList.remove('hidden');
|
||
renderRecentOrders(affiliate.recent_orders);
|
||
}
|
||
} else {
|
||
showToast(data.message || '获取推广人信息失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
console.error('获取推广人详情失败:', error);
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
function closeAffiliateDetailModal() {
|
||
closeModal('affiliateDetailModal');
|
||
currentAffiliateCode = null;
|
||
currentPendingCommission = 0;
|
||
}
|
||
|
||
// 结清佣金模态框
|
||
function openSettleAffiliateModal() {
|
||
if (!currentAffiliateCode || currentPendingCommission <= 0) {
|
||
showToast('没有待结佣金', 'error');
|
||
return;
|
||
}
|
||
document.getElementById('settleAffiliateCode').textContent = `推广码: ${currentAffiliateCode}`;
|
||
document.getElementById('settlePendingAmount').textContent = `¥${currentPendingCommission.toFixed(2)}`;
|
||
document.getElementById('settleAmount').value = currentPendingCommission.toFixed(2);
|
||
document.getElementById('settleNote').value = '';
|
||
document.getElementById('settleAffiliateModal').classList.remove('hidden');
|
||
}
|
||
|
||
function closeSettleAffiliateModal() {
|
||
closeModal('settleAffiliateModal');
|
||
}
|
||
|
||
async function submitSettleAffiliate(event) {
|
||
event.preventDefault();
|
||
|
||
if (!currentAffiliateCode) {
|
||
showToast('推广码错误', 'error');
|
||
return;
|
||
}
|
||
|
||
const settleAmount = parseFloat(document.getElementById('settleAmount').value);
|
||
const note = document.getElementById('settleNote').value.trim();
|
||
|
||
if (!settleAmount || settleAmount <= 0) {
|
||
showToast('结算金额必须大于0', 'error');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const data = await apiRequest(`/api/admin/affiliates/${currentAffiliateCode}/settle`, {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
settle_amount: settleAmount,
|
||
note: note
|
||
})
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast('佣金结清成功', 'success');
|
||
closeSettleAffiliateModal();
|
||
// 刷新详情
|
||
openAffiliateDetailModal(currentAffiliateCode);
|
||
} else {
|
||
showToast(data.message || '结清失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
console.error('结清佣金失败:', error);
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
function renderRecentOrders(orders) {
|
||
const container = document.getElementById('recentOrdersList');
|
||
container.innerHTML = orders.map(order => `
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-lg p-3 text-sm">
|
||
<div class="flex justify-between items-start">
|
||
<div>
|
||
<p class="font-medium text-neutral-900 dark:text-white">${order.email}</p>
|
||
<p class="text-xs text-neutral-500">订单号: ${order.order_id}</p>
|
||
</div>
|
||
<div class="text-right">
|
||
<p class="font-medium text-neutral-900 dark:text-white">¥${order.final_amount}</p>
|
||
<p class="text-xs text-neutral-500">${order.quantity} 份</p>
|
||
</div>
|
||
</div>
|
||
<div class="flex justify-between items-center mt-2 pt-2 border-t border-neutral-200 dark:border-neutral-700">
|
||
<span class="text-xs text-neutral-500">${order.paid_at ? formatDate(order.paid_at) : '-'}</span>
|
||
<span class="text-xs text-orange-600 dark:text-orange-400">佣金: ¥${order.commission_amount.toFixed(2)}</span>
|
||
</div>
|
||
${order.ticket_codes && order.ticket_codes.length > 0 ? `
|
||
<div class="mt-2 pt-2 border-t border-neutral-200 dark:border-neutral-700">
|
||
<p class="text-xs text-neutral-500 mb-1">注册码:</p>
|
||
<div class="flex flex-wrap gap-1">
|
||
${order.ticket_codes.map(code => `<span class="px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 text-xs rounded">${code}</span>`).join('')}
|
||
</div>
|
||
</div>
|
||
` : ''}
|
||
</div>
|
||
`).join('');
|
||
}
|
||
|
||
function copyAffiliateLink() {
|
||
const input = document.getElementById('affiliateLink');
|
||
input.select();
|
||
document.execCommand('copy');
|
||
showToast('推广链接已复制', 'success');
|
||
}
|
||
function showBatchRefreshModal() {
|
||
document.getElementById('batchForceRefresh').checked = false;
|
||
document.getElementById('batchRefreshResult').classList.add('hidden');
|
||
openModal('batchRefreshModal');
|
||
}
|
||
function closeBatchRefreshModal() {
|
||
closeModal('batchRefreshModal');
|
||
}
|
||
function refreshUserSession(userId, username) {
|
||
document.getElementById('singleRefreshUserId').value = userId;
|
||
document.getElementById('singleRefreshUsername').value = username;
|
||
document.getElementById('singleRefreshPassword').value = '';
|
||
document.getElementById('singleForceRefresh').checked = false;
|
||
document.getElementById('singleRefreshResult').innerHTML = '';
|
||
openModal('singleRefreshModal');
|
||
}
|
||
function closeSingleRefreshModal() {
|
||
closeModal('singleRefreshModal');
|
||
}
|
||
|
||
// 提交创建用户
|
||
async function submitCreateUser(event) {
|
||
event.preventDefault();
|
||
const username = document.getElementById('newUsername').value.trim();
|
||
const password = document.getElementById('newPassword').value;
|
||
const isAdmin = document.getElementById('newIsAdmin').checked;
|
||
const schoolId = document.getElementById('newUserSchool').value;
|
||
|
||
if (!username || !password) {
|
||
showToast('请填写完整信息', 'error');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/users/create', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username, password, is_admin: isAdmin, school_id: schoolId })
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast('用户创建成功', 'success');
|
||
closeCreateUserModal();
|
||
loadUsers();
|
||
loadStats();
|
||
} else {
|
||
showToast(data.message || '创建失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 提交创建注册码
|
||
async function submitCreateTicket(event) {
|
||
event.preventDefault();
|
||
const count = parseInt(document.getElementById('ticketCount').value);
|
||
const maxUses = parseInt(document.getElementById('ticketMaxUses').value);
|
||
const activateOnUse = document.getElementById('ticketActivateOnUse').checked;
|
||
const payload = { count, max_uses: maxUses, activate_on_use: activateOnUse };
|
||
if (document.getElementById('ticketSchoolScope').value === 'selected') {
|
||
payload.school_ids = [...document.querySelectorAll('.ticket-school-checkbox:checked')].map(input => input.value);
|
||
if (!payload.school_ids.length) { showToast('至少选择一所学校', 'error'); return; }
|
||
}
|
||
if (activateOnUse) {
|
||
payload.valid_days = parseInt(document.getElementById('ticketValidDays').value);
|
||
} else {
|
||
payload.expiry_days = parseInt(document.getElementById('ticketExpiryDays').value);
|
||
}
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/tickets/create', {
|
||
method: 'POST',
|
||
body: JSON.stringify(payload)
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast(`成功生成 ${data.codes.length} 个注册码`, 'success');
|
||
// 展示生成的注册码并提供一键复制
|
||
document.getElementById('ticketCreateCodes').value = data.codes.join('\n');
|
||
document.getElementById('ticketCreateResult').classList.remove('hidden');
|
||
if (currentTab === 'tickets') {
|
||
loadTickets();
|
||
}
|
||
} else {
|
||
showToast(data.message || '生成失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 禁用/启用/删除注册码
|
||
async function disableTicket(code) {
|
||
if (!confirm(`确定要禁用注册码 ${code} 吗?`)) return;
|
||
try {
|
||
const data = await apiRequest(`/api/admin/tickets/${code}/disable`, { method: 'POST' });
|
||
if (data.success) {
|
||
showToast('注册码已禁用', 'success');
|
||
loadTickets();
|
||
} else {
|
||
showToast(data.message || '操作失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
async function enableTicket(code) {
|
||
try {
|
||
const data = await apiRequest(`/api/admin/tickets/${code}/enable`, { method: 'POST' });
|
||
if (data.success) {
|
||
showToast('注册码已启用', 'success');
|
||
loadTickets();
|
||
} else {
|
||
showToast(data.message || '操作失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
async function deleteTicket(code) {
|
||
if (!confirm(`确定要删除注册码 ${code} 吗?此操作不可恢复。`)) return;
|
||
try {
|
||
const data = await apiRequest(`/api/admin/tickets/${code}/delete`, { method: 'POST' });
|
||
if (data.success) {
|
||
showToast('注册码已删除', 'success');
|
||
loadTickets();
|
||
} else {
|
||
showToast(data.message || '操作失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 批量检查 Session
|
||
async function batchCheckSession() {
|
||
if (!confirm('开始批量检查所有用户的 Session 状态?')) return;
|
||
showToast('正在检查 Session 状态...', 'info');
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/session/batch_check', { method: 'POST', body: JSON.stringify({}) });
|
||
if (data.success) {
|
||
const results = data.results;
|
||
showToast(`检查完成:有效${results.valid}个,过期${results.invalid}个`, 'success');
|
||
loadStats();
|
||
loadUsers();
|
||
} else {
|
||
showToast(data.message || '检查失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 删除用户
|
||
async function deleteUser(userId, username) {
|
||
if (!confirm(`确定要删除用户 "${username}" 吗?\n\n此操作将同时删除该用户的所有任务,且不可恢复。`)) return;
|
||
try {
|
||
const data = await apiRequest(`/api/admin/users/${userId}/delete`, { method: 'POST' });
|
||
if (data.success) {
|
||
showToast('用户已删除', 'success');
|
||
loadUsers();
|
||
loadStats();
|
||
} else {
|
||
showToast(data.message || '删除失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 仅检查
|
||
async function batchCheckOnly() {
|
||
showToast('正在检查...', 'info');
|
||
try {
|
||
const data = await apiRequest('/api/admin/session/batch_check', { method: 'POST', body: JSON.stringify({}) });
|
||
if (data.success) {
|
||
const results = data.results;
|
||
document.getElementById('resultValid').textContent = results.valid;
|
||
document.getElementById('resultRefreshed').textContent = 0;
|
||
document.getElementById('resultFailed').textContent = results.invalid + results.no_jwxt;
|
||
|
||
const tbody = document.getElementById('batchRefreshDetails');
|
||
tbody.innerHTML = results.details.map(d => `
|
||
<tr>
|
||
<td>${escapeHtml(d.username)}</td>
|
||
<td>
|
||
${d.status === 'valid' ? '<span class="status-badge status-success">有效</span>' :
|
||
d.status === 'no_jwxt' ? '<span class="status-badge" style="background: #f3f4f6; color: #6b7280;">未配置</span>' :
|
||
'<span class="status-badge status-danger">过期</span>'}
|
||
</td>
|
||
<td class="text-sm">${escapeHtml(d.message) || '-'}</td>
|
||
</tr>
|
||
`).join('');
|
||
|
||
document.getElementById('batchRefreshResult').classList.remove('hidden');
|
||
loadStats();
|
||
}
|
||
} catch (error) {
|
||
showToast('检查失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 执行批量刷新
|
||
async function doBatchRefresh() {
|
||
const force = document.getElementById('batchForceRefresh').checked;
|
||
|
||
showToast('正在刷新...', 'info');
|
||
try {
|
||
const data = await apiRequest('/api/admin/session/batch_refresh', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ force })
|
||
});
|
||
|
||
if (data.success) {
|
||
const results = data.results;
|
||
document.getElementById('resultValid').textContent = results.valid;
|
||
document.getElementById('resultRefreshed').textContent = results.refreshed;
|
||
document.getElementById('resultFailed').textContent = results.failed + results.no_password;
|
||
|
||
const tbody = document.getElementById('batchRefreshDetails');
|
||
tbody.innerHTML = results.details.map(d => `
|
||
<tr>
|
||
<td>${escapeHtml(d.username)}</td>
|
||
<td>
|
||
${d.status === 'valid' ? '<span class="status-badge status-success">有效</span>' :
|
||
d.status === 'refreshed' ? '<span class="status-badge status-info">已刷新</span>' :
|
||
d.status === 'no_password' ? '<span class="status-badge status-warning">无密码</span>' :
|
||
'<span class="status-badge status-danger">失败</span>'}
|
||
</td>
|
||
<td class="text-sm">${escapeHtml(d.message) || '-'}</td>
|
||
</tr>
|
||
`).join('');
|
||
|
||
document.getElementById('batchRefreshResult').classList.remove('hidden');
|
||
showToast(`刷新完成`, 'success');
|
||
loadStats();
|
||
loadUsers();
|
||
} else {
|
||
showToast(data.message || '刷新失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 执行单用户刷新
|
||
async function doSingleRefresh() {
|
||
const userId = document.getElementById('singleRefreshUserId').value;
|
||
const password = document.getElementById('singleRefreshPassword').value.trim();
|
||
const force = document.getElementById('singleForceRefresh').checked;
|
||
|
||
if (!password) {
|
||
document.getElementById('singleRefreshResult').innerHTML = '<div class="p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 rounded-lg text-sm">请输入密码</div>';
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const data = await apiRequest(`/api/admin/users/${userId}/session/refresh`, {
|
||
method: 'POST',
|
||
body: JSON.stringify({ jwxt_password: password, force })
|
||
});
|
||
|
||
if (data.success) {
|
||
document.getElementById('singleRefreshResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
|
||
setTimeout(() => {
|
||
closeSingleRefreshModal();
|
||
loadStats();
|
||
loadUsers();
|
||
}, 1500);
|
||
} else {
|
||
document.getElementById('singleRefreshResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
|
||
}
|
||
} catch (error) {
|
||
document.getElementById('singleRefreshResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">刷新失败</div>';
|
||
}
|
||
}
|
||
|
||
// 查看用户任务
|
||
function viewUserTasks(userId) {
|
||
window.location.href = `/tasks?user_id=${userId}`;
|
||
}
|
||
|
||
|
||
// 加载推广码列表
|
||
async function loadAffiliates() {
|
||
const loading = document.getElementById('affiliatesLoading');
|
||
const empty = document.getElementById('affiliatesEmpty');
|
||
const table = document.getElementById('affiliatesTable');
|
||
|
||
loading.classList.remove('hidden');
|
||
empty.classList.add('hidden');
|
||
table.classList.add('hidden');
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/affiliates/list');
|
||
loading.classList.add('hidden');
|
||
|
||
if (!data.success || !data.affiliates || data.affiliates.length === 0) {
|
||
empty.classList.remove('hidden');
|
||
return;
|
||
}
|
||
|
||
renderAffiliatesTable(data.affiliates);
|
||
table.classList.remove('hidden');
|
||
} catch (error) {
|
||
loading.classList.add('hidden');
|
||
showToast('加载失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 渲染推广码表格
|
||
function renderAffiliatesTable(affiliates) {
|
||
const tbody = document.getElementById('affiliatesTableBody');
|
||
tbody.innerHTML = affiliates.map((aff, index) => `
|
||
<tr>
|
||
<td class="font-mono text-sm font-bold">${aff.code}</td>
|
||
<td class="font-medium">${escapeHtml(aff.name)}</td>
|
||
<td>
|
||
<span class="status-badge status-info">${aff.commission_rate}%</span>
|
||
</td>
|
||
<td>
|
||
<span class="status-badge status-success">-¥${aff.discount_amount}</span>
|
||
</td>
|
||
<td class="text-sm text-neutral-500">${formatDate(aff.created_at)}</td>
|
||
<td>
|
||
<div class="flex gap-2">
|
||
<button onclick="openAffiliateDetailModal('${aff.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-green-600" title="查看详情">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
|
||
</svg>
|
||
</button>
|
||
<button onclick="editAffiliate('${aff.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-blue-600" title="编辑">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
|
||
</svg>
|
||
</button>
|
||
<button onclick="deleteAffiliate('${aff.code}', "${aff.name}")" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-red-600" title="删除">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
`).join('');
|
||
}
|
||
|
||
// 提交创建推广人
|
||
async function submitCreateAffiliate(event) {
|
||
event.preventDefault();
|
||
const code = document.getElementById('affiliateCode').value.trim().toUpperCase();
|
||
const name = document.getElementById('affiliateName').value.trim();
|
||
const commissionRate = parseInt(document.getElementById('affiliateCommission').value);
|
||
const discountAmount = parseInt(document.getElementById('affiliateDiscount').value);
|
||
|
||
if (!code || !name) {
|
||
showToast('请填写完整信息', 'error');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const data = await apiRequest('/api/admin/affiliates/create', {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
code,
|
||
name,
|
||
commission_rate: commissionRate,
|
||
discount_amount: discountAmount
|
||
})
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast('推广人创建成功', 'success');
|
||
closeCreateAffiliateModal();
|
||
loadAffiliates();
|
||
} else {
|
||
showToast(data.message || '创建失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 删除推广人
|
||
async function deleteAffiliate(code, name) {
|
||
if (!confirm(`确定要删除推广人 "${name}" (${code}) 吗?\n\n此操作不可恢复。`)) return;
|
||
try {
|
||
const data = await apiRequest(`/api/admin/affiliates/${code}/delete`, { method: 'POST' });
|
||
if (data.success) {
|
||
showToast('推广人已删除', 'success');
|
||
loadAffiliates();
|
||
} else {
|
||
showToast(data.message || '删除失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 编辑推广人(简化版:直接删除后重新创建)
|
||
async function editAffiliate(code) {
|
||
// 获取当前信息
|
||
try {
|
||
const data = await apiRequest(`/api/admin/affiliates/${code}`);
|
||
if (data.success && data.affiliate) {
|
||
const aff = data.affiliate;
|
||
// 填充表单
|
||
document.getElementById('affiliateCode').value = aff.code;
|
||
document.getElementById('affiliateName').value = aff.name;
|
||
document.getElementById('affiliateCommission').value = aff.commission_rate;
|
||
document.getElementById('affiliateDiscount').value = aff.discount_amount;
|
||
// 禁用推广码输入(不允许修改)
|
||
document.getElementById('affiliateCode').disabled = true;
|
||
// 显示模态框
|
||
document.getElementById('createAffiliateModal').classList.remove('hidden');
|
||
// 修改标题
|
||
document.querySelector('#createAffiliateModal h3').textContent = '编辑推广人';
|
||
// 修改提交函数
|
||
document.getElementById('createAffiliateForm').onsubmit = async function(e) {
|
||
e.preventDefault();
|
||
await updateAffiliate(code);
|
||
};
|
||
}
|
||
} catch (error) {
|
||
showToast('加载推广人信息失败', 'error');
|
||
}
|
||
}
|
||
|
||
// 更新推广人
|
||
async function updateAffiliate(code) {
|
||
const name = document.getElementById('affiliateName').value.trim();
|
||
const commissionRate = parseInt(document.getElementById('affiliateCommission').value);
|
||
const discountAmount = parseInt(document.getElementById('affiliateDiscount').value);
|
||
|
||
try {
|
||
const data = await apiRequest(`/api/admin/affiliates/${code}/update`, {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
name,
|
||
commission_rate: commissionRate,
|
||
discount_amount: discountAmount
|
||
})
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast('推广人更新成功', 'success');
|
||
closeCreateAffiliateModal();
|
||
loadAffiliates();
|
||
// 重置表单
|
||
document.getElementById('affiliateCode').disabled = false;
|
||
document.querySelector('#createAffiliateModal h3').textContent = '添加推广人';
|
||
document.getElementById('createAffiliateForm').onsubmit = submitCreateAffiliate;
|
||
} else {
|
||
showToast(data.message || '更新失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// ==================== 支付管理功能 ====================
|
||
|
||
|
||
// 加载订单数据
|
||
async function loadPaymentOrders() {
|
||
const loadingState = document.getElementById('paymentLoadingState');
|
||
const emptyState = document.getElementById('paymentEmptyState');
|
||
const tbody = document.getElementById('paymentOrdersTableBody');
|
||
|
||
loadingState.classList.remove('hidden');
|
||
emptyState.classList.add('hidden');
|
||
tbody.innerHTML = '';
|
||
|
||
try {
|
||
const status = document.getElementById('paymentFilterStatus').value;
|
||
const search = document.getElementById('paymentSearchInput').value;
|
||
|
||
let url = '/api/admin/orders?status=' + status;
|
||
if (search) {
|
||
url += '&search=' + encodeURIComponent(search);
|
||
}
|
||
|
||
const data = await apiRequest(url);
|
||
|
||
loadingState.classList.add('hidden');
|
||
|
||
if (data.success) {
|
||
currentPaymentOrders = data.orders;
|
||
renderPaymentOrders(currentPaymentOrders);
|
||
updatePaymentStats(data.stats);
|
||
} else {
|
||
showToast(data.message || '加载失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
console.error('加载订单失败:', error);
|
||
loadingState.classList.add('hidden');
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 渲染订单列表
|
||
function renderPaymentOrders(orders) {
|
||
const tbody = document.getElementById('paymentOrdersTableBody');
|
||
const emptyState = document.getElementById('paymentEmptyState');
|
||
|
||
if (orders.length === 0) {
|
||
emptyState.classList.remove('hidden');
|
||
tbody.innerHTML = '';
|
||
return;
|
||
}
|
||
|
||
emptyState.classList.add('hidden');
|
||
|
||
tbody.innerHTML = orders.map((order, index) => `
|
||
<tr class="hover:bg-neutral-50 dark:hover:bg-neutral-800/50">
|
||
<td class="font-mono text-xs">${order.order_id}</td>
|
||
<td>${escapeHtml(order.email)}</td>
|
||
<td>${order.quantity}</td>
|
||
<td>¥${order.amount}</td>
|
||
<td class="text-green-600">-¥${order.invite_discount_total || 0}</td>
|
||
<td class="font-bold">¥${order.final_amount}</td>
|
||
<td>
|
||
${order.invite_code ? `<span class="px-2 py-1 bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded text-xs">${order.invite_code}</span>` : '-'}
|
||
</td>
|
||
<td>${getPaymentStatusBadge(order.status)}</td>
|
||
<td class="text-neutral-500">${formatDate(order.created_at)}</td>
|
||
<td class="text-neutral-500">${order.paid_at ? formatDate(order.paid_at) : '-'}</td>
|
||
<td>
|
||
<div class="flex gap-2">
|
||
<button onclick="viewPaymentOrderDetail('${order.order_id}')" class="p-1.5 text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded" title="查看详情">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
|
||
</svg>
|
||
</button>
|
||
${order.status === 'pending' ? `
|
||
<button onclick="openConfirmPayment('${order.order_id}')" class="p-1.5 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20 rounded" title="确认支付">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
</button>
|
||
<button onclick="openRejectOrder('${order.order_id}')" class="p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded" title="拒绝订单">
|
||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
</button>
|
||
` : ''}
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
`).join('');
|
||
}
|
||
|
||
// 获取状态标签
|
||
function getPaymentStatusBadge(status) {
|
||
const statusMap = {
|
||
'pending': '<span class="status-badge status-pending">待支付</span>',
|
||
'paid': '<span class="status-badge status-paid">已支付</span>',
|
||
'processed': '<span class="status-badge status-processed">已处理</span>',
|
||
'failed': '<span class="status-badge status-failed">支付失败</span>',
|
||
'cancelled': '<span class="status-badge status-cancelled">已取消</span>',
|
||
'expired': '<span class="status-badge status-cancelled">已过期</span>',
|
||
'refunded': '<span class="status-badge status-refunded">已退款</span>'
|
||
};
|
||
return statusMap[status] || `<span class="status-badge">${status}</span>`;
|
||
}
|
||
|
||
// 更新统计
|
||
function updatePaymentStats(stats) {
|
||
document.getElementById('paymentStatTotal').textContent = stats.total;
|
||
document.getElementById('paymentStatPending').textContent = stats.pending;
|
||
document.getElementById('paymentStatPaid').textContent = stats.paid;
|
||
document.getElementById('paymentStatProcessed').textContent = stats.processed;
|
||
document.getElementById('paymentStatRevenue').textContent = '¥' + stats.revenue;
|
||
}
|
||
|
||
// 查看订单详情
|
||
async function viewPaymentOrderDetail(orderId) {
|
||
const order = currentPaymentOrders.find(o => o.order_id === orderId);
|
||
if (!order) return;
|
||
|
||
currentPaymentOrderId = orderId;
|
||
const content = document.getElementById('paymentOrderDetailContent');
|
||
|
||
content.innerHTML = `
|
||
<div class="space-y-4">
|
||
<div class="grid grid-cols-2 gap-4">
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500">订单号</p>
|
||
<p class="font-mono text-sm">${order.order_id}</p>
|
||
</div>
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500">状态</p>
|
||
<p>${getPaymentStatusBadge(order.status)}</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500 mb-1">邮箱</p>
|
||
<p class="font-medium">${escapeHtml(order.email)}</p>
|
||
</div>
|
||
|
||
<div class="grid grid-cols-2 gap-4">
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500">购买数量</p>
|
||
<p class="text-lg font-bold">${order.quantity} 份</p>
|
||
</div>
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500">推广码</p>
|
||
<p class="text-lg font-bold">${order.invite_code || '-'}</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500 mb-2">金额明细</p>
|
||
<div class="flex justify-between text-sm">
|
||
<span>原价</span>
|
||
<span>¥${order.amount}</span>
|
||
</div>
|
||
<div class="flex justify-between text-sm text-green-600">
|
||
<span>推广优惠</span>
|
||
<span>-¥${order.invite_discount_total || 0}</span>
|
||
</div>
|
||
<div class="flex justify-between font-bold mt-1 pt-1 border-t border-neutral-200 dark:border-neutral-700">
|
||
<span>实付</span>
|
||
<span>¥${order.final_amount}</span>
|
||
</div>
|
||
</div>
|
||
|
||
${order.platform_order_no ? `
|
||
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
|
||
<p class="text-xs text-neutral-500">支付平台订单号</p>
|
||
<p class="font-mono text-sm">${order.platform_order_no}</p>
|
||
</div>
|
||
` : ''}
|
||
|
||
${order.ticket_codes && order.ticket_codes.length > 0 ? `
|
||
<div class="bg-green-50 dark:bg-green-900/20 rounded-xl p-3">
|
||
<p class="text-xs text-green-600 mb-2">注册码</p>
|
||
<div class="space-y-1">
|
||
${order.ticket_codes.map(code => `
|
||
<div class="font-mono text-sm bg-white dark:bg-neutral-800 rounded px-2 py-1">${code}</div>
|
||
`).join('')}
|
||
</div>
|
||
</div>
|
||
` : ''}
|
||
|
||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||
<div>
|
||
<p class="text-xs text-neutral-500">创建时间</p>
|
||
<p>${formatDate(order.created_at)}</p>
|
||
</div>
|
||
<div>
|
||
<p class="text-xs text-neutral-500">支付时间</p>
|
||
<p>${order.paid_at ? formatDate(order.paid_at) : '-'}</p>
|
||
</div>
|
||
</div>
|
||
|
||
${order.status === 'pending' ? `
|
||
<button onclick="closePaymentOrderDetail(); openConfirmPayment('${order.order_id}')"
|
||
class="w-full py-3 bg-green-600 text-white rounded-xl hover:bg-green-700 transition font-medium">
|
||
<svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
</svg>
|
||
手动确认支付
|
||
</button>
|
||
` : ''}
|
||
${order.status === 'pending' ? `
|
||
<button onclick="closePaymentOrderDetail(); openRejectOrder('${order.order_id}')"
|
||
class="w-full py-3 bg-red-600 text-white rounded-xl hover:bg-red-700 transition font-medium">
|
||
<svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||
</svg>
|
||
拒绝订单
|
||
</button>
|
||
` : ''}
|
||
</div>
|
||
`;
|
||
|
||
document.getElementById('paymentOrderDetailModal').classList.remove('hidden');
|
||
}
|
||
|
||
function closePaymentOrderDetail() {
|
||
document.getElementById('paymentOrderDetailModal').classList.add('hidden');
|
||
}
|
||
|
||
// 打开确认支付模态框
|
||
function openConfirmPayment(orderId) {
|
||
currentPaymentOrderId = orderId;
|
||
document.getElementById('confirmOrderId').textContent = orderId;
|
||
document.getElementById('confirmPaymentModal').classList.remove('hidden');
|
||
}
|
||
|
||
function closeConfirmPayment() {
|
||
document.getElementById('confirmPaymentModal').classList.add('hidden');
|
||
}
|
||
|
||
// 打开拒绝订单模态框
|
||
let currentRejectOrderId = null;
|
||
function openRejectOrder(orderId) {
|
||
currentRejectOrderId = orderId;
|
||
document.getElementById('rejectOrderId').textContent = orderId;
|
||
document.getElementById('rejectReason').value = '';
|
||
document.getElementById('rejectOrderModal').classList.remove('hidden');
|
||
}
|
||
|
||
function closeRejectOrder() {
|
||
document.getElementById('rejectOrderModal').classList.add('hidden');
|
||
currentRejectOrderId = null;
|
||
}
|
||
|
||
// 提交拒绝订单
|
||
async function submitRejectOrder() {
|
||
if (!currentRejectOrderId) return;
|
||
|
||
const reason = document.getElementById('rejectReason').value.trim();
|
||
|
||
try {
|
||
const response = await fetch(`/api/orders/${currentRejectOrderId}/cancel`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ reason: reason || '管理员拒绝' })
|
||
});
|
||
const data = await response.json();
|
||
|
||
if (data.success) {
|
||
showToast('订单已拒绝', 'success');
|
||
closeRejectOrder();
|
||
loadPaymentOrders();
|
||
} else {
|
||
showToast(data.message || '拒绝失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 提交确认支付
|
||
async function submitConfirmPayment() {
|
||
try {
|
||
const data = await apiRequest('/api/admin/orders/' + currentPaymentOrderId + '/confirm-payment', {
|
||
method: 'POST'
|
||
});
|
||
|
||
if (data.success) {
|
||
showToast('支付确认成功!注册码已生成并发送给用户。', 'success');
|
||
closeConfirmPayment();
|
||
loadPaymentOrders();
|
||
} else {
|
||
showToast('确认失败: ' + (data.message || '未知错误'), 'error');
|
||
}
|
||
} catch (error) {
|
||
console.error('确认支付失败:', error);
|
||
showToast('网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// 刷新数据
|
||
function refreshPaymentData() {
|
||
loadPaymentOrders();
|
||
}
|
||
|
||
// 格式化日期(强制北京时间)
|
||
function formatDate(dateStr) {
|
||
if (!dateStr) return '-';
|
||
const date = new Date(dateStr);
|
||
return date.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false }).replace(/\//g, '-');
|
||
}
|
||
|
||
// ==================== IP管理相关 ====================
|
||
let ipChartHour = null, ipChartRegion = null;
|
||
|
||
async function loadIpStats() {
|
||
const hours = document.getElementById('ipStatsHours') ? document.getElementById('ipStatsHours').value : 24;
|
||
const data = await apiRequest(`/api/admin/ip/stats?hours=${hours}`);
|
||
if (!data.success) return;
|
||
const s = data.stats;
|
||
document.getElementById('ipStatTotal').textContent = s.total.toLocaleString();
|
||
document.getElementById('ipStatUnique').textContent = s.unique_ips.toLocaleString();
|
||
document.getElementById('ipStatBlocked').textContent = s.blocked.toLocaleString();
|
||
document.getElementById('ipStatBans').textContent = s.active_bans;
|
||
|
||
// 时段分布(UTC+8)
|
||
const nowMs = Date.now();
|
||
const bjOffset = 8 * 3600000;
|
||
const allHours = [];
|
||
for (let i = parseInt(hours) - 1; i >= 0; i--) {
|
||
const bj = new Date(nowMs + bjOffset - i * 3600000);
|
||
if (hours <= 24) {
|
||
allHours.push(bj.toISOString().slice(11, 16)); // HH:MM(Beijing)
|
||
} else {
|
||
allHours.push(bj.toISOString().slice(5, 10)); // MM-DD
|
||
}
|
||
}
|
||
// 后端按 UTC 小时聚合,转成 UTC+8 小时映射
|
||
const hourMap = {};
|
||
s.by_hour.forEach(h => {
|
||
const bjHour = (parseInt(h.hour) + 8) % 24;
|
||
hourMap[String(bjHour).padStart(2,'0')] = h.count;
|
||
});
|
||
const hourData = allHours.map((_, idx) => {
|
||
return hourMap[String(idx).padStart(2,'0')] || 0;
|
||
});
|
||
renderIpBar('chartIpHour', allHours, hourData);
|
||
|
||
// 省市分布 - 环形图
|
||
const topRegions = s.by_region.slice(0, 10);
|
||
if (topRegions.length > 0) {
|
||
renderIpDoughnut('chartIpRegion', topRegions.map(r => r.region || '未知'), topRegions.map(r => r.count));
|
||
}
|
||
}
|
||
|
||
function renderIpBar(domId, labels, data) {
|
||
const dom = document.getElementById(domId);
|
||
if (!dom) return;
|
||
if (ipChartHour) {
|
||
ipChartHour.dispose();
|
||
ipChartHour = null;
|
||
}
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
ipChartHour = echarts.init(dom);
|
||
ipChartHour.setOption({
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
backgroundColor: isDark ? '#262626' : '#fff',
|
||
textStyle: { color: isDark ? '#fff' : '#333' }
|
||
},
|
||
grid: { left: '3%', right: '4%', bottom: '3%', top: '10%', containLabel: true },
|
||
xAxis: {
|
||
type: 'category',
|
||
data: labels,
|
||
axisLabel: { color: isDark ? '#888' : '#666', rotate: labels.length > 12 ? 45 : 0 },
|
||
axisLine: { lineStyle: { color: isDark ? '#444' : '#ddd' } }
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
axisLabel: { color: isDark ? '#888' : '#666' },
|
||
splitLine: { lineStyle: { color: isDark ? '#333' : '#eee' } }
|
||
},
|
||
series: [{
|
||
type: 'bar',
|
||
data: data,
|
||
itemStyle: {
|
||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#3b82f6' },
|
||
{ offset: 1, color: '#60a5fa' }
|
||
]),
|
||
borderRadius: [4, 4, 0, 0]
|
||
},
|
||
emphasis: { itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#2563eb' },
|
||
{ offset: 1, color: '#3b82f6' }
|
||
])}}
|
||
}]
|
||
});
|
||
window.addEventListener('resize', () => ipChartHour && ipChartHour.resize());
|
||
}
|
||
|
||
function renderIpDoughnut(domId, labels, data) {
|
||
const dom = document.getElementById(domId);
|
||
if (!dom) return;
|
||
if (ipChartRegion) {
|
||
ipChartRegion.dispose();
|
||
ipChartRegion = null;
|
||
}
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
ipChartRegion = echarts.init(dom);
|
||
const colors = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#f97316', '#22c55e', '#6366f1'];
|
||
ipChartRegion.setOption({
|
||
tooltip: {
|
||
trigger: 'item',
|
||
backgroundColor: isDark ? '#262626' : '#fff',
|
||
textStyle: { color: isDark ? '#fff' : '#333' }
|
||
},
|
||
legend: {
|
||
orient: 'vertical',
|
||
right: '5%',
|
||
top: 'center',
|
||
textStyle: { color: isDark ? '#888' : '#666', fontSize: 11 },
|
||
itemWidth: 12,
|
||
itemHeight: 12
|
||
},
|
||
series: [{
|
||
type: 'doughnut',
|
||
radius: ['45%', '70%'],
|
||
center: ['35%', '50%'],
|
||
avoidLabelOverlap: true,
|
||
itemStyle: { borderRadius: 4, borderColor: isDark ? '#171717' : '#fff', borderWidth: 2 },
|
||
label: { show: false },
|
||
emphasis: { label: { show: false } },
|
||
data: labels.map((label, i) => ({
|
||
value: data[i],
|
||
name: `${label} (${data[i]})`,
|
||
itemStyle: { color: colors[i % colors.length] }
|
||
}))
|
||
}]
|
||
});
|
||
window.addEventListener('resize', () => ipChartRegion && ipChartRegion.resize());
|
||
}
|
||
|
||
async function loadIpBansPreview() {
|
||
const data = await apiRequest('/api/admin/ip/bans');
|
||
const bans = data.bans || [];
|
||
const active = bans.filter(b => b.is_active);
|
||
const div = document.getElementById('ipBansPreview');
|
||
if (active.length === 0) {
|
||
div.innerHTML = '<div class="text-center text-neutral-400 py-4">暂无活跃封禁规则</div>';
|
||
return;
|
||
}
|
||
div.innerHTML = `<table class="w-full text-sm">
|
||
<thead>
|
||
<tr class="text-left text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700">
|
||
<th class="pb-2 pr-4 font-medium">类型</th>
|
||
<th class="pb-2 pr-4 font-medium">值</th>
|
||
<th class="pb-2 pr-4 font-medium">原因</th>
|
||
<th class="pb-2 pr-4 font-medium">到期</th>
|
||
<th class="pb-2 font-medium">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody class="divide-y divide-neutral-100 dark:divide-neutral-800">
|
||
${active.slice(0, 5).map(b => `
|
||
<tr class="hover:bg-neutral-50 dark:hover:bg-neutral-800/50">
|
||
<td class="py-2 pr-4"><span class="text-xs px-2 py-0.5 rounded-full font-medium ${b.ban_type==='ip'?'bg-red-100 text-red-600':b.ban_type==='cidr'?'bg-orange-100 text-orange-600':'bg-purple-100 text-purple-600'}">${b.ban_type.toUpperCase()}</span></td>
|
||
<td class="py-2 pr-4 font-mono text-sm text-neutral-800 dark:text-neutral-200">${b.value}</td>
|
||
<td class="py-2 pr-4 text-xs text-neutral-500">${b.reason || '-'}</td>
|
||
<td class="py-2 pr-4 text-xs text-neutral-500">${b.is_permanent ? '<span class="text-red-500 font-semibold">永久</span>' : (b.expires_at ? formatDate(b.expires_at) : '-')}</td>
|
||
<td class="py-2"><button onclick="unbanIpQuick(${b.id},'${b.value}')" class="text-xs px-2 py-1 rounded-lg bg-green-50 text-green-600 hover:bg-green-100">解封</button></td>
|
||
</tr>`).join('')}
|
||
</tbody></table>`;
|
||
}
|
||
|
||
async function unbanIpQuick(id, value) {
|
||
if (!confirm(`确认解封 ${value}?`)) return;
|
||
const data = await apiRequest('/api/admin/ip/unban', { method: 'POST', body: JSON.stringify({ id }) });
|
||
showToast(data.message, data.success ? 'success' : 'error');
|
||
if (data.success) { loadIpStats(); loadIpBansPreview(); }
|
||
}
|
||
|
||
// 添加封禁 Modal
|
||
function openIpBanModal() {
|
||
document.getElementById('ipBanModal').classList.remove('hidden');
|
||
}
|
||
|
||
async function submitIpBan() {
|
||
const value = document.getElementById('ipBanValue').value.trim();
|
||
if (!value) { showToast('请填写封禁值', 'error'); return; }
|
||
const data = await apiRequest('/api/admin/ip/ban', {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
value,
|
||
ban_type: document.getElementById('ipBanType').value,
|
||
duration: document.getElementById('ipBanDuration').value || null,
|
||
reason: document.getElementById('ipBanReason').value
|
||
})
|
||
});
|
||
showToast(data.message, data.success ? 'success' : 'error');
|
||
if (data.success) {
|
||
document.getElementById('ipBanModal').classList.add('hidden');
|
||
loadIpStats();
|
||
loadIpBansPreview();
|
||
}
|
||
}
|
||
|
||
// 频率限制配置 Modal
|
||
async function openIpConfigModal() {
|
||
const data = await apiRequest('/api/admin/ip/config');
|
||
if (data.success) {
|
||
document.getElementById('ipCfgWindow').value = data.config.login_window_minutes;
|
||
document.getElementById('ipCfgMax').value = data.config.login_max_attempts;
|
||
document.getElementById('ipCfgChinaOnly').checked = data.config.enable_china_only === 'true';
|
||
}
|
||
document.getElementById('ipConfigModal').classList.remove('hidden');
|
||
}
|
||
|
||
async function submitIpConfig() {
|
||
const data = await apiRequest('/api/admin/ip/config', {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
login_window_minutes: parseInt(document.getElementById('ipCfgWindow').value),
|
||
login_max_attempts: parseInt(document.getElementById('ipCfgMax').value),
|
||
enable_china_only: document.getElementById('ipCfgChinaOnly').checked
|
||
})
|
||
});
|
||
showToast(data.message, data.success ? 'success' : 'error');
|
||
if (data.success) document.getElementById('ipConfigModal').classList.add('hidden');
|
||
}
|
||
|
||
// ════════════════════════════════════════════════════════════
|
||
// 任务列表 Tab
|
||
// ════════════════════════════════════════════════════════════
|
||
|
||
function loadAdminTasks(page) {
|
||
page = page || 1;
|
||
currentAdminTaskPage = page;
|
||
const status = document.getElementById('adminTaskStatusFilter').value;
|
||
document.getElementById('adminTasksLoading').classList.remove('hidden');
|
||
document.getElementById('adminTasksEmpty').classList.add('hidden');
|
||
document.getElementById('adminTasksTableWrap').classList.add('hidden');
|
||
document.getElementById('adminTasksPagination').classList.add('hidden');
|
||
|
||
let url = `/api/admin/tasks/list?page=${page}&per_page=20`;
|
||
if (status) url += `&status=${status}`;
|
||
|
||
apiRequest(url).then(data => {
|
||
document.getElementById('adminTasksLoading').classList.add('hidden');
|
||
if (!data.success || !data.tasks || data.tasks.length === 0) {
|
||
document.getElementById('adminTasksEmpty').classList.remove('hidden');
|
||
return;
|
||
}
|
||
const tbody = document.getElementById('adminTasksBody');
|
||
const statusMap = {
|
||
'pending': '<span class="status-badge status-pending">待执行</span>',
|
||
'running': '<span class="status-badge status-running">执行中</span>',
|
||
'success': '<span class="status-badge status-success">成功</span>',
|
||
'failed': '<span class="status-badge status-failed">失败</span>',
|
||
'cancelled': '<span class="status-badge status-cancelled">已取消</span>',
|
||
'expired': '<span class="status-badge status-cancelled">已过期</span>'
|
||
};
|
||
// 重置批量选择
|
||
selectedTaskIds.clear();
|
||
document.getElementById('adminTaskSelectAll').checked = false;
|
||
updateBatchCancelBtn();
|
||
|
||
tbody.innerHTML = data.tasks.map((t, i) => {
|
||
const canCancel = t.status === 'pending' || t.status === 'running';
|
||
return `
|
||
<tr class="border-b border-neutral-100 dark:border-neutral-800 hover:bg-neutral-50 dark:hover:bg-neutral-900/50 transition-colors">
|
||
<td class="py-2 pr-2 w-8">
|
||
${canCancel ? `<input type="checkbox" class="admin-task-checkbox rounded" value="${t.id}" onchange="onTaskCheckboxChange()">` : ''}
|
||
</td>
|
||
<td class="py-2 pr-2 text-neutral-500 font-mono">#${t.id}</td>
|
||
<td class="py-2 pr-2">${escapeHtml(t.username || '?')}</td>
|
||
<td class="py-2 pr-2 font-medium">${escapeHtml(t.course_name)}</td>
|
||
<td class="py-2 pr-2">${statusMap[t.status] || t.status}</td>
|
||
<td class="py-2 pr-2 text-neutral-500">${t.retry_count}/${t.max_retries === 0 ? '∞' : t.max_retries}</td>
|
||
<td class="py-2 pr-2 text-neutral-500 text-xs">${formatTime(t.created_at)}</td>
|
||
<td class="py-2 flex gap-1">
|
||
<button onclick="window.open('/tasks?user_id=${t.user_id}','_blank')" class="text-xs px-2 py-1 rounded-lg border border-neutral-200 dark:border-neutral-700 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">查看</button>
|
||
${canCancel ? `<button onclick="adminCancelTask(${t.id})" class="text-xs px-2 py-1 rounded-lg bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 border border-red-200 dark:border-red-800 hover:bg-red-100 dark:hover:bg-red-900/40 transition-colors">取消</button>` : ''}
|
||
</td>
|
||
</tr>`;
|
||
}).join('');
|
||
document.getElementById('adminTasksBatchBar').classList.remove('hidden');
|
||
document.getElementById('adminTasksTableWrap').classList.remove('hidden');
|
||
|
||
// 分页
|
||
const nav = document.getElementById('adminTasksPagination').querySelector('div');
|
||
let ph = '';
|
||
ph += `<button onclick="loadAdminTasks(${page-1})" ${page===1?'disabled':''} class="px-2 py-1 text-xs rounded border border-neutral-200 dark:border-neutral-600 hover:bg-neutral-100 disabled:opacity-50">‹</button>`;
|
||
for (let i=1; i<=data.pages; i++) {
|
||
if (i===1||i===data.pages||(i>=page-2&&i<=page+2)) {
|
||
ph += `<button onclick="loadAdminTasks(${i})" class="px-2 py-1 text-xs rounded transition-colors ${i===page?'bg-black dark:bg-white text-white dark:text-black':'border border-neutral-200 dark:border-neutral-600 hover:bg-neutral-100'}">${i}</button>`;
|
||
} else if (i===page-3||i===page+3) {
|
||
ph += `<span class="px-1 text-neutral-400 text-xs">…</span>`;
|
||
}
|
||
}
|
||
ph += `<button onclick="loadAdminTasks(${page+1})" ${page===data.pages?'disabled':''} class="px-2 py-1 text-xs rounded border border-neutral-200 dark:border-neutral-600 hover:bg-neutral-100 disabled:opacity-50">›</button>`;
|
||
nav.innerHTML = ph;
|
||
document.getElementById('adminTasksPagination').classList.remove('hidden');
|
||
}).catch(() => {
|
||
document.getElementById('adminTasksLoading').classList.add('hidden');
|
||
});
|
||
}
|
||
|
||
// ── 管理员取消任务 ──
|
||
const selectedTaskIds = new Set();
|
||
|
||
function adminCancelTask(taskId) {
|
||
if (!confirm('确定要取消任务 #' + taskId + ' 吗?')) return;
|
||
apiRequest(`/api/tasks/${taskId}/cancel`, { method: 'POST' }).then(data => {
|
||
if (data.success) {
|
||
showToast('任务 #' + taskId + ' 已取消', 'success');
|
||
loadAdminTasks(currentAdminTaskPage || 1);
|
||
} else {
|
||
showToast(data.message || '取消失败', 'error');
|
||
}
|
||
}).catch(() => showToast('网络错误', 'error'));
|
||
}
|
||
|
||
function toggleSelectAll() {
|
||
const allChecked = Array.from(document.querySelectorAll('.admin-task-checkbox')).every(cb => cb.checked);
|
||
document.querySelectorAll('.admin-task-checkbox').forEach(cb => cb.checked = !allChecked);
|
||
document.getElementById('adminTaskSelectAll').checked = !allChecked;
|
||
selectedTaskIds.clear();
|
||
if (!allChecked) {
|
||
document.querySelectorAll('.admin-task-checkbox:checked').forEach(cb => selectedTaskIds.add(parseInt(cb.value)));
|
||
}
|
||
updateBatchCancelBtn();
|
||
}
|
||
|
||
function toggleAllCheckboxes(checked) {
|
||
document.querySelectorAll('.admin-task-checkbox').forEach(cb => cb.checked = checked);
|
||
selectedTaskIds.clear();
|
||
if (checked) {
|
||
document.querySelectorAll('.admin-task-checkbox').forEach(cb => selectedTaskIds.add(parseInt(cb.value)));
|
||
}
|
||
updateBatchCancelBtn();
|
||
}
|
||
|
||
function onTaskCheckboxChange() {
|
||
selectedTaskIds.clear();
|
||
document.querySelectorAll('.admin-task-checkbox:checked').forEach(cb => selectedTaskIds.add(parseInt(cb.value)));
|
||
const allCheckboxes = document.querySelectorAll('.admin-task-checkbox');
|
||
const allChecked = allCheckboxes.length > 0 && Array.from(allCheckboxes).every(cb => cb.checked);
|
||
document.getElementById('adminTaskSelectAll').checked = allChecked;
|
||
updateBatchCancelBtn();
|
||
}
|
||
|
||
function updateBatchCancelBtn() {
|
||
const btn = document.getElementById('adminBatchCancelBtn');
|
||
const countSpan = document.getElementById('adminBatchCount');
|
||
const count = selectedTaskIds.size;
|
||
countSpan.textContent = count;
|
||
btn.disabled = count === 0;
|
||
}
|
||
|
||
let currentAdminTaskPage = 1;
|
||
|
||
function batchCancelTasks() {
|
||
if (selectedTaskIds.size === 0) return;
|
||
if (!confirm(`确定要批量取消 ${selectedTaskIds.size} 个任务吗?`)) return;
|
||
|
||
apiRequest('/api/admin/tasks/batch_cancel', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ task_ids: Array.from(selectedTaskIds) })
|
||
}).then(data => {
|
||
if (data.success) {
|
||
showToast(`批量取消完成:${data.success_count}/${data.total} 成功`, 'success');
|
||
loadAdminTasks(currentAdminTaskPage || 1);
|
||
} else {
|
||
showToast(data.message || '批量取消失决', 'error');
|
||
}
|
||
}).catch(() => showToast('网络错误', 'error'));
|
||
}
|
||
|
||
let chartRealtime = null, chart24h = null;
|
||
let realtimeTimer = null;
|
||
|
||
function loadRequestStats() {
|
||
apiRequest('/api/admin/stats/requests').then(data => {
|
||
if (!data.success) return;
|
||
renderRealtimeChart(data.last_60s);
|
||
render24hChart(data.last_24h);
|
||
});
|
||
}
|
||
|
||
function renderRealtimeChart(data) {
|
||
const dom = document.getElementById('chartRealtime');
|
||
if (!dom) return;
|
||
if (!chartRealtime) chartRealtime = echarts.init(dom);
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
chartRealtime.setOption({
|
||
tooltip: { trigger: 'axis', formatter: '{b0}<br/>{c0} 次/秒' },
|
||
grid: { left: 44, right: 8, top: 8, bottom: 24 },
|
||
xAxis: {
|
||
type: 'category',
|
||
data: data.map(d => d.time.slice(3)), // MM:SS
|
||
axisLabel: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
axisLine: { show: false },
|
||
axisTick: { show: false },
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
minInterval: 1,
|
||
name: '次/秒',
|
||
nameTextStyle: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
axisLabel: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
splitLine: { lineStyle: { color: isDark ? '#333' : '#eee', type: 'dashed' } },
|
||
},
|
||
series: [{
|
||
type: 'line',
|
||
data: data.map(d => d.count),
|
||
smooth: true,
|
||
symbol: 'none',
|
||
lineStyle: { width: 2, color: '#3b82f6' },
|
||
areaStyle: {
|
||
color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1,
|
||
colorStops: [{ offset: 0, color: 'rgba(59,130,246,0.3)' }, { offset: 1, color: 'rgba(59,130,246,0)' }] }
|
||
}
|
||
}]
|
||
});
|
||
}
|
||
|
||
function render24hChart(data) {
|
||
const dom = document.getElementById('chart24h');
|
||
if (!dom) return;
|
||
if (!chart24h) chart24h = echarts.init(dom);
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
chart24h.setOption({
|
||
tooltip: { trigger: 'axis', formatter: '{b0}<br/>{c0} 次/小时' },
|
||
grid: { left: 44, right: 8, top: 8, bottom: 24 },
|
||
xAxis: {
|
||
type: 'category',
|
||
data: data.map(d => d.time),
|
||
axisLabel: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
axisLine: { show: false },
|
||
axisTick: { show: false },
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
minInterval: 1,
|
||
name: '次/小时',
|
||
nameTextStyle: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
axisLabel: { fontSize: 10, color: isDark ? '#999' : '#888' },
|
||
splitLine: { lineStyle: { color: isDark ? '#333' : '#eee', type: 'dashed' } },
|
||
},
|
||
series: [{
|
||
type: 'bar',
|
||
data: data.map(d => d.count),
|
||
itemStyle: {
|
||
color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1,
|
||
colorStops: [{ offset: 0, color: '#22c55e' }, { offset: 1, color: '#16a34a' }] }
|
||
},
|
||
barMaxWidth: 20,
|
||
}]
|
||
});
|
||
}
|
||
|
||
// 切换Tab时开始/停止实时刷新
|
||
window.addEventListener('resize', () => {
|
||
if (chartRealtime && document.getElementById('panel-tasks') && !document.getElementById('panel-tasks').classList.contains('hidden')) chartRealtime.resize();
|
||
if (chart24h) chart24h.resize();
|
||
});
|
||
|
||
</script>
|
||
|
||
<script>
|
||
// ==================== 多线路 & 选课模式 ====================
|
||
let mlBusy = false; // 写操作在途标志:轮询期间不回拨开关
|
||
|
||
async function mlFetch(url, opts = {}) {
|
||
const resp = await fetch(url, Object.assign({
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/json'},
|
||
credentials: 'same-origin',
|
||
}, opts));
|
||
let data;
|
||
try {
|
||
data = await resp.json();
|
||
} catch (e) {
|
||
throw new Error('响应非 JSON (HTTP ' + resp.status + ')');
|
||
}
|
||
if (!data || typeof data.success === 'undefined') {
|
||
throw new Error('HTTP ' + resp.status);
|
||
}
|
||
return data;
|
||
}
|
||
|
||
function mlLatencyText(lat) {
|
||
if (lat === null || lat === undefined) return '测速中';
|
||
return (lat * 1000).toFixed(0) + 'ms';
|
||
}
|
||
|
||
function mlCurrentSchool() {
|
||
return document.getElementById('mlSchool').value || '';
|
||
}
|
||
|
||
function mlSyncSchoolSelect(schools) {
|
||
const sel = document.getElementById('mlSchool');
|
||
if (!sel) return;
|
||
const cur = sel.value;
|
||
sel.replaceChildren();
|
||
for (const s of schools) {
|
||
const opt = document.createElement('option');
|
||
opt.value = s.id;
|
||
opt.textContent = s.name;
|
||
sel.appendChild(opt);
|
||
}
|
||
if (cur && schools.some(s => s.id === cur)) sel.value = cur;
|
||
}
|
||
|
||
async function mlEnsureSchools() {
|
||
if (document.getElementById('mlSchool').options.length) return;
|
||
try {
|
||
const data = await mlFetch('/api/admin/schools', {method: 'GET'});
|
||
if (data.success) mlSyncSchoolSelect(data.schools || []);
|
||
} catch (e) { /* 静默:状态接口仍会返回管理员所属学校 */ }
|
||
}
|
||
|
||
async function mlRefreshStatus() {
|
||
try {
|
||
const sid = mlCurrentSchool();
|
||
const data = await mlFetch('/api/admin/lines/status' + (sid ? ('?school_id=' + encodeURIComponent(sid)) : ''), {method: 'GET'});
|
||
if (!data.success) return;
|
||
// 写操作在途时不动开关位置,避免把用户刚拨的状态弹回
|
||
if (!mlBusy) {
|
||
document.getElementById('mlToggle').checked = !!data.multi_line_enabled;
|
||
document.getElementById('xkModeToggle').checked = !!data.xk_mode;
|
||
}
|
||
document.getElementById('mlCurrentLine').textContent = data.current_line || '-';
|
||
document.getElementById('mlAccounts').textContent =
|
||
(data.lines && data.lines.length ? Math.min(...data.lines.map(l => l.prewarmed || 0)) : 0)
|
||
+ ' / ' + (data.accounts || 0);
|
||
const box = document.getElementById('mlLinesBox');
|
||
box.innerHTML = (data.lines || []).map(l => `
|
||
<span class="px-3 py-1 rounded-full ${l.is_current
|
||
? 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400'
|
||
: 'bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300'}">
|
||
${l.tag} · ${mlLatencyText(l.latency)} · 预热 ${l.prewarmed || 0}
|
||
</span>`).join('');
|
||
} catch (e) { console.error(e); }
|
||
}
|
||
|
||
async function mlSetEnabled(enabled) {
|
||
mlBusy = true;
|
||
try {
|
||
const data = await mlFetch('/api/admin/lines/toggle', {body: JSON.stringify({enabled, school_id: mlCurrentSchool()})});
|
||
showToast(data.message || (data.success ? '操作成功' : '操作失败'), data.success ? 'success' : 'error');
|
||
} catch (e) {
|
||
showToast('操作失败:' + e.message, 'error');
|
||
} finally {
|
||
mlBusy = false;
|
||
mlRefreshStatus();
|
||
}
|
||
}
|
||
|
||
async function mlPrelogin() {
|
||
if (!confirm('对该校所有账号在全部线路上强制重新预热?')) return;
|
||
mlBusy = true;
|
||
try {
|
||
const data = await mlFetch('/api/admin/lines/prelogin', {body: JSON.stringify({school_id: mlCurrentSchool()})});
|
||
showToast(data.message || (data.success ? '预热已启动' : '操作失败'), data.success ? 'success' : 'error');
|
||
} catch (e) {
|
||
showToast('操作失败:' + e.message, 'error');
|
||
} finally {
|
||
mlBusy = false;
|
||
mlRefreshStatus();
|
||
}
|
||
}
|
||
|
||
async function xkModeSet(enabled) {
|
||
if (enabled && !confirm('开启该校的选课模式?该校非核心服务将被暂停和拦截。')) {
|
||
document.getElementById('xkModeToggle').checked = false;
|
||
return;
|
||
}
|
||
mlBusy = true;
|
||
try {
|
||
const data = await mlFetch('/api/admin/xk_mode', {body: JSON.stringify({enabled, school_id: mlCurrentSchool()})});
|
||
showToast(data.message || (data.success ? '操作成功' : '操作失败'), data.success ? (enabled ? 'warning' : 'success') : 'error');
|
||
} catch (e) {
|
||
showToast('操作失败:' + e.message, 'error');
|
||
} finally {
|
||
mlBusy = false;
|
||
mlRefreshStatus();
|
||
}
|
||
}
|
||
|
||
document.addEventListener('DOMContentLoaded', async () => {
|
||
await mlEnsureSchools();
|
||
mlRefreshStatus();
|
||
});
|
||
setInterval(mlRefreshStatus, 30000);
|
||
</script>
|
||
{% endblock %}
|