fix: 管理页改成和 EunivTools 一样的页头和表格

This commit is contained in:
2026-10-30 10:55:28 +08:00
parent 6b34fb438c
commit b052ce2ed0
6 changed files with 229 additions and 146 deletions
+36 -24
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NDataTable, NModal, NSelect } from "naive-ui";
import { NButton, NModal, NSelect } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import LoginView from "../auth/LoginView.vue";
import { api } from "../../shared/http";
@@ -8,21 +8,10 @@ import { api } from "../../shared/http";
interface Account { id: number; loginId: string; userName: string; cityName: string; role: string; sessionOpen: boolean; credentialValid: boolean }
const accounts = ref<Account[]>([]);
const show = ref(false);
const columns = [
{ title: "账号", key: "loginId" },
{ title: "姓名", key: "userName" },
{ title: "地市", key: "cityName" },
{ title: "凭证", key: "validLabel" },
{ title: "登录", key: "openLabel" },
];
async function load() {
const result = await api<{ accounts: Account[] }>("/api/admin/pool");
accounts.value = result.accounts.map((item) => ({
...item,
validLabel: item.credentialValid ? "有效" : "失效",
openLabel: item.sessionOpen ? "未退出" : "已退出",
}));
accounts.value = result.accounts;
}
async function setRole(id: number, role: string) {
@@ -40,18 +29,41 @@ onMounted(load);
<template>
<Shell>
<header class="topbar">
<h1>账号池</h1>
<n-button type="primary" @click="show = true">添加账号</n-button>
</header>
<div class="content">
<n-data-table :columns="columns" :data="accounts" :bordered="false" />
<div v-for="account in accounts" :key="account.id" class="row-actions" style="margin-top: 8px">
<span>{{ account.loginId }}</span>
<n-select :value="account.role" size="small" style="width: 120px" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" @update:value="(value) => setRole(account.id, value)" />
<n-button size="small" @click="remove(account.id)">删除</n-button>
<section class="page admin-page">
<header class="page-head">
<h2>账号池</h2>
<n-button type="primary" @click="show = true">添加账号</n-button>
</header>
<div class="admin-scroll">
<table v-if="accounts.length" class="admin-table">
<thead>
<tr>
<th>账号</th>
<th>姓名</th>
<th>地市</th>
<th>凭证</th>
<th>登录</th>
<th>角色</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="account in accounts" :key="account.id">
<td>{{ account.loginId }}</td>
<td>{{ account.userName }}</td>
<td>{{ account.cityName }}</td>
<td>{{ account.credentialValid ? "有效" : "失效" }}</td>
<td>{{ account.sessionOpen ? "未退出" : "已退出" }}</td>
<td>
<n-select :value="account.role" size="small" style="width: 120px" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" @update:value="(value) => setRole(account.id, value)" />
</td>
<td><n-button size="small" quaternary @click="remove(account.id)">删除</n-button></td>
</tr>
</tbody>
</table>
<p v-else class="admin-status">没有账号</p>
</div>
</div>
</section>
<n-modal v-model:show="show" preset="card" title="添加账号" style="width: 520px">
<LoginView purpose="pool" @done="show = false; load()" />
</n-modal>
+24 -18
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInputNumber, NRadio, NRadioGroup, NTooltip } from "naive-ui";
import { NButton, NInputNumber, NRadio, NRadioGroup } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
@@ -34,23 +34,29 @@ onMounted(load);
<template>
<Shell>
<header class="topbar">
<h1>设置</h1>
<n-button type="primary" @click="save">保存</n-button>
</header>
<div class="content">
<div class="form-grid">
<label>方式 <n-tooltip><template #trigger><span class="hint">?</span></template>同时只启用一种登录方式</n-tooltip></label>
<n-radio-group v-model:value="mode">
<n-radio value="local">自有账号</n-radio>
<n-radio value="nqi">大数据平台账号</n-radio>
</n-radio-group>
<label>刷新间隔</label>
<n-input-number v-model:value="seconds" :min="60" :max="86400" />
<label>并行数量 <n-tooltip><template #trigger><span class="hint">?</span></template>采集和导出共用。调大后马上多领任务;调小后等正在运行的结束,再降到新的数量</n-tooltip></label>
<n-input-number v-model:value="concurrency" :min="1" :max="32" />
<section class="page admin-page">
<header class="page-head">
<h2>设置</h2>
<n-button type="primary" @click="save">保存</n-button>
</header>
<div class="settings-form">
<div class="form-row">
<label>方式</label>
<n-radio-group v-model:value="mode">
<n-radio value="local">自有账号</n-radio>
<n-radio value="nqi">大数据平台账号</n-radio>
</n-radio-group>
</div>
<div class="form-row">
<label>刷新间隔</label>
<n-input-number v-model:value="seconds" :min="60" :max="86400" :show-button="false" />
</div>
<div class="form-row">
<label>并行数量</label>
<n-input-number v-model:value="concurrency" :min="1" :max="32" :show-button="false" />
</div>
<p v-if="message">{{ message }}</p>
</div>
<p>{{ message }}</p>
</div>
</section>
</Shell>
</template>
+48 -50
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NDataTable, NInput, NInputNumber, NModal, NSelect, NSwitch, NTooltip } from "naive-ui";
import { NButton, NInput, NInputNumber, NModal, NSelect, NSwitch } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
@@ -28,12 +28,6 @@ const password = ref("");
const path = ref("");
const url = ref("");
const errorText = ref("");
const columns = [
{ title: "名称", key: "name" },
{ title: "来源", key: "kindLabel" },
{ title: "周期(天)", key: "periodDays" },
{ title: "状态", key: "stateLabel" },
];
function reset(source?: Source) {
editing.value = source || null;
@@ -54,11 +48,7 @@ function reset(source?: Source) {
async function load() {
const result = await api<{ sources: Source[] }>("/api/admin/sources");
sources.value = result.sources.map((item) => ({
...item,
kindLabel: item.kind === "nqi" ? "NQI" : "FTP/SFTP",
stateLabel: item.lastError || (item.enabled ? "启用" : "停用"),
}));
sources.value = result.sources;
}
async function save() {
@@ -91,46 +81,54 @@ onMounted(load);
<template>
<Shell>
<header class="topbar">
<h1>采集 <n-tooltip><template #trigger><span class="hint">?</span></template>周期最短一天,最长一个月</n-tooltip></h1>
<n-button type="primary" @click="reset()">添加采集</n-button>
</header>
<div class="content">
<n-data-table :columns="columns" :data="sources" :bordered="false" />
<div v-for="source in sources" :key="source.id" class="row-actions" style="margin-top: 8px">
<n-button size="small" @click="reset(source)">编辑</n-button>
<n-button size="small" @click="remove(source.id)">删除</n-button>
<section class="page admin-page">
<header class="page-head">
<h2>采集</h2>
<n-button type="primary" @click="reset()">添加采集</n-button>
</header>
<div class="admin-scroll">
<table v-if="sources.length" class="admin-table">
<thead>
<tr>
<th>名称</th>
<th>来源</th>
<th>周期(天)</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="source in sources" :key="source.id">
<td>{{ source.name }}</td>
<td>{{ source.kind === "nqi" ? "NQI" : "FTP/SFTP" }}</td>
<td>{{ source.periodDays }}</td>
<td>{{ source.lastError || (source.enabled ? "启用" : "停用") }}</td>
<td>
<n-button size="small" quaternary @click="reset(source)">编辑</n-button>
<n-button size="small" quaternary @click="remove(source.id)">删除</n-button>
</td>
</tr>
</tbody>
</table>
<p v-else class="admin-status">没有采集</p>
</div>
</div>
</section>
<n-modal v-model:show="show" preset="dialog" title="采集" positive-text="保存" negative-text="取消" @positive-click="save">
<div class="form-grid">
<label>名称</label>
<n-input v-model:value="name" />
<label>来源</label>
<n-select v-model:value="kind" :options="[{ label: 'FTP/SFTP', value: 'ftp' }, { label: 'NQI', value: 'nqi' }]" />
<label>周期(天)</label>
<n-input-number v-model:value="periodDays" :min="1" :max="31" />
<label>启用</label>
<n-switch v-model:value="enabled" />
<template v-if="kind === 'ftp'">
<label>协议</label>
<n-select v-model:value="protocol" :options="[{ label: 'SFTP', value: 'sftp' }, { label: 'FTP', value: 'ftp' }]" />
<label>主机</label>
<n-input v-model:value="host" />
<label>端口</label>
<n-input-number v-model:value="port" />
<label>账号</label>
<n-input v-model:value="username" />
<label>密码</label>
<n-input v-model:value="password" type="password" />
<label>路径</label>
<n-input v-model:value="path" />
</template>
<template v-else>
<label>地址</label>
<n-input v-model:value="url" />
</template>
</div>
<div class="form-row"><label>名称</label><n-input v-model:value="name" /></div>
<div class="form-row"><label>来源</label><n-select v-model:value="kind" :options="[{ label: 'FTP/SFTP', value: 'ftp' }, { label: 'NQI', value: 'nqi' }]" /></div>
<div class="form-row"><label>周期(天)</label><n-input-number v-model:value="periodDays" :min="1" :max="31" :show-button="false" /></div>
<div class="form-row"><label>启用</label><n-switch v-model:value="enabled" /></div>
<template v-if="kind === 'ftp'">
<div class="form-row"><label>协议</label><n-select v-model:value="protocol" :options="[{ label: 'SFTP', value: 'sftp' }, { label: 'FTP', value: 'ftp' }]" /></div>
<div class="form-row"><label>主机</label><n-input v-model:value="host" /></div>
<div class="form-row"><label>端口</label><n-input-number v-model:value="port" :show-button="false" /></div>
<div class="form-row"><label>账号</label><n-input v-model:value="username" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="password" type="password" /></div>
<div class="form-row"><label>路径</label><n-input v-model:value="path" /></div>
</template>
<template v-else>
<div class="form-row"><label>地址</label><n-input v-model:value="url" /></div>
</template>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
</n-modal>
</Shell>
+29 -24
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NDataTable, NInput, NModal, NSelect } from "naive-ui";
import { NButton, NInput, NModal, NSelect } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
@@ -11,14 +11,10 @@ const username = ref("");
const password = ref("");
const role = ref("user");
const errorText = ref("");
const columns = [
{ title: "账号", key: "username" },
{ title: "角色", key: "roleLabel" },
];
async function load() {
const result = await api<{ users: User[] }>("/api/admin/users");
users.value = result.users.map((item) => ({ ...item, roleLabel: item.role === "admin" ? "管理员" : "用户" }));
users.value = result.users;
}
async function create() {
@@ -45,26 +41,35 @@ onMounted(load);
<template>
<Shell>
<header class="topbar">
<h1>用户</h1>
<n-button type="primary" @click="show = true">添加用户</n-button>
</header>
<div class="content">
<n-data-table :columns="columns" :data="users" :bordered="false" />
<div v-for="user in users" :key="user.id" class="row-actions" style="margin-top: 8px">
<span>{{ user.username }}</span>
<n-button size="small" @click="remove(user.id)">删除</n-button>
<section class="page admin-page">
<header class="page-head">
<h2>用户</h2>
<n-button type="primary" @click="show = true">添加用户</n-button>
</header>
<div class="admin-scroll">
<table v-if="users.length" class="admin-table">
<thead>
<tr>
<th>账号</th>
<th>角色</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.username }}</td>
<td>{{ user.role === "admin" ? "管理员" : "用户" }}</td>
<td><n-button size="small" quaternary @click="remove(user.id)">删除</n-button></td>
</tr>
</tbody>
</table>
<p v-else class="admin-status">没有用户</p>
</div>
</div>
</section>
<n-modal v-model:show="show" preset="dialog" title="添加用户" positive-text="保存" negative-text="取消" @positive-click="create">
<div class="form-grid">
<label>账号</label>
<n-input v-model:value="username" />
<label>密码</label>
<n-input v-model:value="password" type="password" />
<label>角色</label>
<n-select v-model:value="role" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" />
</div>
<div class="form-row"><label>账号</label><n-input v-model:value="username" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="password" type="password" /></div>
<div class="form-row"><label>角色</label><n-select v-model:value="role" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" /></div>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
</n-modal>
</Shell>
+32 -29
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NDataTable, NInput, NModal, NSelect, NTooltip } from "naive-ui";
import { NButton, NInput, NModal, NSelect } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api, token } from "../../shared/http";
@@ -13,12 +13,6 @@ const start = ref("");
const end = ref("");
const errorText = ref("");
const formats = [{ label: "xlsx", value: "xlsx" }, { label: "xls", value: "xls" }, { label: "csv", value: "csv" }];
const columns = [
{ title: "小区", key: "cellKey" },
{ title: "格式", key: "format" },
{ title: "状态", key: "statusLabel" },
{ title: "结果", key: "action" },
];
function statusLabel(status: string) {
if (status === "queued") return "排队";
@@ -29,7 +23,7 @@ function statusLabel(status: string) {
async function load() {
const result = await api<{ tasks: Task[] }>("/api/tasks");
tasks.value = result.tasks.map((item) => ({ ...item, statusLabel: statusLabel(item.status) }));
tasks.value = result.tasks;
}
async function submit() {
@@ -62,29 +56,38 @@ onMounted(load);
<template>
<Shell>
<header class="topbar">
<h1>任务 <n-tooltip><template #trigger><span class="hint">?</span></template>按已入库的数据生成结果文件</n-tooltip></h1>
<n-button type="primary" @click="show = true">提交任务</n-button>
</header>
<div class="content">
<n-data-table :columns="columns" :data="tasks" :bordered="false">
<template #empty>还没有任务</template>
</n-data-table>
<div v-for="row in tasks.filter((item) => item.status === 'done')" :key="row.id" class="row-actions" style="margin-top: 8px">
<n-button size="small" @click="download(row)">下载 {{ row.cellKey || "全部" }}.{{ row.format }}</n-button>
<section class="page admin-page">
<header class="page-head">
<h2>任务</h2>
<n-button type="primary" @click="show = true">提交任务</n-button>
</header>
<div class="admin-scroll">
<table v-if="tasks.length" class="admin-table">
<thead>
<tr>
<th>小区</th>
<th>格式</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="row in tasks" :key="row.id">
<td>{{ row.cellKey || "全部" }}</td>
<td>{{ row.format }}</td>
<td>{{ statusLabel(row.status) }}</td>
<td><n-button v-if="row.status === 'done'" size="small" quaternary @click="download(row)">下载</n-button></td>
</tr>
</tbody>
</table>
<p v-else class="admin-status">还没有任务</p>
</div>
</div>
</section>
<n-modal v-model:show="show" preset="dialog" title="提交任务" positive-text="提交" negative-text="取消" @positive-click="submit">
<div class="form-grid">
<label>格式</label>
<n-select v-model:value="format" :options="formats" />
<label>小区</label>
<n-input v-model:value="cellKey" placeholder="留空则导出全部" />
<label>开始</label>
<n-input v-model:value="start" placeholder="YYYY-MM-DD" />
<label>结束</label>
<n-input v-model:value="end" placeholder="YYYY-MM-DD" />
</div>
<div class="form-row"><label>格式</label><n-select v-model:value="format" :options="formats" /></div>
<div class="form-row"><label>小区</label><n-input v-model:value="cellKey" placeholder="留空则导出全部" /></div>
<div class="form-row"><label>开始</label><n-input v-model:value="start" placeholder="YYYY-MM-DD" /></div>
<div class="form-row"><label>结束</label><n-input v-model:value="end" placeholder="YYYY-MM-DD" /></div>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
</n-modal>
</Shell>
+60 -1
View File
@@ -48,7 +48,66 @@ button, input, select { font: inherit; }
gap: 8px;
}
.who { color: var(--muted); font-size: 12px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.page {
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
padding: 28px 32px 20px;
box-sizing: border-box;
}
.page-head {
display: flex;
align-items: center;
justify-content: space-between;
flex: none;
margin-bottom: 16px;
}
.page-head h2 {
margin: 0;
font-size: 22px;
font-weight: 650;
letter-spacing: -0.03em;
}
.admin-page { overflow: hidden; }
.admin-alert { flex: none; margin-bottom: 12px; }
.admin-scroll {
flex: 1;
min-height: 0;
overflow: auto;
}
.admin-status { margin: 0; color: var(--muted); }
.admin-table {
width: 100%;
border-collapse: collapse;
}
.admin-table th,
.admin-table td {
padding: 10px 16px 10px 0;
border-bottom: 1px solid var(--line);
text-align: left;
vertical-align: middle;
}
.admin-table th {
position: sticky;
top: 0;
z-index: 1;
background: var(--bg);
color: var(--muted);
font-size: 12px;
font-weight: 400;
}
.form-row {
display: grid;
grid-template-columns: max-content minmax(160px, 280px);
gap: 8px 12px;
align-items: center;
justify-content: start;
margin-bottom: 12px;
}
.form-row label { white-space: nowrap; }
.settings-form { max-width: 640px; }
.topbar {
position: sticky;
top: 0;