feat: 管理后台(/admin) — 用户空间总览/文件管理/按日期批量清理/功能使用统计; usage事件记录; ADMIN_TOKEN鉴权
This commit is contained in:
1 parent
70e03feca6
commit
ae2448aefb
4 files changed
+875
No files matched your search
Vendored
+1
@@ -11,6 +11,7 @@ declare module '@vue/runtime-core' {
|
||||
export interface GlobalComponents {
|
||||
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
||||
About: typeof import('./src/pages/About.vue')['default']
|
||||
'Admin.page': typeof import('./src/pages/Admin.page.vue')['default']
|
||||
AiRetouch: typeof import('./src/tools/ai-retouch/ai-retouch.vue')['default']
|
||||
App: typeof import('./src/App.vue')['default']
|
||||
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
||||
|
||||
@@ -706,6 +706,53 @@ def _auth_user(handler):
|
||||
|
||||
|
||||
TURNSTILE_SECRET = os.environ.get("TURNSTILE_SECRET", "")
|
||||
ADMIN_TOKEN = os.environ.get("ADMIN_TOKEN", "")
|
||||
USAGE_DB = os.environ.get("USAGE_DB", "/app/data/usage.db")
|
||||
|
||||
|
||||
def _usage_db():
|
||||
conn = sqlite3.connect(USAGE_DB)
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS usage (id INTEGER PRIMARY KEY AUTOINCREMENT, machine TEXT, username TEXT, tool TEXT, at REAL)")
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_usage_at ON usage(at)")
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_usage_tool ON usage(tool)")
|
||||
conn.commit()
|
||||
return conn
|
||||
|
||||
|
||||
def log_usage(machine: str, tool: str):
|
||||
"""record a tool usage event (best-effort, never blocks the request)"""
|
||||
if not tool:
|
||||
return
|
||||
try:
|
||||
username = ""
|
||||
try:
|
||||
conn = _db()
|
||||
rows = conn.execute("SELECT username, bound_machines FROM users").fetchall()
|
||||
conn.close()
|
||||
for u, bm in rows:
|
||||
if machine in json.loads(bm or "[]"):
|
||||
username = u
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
conn = _usage_db()
|
||||
conn.execute("INSERT INTO usage (machine, username, tool, at) VALUES (?,?,?,?)",
|
||||
(machine or "", username, tool, time.time()))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _dir_size(path: str) -> int:
|
||||
total = 0
|
||||
for root, _dirs, files in os.walk(path):
|
||||
for f in files:
|
||||
try:
|
||||
total += os.path.getsize(os.path.join(root, f))
|
||||
except OSError:
|
||||
pass
|
||||
return total
|
||||
|
||||
|
||||
def verify_turnstile(token: str) -> bool:
|
||||
@@ -727,6 +774,169 @@ def verify_turnstile(token: str) -> bool:
|
||||
USER_NAME_RE = re.compile(r"^[A-Za-z0-9_\u4e00-\u9fa5-]{3,32}$")
|
||||
|
||||
|
||||
def _admin_auth(handler) -> bool:
|
||||
if not ADMIN_TOKEN:
|
||||
return False
|
||||
tok = handler.headers.get("X-Admin-Token", "")
|
||||
return bool(tok) and tok == ADMIN_TOKEN
|
||||
|
||||
|
||||
def admin_api(method: str, sub: str, payload: dict, handler):
|
||||
"""returns (status, body)"""
|
||||
if not _admin_auth(handler):
|
||||
return 403, {"code": 403, "message": "管理员令牌无效"}
|
||||
|
||||
if method == "GET" and sub == "/overview":
|
||||
conn = _db()
|
||||
users = conn.execute("SELECT username, created, card_key, bound_machines FROM users").fetchall()
|
||||
conn.close()
|
||||
out_users = []
|
||||
total_files = 0
|
||||
total_size = 0
|
||||
for username, created, card_key, bm in users:
|
||||
udir = os.path.join(USERS_ROOT, username)
|
||||
fdir = os.path.join(udir, "files")
|
||||
fcount = 0
|
||||
fsize = 0
|
||||
for root, _d, files in os.walk(fdir):
|
||||
for f in files:
|
||||
fcount += 1
|
||||
try:
|
||||
fsize += os.path.getsize(os.path.join(root, f))
|
||||
except OSError:
|
||||
pass
|
||||
dsize = 0
|
||||
dp = os.path.join(udir, "data.json")
|
||||
if os.path.exists(dp):
|
||||
try:
|
||||
dsize = os.path.getsize(dp)
|
||||
except OSError:
|
||||
pass
|
||||
total_files += fcount
|
||||
total_size += fsize + dsize
|
||||
try:
|
||||
machines = json.loads(bm or "[]")
|
||||
except Exception:
|
||||
machines = []
|
||||
out_users.append({
|
||||
"username": username,
|
||||
"created": int(created or 0),
|
||||
"files": fcount,
|
||||
"file_size": fsize,
|
||||
"data_size": dsize,
|
||||
"total_size": fsize + dsize,
|
||||
"devices": len(machines),
|
||||
"licensed": bool(card_key),
|
||||
})
|
||||
out_users.sort(key=lambda x: -x["total_size"])
|
||||
return 200, {"code": 200, "message": "ok", "data": {
|
||||
"users": out_users,
|
||||
"totals": {"users": len(out_users), "files": total_files, "size": total_size},
|
||||
}}
|
||||
|
||||
if method == "GET" and sub.startswith("/files"):
|
||||
qs = parse.parse_qs(parse.urlparse(handler.path).query)
|
||||
username = (qs.get("username") or [""])[0]
|
||||
if not username or "/" in username or ".." in username:
|
||||
return 400, {"code": 400, "message": "参数错误"}
|
||||
fdir = os.path.join(_user_dir(username), "files")
|
||||
files = []
|
||||
total = 0
|
||||
for root, _d, fs in os.walk(fdir):
|
||||
kind = os.path.basename(root) if root != fdir else ""
|
||||
for f in fs:
|
||||
fp = os.path.join(root, f)
|
||||
try:
|
||||
st = os.stat(fp)
|
||||
except OSError:
|
||||
continue
|
||||
total += st.st_size
|
||||
files.append({"id": f, "name": f, "kind": kind, "size": st.st_size, "mtime": int(st.st_mtime)})
|
||||
files.sort(key=lambda x: -x["mtime"])
|
||||
return 200, {"code": 200, "message": "ok", "data": {"files": files, "total_size": total, "count": len(files)}}
|
||||
|
||||
if method == "POST" and sub == "/cleanup":
|
||||
before = int(payload.get("before") or 0)
|
||||
username = str(payload.get("username") or "")
|
||||
if before <= 0:
|
||||
return 400, {"code": 400, "message": "缺少时间参数"}
|
||||
removed = 0
|
||||
freed = 0
|
||||
roots = []
|
||||
if username:
|
||||
roots.append((username, os.path.join(_user_dir(username), "files")))
|
||||
else:
|
||||
if os.path.isdir(USERS_ROOT):
|
||||
for u in os.listdir(USERS_ROOT):
|
||||
roots.append((u, os.path.join(USERS_ROOT, u, "files")))
|
||||
for _u, fdir in roots:
|
||||
if not os.path.isdir(fdir):
|
||||
continue
|
||||
for root, _d, fs in os.walk(fdir, topdown=False):
|
||||
for f in fs:
|
||||
fp = os.path.join(root, f)
|
||||
try:
|
||||
st = os.stat(fp)
|
||||
except OSError:
|
||||
continue
|
||||
if st.st_mtime < before:
|
||||
try:
|
||||
freed += st.st_size
|
||||
removed += 1
|
||||
os.remove(fp)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
if not os.listdir(root):
|
||||
os.rmdir(root)
|
||||
except OSError:
|
||||
pass
|
||||
return 200, {"code": 200, "message": "ok", "data": {"removed": removed, "freed": freed}}
|
||||
|
||||
if method == "POST" and sub == "/delete-file":
|
||||
file_id = str(payload.get("id") or "")
|
||||
username = str(payload.get("username") or "")
|
||||
if not re.match(r"^[A-Za-z0-9_-]{8,64}$", file_id) or not username:
|
||||
return 400, {"code": 400, "message": "参数错误"}
|
||||
base = os.path.join(_user_dir(username), "files")
|
||||
target = os.path.join(base, file_id)
|
||||
if not os.path.exists(target):
|
||||
# search kind subdirs
|
||||
target = None
|
||||
for d in os.listdir(base) if os.path.isdir(base) else []:
|
||||
p2 = os.path.join(base, d, file_id)
|
||||
if os.path.exists(p2):
|
||||
target = p2
|
||||
break
|
||||
if not target or not os.path.exists(target):
|
||||
return 404, {"code": 404, "message": "文件不存在"}
|
||||
size = os.path.getsize(target)
|
||||
os.remove(target)
|
||||
conn = _db()
|
||||
conn.execute("DELETE FROM files WHERE id=?", (file_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return 200, {"code": 200, "message": "ok", "data": {"freed": size}}
|
||||
|
||||
if method == "GET" and sub == "/usage":
|
||||
qs = parse.parse_qs(parse.urlparse(handler.path).query)
|
||||
days = _int_str((qs.get("days") or ["7"])[0], 1, 365, 7)
|
||||
since = time.time() - days * 86400
|
||||
conn = _usage_db()
|
||||
by_tool = conn.execute("SELECT tool, COUNT(*) c FROM usage WHERE at>? GROUP BY tool ORDER BY c DESC LIMIT 30", (since,)).fetchall()
|
||||
by_user = conn.execute("SELECT username, COUNT(*) c, MAX(at) last FROM usage WHERE at>? AND username!='' GROUP BY username ORDER BY c DESC LIMIT 50", (since,)).fetchall()
|
||||
total = conn.execute("SELECT COUNT(*) FROM usage WHERE at>?", (since,)).fetchone()[0]
|
||||
conn.close()
|
||||
return 200, {"code": 200, "message": "ok", "data": {
|
||||
"days": days,
|
||||
"total": total,
|
||||
"by_tool": [{"tool": t, "count": c} for t, c in by_tool],
|
||||
"by_user": [{"username": u, "count": c, "last": int(l or 0)} for u, c, l in by_user],
|
||||
}}
|
||||
|
||||
return 404, {"code": 404, "message": "unknown admin api"}
|
||||
|
||||
|
||||
def _req_machine(handler):
|
||||
return handler.headers.get("X-Machine-Id", "") if handler else ""
|
||||
|
||||
@@ -926,8 +1136,26 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return # response already sent (file download)
|
||||
self._reply(status, json.dumps(body, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
def _handle_admin(self, method):
|
||||
parsed = parse.urlparse(self.path)
|
||||
sub = parsed.path[len("/admin"):]
|
||||
payload = {}
|
||||
if method == "POST":
|
||||
try:
|
||||
length = int(self.headers.get("Content-Length") or 0)
|
||||
raw = self.rfile.read(length) if length else b"{}"
|
||||
payload = json.loads(raw.decode("utf-8") or "{}")
|
||||
except Exception:
|
||||
self._reply(400, json.dumps({"code": 400, "message": "无效请求体"}, ensure_ascii=False).encode(), "application/json")
|
||||
return
|
||||
status, body = admin_api(method, sub, payload, self)
|
||||
self._reply(status, json.dumps(body, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
|
||||
def do_GET(self):
|
||||
parsed = parse.urlparse(self.path)
|
||||
if parsed.path.startswith("/admin"):
|
||||
self._handle_admin("GET")
|
||||
return
|
||||
if parsed.path.startswith("/user"):
|
||||
self._handle_user("GET")
|
||||
return
|
||||
@@ -953,6 +1181,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
machine = self.headers.get("X-Machine-Id", "")
|
||||
tool = self.headers.get("X-Tool", "")
|
||||
status = check(machine, tool)
|
||||
if status == 200:
|
||||
log_usage(machine, tool)
|
||||
self._reply(status, b"ok" if status == 200 else b"forbidden")
|
||||
return
|
||||
|
||||
@@ -987,6 +1217,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if status != 200:
|
||||
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
log_usage(machine, "video-tools")
|
||||
try:
|
||||
ctype = self.headers.get("Content-Type", "")
|
||||
length = int(self.headers.get("Content-Length") or 0)
|
||||
@@ -1054,6 +1285,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if status != 200:
|
||||
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
log_usage(machine, "audio-tools-tts")
|
||||
try:
|
||||
length = int(self.headers.get("Content-Length") or 0)
|
||||
raw = self.rfile.read(length) if length else b"{}"
|
||||
@@ -1094,6 +1326,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if status != 200:
|
||||
self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json")
|
||||
return
|
||||
log_usage(machine, "audio-tools-asr")
|
||||
workdir = None
|
||||
try:
|
||||
ctype = self.headers.get("Content-Type", "")
|
||||
@@ -1136,6 +1369,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_POST(self):
|
||||
parsed = parse.urlparse(self.path)
|
||||
if parsed.path.startswith("/admin"):
|
||||
self._handle_admin("POST")
|
||||
return
|
||||
if parsed.path.startswith("/user"):
|
||||
self._handle_user("POST")
|
||||
return
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
|
||||
useHead({ title: '管理后台 - IT-TOOLS-PRO' });
|
||||
|
||||
const TOKEN_KEY = 'it-tools-admin-token';
|
||||
const token = ref(localStorage.getItem(TOKEN_KEY) ?? '');
|
||||
const authed = ref(false);
|
||||
const error = ref('');
|
||||
const busy = ref(false);
|
||||
|
||||
async function api(path: string, init: RequestInit = {}) {
|
||||
const res = await fetch(`/relay${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Admin-Token': token.value,
|
||||
...(init.headers ?? {}),
|
||||
},
|
||||
});
|
||||
if (res.status === 403) {
|
||||
authed.value = false;
|
||||
throw new Error('管理员令牌无效');
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function login() {
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const b = await api('/admin/overview');
|
||||
if (b.code === 200) {
|
||||
authed.value = true;
|
||||
localStorage.setItem(TOKEN_KEY, token.value);
|
||||
loadOverview();
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 总览 ============
|
||||
const overview = ref<any>(null);
|
||||
const users = computed(() => overview.value?.users ?? []);
|
||||
const totals = computed(() => overview.value?.totals ?? { users: 0, files: 0, size: 0 });
|
||||
|
||||
function fmtSize(n: number) {
|
||||
if (n > 1024 * 1024 * 1024) {
|
||||
return (n / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
||||
}
|
||||
if (n > 1024 * 1024) {
|
||||
return (n / 1024 / 1024).toFixed(1) + ' MB';
|
||||
}
|
||||
if (n > 1024) {
|
||||
return (n / 1024).toFixed(1) + ' KB';
|
||||
}
|
||||
return n + ' B';
|
||||
}
|
||||
|
||||
function fmtDate(t: number) {
|
||||
if (!t) {
|
||||
return '-';
|
||||
}
|
||||
const d = new Date(t * 1000);
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||
}
|
||||
|
||||
async function loadOverview() {
|
||||
const b = await api('/admin/overview');
|
||||
overview.value = b.data;
|
||||
}
|
||||
|
||||
// ============ 文件管理 ============
|
||||
const fileUser = ref('');
|
||||
const fileList = ref<any[]>([]);
|
||||
const fileTotal = ref(0);
|
||||
const cleanupDays = ref(7);
|
||||
const cleanupUser = ref('');
|
||||
const cleanupResult = ref('');
|
||||
|
||||
async function loadFiles() {
|
||||
if (!fileUser.value) {
|
||||
return;
|
||||
}
|
||||
const b = await api(`/admin/files?username=${encodeURIComponent(fileUser.value)}`);
|
||||
fileList.value = b.data?.files ?? [];
|
||||
fileTotal.value = b.data?.total_size ?? 0;
|
||||
}
|
||||
|
||||
async function delFile(id: string) {
|
||||
const b = await api('/admin/delete-file', { method: 'POST', body: JSON.stringify({ id, username: fileUser.value }) });
|
||||
if (b.code === 200) {
|
||||
await loadFiles();
|
||||
loadOverview();
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanup() {
|
||||
if (!window.confirm(`确认删除 ${cleanupUser.value || '全部用户'} 在 ${cleanupDays.value} 天前的所有云端文件?不可恢复!`)) {
|
||||
return;
|
||||
}
|
||||
const before = Math.floor(Date.now() / 1000) - cleanupDays.value * 86400;
|
||||
const b = await api('/admin/cleanup', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ before, username: cleanupUser.value }),
|
||||
});
|
||||
if (b.code === 200) {
|
||||
cleanupResult.value = `已删除 ${b.data.removed} 个文件,释放 ${fmtSize(b.data.freed)}`;
|
||||
loadOverview();
|
||||
if (fileUser.value) {
|
||||
loadFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pickUser(u: string) {
|
||||
fileUser.value = u;
|
||||
cleanupUser.value = u;
|
||||
tab.value = 'files';
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
// ============ 使用统计 ============
|
||||
const usageDays = ref(7);
|
||||
const usage = ref<any>(null);
|
||||
|
||||
async function loadUsage() {
|
||||
const b = await api(`/admin/usage?days=${usageDays.value}`);
|
||||
usage.value = b.data;
|
||||
}
|
||||
|
||||
const TOOL_LABELS: Record<string, string> = {
|
||||
'translator': '在线翻译',
|
||||
'image-ocr': '图片OCR',
|
||||
'pdf-ocr': 'PDF文字识别',
|
||||
'ai-retouch': 'AI修图',
|
||||
'label-designer': '面单设计',
|
||||
'doc-convert': '文档格式转换',
|
||||
'image-tools': '图片工具',
|
||||
'pdf-tools': 'PDF工具',
|
||||
'video-tools': '视频工具',
|
||||
'audio-tools': '音频工具',
|
||||
'audio-tools-tts': '音频工具·文字转语音',
|
||||
'audio-tools-asr': '音频工具·语音识别',
|
||||
};
|
||||
|
||||
function toolLabel(t: string) {
|
||||
return TOOL_LABELS[t] ?? t;
|
||||
}
|
||||
|
||||
function fmtTime(t: number) {
|
||||
if (!t) {
|
||||
return '-';
|
||||
}
|
||||
const d = new Date(t * 1000);
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getMonth() + 1}/${d.getDate()} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
// ============ tabs ============
|
||||
const tab = ref<'overview' | 'files' | 'usage'>('overview');
|
||||
|
||||
function switchTab(id: 'overview' | 'files' | 'usage') {
|
||||
tab.value = id;
|
||||
if (id === 'overview') {
|
||||
loadOverview();
|
||||
}
|
||||
if (id === 'usage') {
|
||||
loadUsage();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="adm-root">
|
||||
<!-- login -->
|
||||
<div v-if="!authed" class="adm-login">
|
||||
<div class="adm-login-box">
|
||||
<div class="adm-login-title">🛠️ 管理后台</div>
|
||||
<input v-model="token" class="adm-input" type="password" placeholder="管理员令牌" @keyup.enter="login">
|
||||
<div v-if="error" class="adm-error">{{ error }}</div>
|
||||
<button class="adm-btn" :disabled="busy || !token" @click="login">
|
||||
{{ busy ? '验证中…' : '进入后台' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- panel -->
|
||||
<div v-else class="adm-layout">
|
||||
<div class="adm-nav">
|
||||
<div class="adm-nav-title">🛠️ 管理后台</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'overview' }" @click="switchTab('overview')">📊 总览与用户</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'files' }" @click="switchTab('files')">📁 文件管理</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'usage' }" @click="switchTab('usage')">📈 使用统计</div>
|
||||
<a href="javascript:;" class="adm-logout" @click="authed = false; localStorage.removeItem(TOKEN_KEY)">退出</a>
|
||||
</div>
|
||||
|
||||
<div class="adm-main">
|
||||
<!-- overview -->
|
||||
<template v-if="tab === 'overview'">
|
||||
<div class="adm-cards">
|
||||
<div class="adm-card"><div class="adm-card-num">{{ totals.users }}</div><div class="adm-card-label">注册用户</div></div>
|
||||
<div class="adm-card"><div class="adm-card-num">{{ totals.files }}</div><div class="adm-card-label">云端文件</div></div>
|
||||
<div class="adm-card"><div class="adm-card-num">{{ fmtSize(totals.size) }}</div><div class="adm-card-label">总占用</div></div>
|
||||
</div>
|
||||
<h3 class="adm-h3">用户列表 <span class="adm-sub">按占用排序,点击行查看文件</span></h3>
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr><th>用户名</th><th>文件数</th><th>文件占用</th><th>数据</th><th>设备</th><th>授权</th><th>注册</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="u in users" :key="u.username" @click="pickUser(u.username)">
|
||||
<td class="adm-user">{{ u.username }}</td>
|
||||
<td>{{ u.files }}</td>
|
||||
<td>{{ fmtSize(u.file_size) }}</td>
|
||||
<td>{{ fmtSize(u.data_size) }}</td>
|
||||
<td>{{ u.devices }}</td>
|
||||
<td><span class="adm-badge" :class="u.licensed ? 'ok' : ''">{{ u.licensed ? '已授权' : '-' }}</span></td>
|
||||
<td>{{ fmtDate(u.created) }}</td>
|
||||
<td><a href="javascript:;" class="adm-link" @click.stop="pickUser(u.username)">查看文件</a></td>
|
||||
</tr>
|
||||
<tr v-if="!users.length"><td colspan="8" class="adm-none">暂无注册用户</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<!-- files -->
|
||||
<template v-if="tab === 'files'">
|
||||
<div class="adm-toolbar">
|
||||
<select v-model="fileUser" class="adm-select" @change="loadFiles">
|
||||
<option value="">选择用户…</option>
|
||||
<option v-for="u in users" :key="u.username" :value="u.username">{{ u.username }}</option>
|
||||
</select>
|
||||
<span v-if="fileList.length" class="adm-sub">{{ fileList.length }} 个文件 · 合计 {{ fmtSize(fileTotal) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="adm-cleanup">
|
||||
<b>🗑️ 按日期清理</b>
|
||||
<select v-model="cleanupUser" class="adm-select">
|
||||
<option value="">全部用户</option>
|
||||
<option v-for="u in users" :key="u.username" :value="u.username">{{ u.username }}</option>
|
||||
</select>
|
||||
<select v-model.number="cleanupDays" class="adm-select">
|
||||
<option :value="1">1 天前</option>
|
||||
<option :value="3">3 天前</option>
|
||||
<option :value="7">7 天前</option>
|
||||
<option :value="14">14 天前</option>
|
||||
<option :value="30">30 天前</option>
|
||||
<option :value="90">90 天前</option>
|
||||
</select>
|
||||
<button class="adm-btn adm-btn-sm" @click="cleanup">执行清理</button>
|
||||
<span v-if="cleanupResult" class="adm-ok">{{ cleanupResult }}</span>
|
||||
</div>
|
||||
|
||||
<table class="adm-table">
|
||||
<thead>
|
||||
<tr><th>文件</th><th>类型</th><th>大小</th><th>时间</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="f in fileList" :key="f.id">
|
||||
<td class="adm-fname">{{ f.name }}</td>
|
||||
<td>{{ f.kind || '-' }}</td>
|
||||
<td>{{ fmtSize(f.size) }}</td>
|
||||
<td>{{ fmtTime(f.mtime) }}</td>
|
||||
<td><a href="javascript:;" class="adm-del" @click="delFile(f.id)">删除</a></td>
|
||||
</tr>
|
||||
<tr v-if="!fileList.length"><td colspan="5" class="adm-none">{{ fileUser ? '该用户暂无文件' : '请先选择用户' }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<!-- usage -->
|
||||
<template v-if="tab === 'usage'">
|
||||
<div class="adm-toolbar">
|
||||
<select v-model.number="usageDays" class="adm-select" @change="loadUsage">
|
||||
<option :value="7">近 7 天</option>
|
||||
<option :value="30">近 30 天</option>
|
||||
<option :value="90">近 90 天</option>
|
||||
</select>
|
||||
<span v-if="usage" class="adm-sub">总使用次数:{{ usage.total }}</span>
|
||||
</div>
|
||||
<div class="adm-usage-grid">
|
||||
<div>
|
||||
<h3 class="adm-h3">功能使用排行</h3>
|
||||
<div v-for="t in usage?.by_tool ?? []" :key="t.tool" class="adm-bar-row">
|
||||
<span class="adm-bar-label">{{ toolLabel(t.tool) }}</span>
|
||||
<div class="adm-bar-track"><div class="adm-bar" :style="{ width: Math.min(100, t.count * 100 / Math.max(1, usage.by_tool[0].count)) + '%' }" /></div>
|
||||
<span class="adm-bar-count">{{ t.count }}</span>
|
||||
</div>
|
||||
<div v-if="!usage?.by_tool?.length" class="adm-none">暂无使用记录</div>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="adm-h3">用户活跃排行</h3>
|
||||
<table class="adm-table">
|
||||
<thead><tr><th>用户</th><th>次数</th><th>最近活跃</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="u in usage?.by_user ?? []" :key="u.username">
|
||||
<td class="adm-user">{{ u.username }}</td>
|
||||
<td>{{ u.count }}</td>
|
||||
<td>{{ fmtTime(u.last) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!usage?.by_user?.length"><td colspan="3" class="adm-none">暂无登录用户使用记录</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.adm-root {
|
||||
min-height: 80vh;
|
||||
padding-bottom: 60px;
|
||||
}
|
||||
|
||||
.adm-login {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding-top: 90px;
|
||||
|
||||
.adm-login-box {
|
||||
width: 320px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 14px;
|
||||
padding: 26px;
|
||||
text-align: center;
|
||||
|
||||
.adm-login-title {
|
||||
font-size: 19px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.adm-input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 8px;
|
||||
padding: 9px 12px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:focus {
|
||||
border-color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-btn {
|
||||
background: #18a058;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 8px 24px;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.adm-btn-sm {
|
||||
padding: 5px 14px;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-error {
|
||||
color: #d03050;
|
||||
font-size: 12.5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.adm-layout {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.adm-nav {
|
||||
width: 170px;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 12px;
|
||||
position: sticky;
|
||||
top: 70px;
|
||||
|
||||
.adm-nav-title {
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
padding: 4px 8px 10px;
|
||||
}
|
||||
|
||||
.adm-nav-item {
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: rgba(128, 128, 128, 0.07);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: rgba(24, 160, 88, 0.12);
|
||||
color: #18a058;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-logout {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
padding: 8px 10px;
|
||||
font-size: 12px;
|
||||
color: #d03050;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 18px 20px;
|
||||
}
|
||||
|
||||
.adm-cards {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 18px;
|
||||
|
||||
.adm-card {
|
||||
flex: 1;
|
||||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||
border-radius: 10px;
|
||||
padding: 14px;
|
||||
text-align: center;
|
||||
|
||||
.adm-card-num {
|
||||
font-size: 22px;
|
||||
font-weight: 800;
|
||||
color: #18a058;
|
||||
}
|
||||
|
||||
.adm-card-label {
|
||||
font-size: 12px;
|
||||
opacity: 0.55;
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.adm-h3 {
|
||||
font-size: 14.5px;
|
||||
font-weight: 700;
|
||||
margin: 14px 0 10px;
|
||||
|
||||
.adm-sub {
|
||||
font-size: 11.5px;
|
||||
font-weight: 400;
|
||||
opacity: 0.5;
|
||||
margin-left: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12.5px;
|
||||
|
||||
th, td {
|
||||
text-align: left;
|
||||
padding: 7px 10px;
|
||||
border-bottom: 1px solid rgba(128, 128, 128, 0.13);
|
||||
}
|
||||
|
||||
th {
|
||||
opacity: 0.55;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background: rgba(128, 128, 128, 0.05);
|
||||
}
|
||||
|
||||
.adm-user {
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
color: #18a058;
|
||||
}
|
||||
|
||||
.adm-fname {
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.adm-none {
|
||||
text-align: center;
|
||||
opacity: 0.45;
|
||||
padding: 24px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-badge {
|
||||
font-size: 11px;
|
||||
padding: 1px 8px;
|
||||
border-radius: 999px;
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
|
||||
&.ok {
|
||||
background: rgba(24, 160, 88, 0.14);
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-link {
|
||||
color: #18a058;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-del {
|
||||
color: #d03050;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.adm-select {
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 7px;
|
||||
padding: 5px 10px;
|
||||
font-size: 12.5px;
|
||||
background: #fff;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.adm-sub {
|
||||
font-size: 12px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.adm-cleanup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: rgba(208, 48, 80, 0.05);
|
||||
border: 1px solid rgba(208, 48, 80, 0.25);
|
||||
border-radius: 10px;
|
||||
padding: 10px 14px;
|
||||
margin-bottom: 14px;
|
||||
font-size: 12.5px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.adm-ok {
|
||||
color: #18a058;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.adm-usage-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.adm-bar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 7px;
|
||||
|
||||
.adm-bar-label {
|
||||
width: 140px;
|
||||
font-size: 12px;
|
||||
text-align: right;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.adm-bar-track {
|
||||
flex: 1;
|
||||
height: 14px;
|
||||
background: rgba(128, 128, 128, 0.1);
|
||||
border-radius: 7px;
|
||||
overflow: hidden;
|
||||
|
||||
.adm-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #3b956f, #18a058);
|
||||
border-radius: 7px;
|
||||
min-width: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.adm-bar-count {
|
||||
width: 40px;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -31,6 +31,11 @@ const router = createRouter({
|
||||
name: 'about',
|
||||
component: () => import('./pages/About.vue'),
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'admin',
|
||||
component: () => import('./pages/Admin.page.vue'),
|
||||
},
|
||||
{
|
||||
path: '/user-center',
|
||||
name: 'user-center',
|
||||
|
||||
Reference in new issue
Block a user