feat(admin): 封禁列表管理页(/admin/banned + Banned.vue)
- 后端新增 8 个接口:GET/POST /admin/banned、PUT/DELETE /admin/banned/{ip}、
GET /admin/banned/history、DELETE /admin/banned/history[/{hid}]、DELETE /admin/banned
- 配置新增 server.auth_fail_ban_seconds(默认 3600,0=只限流不拉黑):
同一 IP 每分钟鉴权失败超限即自动封禁,被封期间该 IP 的 API 请求返回 429
- 前端新增「封禁列表」页(仅管理员可见)+ 中英文文案,
支持单个解封 / 全部解封 / 删除历史记录 / 查看解封时间与剩余时长
This commit is contained in:
1 parent
8320258ff0
commit
1ed82f6d73
8 files changed
+927
-9
No files matched your search
@@ -45,6 +45,7 @@ export function navGroups(isAdmin: boolean): NavGroup[] {
|
||||
// 第二十二轮定稿:管理员只处理反馈(「用户反馈」),不提意见 —— 所以这两项互斥。
|
||||
if (isAdmin) sys.push({ path: '/users', key: 'users', icon: 'users' })
|
||||
if (isAdmin) sys.push({ path: '/feedback-inbox', key: 'feedbackinbox', icon: 'inbox' })
|
||||
if (isAdmin) sys.push({ path: '/banned', key: 'banned', icon: 'ban' })
|
||||
// 第二十三轮追加:老板要求「网关配置先不要删掉、先隐藏起来,这块先不支持页面配置」→
|
||||
// 入口由 `lib/features.ts` 的开关统一控制(页面与路由都还在,只是不挂出来)。
|
||||
if (isAdmin && GATEWAY_CONFIG_ENABLED) sys.push({ path: '/gateway-config', key: 'gatewaycfg', icon: 'sliders' })
|
||||
|
||||
@@ -1,5 +1,69 @@
|
||||
// English locale resource
|
||||
export default {
|
||||
banned: {
|
||||
title: 'Banned IPs',
|
||||
count: '{n} IP(s) banned',
|
||||
rule: 'An IP is auto-banned for {mins} min after {n} auth failures within a minute. While banned, every API request from it returns 429; other sources are unaffected.',
|
||||
remaining: '{mins} min left',
|
||||
until: 'Unban at',
|
||||
unban: 'Unban',
|
||||
empty: 'No banned IPs',
|
||||
unbanned: 'Unbanned {ip}',
|
||||
clearAll: 'Unban all',
|
||||
clearTitle: 'Clear all bans',
|
||||
clearConfirm: 'Clear all bans? Those IPs can access immediately afterwards.',
|
||||
cleared: 'Cleared {n} ban(s)',
|
||||
manualTitle: 'Manual ban',
|
||||
manualSub: 'Ban an IP right away instead of waiting for the auto rule',
|
||||
manualHint: 'Public IPs only. Loopback and private ranges (10./192.168./172.) cannot be banned, so the local reverse proxy and your own LAN devices stay reachable.',
|
||||
ipPlaceholder: 'IP address, e.g. 1.2.3.4',
|
||||
notePlaceholder: 'Note (optional, e.g. "brute force")',
|
||||
doBan: 'Ban',
|
||||
ipRequired: 'Please enter an IP address',
|
||||
banned: 'Banned {ip} for {mins} min',
|
||||
bannedForever: 'Permanently banned {ip}',
|
||||
extend: 'Extend',
|
||||
extended: 'Extended {ip} by {mins} min',
|
||||
extendedForever: '{ip} is now banned permanently',
|
||||
toPermanent: 'Make permanent',
|
||||
permanentTag: 'permanent',
|
||||
neverExpire: 'Permanent — will not expire automatically',
|
||||
historyTitle: 'Ban history',
|
||||
historySub: 'Recent actions (ban / unban / extend)',
|
||||
historyEmpty: 'No ban actions yet',
|
||||
unitDay: '{n} day(s)',
|
||||
unitHour: '{n} hour(s)',
|
||||
unitMin: '{n} min',
|
||||
hisOps: 'Action',
|
||||
hisDelete: 'Delete',
|
||||
hisDeleted: 'History entry deleted',
|
||||
hisClearAll: 'Clear history',
|
||||
hisClearConfirm: 'Clear all ban history? This cannot be undone (active bans are not affected).',
|
||||
hisCleared: 'Cleared {n} history entries',
|
||||
hisTime: 'Time',
|
||||
hisAction: 'Action',
|
||||
hisIp: 'IP',
|
||||
hisDuration: 'Duration',
|
||||
hisActor: 'By',
|
||||
hisNote: 'Note',
|
||||
act: {
|
||||
manual_ban: 'manual ban',
|
||||
auto_ban: 'auto ban',
|
||||
extend: 'extend',
|
||||
unban: 'unban',
|
||||
unban_all: 'clear all',
|
||||
},
|
||||
dur: {
|
||||
m10: '10 minutes',
|
||||
m30: '30 minutes',
|
||||
h1: '1 hour',
|
||||
h6: '6 hours',
|
||||
d1: '1 day',
|
||||
d30: '30 days',
|
||||
forever: 'permanent',
|
||||
},
|
||||
},
|
||||
|
||||
nav: {
|
||||
title: 'API Gateway',
|
||||
connected: 'Connected to 127.0.0.1:8808',
|
||||
@@ -16,6 +80,7 @@ export default {
|
||||
menulogs: 'Logs',
|
||||
menufeedback: 'Feedback',
|
||||
menufeedbackinbox: 'User feedback',
|
||||
menubanned: 'Banned IPs',
|
||||
feedbackTodoTip: '{n} pending (open + in progress)',
|
||||
menusettings: 'Settings',
|
||||
control: 'Console',
|
||||
|
||||
@@ -1,5 +1,69 @@
|
||||
// 中文文案资源
|
||||
export default {
|
||||
banned: {
|
||||
title: '封禁列表',
|
||||
count: '共 {n} 个 IP 被封',
|
||||
rule: '同一 IP 每分钟鉴权失败达到 {n} 次即自动封禁 {mins} 分钟;被封期间该 IP 的所有 API 请求返回 429,其他来源不受影响。',
|
||||
remaining: '剩余 {mins} 分钟',
|
||||
until: '解封时间',
|
||||
unban: '解封',
|
||||
empty: '当前没有被封禁的 IP',
|
||||
unbanned: '已解封 {ip}',
|
||||
clearAll: '全部解封',
|
||||
clearTitle: '清空全部封禁',
|
||||
clearConfirm: '确定清空全部封禁?清空后这些 IP 可以立即重新访问。',
|
||||
cleared: '已清空 {n} 个封禁',
|
||||
manualTitle: '手动封禁',
|
||||
manualSub: '立即拉黑指定 IP,不必等它触发自动规则',
|
||||
manualHint: '只支持公网 IP;回环地址和内网段(10./192.168./172.)不允许封禁,避免把本机反代或自家设备锁死。',
|
||||
ipPlaceholder: 'IP 地址,例如 1.2.3.4',
|
||||
notePlaceholder: '备注(可选,例如「持续爆破」)',
|
||||
doBan: '封禁',
|
||||
ipRequired: '请先填写 IP 地址',
|
||||
banned: '已封禁 {ip},时长 {mins} 分钟',
|
||||
bannedForever: '已永久封禁 {ip}',
|
||||
extend: '延长',
|
||||
extended: '已为 {ip} 延长 {mins} 分钟',
|
||||
extendedForever: '{ip} 已改为永久封禁',
|
||||
toPermanent: '改为永久',
|
||||
permanentTag: '永久',
|
||||
neverExpire: '永久有效,不会自动解封',
|
||||
historyTitle: '封禁历史',
|
||||
historySub: '最近的操作记录(封禁 / 解封 / 延长)',
|
||||
historyEmpty: '还没有封禁操作记录',
|
||||
unitDay: '{n} 天',
|
||||
unitHour: '{n} 小时',
|
||||
unitMin: '{n} 分钟',
|
||||
hisOps: '操作',
|
||||
hisDelete: '删除',
|
||||
hisDeleted: '已删除该条历史',
|
||||
hisClearAll: '清空历史',
|
||||
hisClearConfirm: '确定清空全部封禁历史?此操作不可恢复(不会影响当前封禁)。',
|
||||
hisCleared: '已清空 {n} 条历史',
|
||||
hisTime: '时间',
|
||||
hisAction: '操作',
|
||||
hisIp: 'IP',
|
||||
hisDuration: '时长',
|
||||
hisActor: '操作人',
|
||||
hisNote: '备注',
|
||||
act: {
|
||||
manual_ban: '手动封禁',
|
||||
auto_ban: '自动封禁',
|
||||
extend: '延长',
|
||||
unban: '解封',
|
||||
unban_all: '清空',
|
||||
},
|
||||
dur: {
|
||||
m10: '10 分钟',
|
||||
m30: '30 分钟',
|
||||
h1: '1 小时',
|
||||
h6: '6 小时',
|
||||
d1: '1 天',
|
||||
d30: '30 天',
|
||||
forever: '永久',
|
||||
},
|
||||
},
|
||||
|
||||
nav: {
|
||||
title: 'API 网关',
|
||||
connected: '已连接 127.0.0.1:8808',
|
||||
@@ -16,6 +80,7 @@ export default {
|
||||
menulogs: '日志',
|
||||
menufeedback: '意见反馈',
|
||||
menufeedbackinbox: '用户反馈',
|
||||
menubanned: '封禁管理',
|
||||
feedbackTodoTip: '{n} 条待办(未处理 + 处理中)',
|
||||
menusettings: '设置',
|
||||
control: '控制台',
|
||||
|
||||
@@ -25,6 +25,7 @@ const router = createRouter({
|
||||
{ path: 'keys', name: 'keys', component: () => import('./views/ApiKeys.vue') },
|
||||
{ path: 'users', name: 'users', component: () => import('./views/Users.vue'), meta: { admin: true } },
|
||||
{ path: 'feedback-inbox', name: 'feedbackinbox', component: () => import('./views/FeedbackInbox.vue'), meta: { admin: true } },
|
||||
{ path: 'banned', name: 'banned', component: () => import('./views/Banned.vue'), meta: { admin: true } },
|
||||
{ path: 'feedback', name: 'feedback', component: () => import('./views/Feedback.vue'), meta: { memberOnly: true } },
|
||||
{ path: 'gateway-config', name: 'gatewaycfg', component: () => import('./views/GatewayConfig.vue'), meta: { admin: true } },
|
||||
{ path: 'logs', name: 'logs', component: () => import('./views/Logs.vue') },
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
<template>
|
||||
<div class="page page-col">
|
||||
<!-- ── 手动封禁 ─────────────────────────────────────────── -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<Icon name="ban" :size="15" />
|
||||
<b>{{ t('banned.manualTitle') }}</b>
|
||||
<span class="sub">{{ t('banned.manualSub') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="ban-form">
|
||||
<el-input
|
||||
v-model="newIp" size="small" class="w-ip" clearable
|
||||
:placeholder="t('banned.ipPlaceholder')" @keyup.enter="doBan"
|
||||
/>
|
||||
<el-select v-model="newDur" size="small" class="w-dur">
|
||||
<el-option
|
||||
v-for="o in DURATIONS" :key="o.k" :value="o.k"
|
||||
:label="t(`banned.dur.${o.k}`)"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-model="newNote" size="small" class="w-note" clearable
|
||||
:placeholder="t('banned.notePlaceholder')" @keyup.enter="doBan"
|
||||
/>
|
||||
<el-button type="primary" size="small" :loading="banning" @click="doBan">
|
||||
<Icon name="ban" :size="13" /><span>{{ t('banned.doBan') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="form-hint">
|
||||
<Icon name="bell" :size="12" />
|
||||
<span>{{ t('banned.manualHint') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── 封禁列表 ─────────────────────────────────────────── -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<b>{{ t('banned.title') }}</b>
|
||||
<span class="sub">{{ t('banned.count', { n: items.length }) }}</span>
|
||||
<div class="pager">
|
||||
<el-button size="small" :loading="loading" @click="reload">
|
||||
<Icon name="refresh" :size="13" /><span>{{ t('common.refresh') }}</span>
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" plain :disabled="!items.length" @click="clearAll">
|
||||
<Icon name="trash" :size="13" /><span>{{ t('banned.clearAll') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="warn-bar">
|
||||
<Icon name="ban" :size="14" />
|
||||
<span>{{ t('banned.rule', { n: limit, mins: banMinutes }) }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="items.length" class="ban-list">
|
||||
<div v-for="b in items" :key="b.ip" class="ban-row">
|
||||
<span class="dot" :class="{ perm: b.permanent }" />
|
||||
<div class="ban-main">
|
||||
<div class="ban-top">
|
||||
<b class="code ban-ip">{{ b.ip }}</b>
|
||||
<el-tag v-if="b.permanent" size="small" type="danger" effect="plain">
|
||||
{{ t('banned.permanentTag') }}
|
||||
</el-tag>
|
||||
<el-tag v-if="b.note" size="small" type="warning" effect="plain">
|
||||
{{ b.note }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="ban-meta">
|
||||
<template v-if="b.permanent">
|
||||
<span>{{ t('banned.neverExpire') }}</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ t('banned.remaining', { mins: b.remaining_minutes }) }}</span>
|
||||
<span class="sep">·</span>
|
||||
<span>{{ t('banned.until') }} {{ fmtTs(b.banned_until) }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ban-acts">
|
||||
<el-dropdown trigger="click" :disabled="b.permanent" @command="(k: string) => extend(b.ip, k)">
|
||||
<el-button size="small" :disabled="b.permanent">
|
||||
<Icon name="plus" :size="13" /><span>{{ t('banned.extend') }}</span>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="o in DURATIONS" :key="o.k" :command="o.k">
|
||||
+{{ t(`banned.dur.${o.k}`) }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="forever" divided>
|
||||
{{ t('banned.toPermanent') }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<el-button size="small" @click="unban(b.ip)">
|
||||
<Icon name="check" :size="13" /><span>{{ t('banned.unban') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else :description="t('banned.empty')" :image-size="72" />
|
||||
</div>
|
||||
|
||||
<!-- ── 封禁历史 ─────────────────────────────────────────── -->
|
||||
<div class="card">
|
||||
<div class="card-h">
|
||||
<Icon name="log" :size="15" />
|
||||
<b>{{ t('banned.historyTitle') }}</b>
|
||||
<span class="sub">{{ t('banned.historySub') }}</span>
|
||||
<div class="pager">
|
||||
<el-select v-model="hisLimit" size="small" class="w-his" @change="loadHistory">
|
||||
<el-option :value="20" label="20" />
|
||||
<el-option :value="50" label="50" />
|
||||
<el-option :value="100" label="100" />
|
||||
</el-select>
|
||||
<el-button size="small" :loading="hisLoading" @click="loadHistory">
|
||||
<Icon name="refresh" :size="13" /><span>{{ t('common.refresh') }}</span>
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" plain :disabled="!history.length" @click="clearHistory">
|
||||
<Icon name="trash" :size="13" /><span>{{ t('banned.hisClearAll') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table v-if="history.length" :data="history" size="small" class="his-table">
|
||||
<el-table-column :label="t('banned.hisTime')" width="150">
|
||||
<template #default="{ row }">{{ fmtTs(row.ts) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisAction')" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="ACTION_TAG[row.action] || 'info'" size="small" effect="plain">
|
||||
{{ t(`banned.act.${row.action}`) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisIp')" min-width="140">
|
||||
<template #default="{ row }"><span class="code">{{ row.ip }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisDuration')" width="110">
|
||||
<template #default="{ row }">
|
||||
{{ row.permanent ? t('banned.permanentTag') : (row.seconds ? fmtDur(row.seconds) : '—') }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisActor')" width="110">
|
||||
<template #default="{ row }">{{ row.actor || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisNote')" min-width="140">
|
||||
<template #default="{ row }"><span class="muted-2">{{ row.note || '—' }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('banned.hisOps')" width="76" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" type="danger" text :title="t('common.delete')" @click="delHistory(row)">
|
||||
<Icon name="trash" :size="13" />
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-empty v-else :description="t('banned.historyEmpty')" :image-size="60" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { api, errText } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
const items = ref<any[]>([])
|
||||
const history = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const banning = ref(false)
|
||||
const hisLoading = ref(false)
|
||||
const hisLimit = ref(50)
|
||||
const limit = ref(60)
|
||||
const banSeconds = ref(3600)
|
||||
let timer: any = null
|
||||
|
||||
const newIp = ref('')
|
||||
const newDur = ref('h1')
|
||||
const newNote = ref('')
|
||||
|
||||
const banMinutes = computed(() => Math.max(1, Math.round(banSeconds.value / 60)))
|
||||
|
||||
/** 时长预设。forever 走 permanent 字段,其余按秒传。 */
|
||||
const DURATIONS = [
|
||||
{ k: 'm10', v: 600 },
|
||||
{ k: 'm30', v: 1800 },
|
||||
{ k: 'h1', v: 3600 },
|
||||
{ k: 'h6', v: 21600 },
|
||||
{ k: 'd1', v: 86400 },
|
||||
{ k: 'd30', v: 2592000 },
|
||||
{ k: 'forever', v: 0 },
|
||||
] as { k: string; v: number }[]
|
||||
|
||||
const ACTION_TAG: Record<string, string> = {
|
||||
manual_ban: 'warning',
|
||||
auto_ban: 'info',
|
||||
extend: 'primary',
|
||||
unban: 'success',
|
||||
unban_all: 'danger',
|
||||
}
|
||||
|
||||
function fmtTs(ts: number): string {
|
||||
if (!ts) return '—'
|
||||
const d = new Date(ts * 1000)
|
||||
const p = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
|
||||
}
|
||||
|
||||
function fmtDur(sec: number): string {
|
||||
if (sec >= 86400 && sec % 86400 === 0) return t('banned.unitDay', { n: sec / 86400 })
|
||||
if (sec >= 3600) return t('banned.unitHour', { n: Math.round(sec / 3600) })
|
||||
return t('banned.unitMin', { n: Math.round(sec / 60) })
|
||||
}
|
||||
|
||||
function durPayload(k: string): any {
|
||||
if (k === 'forever') return { permanent: true }
|
||||
const d = DURATIONS.find((x) => x.k === k)
|
||||
return { seconds: d ? d.v : 3600 }
|
||||
}
|
||||
|
||||
async function reload() {
|
||||
loading.value = true
|
||||
try {
|
||||
const j = await api('/admin/banned')
|
||||
items.value = j.items || []
|
||||
if (typeof j.auth_fail_limit_per_min === 'number') limit.value = j.auth_fail_limit_per_min
|
||||
if (typeof j.ban_seconds === 'number' && j.ban_seconds > 0) banSeconds.value = j.ban_seconds
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadHistory() {
|
||||
hisLoading.value = true
|
||||
try {
|
||||
const j = await api(`/admin/banned/history?limit=${hisLimit.value}`)
|
||||
history.value = j.items || []
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
} finally {
|
||||
hisLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function doBan() {
|
||||
const ip = newIp.value.trim()
|
||||
if (!ip) { ElMessage.warning(t('banned.ipRequired')); return }
|
||||
banning.value = true
|
||||
try {
|
||||
const j = await api('/admin/banned', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ip, note: newNote.value.trim(), ...durPayload(newDur.value) }),
|
||||
})
|
||||
ElMessage.success(
|
||||
j.permanent
|
||||
? t('banned.bannedForever', { ip: j.ip })
|
||||
: t('banned.banned', { ip: j.ip, mins: Math.round(j.banned_seconds / 60) }),
|
||||
)
|
||||
newIp.value = ''
|
||||
newNote.value = ''
|
||||
await Promise.all([reload(), loadHistory()])
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
} finally {
|
||||
banning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function extend(ip: string, k: string) {
|
||||
try {
|
||||
const j = await api(`/admin/banned/${encodeURIComponent(ip)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(durPayload(k)),
|
||||
})
|
||||
ElMessage.success(
|
||||
j.permanent ? t('banned.extendedForever', { ip }) : t('banned.extended', { ip, mins: Math.round(j.extended_seconds / 60) }),
|
||||
)
|
||||
await Promise.all([reload(), loadHistory()])
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function unban(ip: string) {
|
||||
try {
|
||||
await api(`/admin/banned/${encodeURIComponent(ip)}`, { method: 'DELETE' })
|
||||
ElMessage.success(t('banned.unbanned', { ip }))
|
||||
await Promise.all([reload(), loadHistory()])
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function delHistory(row: any) {
|
||||
try {
|
||||
await api(`/admin/banned/history/${encodeURIComponent(row.id)}`, { method: 'DELETE' })
|
||||
ElMessage.success(t('banned.hisDeleted'))
|
||||
await loadHistory()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function clearHistory() {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('banned.hisClearConfirm'), t('banned.hisClearAll'), { type: 'warning' })
|
||||
} catch { return }
|
||||
try {
|
||||
const j = await api('/admin/banned/history', { method: 'DELETE' })
|
||||
ElMessage.success(t('banned.hisCleared', { n: j.cleared ?? 0 }))
|
||||
await loadHistory()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function clearAll() {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('banned.clearConfirm'), t('banned.clearTitle'), { type: 'warning' })
|
||||
} catch { return }
|
||||
try {
|
||||
const j = await api('/admin/banned', { method: 'DELETE' })
|
||||
ElMessage.success(t('banned.cleared', { n: j.cleared ?? 0 }))
|
||||
await Promise.all([reload(), loadHistory()])
|
||||
} catch (e: any) {
|
||||
ElMessage.error(errText(e))
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
reload()
|
||||
loadHistory()
|
||||
timer = setInterval(reload, 10000)
|
||||
})
|
||||
onUnmounted(() => { if (timer) clearInterval(timer) })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 手动封禁表单:一行放下,窄屏自动换行 */
|
||||
.ban-form { display: flex; align-items: center; gap: var(--gap-sm); flex-wrap: wrap; }
|
||||
.w-ip { width: 220px; }
|
||||
.w-dur { width: 130px; }
|
||||
.w-note { width: 200px; }
|
||||
.w-his { width: 84px; }
|
||||
.form-hint {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
margin-top: var(--gap-sm); font-size: 11.5px; line-height: 1.6; color: var(--muted-2);
|
||||
}
|
||||
.form-hint .gw-icon { flex: none; }
|
||||
|
||||
/* 规则提示条 —— 与 ApiKeys 的 warn-bar 同一套观感(那边是 scoped,这里要自带) */
|
||||
.warn-bar {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
background: var(--warn-soft); color: var(--warn);
|
||||
border-radius: var(--radius-s); padding: 9px 12px;
|
||||
font-size: 12px; line-height: 1.6; margin-bottom: var(--gap-sm);
|
||||
}
|
||||
.warn-bar .gw-icon { flex: none; }
|
||||
|
||||
.ban-list { display: flex; flex-direction: column; }
|
||||
.ban-row {
|
||||
display: flex; align-items: center; gap: var(--gap-sm);
|
||||
padding: 11px 2px; border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.ban-row:last-child { border-bottom: none; }
|
||||
.ban-row .dot {
|
||||
flex: none; width: 7px; height: 7px; border-radius: 50%;
|
||||
background: var(--warn);
|
||||
}
|
||||
.ban-row .dot.perm { background: var(--err, #e5484d); }
|
||||
.ban-main { flex: 1; min-width: 0; }
|
||||
.ban-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.ban-ip { font-size: 13px; font-weight: 600; }
|
||||
.ban-meta {
|
||||
margin-top: 3px; font-size: 11.5px; color: var(--muted-2);
|
||||
display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
|
||||
}
|
||||
.ban-meta .sep { color: var(--line); }
|
||||
.ban-acts { display: flex; align-items: center; gap: 6px; flex: none; }
|
||||
.his-table { width: 100%; }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.w-ip, .w-note, .w-dur { width: 100%; }
|
||||
.ban-form :deep(.el-button) { width: 100%; }
|
||||
.ban-row { flex-wrap: wrap; }
|
||||
.ban-acts { width: 100%; justify-content: flex-end; }
|
||||
}
|
||||
</style>
|
||||
@@ -144,7 +144,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { api } from '../api'
|
||||
import { api, errText } from '../api'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { stamp } from '../lib/download'
|
||||
import { useSessionStore } from '../store/session'
|
||||
@@ -209,7 +209,7 @@ async function loadFull(row: any) {
|
||||
row.respLen = d.completion_len || 0
|
||||
row.full = true
|
||||
} catch (e: any) {
|
||||
row.fullErr = err(e)
|
||||
row.fullErr = errText(e)
|
||||
} finally {
|
||||
row.fullLoading = false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user