- 去掉手填 path/名称输入框, 改为按分类分组的工具下拉框(80+工具) - 选中自动回填 名称/描述/图标emoji, 描述可微调 - 副标题与底部说明同步(对应精选推荐区块) 验证: 下拉70分类756选项, 选二维码生成器自动填icon/描述, path+name输入框移除 CHANGELOG记录
1238 lines
35 KiB
Vue
1238 lines
35 KiB
Vue
<script setup lang="ts">
|
||
import { computed, ref } from 'vue';
|
||
import { useHead } from '@vueuse/head';
|
||
import { useUserAuth } from '@/composable/user-auth';
|
||
import { useToolStore } from '@/tools/tools.store';
|
||
|
||
useHead({ title: '管理后台 - IT-TOOLS-PRO' });
|
||
|
||
const { username: adminName, login: authLogin, logout: authLogout, isAdmin } = useUserAuth();
|
||
|
||
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);
|
||
const loginUser = ref('');
|
||
const loginPass = ref('');
|
||
|
||
function authHeaders(): Record<string, string> {
|
||
const h: Record<string, string> = {};
|
||
if (token.value) {
|
||
h['Authorization'] = `Bearer ${token.value}`;
|
||
}
|
||
return h;
|
||
}
|
||
|
||
async function api(path: string, init: RequestInit = {}) {
|
||
const res = await fetch(`/relay${path}`, {
|
||
...init,
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
...authHeaders(),
|
||
...(init.headers ?? {}),
|
||
},
|
||
});
|
||
if (res.status === 403) {
|
||
authed.value = false;
|
||
throw new Error('无权限或登录已失效');
|
||
}
|
||
return res.json();
|
||
}
|
||
|
||
async function login() {
|
||
busy.value = true;
|
||
error.value = '';
|
||
try {
|
||
// channel A: admin account login (normal flow)
|
||
if (loginUser.value && loginPass.value) {
|
||
await authLogin(loginUser.value.trim(), loginPass.value);
|
||
if (!isAdmin.value) {
|
||
authLogout();
|
||
throw new Error('该账号不是管理员');
|
||
}
|
||
const auth = JSON.parse(localStorage.getItem('it-tools-auth') ?? '{}');
|
||
token.value = auth.token ?? '';
|
||
localStorage.setItem(TOKEN_KEY, token.value);
|
||
}
|
||
// verify access (also supports the bootstrap ADMIN_TOKEN pasted below)
|
||
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 showAdd = ref(false);
|
||
const addName = ref('');
|
||
const addPass = ref('');
|
||
const addRole = ref('user');
|
||
const adminMsg = ref('');
|
||
|
||
function setMsg(m: string) {
|
||
adminMsg.value = m;
|
||
setTimeout(() => (adminMsg.value = ''), 3500);
|
||
}
|
||
|
||
async function addUser() {
|
||
const b = await api('/admin/user-create', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username: addName.value.trim(), password: addPass.value, role: addRole.value }),
|
||
});
|
||
if (b.code === 200) {
|
||
setMsg(`用户 ${addName.value} 已创建`);
|
||
addName.value = '';
|
||
addPass.value = '';
|
||
showAdd.value = false;
|
||
loadOverview();
|
||
}
|
||
else {
|
||
setMsg(b.message || '创建失败');
|
||
}
|
||
}
|
||
|
||
async function toggleDisabled(u: any) {
|
||
const b = await api('/admin/user-update', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username: u.username, disabled: !u.disabled }),
|
||
});
|
||
if (b.code === 200) {
|
||
setMsg(u.disabled ? `已启用 ${u.username}` : `已禁用 ${u.username}`);
|
||
loadOverview();
|
||
}
|
||
else {
|
||
setMsg(b.message || '操作失败');
|
||
}
|
||
}
|
||
|
||
async function resetPassword(u: any) {
|
||
const np = window.prompt(`为 ${u.username} 设置新密码(至少 6 位):`);
|
||
if (!np) {
|
||
return;
|
||
}
|
||
const b = await api('/admin/user-update', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username: u.username, password: np }),
|
||
});
|
||
setMsg(b.code === 200 ? `已重置 ${u.username} 的密码` : (b.message || '失败'));
|
||
}
|
||
|
||
async function toggleRole(u: any) {
|
||
if (u.username === 'jinghui') {
|
||
setMsg('默认管理员不可降级');
|
||
return;
|
||
}
|
||
const b = await api('/admin/user-update', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username: u.username, role: u.role === 'admin' ? 'user' : 'admin' }),
|
||
});
|
||
if (b.code === 200) {
|
||
setMsg('角色已更新');
|
||
loadOverview();
|
||
}
|
||
else {
|
||
setMsg(b.message || '失败');
|
||
}
|
||
}
|
||
|
||
async function deleteUser(u: any) {
|
||
if (!window.confirm(`确认删除用户 ${u.username}?其云端文件与数据将一并删除,不可恢复!`)) {
|
||
return;
|
||
}
|
||
const b = await api('/admin/user-delete', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ username: u.username }),
|
||
});
|
||
if (b.code === 200) {
|
||
setMsg(`已删除 ${u.username}`);
|
||
loadOverview();
|
||
}
|
||
else {
|
||
setMsg(b.message || '失败');
|
||
}
|
||
}
|
||
|
||
// ============ 存储设置 ============
|
||
const storage = ref<any>(null);
|
||
const newRoot = ref('');
|
||
|
||
async function loadStorage() {
|
||
const b = await api('/admin/storage');
|
||
storage.value = b.data;
|
||
if (b.data?.root) {
|
||
newRoot.value = b.data.root;
|
||
}
|
||
}
|
||
|
||
async function saveStorage() {
|
||
if (!window.confirm(`确认将文件存储路径修改为 ${newRoot.value}?现有数据将自动迁移,服务随即重启(约几秒恢复)。`)) {
|
||
return;
|
||
}
|
||
const b = await api('/admin/storage', { method: 'POST', body: JSON.stringify({ root: newRoot.value }) });
|
||
if (b.code === 200) {
|
||
setMsg(`已切换到 ${b.data.root}(${(b.data.moved ?? []).length} 项已迁移),服务重启中…`);
|
||
setTimeout(() => loadStorage(), 6000);
|
||
}
|
||
else {
|
||
setMsg(b.message || '修改失败');
|
||
}
|
||
}
|
||
|
||
// ============ 使用统计 ============
|
||
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 reco = ref<any[]>([]);
|
||
const recoBusy = ref(false);
|
||
|
||
// 工具下拉数据:全部工具按分类分组(选择已有功能,无需手填 path/名称)
|
||
const toolStore = useToolStore();
|
||
const toolGroups = computed(() => {
|
||
const byCat = new Map<string, { path: string; name: string; description: string }[]>();
|
||
for (const t of toolStore.tools) {
|
||
const c = t.category || '其他';
|
||
if (!byCat.has(c)) {
|
||
byCat.set(c, []);
|
||
}
|
||
byCat.get(c)!.push({ path: t.path, name: t.name, description: t.description });
|
||
}
|
||
return [...byCat.entries()]
|
||
.map(([cat, list]) => ({ cat, list: [...list].sort((a, b) => a.name.localeCompare(b.name, 'zh')) }))
|
||
.sort((a, b) => a.cat.localeCompare(b.cat, 'zh'));
|
||
});
|
||
const toolMap = computed(() => new Map(toolStore.tools.map(t => [t.path, t])));
|
||
|
||
// 常见工具 emoji:选中工具时自动填图标
|
||
const RECO_EMOJI: Record<string, string> = {
|
||
'/ai-chat': '🤖', '/ai-image-lab': '🪄', '/ai-retouch': '🎨', '/copywriting': '✍️',
|
||
'/video-tools': '🎥', '/audio-tools': '🎙️', '/seal-maker': '🔴', '/signature-pad': '✍️',
|
||
'/zh-convert': '🈶', '/pinyin-converter': '🀄', '/user-center': '👤', '/pricing': '🔑',
|
||
'/image-ocr': '🔍', '/pdf-ocr': '📄', '/image-tools': '🖼️', '/pdf-tools': '📑',
|
||
'/doc-convert': '🔄', '/text-to-image': '🖼️', '/qrcode-generator': '📱', '/encryption': '🔒',
|
||
'/hash-text': '#️⃣', '/jwt-parser': '🎫', '/regex-tester': ' .*', '/json-prettify': '{ }',
|
||
'/lorem-ipsum-generator': '📝', '/password-strength-analyser': '🔐', '/color-converter': '🎨',
|
||
'/markdown-to-html': 'MD', '/base64-string-converter': '64', '/random-port-generator': '🔌',
|
||
'/crontab-generator': '⏰', '/uuid-generator': '🆔', '/token-generator': '🎟️',
|
||
'/site-bookmarks': '🔖', '/label-designer': '🏷️', '/emoji-picker': '😀', '/git-memo': '🐙',
|
||
'/camera-recorder': '📷', '/chronometer': '⏱️', '/device-information': '💻', '/math-evaluator': '🧮',
|
||
};
|
||
function emojiFor(path: string) {
|
||
return RECO_EMOJI[path] || '🧰';
|
||
}
|
||
|
||
// 选中工具:自动填 名称 / 描述 / 图标(无需手动输入)
|
||
function onToolPick(it: any) {
|
||
const t = toolMap.value.get(it.path);
|
||
if (t) {
|
||
it.name = t.name;
|
||
it.desc = t.description;
|
||
it.icon = emojiFor(t.path);
|
||
}
|
||
}
|
||
|
||
async function loadReco() {
|
||
const b = await api('/admin/reco');
|
||
reco.value = (b.data ?? []).map((x: any) => ({ ...x }));
|
||
}
|
||
|
||
async function saveReco() {
|
||
recoBusy.value = true;
|
||
try {
|
||
const b = await api('/admin/reco', { method: 'POST', body: JSON.stringify({ items: reco.value }) });
|
||
setMsg(b.code === 200 ? '首页推荐已保存,首页立即生效' : (b.message || '保存失败'));
|
||
}
|
||
finally {
|
||
recoBusy.value = false;
|
||
}
|
||
}
|
||
|
||
function recoAdd() {
|
||
reco.value.unshift({ path: '', icon: '🧰', name: '', desc: '', enabled: true });
|
||
}
|
||
|
||
function recoDel(i: number) {
|
||
reco.value.splice(i, 1);
|
||
}
|
||
|
||
function recoMove(i: number, d: -1 | 1) {
|
||
const j = i + d;
|
||
if (j < 0 || j >= reco.value.length) {
|
||
return;
|
||
}
|
||
const [it] = reco.value.splice(i, 1);
|
||
reco.value.splice(j, 0, it);
|
||
}
|
||
|
||
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco'>('overview');
|
||
|
||
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
|
||
tab.value = id;
|
||
if (id === 'overview') {
|
||
loadOverview();
|
||
}
|
||
if (id === 'reco') {
|
||
loadReco();
|
||
}
|
||
if (id === 'usage') {
|
||
loadUsage();
|
||
}
|
||
if (id === 'storage') {
|
||
loadStorage();
|
||
}
|
||
}
|
||
</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="loginUser" class="adm-input" placeholder="管理员账号" autocomplete="username" @keyup.enter="login">
|
||
<input v-model="loginPass" class="adm-input" type="password" placeholder="密码" autocomplete="current-password" @keyup.enter="login">
|
||
<div v-if="error" class="adm-error">{{ error }}</div>
|
||
<button class="adm-btn" :disabled="busy || !loginUser || !loginPass" @click="login">
|
||
{{ busy ? '验证中…' : '登录后台' }}
|
||
</button>
|
||
<div class="adm-login-alt">
|
||
或粘贴应急令牌:<input v-model="token" class="adm-token-input" type="password" placeholder="ADMIN_TOKEN" @keyup.enter="login">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- panel -->
|
||
<div v-else>
|
||
<div class="adm-topbar">
|
||
<div class="adm-nav-title">🛠️ 管理后台</div>
|
||
<div class="adm-nav">
|
||
<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>
|
||
<div class="adm-nav-item" :class="{ active: tab === 'storage' }" @click="switchTab('storage')">💾 存储设置</div>
|
||
<div class="adm-nav-item" :class="{ active: tab === 'reco' }" @click="switchTab('reco')">🏠 首页推荐</div>
|
||
</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>
|
||
<div class="adm-userbar">
|
||
<h3 class="adm-h3" style="margin: 0">用户列表 <span class="adm-sub">按占用排序,点击用户名查看文件</span></h3>
|
||
<div class="adm-userbar-right">
|
||
<span v-if="adminMsg" class="adm-ok">{{ adminMsg }}</span>
|
||
<button class="adm-btn adm-btn-sm" @click="showAdd = !showAdd">+ 添加用户</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="showAdd" class="adm-addbox">
|
||
<input v-model="addName" class="adm-mini-input" placeholder="用户名(3-32位)">
|
||
<input v-model="addPass" class="adm-mini-input" type="password" placeholder="密码(至少6位)">
|
||
<select v-model="addRole" class="adm-select">
|
||
<option value="user">普通用户</option>
|
||
<option value="admin">管理员</option>
|
||
</select>
|
||
<button class="adm-btn adm-btn-sm" :disabled="!addName || addPass.length < 6" @click="addUser">创建</button>
|
||
</div>
|
||
|
||
<table class="adm-table">
|
||
<thead>
|
||
<tr><th>用户名</th><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">
|
||
<td class="adm-user" @click="pickUser(u.username)">{{ u.username }}</td>
|
||
<td><span class="adm-badge" :class="u.role === 'admin' ? 'admin' : ''">{{ u.role === 'admin' ? '管理员' : '用户' }}</span></td>
|
||
<td><span class="adm-badge" :class="u.disabled ? 'bad' : 'ok'">{{ u.disabled ? '已禁用' : '正常' }}</span></td>
|
||
<td>{{ u.files }}</td>
|
||
<td>{{ fmtSize(u.file_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 class="adm-ops">
|
||
<a href="javascript:;" class="adm-link" @click="pickUser(u.username)">文件</a>
|
||
<a href="javascript:;" class="adm-link" @click="resetPassword(u)">改密</a>
|
||
<a href="javascript:;" class="adm-link" @click="toggleRole(u)">{{ u.role === 'admin' ? '降为用户' : '升管理员' }}</a>
|
||
<a href="javascript:;" :class="u.disabled ? 'adm-link' : 'adm-del'" @click="toggleDisabled(u)">{{ u.disabled ? '启用' : '禁用' }}</a>
|
||
<a v-if="u.username !== 'jinghui'" href="javascript:;" class="adm-del" @click="deleteUser(u)">删除</a>
|
||
</td>
|
||
</tr>
|
||
<tr v-if="!users.length"><td colspan="9" 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>
|
||
|
||
<!-- storage -->
|
||
<template v-if="tab === 'storage'">
|
||
<h3 class="adm-h3">💾 文件存储设置 <span class="adm-sub">用户上传文件与云端数据的实际存放位置</span></h3>
|
||
<div class="adm-storage-info" v-if="storage">
|
||
<div class="adm-storage-row">
|
||
<span class="adm-storage-label">当前存储目录</span>
|
||
<code class="adm-storage-path">{{ storage.root }}</code>
|
||
</div>
|
||
<div class="adm-storage-row">
|
||
<span class="adm-storage-label">用户文件结构</span>
|
||
<code class="adm-storage-path">{{ storage.root }}/users/<用户名>/files/<工具名>/</code>
|
||
</div>
|
||
<div class="adm-storage-row">
|
||
<span class="adm-storage-label">当前总占用</span>
|
||
<b>{{ fmtSize(storage.size) }}</b>
|
||
</div>
|
||
<div class="adm-storage-tip">
|
||
💡 这里显示的是<strong>宿主机真实路径</strong>,在宿主机上可直接访问(如 <code>ls {{ storage.root }}/users</code>)。
|
||
常用场景:系统盘(/vol1)空间不足时,把存储切到数据盘(/vol2)。
|
||
</div>
|
||
</div>
|
||
|
||
<div class="adm-storage-edit">
|
||
<b>修改宿主机存储目录</b>
|
||
<input v-model="newRoot" class="adm-storage-input" placeholder="宿主机绝对路径,如 /vol2/1000/HD2/it-tools-data">
|
||
<button class="adm-btn adm-btn-sm" @click="saveStorage">保存并重启</button>
|
||
<span v-if="adminMsg" class="adm-ok">{{ adminMsg }}</span>
|
||
</div>
|
||
<div class="adm-storage-note">
|
||
修改后:现有用户文件与数据库<strong>自动迁移</strong>到新目录(宿主机上直接移动),服务自动重启生效(约几秒)。
|
||
系统目录(/etc、/usr、/root 等)禁止使用;请确保目标磁盘已挂载(如 /vol1、/vol2)。
|
||
</div>
|
||
</template>
|
||
|
||
<!-- reco -->
|
||
<template v-if="tab === 'reco'">
|
||
<div class="adm-toolbar">
|
||
<h3 class="adm-h3" style="margin:0">🏠 首页推荐管理 <span class="adm-sub">配置首页「⭐ 精选推荐」展示的工具,下拉选择已有功能,按顺序排列,可启停</span></h3>
|
||
<button class="adm-btn adm-btn-sm" @click="recoAdd">+ 添加推荐</button>
|
||
<button class="adm-btn adm-btn-sm adm-btn-primary" :disabled="recoBusy" @click="saveReco">{{ recoBusy ? '保存中…' : '💾 保存并发布' }}</button>
|
||
<span v-if="adminMsg" class="adm-ok">{{ adminMsg }}</span>
|
||
</div>
|
||
|
||
<div class="adm-reco-list">
|
||
<div v-for="(it, i) in reco" :key="i" class="adm-reco-row">
|
||
<span class="adm-reco-ord">{{ i + 1 }}</span>
|
||
<input v-model="it.icon" class="adm-reco-icon" maxlength="4" title="图标(emoji),选中工具自动填">
|
||
<select v-model="it.path" class="adm-reco-sel" :title="it.path || '选择工具'" @change="onToolPick(it)">
|
||
<option value="" disabled>▼ 选择工具</option>
|
||
<optgroup v-for="g in toolGroups" :key="g.cat" :label="g.cat">
|
||
<option v-for="t in g.list" :key="t.path" :value="t.path">{{ t.name }}</option>
|
||
</optgroup>
|
||
</select>
|
||
<input v-model="it.desc" class="adm-reco-desc" placeholder="描述(选中工具自动填)">
|
||
<label class="adm-reco-on"><input v-model="it.enabled" type="checkbox"> 显示</label>
|
||
<span class="adm-reco-ops">
|
||
<button class="adm-mini" :disabled="i === 0" @click="recoMove(i, -1)" title="上移">↑</button>
|
||
<button class="adm-mini" :disabled="i === reco.length - 1" @click="recoMove(i, 1)" title="下移">↓</button>
|
||
<button class="adm-mini adm-mini-del" @click="recoDel(i)" title="删除">✕</button>
|
||
</span>
|
||
</div>
|
||
<div v-if="!reco.length" class="adm-empty">暂无推荐项,点右上「添加推荐」新增</div>
|
||
</div>
|
||
<div class="adm-storage-note" style="margin-top:10px">
|
||
💡 点「保存并发布」后首页「⭐ 精选推荐」立即生效,所有访客可见。下拉框直接选择已有工具(自动填名称/描述/图标),未启用的项不显示。
|
||
</div>
|
||
</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-btn-primary {
|
||
background: #2563eb;
|
||
}
|
||
|
||
.adm-mini {
|
||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||
background: #fff;
|
||
border-radius: 6px;
|
||
padding: 2px 9px;
|
||
font-size: 12.5px;
|
||
cursor: pointer;
|
||
line-height: 1.5;
|
||
|
||
&:disabled {
|
||
opacity: 0.35;
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
&:hover:not(:disabled) {
|
||
border-color: #18a058;
|
||
color: #18a058;
|
||
}
|
||
|
||
&.adm-mini-del:hover:not(:disabled) {
|
||
border-color: #d03050;
|
||
color: #d03050;
|
||
}
|
||
}
|
||
|
||
.adm-empty {
|
||
text-align: center;
|
||
opacity: 0.45;
|
||
font-size: 13px;
|
||
padding: 26px 0;
|
||
}
|
||
|
||
.adm-reco-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 7px;
|
||
}
|
||
|
||
.adm-reco-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 7px;
|
||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||
border-radius: 9px;
|
||
padding: 7px 10px;
|
||
background: rgba(128, 128, 128, 0.03);
|
||
|
||
.adm-reco-ord {
|
||
width: 22px;
|
||
height: 22px;
|
||
border-radius: 50%;
|
||
background: rgba(24, 160, 88, 0.15);
|
||
color: #18a058;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
input,
|
||
select {
|
||
border: 1px solid rgba(128, 128, 128, 0.32);
|
||
border-radius: 7px;
|
||
padding: 5px 8px;
|
||
font-size: 12.5px;
|
||
outline: none;
|
||
background: #fff;
|
||
|
||
&:focus {
|
||
border-color: #18a058;
|
||
}
|
||
}
|
||
|
||
.adm-reco-icon {
|
||
width: 46px;
|
||
text-align: center;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.adm-reco-sel {
|
||
width: 190px;
|
||
flex-shrink: 0;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.adm-reco-desc {
|
||
flex: 1;
|
||
min-width: 120px;
|
||
}
|
||
|
||
.adm-reco-on {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
font-size: 12px;
|
||
flex-shrink: 0;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.adm-reco-ops {
|
||
display: flex;
|
||
gap: 4px;
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
.adm-error {
|
||
color: #d03050;
|
||
font-size: 12.5px;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.adm-topbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 18px;
|
||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||
border-radius: 12px;
|
||
padding: 8px 16px;
|
||
margin-bottom: 14px;
|
||
position: sticky;
|
||
top: 62px;
|
||
z-index: 20;
|
||
background: #fff;
|
||
flex-wrap: wrap;
|
||
|
||
.adm-nav-title {
|
||
font-size: 15px;
|
||
font-weight: 800;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.adm-nav {
|
||
display: flex;
|
||
gap: 4px;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
|
||
.adm-nav-item {
|
||
padding: 7px 14px;
|
||
border-radius: 999px;
|
||
font-size: 13px;
|
||
cursor: pointer;
|
||
transition: background 0.15s;
|
||
|
||
&:hover {
|
||
background: rgba(128, 128, 128, 0.07);
|
||
}
|
||
|
||
&.active {
|
||
background: rgba(24, 160, 88, 0.12);
|
||
color: #18a058;
|
||
font-weight: 700;
|
||
}
|
||
}
|
||
}
|
||
|
||
.adm-logout {
|
||
margin-left: auto;
|
||
font-size: 12.5px;
|
||
color: #d03050;
|
||
text-decoration: none;
|
||
flex-shrink: 0;
|
||
|
||
&:hover {
|
||
text-decoration: underline;
|
||
}
|
||
}
|
||
}
|
||
|
||
.adm-main {
|
||
width: 100%;
|
||
box-sizing: border-box;
|
||
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;
|
||
}
|
||
|
||
&.bad {
|
||
background: rgba(208, 48, 80, 0.14);
|
||
color: #d03050;
|
||
}
|
||
|
||
&.admin {
|
||
background: rgba(240, 146, 38, 0.16);
|
||
color: #d97706;
|
||
}
|
||
}
|
||
|
||
.adm-link {
|
||
color: #18a058;
|
||
text-decoration: none;
|
||
|
||
&:hover {
|
||
text-decoration: underline;
|
||
}
|
||
}
|
||
|
||
.adm-del {
|
||
color: #d03050;
|
||
text-decoration: none;
|
||
|
||
&:hover {
|
||
text-decoration: underline;
|
||
}
|
||
}
|
||
|
||
.adm-userbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 10px;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
|
||
.adm-userbar-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
}
|
||
|
||
.adm-addbox {
|
||
display: flex;
|
||
gap: 8px;
|
||
align-items: center;
|
||
background: rgba(24, 160, 88, 0.05);
|
||
border: 1px solid rgba(24, 160, 88, 0.3);
|
||
border-radius: 10px;
|
||
padding: 10px 14px;
|
||
margin-bottom: 12px;
|
||
flex-wrap: wrap;
|
||
|
||
.adm-mini-input {
|
||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||
border-radius: 7px;
|
||
padding: 5px 10px;
|
||
font-size: 12.5px;
|
||
outline: none;
|
||
width: 160px;
|
||
|
||
&:focus {
|
||
border-color: #18a058;
|
||
}
|
||
}
|
||
}
|
||
|
||
.adm-ops {
|
||
white-space: nowrap;
|
||
|
||
a {
|
||
margin-right: 8px;
|
||
}
|
||
}
|
||
|
||
.adm-token-input {
|
||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||
border-radius: 6px;
|
||
padding: 3px 8px;
|
||
font-size: 12px;
|
||
outline: none;
|
||
width: 150px;
|
||
margin-left: 6px;
|
||
}
|
||
|
||
.adm-login-alt {
|
||
margin-top: 12px;
|
||
font-size: 11.5px;
|
||
opacity: 0.6;
|
||
}
|
||
|
||
.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-storage-info {
|
||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||
border-radius: 10px;
|
||
padding: 14px 16px;
|
||
margin-bottom: 14px;
|
||
background: rgba(24, 160, 88, 0.03);
|
||
|
||
.adm-storage-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 8px;
|
||
font-size: 13px;
|
||
|
||
.adm-storage-label {
|
||
width: 110px;
|
||
opacity: 0.6;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.adm-storage-path {
|
||
background: rgba(128, 128, 128, 0.1);
|
||
padding: 2px 10px;
|
||
border-radius: 5px;
|
||
font-size: 12.5px;
|
||
word-break: break-all;
|
||
}
|
||
}
|
||
|
||
.adm-storage-tip {
|
||
font-size: 12px;
|
||
opacity: 0.6;
|
||
line-height: 1.8;
|
||
margin-top: 10px;
|
||
|
||
code {
|
||
background: rgba(128, 128, 128, 0.12);
|
||
padding: 1px 6px;
|
||
border-radius: 4px;
|
||
font-size: 11.5px;
|
||
}
|
||
}
|
||
}
|
||
|
||
.adm-storage-edit {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
background: rgba(240, 146, 38, 0.06);
|
||
border: 1px solid rgba(240, 146, 38, 0.3);
|
||
border-radius: 10px;
|
||
padding: 10px 14px;
|
||
margin-bottom: 10px;
|
||
font-size: 12.5px;
|
||
flex-wrap: wrap;
|
||
|
||
.adm-storage-input {
|
||
flex: 1;
|
||
min-width: 220px;
|
||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||
border-radius: 7px;
|
||
padding: 6px 10px;
|
||
font-size: 12.5px;
|
||
font-family: monospace;
|
||
outline: none;
|
||
|
||
&:focus {
|
||
border-color: #18a058;
|
||
}
|
||
}
|
||
}
|
||
|
||
.adm-storage-note {
|
||
font-size: 11.5px;
|
||
opacity: 0.5;
|
||
line-height: 1.7;
|
||
}
|
||
|
||
.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>
|