feat: 交付任务005-021全量改动(自动化/AI/联系人中心、消息中心改造、运维与容器化)
- 自动化中心:规则引擎、流程画布与触发器(V7/V10/V12/V18/V21)、测试全流程、安全边界、执行记录 - AI 中心:服务商/模型/调用与工具授权/治理(V8/V17)及配套前端页面 - 联系人中心:联系人目录、分组/标签、同步幂等(V19)与实装页面 - 消息中心:三栏布局重做、头像昵称服务端抓取与缓存(V16 conversation_profile)、出站归属修复 - 接入管理:NapCat 反向 WS/HTTP 回调多通道发送传输、连接状态统一口径 - 运维中心:备份保留与恢复确认(V13/V22/V24)、监控告警(V23)、日志与审计 - 全局:账号上下文切换(V20 account_profile)、统一 UI 基础组件、分页样式、Flyway 增量迁移护栏 - 部署:Dockerfile/docker-compose/Nginx 容器化编排与 CI 校验脚本 - 文档:任务 005-021 交付记录、设计画板导出、接口/数据库/架构文档同步
@@ -0,0 +1,30 @@
|
||||
# QLinker 前端镜像(任务 020)
|
||||
# 构建阶段:Node 24 + npm ci + vite build;运行阶段:Nginx 托管 dist 并反代后端接口。
|
||||
FROM node:24-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 生产构建必须关闭演示数据(frontend/src/demo/config.js 默认开启)。
|
||||
ARG VITE_ENABLE_MOCK=false
|
||||
ENV VITE_ENABLE_MOCK=$VITE_ENABLE_MOCK
|
||||
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci --no-audit --no-fund
|
||||
|
||||
COPY frontend/ ./
|
||||
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:1.27-alpine AS runtime
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
COPY deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1
|
||||
@@ -4,6 +4,10 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>QLinker 管理台</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/logo/qlinker-favicon-32.svg" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/logo/qlinker-favicon-32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/logo/qlinker-favicon-16.png" />
|
||||
<link rel="apple-touch-icon" sizes="64x64" href="/logo/qlinker-favicon-64.png" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"element-plus": "^2.14.8",
|
||||
"unplugin-auto-import": "^19.3.0",
|
||||
"unplugin-vue-components": "^28.8.0",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
|
||||
|
After Width: | Height: | Size: 168 KiB |
|
After Width: | Height: | Size: 881 B |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16"><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 1.3 5.2)" cx="6.65" cy="4.7" rx="6.65" ry="4.7"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 2.4 0.2)" cx="5.65" cy="5.05" rx="5.65" ry="5.05"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 3.4 14.5)" cx="1.85" cy="0.75" rx="1.85" ry="0.75"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 8.9 14.5)" cx="1.85" cy="0.75" rx="1.85" ry="0.75"/><circle fill="#FFF" transform="matrix(1 0 0 1 4.4 3.4)" cx="1.35" cy="1.35" r="1.35"/><circle fill="#FFF" transform="matrix(1 0 0 1 8.9 3.4)" cx="1.35" cy="1.35" r="1.35"/><ellipse fill="#3B45C9" transform="matrix(1 0 0 1 7.07 6.74)" cx="1.01" cy="0.59" rx="1.01" ry="0.59"/><ellipse fill="#FFF" transform="matrix(1 0 0 1 4.21 9.77)" cx="3.79" cy="2.36" rx="3.79" ry="2.36"/><ellipse fill="#EEF0FE" transform="matrix(1 0 0 1 4.04 8.93)" cx="3.96" cy="1.01" rx="3.96" ry="1.01"/><circle fill="#171B26" transform="matrix(1 0 0 1 5 4)" cx="0.75" cy="0.75" r="0.75"/><circle fill="#171B26" transform="matrix(1 0 0 1 9.5 4)" cx="0.75" cy="0.75" r="0.75"/></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24"><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 2 7.8)" cx="10" cy="7.05" rx="10" ry="7.05"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 3.5 0.3)" cx="8.45" cy="7.6" rx="8.45" ry="7.6"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 5.1 21.7)" cx="2.8" cy="1.15" rx="2.8" ry="1.15"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 13.4 21.7)" cx="2.8" cy="1.15" rx="2.8" ry="1.15"/><circle fill="#FFF" transform="matrix(1 0 0 1 6.6 5.1)" cx="2" cy="2" r="2"/><circle fill="#FFF" transform="matrix(1 0 0 1 13.4 5.1)" cx="2" cy="2" r="2"/><ellipse fill="#3B45C9" transform="matrix(1 0 0 1 10.61 10.11)" cx="1.515" cy="0.885" rx="1.515" ry="0.885"/><ellipse fill="#FFF" transform="matrix(1 0 0 1 6.32 14.65)" cx="5.685" cy="3.535" rx="5.685" ry="3.535"/><ellipse fill="#EEF0FE" transform="matrix(1 0 0 1 6.06 13.39)" cx="5.935" cy="1.515" rx="5.935" ry="1.515"/><circle fill="#171B26" transform="matrix(1 0 0 1 7.5 5.9)" cx="1.15" cy="1.15" r="1.15"/><circle fill="#171B26" transform="matrix(1 0 0 1 14.3 5.9)" cx="1.15" cy="1.15" r="1.15"/></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 4 15.7)" cx="19.95" cy="14.15" rx="19.95" ry="14.15"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 7.1 0.5)" cx="16.95" cy="15.15" rx="16.95" ry="15.15"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 10.1 43.5)" cx="5.55" cy="2.25" rx="5.55" ry="2.25"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 26.8 43.5)" cx="5.55" cy="2.25" rx="5.55" ry="2.25"/><circle fill="#FFF" transform="matrix(1 0 0 1 13.1 10.1)" cx="4.05" cy="4.05" r="4.05"/><circle fill="#FFF" transform="matrix(1 0 0 1 26.8 10.1)" cx="4.05" cy="4.05" r="4.05"/><ellipse fill="#3B45C9" transform="matrix(1 0 0 1 21.22 20.21)" cx="3.03" cy="1.77" rx="3.03" ry="1.77"/><ellipse fill="#FFF" transform="matrix(1 0 0 1 12.63 29.31)" cx="11.37" cy="7.075" rx="11.37" ry="7.075"/><circle fill="#3B45C9" transform="matrix(1 0 0 1 21.47 34.61)" cx="2.525" cy="2.525" r="2.525"/><circle fill="#FFF" transform="matrix(1 0 0 1 22.74 35.87)" cx="1.265" cy="1.265" r="1.265"/><circle fill="#FFF" transform="matrix(1 0 0 1 32.34 27.28)" cx="1.77" cy="1.77" r="1.77"/><clipPath id="clip_0"><circle cx="34.11" cy="29.05" r="1.77"/></clipPath><g clip-path="url(#clip_0)"><path fill="#4F5BEF" transform="matrix(1 0 0 1 32.34 27.28)" d="M1.77 -0.5Q4.04 -0.5 4.04 1.77Q4.04 2.7103 3.3751 3.3751Q2.7103 4.04 1.77 4.04Q0.8297 4.04 0.1649 3.3751Q-0.5 2.7103 -0.5 1.77Q-0.5 -0.5 1.77 -0.5ZM1.77 0.5Q0.5 0.5 0.5 1.77Q0.5 3.04 1.77 3.04Q2.2961 3.04 2.668 2.668Q3.04 2.2961 3.04 1.77Q3.04 1.2439 2.668 0.872Q2.2961 0.5 1.77 0.5Z"/></g><ellipse fill="#EEF0FE" transform="matrix(1 0 0 1 12.13 26.78)" cx="11.875" cy="3.03" rx="11.875" ry="3.03"/><rect fill="#EEF0FE" transform="matrix(1 0 0 1 35.37 31.83)" width="4.04" height="6.57" rx="2.02" ry="2.02"/><circle fill="#171B26" transform="matrix(1 0 0 1 14.9 11.9)" cx="2.25" cy="2.25" r="2.25"/><circle fill="#171B26" transform="matrix(1 0 0 1 28.5 11.9)" cx="2.25" cy="2.25" r="2.25"/><circle fill="#FFF" transform="matrix(1 0 0 1 15.7 12.6)" cx="0.75" cy="0.75" r="0.75"/><circle fill="#FFF" transform="matrix(1 0 0 1 29.3 12.6)" cx="0.75" cy="0.75" r="0.75"/></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="1024"><rect fill="#EEF0FE" width="1024" height="1024"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 196 380)" cx="316" cy="224" rx="316" ry="224"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 244 140)" cx="268" cy="240" rx="268" ry="240"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 292 820)" cx="88" cy="36" rx="88" ry="36"/><ellipse fill="#4F5BEF" transform="matrix(1 0 0 1 556 820)" cx="88" cy="36" rx="88" ry="36"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 340 292)" cx="64" cy="64" r="64"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 556 292)" cx="64" cy="64" r="64"/><ellipse fill="#3B45C8" transform="matrix(1 0 0 1 468 452)" cx="48" cy="28" rx="48" ry="28"/><ellipse fill="#EDF0FE" transform="matrix(1 0 0 1 332 596)" cx="180" cy="112" rx="180" ry="112"/><circle fill="#3B45C8" transform="matrix(1 0 0 1 472 680)" cx="40" cy="40" r="40"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 492 700)" cx="20" cy="20" r="20"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 644 564)" cx="28" cy="28" r="28"/><ellipse fill="#EDF0FE" transform="matrix(1 0 0 1 324 556)" cx="188" cy="48" rx="188" ry="48"/><ellipse fill="#4E5BEF" fill-opacity="0.3" transform="matrix(1 0 0 1 364 596)" cx="40" cy="6" rx="40" ry="6"/><ellipse fill="#4E5BEF" fill-opacity="0.3" transform="matrix(1 0 0 1 420 620)" cx="32" cy="6" rx="32" ry="6"/><ellipse fill="#3B45C8" transform="matrix(1 0 0 1 540 728)" cx="10" cy="30" rx="10" ry="30"/><rect fill="#EDF0FE" transform="matrix(1 0 0 1 692 636)" width="64" height="104" rx="32" ry="32"/><circle fill="#1A1C25" transform="matrix(1 0 0 1 368 320)" cx="36" cy="36" r="36"/><circle fill="#1A1C25" transform="matrix(1 0 0 1 584 320)" cx="36" cy="36" r="36"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 380 332)" cx="12" cy="12" r="12"/><circle fill="#EDF0FE" transform="matrix(1 0 0 1 596 332)" cx="12" cy="12" r="12"/><ellipse fill="#EDF0FE" fill-opacity="0.6" transform="matrix(1 0 0 1 308 468)" cx="32" cy="16" rx="32" ry="16"/><ellipse fill="#EDF0FE" fill-opacity="0.6" transform="matrix(1 0 0 1 652 468)" cx="32" cy="16" rx="32" ry="16"/></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
@@ -2,8 +2,10 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { RouterLink, RouterView, useRoute, useRouter } from 'vue-router'
|
||||
import { api, getToken, setToken } from './api'
|
||||
import { describeError, notify, toastState, hideToast } from './ui'
|
||||
import { demoState } from './demo/config'
|
||||
import { describeError, notify } from './ui'
|
||||
import AccountSwitcher from './components/account/AccountSwitcher.vue'
|
||||
import { accountState, loadAccounts } from './account-context'
|
||||
import { setSessionUser, can } from './permissions'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@@ -16,6 +18,7 @@ const instance = ref(null)
|
||||
const searchText = ref('')
|
||||
const menuOpen = ref(false)
|
||||
const dark = ref(localStorage.getItem('qlinker.theme') === 'dark')
|
||||
const navCollapsed = ref(localStorage.getItem('qlinker.nav.collapsed') === '1')
|
||||
|
||||
const navGroups = [
|
||||
{
|
||||
@@ -23,6 +26,7 @@ const navGroups = [
|
||||
items: [
|
||||
{ to: '/dashboard', label: '工作台', icon: '▤' },
|
||||
{ to: '/messages', label: '消息中心', icon: '◫' },
|
||||
{ to: '/contacts', label: '联系人', icon: '◍', permission: 'contact.read' },
|
||||
{ to: '/message-search', label: '消息检索', icon: '⌕' },
|
||||
{ to: '/automation', label: '自动化中心', icon: '⌗' },
|
||||
{ to: '/ai', label: 'AI 中心', icon: '✦' }
|
||||
@@ -49,6 +53,7 @@ const navGroups = [
|
||||
const mobileNav = [
|
||||
{ to: '/dashboard', label: '工作台', icon: '▤' },
|
||||
{ to: '/messages', label: '消息', icon: '◫' },
|
||||
{ to: '/contacts', label: '联系人', icon: '◍', permission: 'contact.read' },
|
||||
{ to: '/automation', label: '自动化', icon: '⌗' },
|
||||
{ to: '/ops', label: '运维', icon: '◉' },
|
||||
{ to: '/settings', label: '设置', icon: '◌' }
|
||||
@@ -61,6 +66,8 @@ const instanceLabel = computed(() => {
|
||||
return instance.value ? '实例未初始化' : '实例状态读取中'
|
||||
})
|
||||
const activePath = computed(() => route.path)
|
||||
const crumbGroup = computed(() => route.meta.group || '工作空间')
|
||||
const crumbTitle = computed(() => route.meta.title || '管理台')
|
||||
|
||||
function applyTheme() {
|
||||
document.documentElement.style.colorScheme = dark.value ? 'dark' : 'light'
|
||||
@@ -72,16 +79,24 @@ function toggleTheme() {
|
||||
applyTheme()
|
||||
}
|
||||
|
||||
function toggleNav() {
|
||||
navCollapsed.value = !navCollapsed.value
|
||||
localStorage.setItem('qlinker.nav.collapsed', navCollapsed.value ? '1' : '0')
|
||||
}
|
||||
|
||||
async function loadUser() {
|
||||
if (!getToken() || publicPage.value) return
|
||||
userLoading.value = true
|
||||
userError.value = null
|
||||
try {
|
||||
user.value = await api.me()
|
||||
setSessionUser(user.value)
|
||||
if (!accountState.loaded) loadAccounts()
|
||||
} catch (error) {
|
||||
if (error.code === 'UNAUTHENTICATED' || error.httpStatus === 401) {
|
||||
setToken('')
|
||||
user.value = null
|
||||
setSessionUser(null)
|
||||
router.push('/login')
|
||||
} else {
|
||||
userError.value = describeError(error)
|
||||
@@ -109,6 +124,7 @@ async function logout() {
|
||||
} finally {
|
||||
setToken('')
|
||||
user.value = null
|
||||
setSessionUser(null)
|
||||
loggingOut.value = false
|
||||
menuOpen.value = false
|
||||
router.push('/login')
|
||||
@@ -170,11 +186,11 @@ onBeforeUnmount(() => {
|
||||
<div v-if="publicPage" class="auth-shell">
|
||||
<aside class="auth-brand">
|
||||
<div class="brand">
|
||||
<span class="logo">Q</span>
|
||||
<div class="brand-text">
|
||||
<strong>QLinker</strong>
|
||||
<span>QQ 消息管理台</span>
|
||||
</div>
|
||||
<picture class="brand-lockup">
|
||||
<source srcset="/logo/qlinker-logo-horizontal-512.svg" type="image/svg+xml" />
|
||||
<img src="/logo/qlinker-logo-horizontal-512.png" alt="QLinker" width="173" height="54" />
|
||||
</picture>
|
||||
<span class="brand-tagline">QQ 消息管理台</span>
|
||||
</div>
|
||||
<div class="auth-pitch">
|
||||
<h1>独立部署的 QQ 消息管理实例</h1>
|
||||
@@ -194,38 +210,37 @@ onBeforeUnmount(() => {
|
||||
|
||||
<div v-else class="app">
|
||||
<header class="topbar">
|
||||
<RouterLink to="/dashboard" class="brand" style="text-decoration: none">
|
||||
<span class="logo">Q</span>
|
||||
<div class="brand-text">
|
||||
<strong>QLinker</strong>
|
||||
<span>QQ 消息管理台</span>
|
||||
</div>
|
||||
</RouterLink>
|
||||
<div class="crumb" aria-label="当前位置">
|
||||
<span>{{ crumbGroup }}</span>
|
||||
<span class="crumb-sep">/</span>
|
||||
<strong>{{ crumbTitle }}</strong>
|
||||
</div>
|
||||
|
||||
<div class="instance" :title="instanceLabel">
|
||||
<strong>当前实例</strong>
|
||||
<div class="instance" v-tooltip="instanceLabel">
|
||||
<span class="dot-live" aria-hidden="true"></span>
|
||||
<span>{{ instanceLabel }}</span>
|
||||
</div>
|
||||
|
||||
<span class="mode-chip" v-tooltip="'当前未启用紧急停止'">紧急停止未启用</span>
|
||||
|
||||
<form class="global-search" @submit.prevent="submitSearch">
|
||||
<span aria-hidden="true">⌕</span>
|
||||
<input
|
||||
id="global-search-input"
|
||||
v-model="searchText"
|
||||
type="search"
|
||||
placeholder="搜索消息摘要前缀(Ctrl+K)"
|
||||
placeholder="搜索消息摘要(Ctrl+K)"
|
||||
aria-label="全局消息检索"
|
||||
/>
|
||||
</form>
|
||||
|
||||
<div class="top-actions">
|
||||
<button class="icon-btn" type="button" :title="dark ? '切换为浅色' : '切换为深色'" @click="toggleTheme">
|
||||
<button class="icon-btn" type="button" v-tooltip="dark ? '切换为浅色' : '切换为深色'" @click="toggleTheme">
|
||||
{{ dark ? '☾' : '☀' }}
|
||||
</button>
|
||||
<button
|
||||
class="icon-btn"
|
||||
type="button"
|
||||
title="通知中心未实现:后端未提供通知接口"
|
||||
type="button" v-tooltip="'通知中心未实现:后端未提供通知接口'"
|
||||
@click="notify('通知中心未实现', '后端 /api/v1 尚未提供通知接口,本按钮不代表真实告警。', 'info')"
|
||||
>
|
||||
⌁
|
||||
@@ -247,25 +262,57 @@ onBeforeUnmount(() => {
|
||||
</header>
|
||||
|
||||
<div class="shell">
|
||||
<aside class="sidebar">
|
||||
<nav v-for="group in navGroups" :key="group.label" class="nav-group" aria-label="主导航">
|
||||
<div class="nav-label">{{ group.label }}</div>
|
||||
<RouterLink
|
||||
v-for="item in group.items"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
class="nav-item"
|
||||
:class="{ active: activePath === item.to }"
|
||||
>
|
||||
<span class="nav-icon" aria-hidden="true">{{ item.icon }}</span>
|
||||
<span>{{ item.label }}</span>
|
||||
<aside id="app-nav" class="sidebar" :class="{ collapsed: navCollapsed }">
|
||||
<div class="sidebar-head">
|
||||
<RouterLink to="/dashboard" class="sidebar-brand" style="text-decoration: none" :title="navCollapsed ? 'QLinker' : ''">
|
||||
<picture class="brand-logo">
|
||||
<source srcset="/logo/qlinker-logo-1024.svg" type="image/svg+xml" />
|
||||
<img src="/logo/qlinker-logo-1024.png" alt="QLinker" width="24" height="24" />
|
||||
</picture>
|
||||
<div class="brand-text">
|
||||
<strong>QLinker</strong>
|
||||
<span>QQ 消息管理台</span>
|
||||
</div>
|
||||
</RouterLink>
|
||||
</nav>
|
||||
<button
|
||||
class="nav-toggle"
|
||||
type="button"
|
||||
:aria-expanded="!navCollapsed"
|
||||
aria-controls="app-nav" v-tooltip="navCollapsed ? '展开导航' : '收起导航'"
|
||||
@click="toggleNav"
|
||||
>
|
||||
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false">
|
||||
<path
|
||||
d="M10 3.5 5.5 8 10 12.5"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-nav">
|
||||
<nav v-for="group in navGroups" :key="group.label" class="nav-group" aria-label="主导航">
|
||||
<div class="nav-label">{{ group.label }}</div>
|
||||
<template v-for="item in group.items" :key="item.to">
|
||||
<RouterLink
|
||||
v-if="!item.permission || can(item.permission) !== false"
|
||||
:to="item.to"
|
||||
class="nav-item"
|
||||
:class="{ active: activePath === item.to }"
|
||||
:data-label="item.label"
|
||||
>
|
||||
<span class="nav-icon" aria-hidden="true">{{ item.icon }}</span>
|
||||
<span class="nav-text">{{ item.label }}</span>
|
||||
</RouterLink>
|
||||
</template>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="sidebar-bottom">
|
||||
<strong>演示数据</strong>
|
||||
<p v-if="demoState.enabled">当前开启,未实现页面显示标注过的演示数据。</p>
|
||||
<p v-else>当前关闭,未实现页面整体显示「未开发 / 规划中」。</p>
|
||||
<RouterLink class="btn sm block" to="/settings">前往开关</RouterLink>
|
||||
<AccountSwitcher />
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -278,27 +325,31 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
<button class="btn sm" type="button" @click="loadUser">重试</button>
|
||||
</div>
|
||||
<div v-if="accountState.loaded && accountState.items.length === 0" class="notice info" role="status" style="margin-bottom: 16px">
|
||||
<div>
|
||||
<strong>当前没有可用 QQ 账号</strong>
|
||||
<div style="margin-top: 4px">
|
||||
消息中心、联系人、自动化与 AI 调用都按账号隔离,需要先在接入管理绑定 NapCat 并确认连接在线。
|
||||
</div>
|
||||
</div>
|
||||
<RouterLink to="/connections" class="btn sm">去接入管理</RouterLink>
|
||||
</div>
|
||||
<RouterView />
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<nav class="mobile-nav" aria-label="移动端导航">
|
||||
<RouterLink
|
||||
v-for="item in mobileNav"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
:class="{ active: activePath === item.to }"
|
||||
style="text-decoration: none"
|
||||
>
|
||||
<span aria-hidden="true">{{ item.icon }}</span>
|
||||
{{ item.label }}
|
||||
</RouterLink>
|
||||
<template v-for="item in mobileNav" :key="item.to">
|
||||
<RouterLink
|
||||
v-if="!item.permission || can(item.permission) !== false"
|
||||
:to="item.to"
|
||||
:class="{ active: activePath === item.to }"
|
||||
style="text-decoration: none"
|
||||
>
|
||||
<span aria-hidden="true">{{ item.icon }}</span>
|
||||
{{ item.label }}
|
||||
</RouterLink>
|
||||
</template>
|
||||
</nav>
|
||||
|
||||
<div class="toast" :class="{ show: toastState.visible }" role="status">
|
||||
<strong>{{ toastState.title }}</strong>
|
||||
<span>{{ toastState.body }}</span>
|
||||
<button class="link" type="button" style="margin-top: 8px" @click="hideToast">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { reactive } from 'vue'
|
||||
import { api } from './api.js'
|
||||
import { bindingStatusLabel } from './binding-status.js'
|
||||
|
||||
/**
|
||||
* 当前 QQ 账号选择的持久化键。
|
||||
* 账号是全局必需上下文:不再支持「全部账号」,仅当实例没有任何 ACTIVE 且回填 QQ 号的绑定时,
|
||||
* current 才为 null(此时各页面显示空态并提示去接入管理绑定)。
|
||||
*/
|
||||
const STORAGE_KEY = 'qlinker.account.current'
|
||||
|
||||
function readStored() {
|
||||
const value = localStorage.getItem(STORAGE_KEY)
|
||||
return value && value.trim() ? value.trim() : null
|
||||
}
|
||||
|
||||
export const accountState = reactive({
|
||||
loaded: false,
|
||||
loading: false,
|
||||
items: [],
|
||||
unattributedBindings: 0,
|
||||
/** 当前 qqAccountId;仅在没有可用账号时为 null。 */
|
||||
current: readStored(),
|
||||
/** 加载/回退提示,供切换器展示,不代表后端错误。 */
|
||||
message: '',
|
||||
error: ''
|
||||
})
|
||||
|
||||
export function accountParam() {
|
||||
return accountState.current
|
||||
}
|
||||
|
||||
/** 是否有可用的当前账号;无账号时页面应展示空态而不是拉全量数据。 */
|
||||
export function hasCurrentAccount() {
|
||||
return Boolean(accountState.current)
|
||||
}
|
||||
|
||||
export function isCurrent(qqAccountId) {
|
||||
return String(qqAccountId) === String(accountState.current)
|
||||
}
|
||||
|
||||
export function currentAccount() {
|
||||
return accountState.items.find((item) => isCurrent(item.qqAccountId)) || null
|
||||
}
|
||||
|
||||
export function setCurrentAccount(qqAccountId) {
|
||||
const next = qqAccountId == null ? '' : String(qqAccountId).trim()
|
||||
// 不再允许空值代表「全部账号」;空值仅用于无账号可选的场景。
|
||||
if (!next) return
|
||||
accountState.current = next
|
||||
accountState.message = ''
|
||||
localStorage.setItem(STORAGE_KEY, next)
|
||||
}
|
||||
|
||||
function eventTime(item) {
|
||||
const time = Date.parse(item?.lastEventAt || '')
|
||||
return Number.isFinite(time) ? time : 0
|
||||
}
|
||||
|
||||
/** 默认账号:优先在线,其次最近有事件的(lastEventAt),最后回退目录首项。 */
|
||||
function pickDefaultAccount(items) {
|
||||
if (!items.length) return null
|
||||
const online = items.filter((item) => item.online === true)
|
||||
const pool = online.length ? online : items
|
||||
const latest = [...pool].sort((a, b) => eventTime(b) - eventTime(a))[0]
|
||||
return latest || items[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载账号目录并校正当前账号(绑定可能停用或 QQ 号变更)。
|
||||
* 当前账号失效时自动切到默认账号;没有任何可用账号时置空并提示去接入管理,
|
||||
* 不回退到「全部账号」聚合,避免不同账号的数据混在一起。
|
||||
*/
|
||||
export async function loadAccounts() {
|
||||
if (accountState.loading) return
|
||||
accountState.loading = true
|
||||
try {
|
||||
const data = await api.accounts()
|
||||
accountState.items = data?.items || []
|
||||
accountState.unattributedBindings = Number(data?.unattributedBindings || 0)
|
||||
accountState.loaded = true
|
||||
accountState.error = ''
|
||||
if (!accountState.items.length) {
|
||||
accountState.current = null
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
accountState.message = '当前实例没有可用 QQ 账号,请先到接入管理绑定并确认连接在线。'
|
||||
return
|
||||
}
|
||||
if (!accountState.current || !accountState.items.some((item) => isCurrent(item.qqAccountId))) {
|
||||
const fallback = pickDefaultAccount(accountState.items)
|
||||
const hadCurrent = Boolean(accountState.current)
|
||||
accountState.current = fallback.qqAccountId
|
||||
localStorage.setItem(STORAGE_KEY, fallback.qqAccountId)
|
||||
accountState.message = hadCurrent
|
||||
? '原选账号已不可用,已切换到当前在线账号'
|
||||
: ''
|
||||
}
|
||||
} catch (e) {
|
||||
accountState.error = e?.message || '账号目录加载失败'
|
||||
accountState.message = ''
|
||||
} finally {
|
||||
accountState.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 账号在线文案与接入管理、画布共用同一判定(connection_status),避免各处口径分裂。 */
|
||||
export function statusText(status) {
|
||||
return bindingStatusLabel({ connectionStatus: status })
|
||||
}
|
||||
@@ -51,6 +51,7 @@ export async function request(path, options = {}) {
|
||||
if (!body || body.success !== true) {
|
||||
const error = new Error(body?.message || `请求失败(HTTP ${response.status})`)
|
||||
error.code = body?.code
|
||||
error.data = body?.data
|
||||
error.requestId = body?.requestId
|
||||
error.httpStatus = response.status
|
||||
throw error
|
||||
@@ -72,7 +73,7 @@ export const api = {
|
||||
logout: () => request('/api/v1/auth/logout', { method: 'POST' }),
|
||||
me: () => request('/api/v1/auth/me'),
|
||||
|
||||
bindings: () => request('/api/v1/napcat-bindings'),
|
||||
bindings: (params) => request(`/api/v1/napcat-bindings${buildQuery(params)}`),
|
||||
binding: (uid) => request(`/api/v1/napcat-bindings/${uid}`),
|
||||
createBinding: (payload) => request('/api/v1/napcat-bindings', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
rotateToken: (uid, accessToken) =>
|
||||
@@ -81,16 +82,55 @@ export const api = {
|
||||
body: JSON.stringify({ accessToken })
|
||||
}),
|
||||
deactivateBinding: (uid) => request(`/api/v1/napcat-bindings/${uid}`, { method: 'DELETE' }),
|
||||
purgeBinding: (uid) => request(`/api/v1/napcat-bindings/${uid}/record`, { method: 'DELETE' }),
|
||||
updateBinding: (uid, payload) =>
|
||||
request(`/api/v1/napcat-bindings/${uid}`, { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
enableBinding: (uid) => request(`/api/v1/napcat-bindings/${uid}/enable`, { method: 'POST' }),
|
||||
disableBinding: (uid) => request(`/api/v1/napcat-bindings/${uid}/disable`, { method: 'POST' }),
|
||||
|
||||
auditEvents: (params) => request(`/api/v1/audit-events${buildQuery(params)}`),
|
||||
|
||||
users: (params) => request(`/api/v1/users${buildQuery(params)}`),
|
||||
createUser: (payload) => request('/api/v1/users', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
updateUser: (userId, payload) =>
|
||||
request(`/api/v1/users/${userId}`, { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
changeUserPassword: (userId, password) =>
|
||||
request(`/api/v1/users/${userId}/password`, { method: 'POST', body: JSON.stringify({ password }) }),
|
||||
enableUser: (userId) => request(`/api/v1/users/${userId}/enable`, { method: 'POST' }),
|
||||
disableUser: (userId) => request(`/api/v1/users/${userId}/disable`, { method: 'POST' }),
|
||||
deleteUser: (userId) => request(`/api/v1/users/${userId}`, { method: 'DELETE' }),
|
||||
|
||||
roles: () => request('/api/v1/roles'),
|
||||
rolePermissions: () => request('/api/v1/roles/permissions'),
|
||||
createRole: (payload) => request('/api/v1/roles', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
updateRole: (roleId, payload) =>
|
||||
request(`/api/v1/roles/${roleId}`, { method: 'PUT', body: JSON.stringify(payload) }),
|
||||
assignRolePermissions: (roleId, permissionCodes) =>
|
||||
request(`/api/v1/roles/${roleId}/permissions`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ permissionCodes })
|
||||
}),
|
||||
|
||||
tokens: (params) => request(`/api/v1/tokens${buildQuery(params)}`),
|
||||
issueToken: (payload) => request('/api/v1/tokens', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
revokeToken: (tokenUid) =>
|
||||
request(`/api/v1/tokens/${encodeURIComponent(tokenUid)}/revoke`, { method: 'POST' }),
|
||||
|
||||
accounts: () => request('/api/v1/accounts'),
|
||||
|
||||
messages: (params) => request(`/api/v1/messages${buildQuery(params)}`),
|
||||
message: (uid) => request(`/api/v1/messages/${encodeURIComponent(uid)}`),
|
||||
conversations: (page = 1, pageSize = 50) =>
|
||||
request(`/api/v1/messages/conversations${buildQuery({ page, pageSize })}`),
|
||||
conversations: (page = 1, pageSize = 50, qqAccount = null) =>
|
||||
request(`/api/v1/messages/conversations${buildQuery({ page, pageSize, qqAccount })}`),
|
||||
messageStats: () => request('/api/v1/messages/stats'),
|
||||
|
||||
mediaStats: () => request('/api/v1/media/stats'),
|
||||
mediaList: (params) => request(`/api/v1/media${buildQuery(params)}`),
|
||||
media: (uid) => request(`/api/v1/media/${encodeURIComponent(uid)}`),
|
||||
mediaAccessUrl: (uid) => request(`/api/v1/media/${encodeURIComponent(uid)}/access-url`),
|
||||
mediaQuota: () => request('/api/v1/media/quota'),
|
||||
messageRuleHits: (uid, params) =>
|
||||
request(`/api/v1/messages/${encodeURIComponent(uid)}/rule-hits${buildQuery(params)}`),
|
||||
|
||||
prepareText: (payload, idempotencyKey) =>
|
||||
request('/api/v1/send/text', {
|
||||
@@ -104,6 +144,88 @@ export const api = {
|
||||
body: JSON.stringify({ confirmToken })
|
||||
}),
|
||||
sendOperation: (uid) => request(`/api/v1/send/operations/${encodeURIComponent(uid)}`),
|
||||
sendOperations: (limit = 50) => request(`/api/v1/send/operations?limit=${limit}`),
|
||||
sendSummary: () => request('/api/v1/send/summary')
|
||||
sendOperations: (params = {}) => request(`/api/v1/send/operations${buildQuery(params)}`),
|
||||
cancelSendOperation: (uid, reason) =>
|
||||
request(`/api/v1/send/operations/${encodeURIComponent(uid)}/cancel`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason })
|
||||
}),
|
||||
resolveSendOperation: (uid, resolution, note) =>
|
||||
request(`/api/v1/send/operations/${encodeURIComponent(uid)}/resolve`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ resolution, note })
|
||||
}),
|
||||
sendSummary: () => request('/api/v1/send/summary'),
|
||||
testSendPolicy: () => request('/api/v1/send/test/policy'),
|
||||
prepareTestSend: (payload, idempotencyKey) =>
|
||||
request('/api/v1/send/test/prepare', {
|
||||
method: 'POST',
|
||||
headers: { 'Idempotency-Key': idempotencyKey },
|
||||
body: JSON.stringify(payload)
|
||||
}),
|
||||
|
||||
systemStatus: () => request('/api/v1/system/status'),
|
||||
|
||||
opsHealth: () => request('/api/v1/ops/health'),
|
||||
opsAlertSummary: () => request('/api/v1/ops/alerts/summary'),
|
||||
opsAlertRules: () => request('/api/v1/ops/alerts/rules'),
|
||||
updateOpsAlertRule: (ruleKey, payload) =>
|
||||
request(`/api/v1/ops/alerts/rules/${encodeURIComponent(ruleKey)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(payload)
|
||||
}),
|
||||
opsAlertEvents: (params) => request(`/api/v1/ops/alerts/events${buildQuery(params)}`),
|
||||
opsAlertEvent: (eventUid) => request(`/api/v1/ops/alerts/events/${encodeURIComponent(eventUid)}`),
|
||||
acknowledgeOpsAlert: (eventUid) =>
|
||||
request(`/api/v1/ops/alerts/events/${encodeURIComponent(eventUid)}/acknowledge`, { method: 'POST' }),
|
||||
closeOpsAlert: (eventUid, note) =>
|
||||
request(`/api/v1/ops/alerts/events/${encodeURIComponent(eventUid)}/close`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ note })
|
||||
}),
|
||||
opsAlertNotificationStatus: () => request('/api/v1/ops/alerts/notifications/status'),
|
||||
|
||||
backups: (params) => request(`/api/v1/ops/backups${buildQuery(params)}`),
|
||||
createBackup: (payload) => request('/api/v1/ops/backups', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
backup: (uid) => request(`/api/v1/ops/backups/${encodeURIComponent(uid)}`),
|
||||
verifyBackup: (uid) => request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/verify`, { method: 'POST' }),
|
||||
preflightBackup: (uid) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/preflight`, { method: 'POST' }),
|
||||
runtimeMode: () => request('/api/v1/system/runtime-mode'),
|
||||
changeRuntimeMode: (mode, reason) =>
|
||||
request('/api/v1/system/runtime-mode', { method: 'PUT', body: JSON.stringify({ mode, reason }) }),
|
||||
createRestoreConfirmation: (uid, reason) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/restore-confirmations`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason })
|
||||
}),
|
||||
restoreBackup: (uid, confirmationToken, reason) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/restore`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ confirmationToken, reason })
|
||||
}),
|
||||
backupRetention: () => request('/api/v1/ops/backups/retention'),
|
||||
recalculateBackupRetention: () =>
|
||||
request('/api/v1/ops/backups/retention/recalculate', { method: 'POST' }),
|
||||
backupDeletePreflight: (uid) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/delete-preflight`, { method: 'POST' }),
|
||||
createBackupDeleteConfirmation: (uid, reason) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}/delete-confirmations`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason })
|
||||
}),
|
||||
deleteBackup: (uid, confirmationToken, reason) =>
|
||||
request(`/api/v1/ops/backups/${encodeURIComponent(uid)}`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({ confirmationToken, reason })
|
||||
}),
|
||||
|
||||
logs: (params) => request(`/api/v1/logs${buildQuery(params)}`),
|
||||
|
||||
settings: () => request('/api/v1/settings'),
|
||||
updateSetting: (key, value) =>
|
||||
request(`/api/v1/settings/${encodeURIComponent(key)}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ value })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { request } from '../api'
|
||||
|
||||
/**
|
||||
* AI 中心接口封装(任务 006)。只依赖既有 request 封装与统一响应结构,
|
||||
* 不引入第三方 HTTP 库;所有调用都返回后端真实数据,失败时抛出可被 describeError 识别的错误。
|
||||
*/
|
||||
function buildQuery(params = {}) {
|
||||
const search = new URLSearchParams()
|
||||
for (const [key, value] of Object.entries(params || {})) {
|
||||
if (value === undefined || value === null || value === '' || value === 'all') continue
|
||||
search.set(key, String(value))
|
||||
}
|
||||
const text = search.toString()
|
||||
return text ? `?${text}` : ''
|
||||
}
|
||||
|
||||
function jsonBody(payload) {
|
||||
return { method: 'POST', body: JSON.stringify(payload) }
|
||||
}
|
||||
|
||||
function putBody(payload) {
|
||||
return { method: 'PUT', body: JSON.stringify(payload) }
|
||||
}
|
||||
|
||||
export const aiApi = {
|
||||
// 服务商
|
||||
providers: () => request('/api/v1/ai/providers'),
|
||||
providerPresets: () => request('/api/v1/ai/providers/presets'),
|
||||
createProvider: (payload) => request('/api/v1/ai/providers', jsonBody(payload)),
|
||||
updateProvider: (providerUid, payload) => request(`/api/v1/ai/providers/${encodeURIComponent(providerUid)}`, putBody(payload)),
|
||||
testProvider: (providerUid) =>
|
||||
request(`/api/v1/ai/providers/${encodeURIComponent(providerUid)}/test`, { method: 'POST' }),
|
||||
testProviderDraft: (payload) => request('/api/v1/ai/providers/test', jsonBody(payload)),
|
||||
probeModelsDraft: (payload) => request('/api/v1/ai/providers/models/probe', jsonBody(payload)),
|
||||
probeModels: (providerUid) =>
|
||||
request(`/api/v1/ai/providers/${encodeURIComponent(providerUid)}/models/probe`, { method: 'POST' }),
|
||||
|
||||
// 模型与能力
|
||||
models: (params) => request(`/api/v1/ai/models${buildQuery(params)}`),
|
||||
createModel: (payload) => request('/api/v1/ai/models', jsonBody(payload)),
|
||||
updateModel: (modelUid, payload) => request(`/api/v1/ai/models/${encodeURIComponent(modelUid)}`, putBody(payload)),
|
||||
testModel: (modelUid, testType) =>
|
||||
request(`/api/v1/ai/models/${encodeURIComponent(modelUid)}/test`, jsonBody({ testType })),
|
||||
deleteModel: (modelUid) => request(`/api/v1/ai/models/${encodeURIComponent(modelUid)}`, { method: 'DELETE' }),
|
||||
|
||||
// 调用记录与用量成本
|
||||
calls: (params) => request(`/api/v1/ai/calls${buildQuery(params)}`),
|
||||
callSummary: (params) => request(`/api/v1/ai/calls/summary${buildQuery(params)}`),
|
||||
|
||||
// 工具注册、策略与执行
|
||||
tools: () => request('/api/v1/ai/tools'),
|
||||
toolPolicies: () => request('/api/v1/ai/tool-policies'),
|
||||
createToolPolicy: (payload) => request('/api/v1/ai/tool-policies', jsonBody(payload)),
|
||||
updateToolPolicy: (policyUid, payload) =>
|
||||
request(`/api/v1/ai/tool-policies/${encodeURIComponent(policyUid)}`, putBody(payload)),
|
||||
toolCalls: (params) => request(`/api/v1/ai/tool-calls${buildQuery(params)}`),
|
||||
toolCall: (toolCallUid) => request(`/api/v1/ai/tool-calls/${encodeURIComponent(toolCallUid)}`),
|
||||
executeToolCall: (toolCallUid) =>
|
||||
request(`/api/v1/ai/tool-calls/${encodeURIComponent(toolCallUid)}/execute`, { method: 'POST' }),
|
||||
approveToolCall: (toolCallUid, decision, reason) =>
|
||||
request(`/api/v1/ai/tool-calls/${encodeURIComponent(toolCallUid)}/approve`,
|
||||
jsonBody({ decision, reason })),
|
||||
|
||||
// 脱敏、缓存与记忆治理
|
||||
governance: () => request('/api/v1/ai/governance'),
|
||||
memories: (params) => request(`/api/v1/ai/memories${buildQuery(params)}`),
|
||||
createMemory: (payload) => request('/api/v1/ai/memories', jsonBody(payload)),
|
||||
deleteMemory: (memoryUid) =>
|
||||
request(`/api/v1/ai/memories/${encodeURIComponent(memoryUid)}`, { method: 'DELETE' }),
|
||||
purgeMemories: () => request('/api/v1/ai/memories/purge', { method: 'POST' }),
|
||||
clearCache: () => request('/api/v1/ai/cache/clear', { method: 'POST' })
|
||||
}
|
||||
|
||||
export default aiApi
|
||||
@@ -0,0 +1,77 @@
|
||||
import { request } from '../api'
|
||||
|
||||
/**
|
||||
* 自动化规则与任务接口封装(任务 005 后端实际契约,见 docs/接口设计.md 第 10、11 章)。
|
||||
* 只依赖既有 request 封装与统一响应结构,不引入第三方 HTTP 库;失败时抛出可被 describeError 识别的错误。
|
||||
*/
|
||||
function buildQuery(params = {}) {
|
||||
const search = new URLSearchParams()
|
||||
for (const [key, value] of Object.entries(params || {})) {
|
||||
if (value === undefined || value === null || value === '' || value === 'all') continue
|
||||
search.set(key, String(value))
|
||||
}
|
||||
const text = search.toString()
|
||||
return text ? `?${text}` : ''
|
||||
}
|
||||
|
||||
function jsonBody(payload) {
|
||||
return { method: 'POST', body: JSON.stringify(payload) }
|
||||
}
|
||||
|
||||
function post() {
|
||||
return { method: 'POST' }
|
||||
}
|
||||
|
||||
export const automationApi = {
|
||||
emergencyState: () => request('/api/v1/automation/emergency-stop'),
|
||||
emergencyStop: (reason) => request('/api/v1/automation/emergency-stop', jsonBody({ reason })),
|
||||
resume: () => request('/api/v1/automation/resume', post()),
|
||||
|
||||
rules: (params) => request(`/api/v1/automation/rules${buildQuery(params)}`),
|
||||
createRule: (payload) => request('/api/v1/automation/rules', jsonBody(payload)),
|
||||
// 写操作可带 qqAccount:后端据此校验规则归属账号,跨账号编辑会被拒绝并提示切换账号。
|
||||
updateRule: (ruleUid, payload, qqAccount) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}${buildQuery({ qqAccount })}`,
|
||||
{ method: 'PATCH', body: JSON.stringify(payload) }),
|
||||
rule: (ruleUid) => request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}`),
|
||||
versions: (ruleUid) => request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/versions`),
|
||||
createVersion: (ruleUid, payload, qqAccount) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/versions${buildQuery({ qqAccount })}`,
|
||||
jsonBody(payload)),
|
||||
validateVersion: (ruleUid, versionUid) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/versions/${encodeURIComponent(versionUid)}/validate`,
|
||||
post()),
|
||||
publish: (ruleUid, versionUid, reason, qqAccount) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/versions/${encodeURIComponent(versionUid)}/publish${buildQuery({ qqAccount })}`,
|
||||
jsonBody({ reason })),
|
||||
rollback: (ruleUid, versionNumber, reason, qqAccount) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/versions/${versionNumber}/rollback${buildQuery({ qqAccount })}`,
|
||||
jsonBody({ reason })),
|
||||
safetyLimits: () => request('/api/v1/automation/safety-limits'),
|
||||
batchRules: (action, ruleUids, reason) =>
|
||||
request('/api/v1/automation/rules/batch', jsonBody({ action, ruleUids, reason })),
|
||||
hits: (params) => request(`/api/v1/automation/hits${buildQuery(params)}`),
|
||||
disable: (ruleUid, reason) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/disable`, jsonBody({ reason })),
|
||||
archive: (ruleUid, reason) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/archive`, jsonBody({ reason })),
|
||||
execute: (ruleUid, payload) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/execute`, jsonBody(payload)),
|
||||
testRun: (ruleUid, payload) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/test-run`, jsonBody(payload)),
|
||||
schedule: (ruleUid) => request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/schedule`),
|
||||
setScheduleEnabled: (ruleUid, enabled, reason) =>
|
||||
request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/schedule`,
|
||||
jsonBody({ enabled, reason })),
|
||||
webhook: (ruleUid) => request(`/api/v1/automation/rules/${encodeURIComponent(ruleUid)}/webhook`),
|
||||
|
||||
tasks: (params) => request(`/api/v1/tasks${buildQuery(params)}`),
|
||||
task: (taskUid) => request(`/api/v1/tasks/${encodeURIComponent(taskUid)}`),
|
||||
taskStatus: (taskUid) => request(`/api/v1/tasks/${encodeURIComponent(taskUid)}/status`),
|
||||
retryTask: (taskUid, reason) =>
|
||||
request(`/api/v1/tasks/${encodeURIComponent(taskUid)}/retry`, jsonBody({ reason })),
|
||||
cancelTask: (taskUid, reason) =>
|
||||
request(`/api/v1/tasks/${encodeURIComponent(taskUid)}/cancel`, jsonBody({ reason }))
|
||||
}
|
||||
|
||||
export default automationApi
|
||||
@@ -0,0 +1,55 @@
|
||||
import { request } from '../api'
|
||||
|
||||
function toQuery(params = {}) {
|
||||
const search = new URLSearchParams()
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value === undefined || value === null || value === '') continue
|
||||
search.set(key, String(value))
|
||||
}
|
||||
const text = search.toString()
|
||||
return text ? `?${text}` : ''
|
||||
}
|
||||
|
||||
function write(path, method, payload, idempotencyKey) {
|
||||
const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}
|
||||
return request(path, { method, headers, body: JSON.stringify(payload || {}) })
|
||||
}
|
||||
|
||||
/** 联系人中心接口封装;请求字段与 ContactController / ContactManageService 保持一致。 */
|
||||
export const contactsApi = {
|
||||
list: (params) => request(`/api/v1/contacts${toQuery(params)}`),
|
||||
detail: (contactUid) => request(`/api/v1/contacts/${encodeURIComponent(contactUid)}`),
|
||||
groups: (qqAccount) => request(`/api/v1/contact-groups${toQuery({ qqAccount })}`),
|
||||
tags: (qqAccount) => request(`/api/v1/contact-tags${toQuery({ qqAccount })}`),
|
||||
syncState: (qqAccount) => request(`/api/v1/contacts/sync/state${toQuery({ qqAccount })}`),
|
||||
sync: (qqAccount, payload = { scope: 'ALL' }) =>
|
||||
request(`/api/v1/contacts/sync${toQuery({ qqAccount })}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
}),
|
||||
updateRemark: (contactUid, payload) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}/remark`, 'PUT', payload),
|
||||
addTag: (contactUid, payload) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}/tags`, 'POST', payload),
|
||||
removeTag: (contactUid, tagUid, payload) =>
|
||||
write(
|
||||
`/api/v1/contacts/${encodeURIComponent(contactUid)}/tags/${encodeURIComponent(tagUid)}`,
|
||||
'DELETE',
|
||||
payload
|
||||
),
|
||||
delete: (contactUid, payload, idempotencyKey) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}`, 'DELETE', payload, idempotencyKey),
|
||||
restore: (contactUid, payload, idempotencyKey) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}/restore`, 'POST', payload, idempotencyKey),
|
||||
block: (contactUid, payload, idempotencyKey) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}/block`, 'POST', payload, idempotencyKey),
|
||||
unblock: (contactUid, payload, idempotencyKey) =>
|
||||
write(`/api/v1/contacts/${encodeURIComponent(contactUid)}/unblock`, 'POST', payload, idempotencyKey),
|
||||
batch: (payload) => write('/api/v1/contacts/batch', 'POST', payload),
|
||||
operations: (params) => request(`/api/v1/contacts/operations${toQuery(params)}`)
|
||||
}
|
||||
|
||||
export function newIdempotencyKey() {
|
||||
const random = Math.random().toString(36).slice(2, 10)
|
||||
return `web-contact-${Date.now()}-${random}`
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 绑定连接状态的唯一判定口径。
|
||||
*
|
||||
* 数据来源固定为 `napcat_binding.connection_status`(连接管理在内存 liveness 变化时回写),
|
||||
* 前端各处(接入管理、画布「所属账号」、账户切换)必须读取同一字段并在打开选择时刷新,
|
||||
* 不再各自使用 connectionState / online 布尔等另一套字段,避免同一绑定出现「在线 / 未连接」。
|
||||
*/
|
||||
|
||||
/** 绑定是否处于可建立连接的状态(DISABLED 停用、UNBOUND 已解绑都不可用)。 */
|
||||
export function isBindingActive(item) {
|
||||
return !/DISABLED|UNBOUND/.test(String(item?.bindingStatus || '').toUpperCase())
|
||||
}
|
||||
|
||||
/** UNBOUND 是已解绑的软删除记录,与 DISABLED 的「停用」必须区分展示。 */
|
||||
export function isBindingUnbound(item) {
|
||||
return String(item?.bindingStatus || '').toUpperCase() === 'UNBOUND'
|
||||
}
|
||||
|
||||
/** 绑定是否真实在线:可用且持久化连接状态为 ONLINE。 */
|
||||
export function isBindingOnline(item) {
|
||||
return isBindingActive(item) && String(item?.connectionStatus || '').toUpperCase() === 'ONLINE'
|
||||
}
|
||||
|
||||
/** 面向用户的绑定状态文案:停用/解绑优先,其次按 connection_status 精确匹配。 */
|
||||
export function bindingStatusLabel(item) {
|
||||
if (isBindingUnbound(item)) return '已解绑'
|
||||
if (!isBindingActive(item)) return '已停用'
|
||||
const status = String(item?.connectionStatus || '').toUpperCase()
|
||||
// 必须精确匹配:DISCONNECTED 也包含子串 CONNECT,用 includes/正则会把断线误判为在线。
|
||||
if (status === 'ONLINE') return '在线'
|
||||
if (status === 'CONNECTING') return '连接中'
|
||||
if (status === 'ERROR') return '连接异常'
|
||||
if (status === 'DISCONNECTED' || status === 'OFFLINE') return '离线'
|
||||
return item?.connectionStatus || '未知'
|
||||
}
|
||||
|
||||
/** 状态标签色调,与接入管理的 StatusTag 保持一致。 */
|
||||
export function bindingStatusTone(item) {
|
||||
const label = bindingStatusLabel(item)
|
||||
if (label === '在线') return 'success'
|
||||
if (label === '连接中') return 'info'
|
||||
if (label === '已停用' || label === '已解绑') return 'neutral'
|
||||
return 'warning'
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<script setup>
|
||||
import { computed, reactive, watch } from 'vue'
|
||||
import { api } from '../api'
|
||||
|
||||
/**
|
||||
* 统一头像组件(会话 / 群 / 联系人 / 账号 / 消息发送者共用)。
|
||||
*
|
||||
* <p>后端只下发 media_uid,头像对象存在 MinIO;这里通过既有媒体访问接口换取短时效预签名 URL,
|
||||
* 浏览器不直连腾讯域名。取不到图(无 media_uid、接口失败、图片加载失败)时降级为首字色块,
|
||||
* 不出现破图或空白。</p>
|
||||
*
|
||||
* <p>缓存为模块级共享:同一 media_uid 在任意位置只请求一次;URL 4 分钟视为新鲜(预签名有效期短于
|
||||
* 头像 TTL),失败记入缓存避免反复打接口;图片加载失败同样记忆,不重复尝试。</p>
|
||||
*/
|
||||
const props = defineProps({
|
||||
mediaUid: { type: String, default: '' },
|
||||
name: { type: String, default: '' },
|
||||
type: { type: String, default: 'PRIVATE' },
|
||||
size: { type: String, default: 'md' }
|
||||
})
|
||||
|
||||
const URL_TTL = 4 * 60 * 1000
|
||||
const cache = reactive({})
|
||||
|
||||
function stateOf(uid) {
|
||||
return uid ? cache[uid] : null
|
||||
}
|
||||
|
||||
const src = computed(() => {
|
||||
const state = stateOf(props.mediaUid)
|
||||
return state && !state.failed ? state.url || '' : ''
|
||||
})
|
||||
|
||||
async function ensure() {
|
||||
const uid = props.mediaUid
|
||||
if (!uid) return
|
||||
const state = cache[uid]
|
||||
if (state && (state.loading || (state.url && Date.now() - state.at < URL_TTL))) return
|
||||
cache[uid] = { ...(state || {}), loading: true }
|
||||
try {
|
||||
const data = await api.mediaAccessUrl(uid)
|
||||
cache[uid] = { url: data?.url || '', at: Date.now(), loading: false, failed: !data?.url }
|
||||
} catch {
|
||||
cache[uid] = { url: '', at: Date.now(), loading: false, failed: true }
|
||||
}
|
||||
}
|
||||
|
||||
function onError() {
|
||||
const uid = props.mediaUid
|
||||
if (!uid) return
|
||||
cache[uid] = { ...(cache[uid] || {}), url: '', at: Date.now(), loading: false, failed: true }
|
||||
}
|
||||
|
||||
const initial = computed(() => {
|
||||
if (props.type === 'GROUP') return '群'
|
||||
const text = String(props.name || '').trim()
|
||||
if (text) return Array.from(text)[0]
|
||||
return props.type === 'ACCOUNT' ? '号' : '?'
|
||||
})
|
||||
|
||||
// 同一个字/昵称得到稳定色相,列表里不会因刷新而变色。
|
||||
const fallbackStyle = computed(() => {
|
||||
const seed = String(props.name || props.mediaUid || props.type || '?')
|
||||
let hash = 0
|
||||
for (let i = 0; i < seed.length; i += 1) {
|
||||
hash = (hash * 31 + seed.charCodeAt(i)) % 360
|
||||
}
|
||||
return { background: `hsl(${hash} 46% 88%)`, color: `hsl(${hash} 52% 34%)` }
|
||||
})
|
||||
|
||||
// 共享缓存跨组件复用,组件卸载时不清空,避免返回列表时重复请求。
|
||||
watch(() => props.mediaUid, ensure, { immediate: true })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="avatar-badge" :class="[`size-${size}`, { group: type === 'GROUP' }]">
|
||||
<img v-if="src" :src="src" alt="" loading="lazy" @error="onError" />
|
||||
<span v-else class="avatar-fallback" :style="fallbackStyle">{{ initial }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.avatar-badge {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
background: #eef1f6;
|
||||
}
|
||||
|
||||
.avatar-badge.group {
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.avatar-badge.size-xs {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.avatar-badge.size-sm {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.avatar-badge.size-md {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.avatar-badge.size-lg {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.avatar-badge img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.avatar-fallback {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,64 +1,54 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, ref, watch } from 'vue'
|
||||
import Modal from './ui/Modal.vue'
|
||||
|
||||
/**
|
||||
* 统一确认弹窗:替代 window.confirm 与页面内零散确认框。
|
||||
* 保留原有 props/事件契约,内部改用 ui/Modal 获得焦点管理、ESC 与锁滚动。
|
||||
*/
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
title: { type: String, default: '确认操作' },
|
||||
subtitle: { type: String, default: '' },
|
||||
message: { type: String, default: '' },
|
||||
hint: { type: String, default: '' },
|
||||
confirmText: { type: String, default: '确认' },
|
||||
cancelText: { type: String, default: '取消' },
|
||||
extraText: { type: String, default: '' },
|
||||
tone: { type: String, default: 'primary' },
|
||||
busy: { type: Boolean, default: false }
|
||||
size: { type: String, default: 'md' },
|
||||
busy: { type: Boolean, default: false },
|
||||
confirmDisabled: { type: Boolean, default: false },
|
||||
closeOnMask: { type: Boolean, default: false }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['confirm', 'cancel'])
|
||||
const cardRef = ref(null)
|
||||
|
||||
function onKeydown(event) {
|
||||
if (event.key === 'Escape' && props.open && !props.busy) emit('cancel')
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
document.addEventListener('keydown', onKeydown)
|
||||
requestAnimationFrame(() => cardRef.value?.focus())
|
||||
} else {
|
||||
document.removeEventListener('keydown', onKeydown)
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => document.removeEventListener('keydown', onKeydown))
|
||||
const emit = defineEmits(['confirm', 'cancel', 'extra'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="open" class="modal-backdrop show" @click.self="!busy && emit('cancel')">
|
||||
<div ref="cardRef" class="modal" role="dialog" aria-modal="true" :aria-label="title" tabindex="-1">
|
||||
<div class="modal-head">
|
||||
<h3>{{ title }}</h3>
|
||||
<button class="btn sm ghost" type="button" aria-label="关闭" :disabled="busy" @click="emit('cancel')">×</button>
|
||||
</div>
|
||||
<p v-if="message" style="margin: 0 0 10px">{{ message }}</p>
|
||||
<p v-if="hint" class="small-muted" style="margin: 0 0 10px">{{ hint }}</p>
|
||||
<slot />
|
||||
<div class="modal-foot">
|
||||
<button class="btn" type="button" :disabled="busy" @click="emit('cancel')">{{ cancelText }}</button>
|
||||
<button
|
||||
class="btn"
|
||||
:class="tone === 'danger' ? 'danger' : 'primary'"
|
||||
type="button"
|
||||
:disabled="busy"
|
||||
@click="emit('confirm')"
|
||||
>
|
||||
{{ busy ? '处理中…' : confirmText }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
<Modal
|
||||
:open="open"
|
||||
:title="title"
|
||||
:subtitle="subtitle"
|
||||
:size="size"
|
||||
:busy="busy"
|
||||
:close-on-mask="closeOnMask && !busy"
|
||||
@close="emit('cancel')"
|
||||
>
|
||||
<p v-if="message" style="margin: 0 0 10px">{{ message }}</p>
|
||||
<p v-if="hint" class="small-muted" style="margin: 0 0 10px; line-height: 1.6">{{ hint }}</p>
|
||||
<slot />
|
||||
<template #foot>
|
||||
<button v-if="extraText" class="btn" type="button" :disabled="busy" @click="emit('extra')">{{ extraText }}</button>
|
||||
<button class="btn" type="button" :disabled="busy" @click="emit('cancel')">{{ cancelText }}</button>
|
||||
<button
|
||||
class="btn"
|
||||
:class="tone === 'danger' ? 'danger-solid' : 'primary'"
|
||||
type="button"
|
||||
:disabled="busy || confirmDisabled"
|
||||
@click="emit('confirm')"
|
||||
>
|
||||
{{ busy ? '处理中…' : confirmText }}
|
||||
</button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<template>
|
||||
<span class="demo-badge" title="演示数据:仅用于界面预览,不代表真实业务状态">演示数据</span>
|
||||
<span class="demo-badge" v-tooltip="'演示数据:仅用于界面预览,不代表真实业务状态'">演示数据</span>
|
||||
</template>
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
<script setup>
|
||||
defineProps({
|
||||
kicker: { type: String, default: '' },
|
||||
title: { type: String, required: true },
|
||||
desc: { type: String, default: '' }
|
||||
})
|
||||
// 页面统一不再展示面包屑 / 标题 / 说明,仅保留页头内的功能性控件。
|
||||
// 兼容旧调用:忽略 kicker/title/desc 等属性,避免透传到 DOM。
|
||||
defineOptions({ inheritAttrs: false })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<div v-if="kicker" class="eyebrow">{{ kicker }}</div>
|
||||
<h1 class="page-title">{{ title }}</h1>
|
||||
<p v-if="desc" class="subtitle">{{ desc }}</p>
|
||||
</div>
|
||||
<div v-if="$slots.actions" class="actions">
|
||||
<slot name="actions" />
|
||||
</div>
|
||||
</header>
|
||||
<div v-if="$slots.actions" class="page-actions">
|
||||
<slot name="actions" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { formatNumber } from '../ui'
|
||||
import Select from './ui/Select.vue'
|
||||
|
||||
const props = defineProps({
|
||||
page: { type: Number, default: 1 },
|
||||
@@ -21,34 +22,57 @@ const pages = computed(() => {
|
||||
return Math.max(1, Math.ceil(total / pageSizeSafe.value))
|
||||
})
|
||||
|
||||
const from = computed(() => {
|
||||
if (props.total === 0) return 0
|
||||
return (props.page - 1) * pageSizeSafe.value + 1
|
||||
})
|
||||
|
||||
const to = computed(() => Math.min(props.page * pageSizeSafe.value, props.total))
|
||||
|
||||
function go(target) {
|
||||
if (target < 1 || target > pages.value || target === props.page) return
|
||||
emit('change', { page: target, pageSize: pageSizeSafe.value })
|
||||
}
|
||||
|
||||
function changeSize(event) {
|
||||
emit('change', { page: 1, pageSize: Number(event.target.value) })
|
||||
const sizeOptions = computed(() => props.sizes.map((size) => ({ value: Number(size), label: `${size} 条/页` })))
|
||||
|
||||
function changeSize(value) {
|
||||
emit('change', { page: 1, pageSize: Number(value) })
|
||||
}
|
||||
|
||||
const pageList = computed(() => {
|
||||
const total = pages.value
|
||||
const current = props.page
|
||||
if (total <= 7) {
|
||||
return Array.from({ length: total }, (_, i) => i + 1)
|
||||
}
|
||||
if (current <= 4) {
|
||||
return [1, 2, 3, 4, 5, '…', total]
|
||||
}
|
||||
if (current >= total - 3) {
|
||||
return [1, '…', total - 4, total - 3, total - 2, total - 1, total]
|
||||
}
|
||||
return [1, '…', current - 1, current, current + 1, '…', total]
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pager">
|
||||
<div class="pager-info">
|
||||
共 {{ formatNumber(total) }} 条 · 第 {{ formatNumber(from) }}–{{ formatNumber(to) }} 条 · 第 {{ page }} / {{ pages }} 页
|
||||
共 {{ formatNumber(total) }} 条 · 每页 {{ formatNumber(pageSizeSafe) }} 条
|
||||
</div>
|
||||
<div class="pager-actions">
|
||||
<select :value="pageSize" aria-label="每页条数" @change="changeSize">
|
||||
<option v-for="size in sizes" :key="size" :value="size">{{ size }} 条/页</option>
|
||||
</select>
|
||||
<button class="btn sm" type="button" :disabled="page <= 1" @click="go(page - 1)">上一页</button>
|
||||
<button class="btn sm" type="button" :disabled="page >= pages" @click="go(page + 1)">下一页</button>
|
||||
<Select
|
||||
:model-value="pageSizeSafe"
|
||||
:options="sizeOptions"
|
||||
size="sm"
|
||||
aria-label="每页条数"
|
||||
@update:model-value="changeSize"
|
||||
/>
|
||||
<button
|
||||
v-for="(entry, index) in pageList"
|
||||
:key="`${entry}-${index}`"
|
||||
class="pg-btn"
|
||||
:class="{ active: entry === page }"
|
||||
type="button"
|
||||
:disabled="entry === '…' || entry === page"
|
||||
@click="go(entry)"
|
||||
>
|
||||
{{ entry }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,396 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { getToken } from '../../api.js'
|
||||
import AvatarBadge from '../AvatarBadge.vue'
|
||||
import {
|
||||
accountState,
|
||||
currentAccount,
|
||||
loadAccounts,
|
||||
setCurrentAccount,
|
||||
statusText
|
||||
} from '../../account-context.js'
|
||||
|
||||
const open = ref(false)
|
||||
const root = ref(null)
|
||||
const search = ref('')
|
||||
|
||||
const current = computed(() => currentAccount())
|
||||
const filteredItems = computed(() => {
|
||||
const keyword = search.value.trim().toLowerCase()
|
||||
if (!keyword) return accountState.items
|
||||
return accountState.items.filter((item) => {
|
||||
const name = String(item.displayName || item.nickname || '').toLowerCase()
|
||||
return name.includes(keyword) || String(item.qqAccountId).toLowerCase().includes(keyword)
|
||||
})
|
||||
})
|
||||
const triggerTitle = computed(() => {
|
||||
if (current.value) {
|
||||
return `${current.value.displayName || current.value.qqAccountId}(${current.value.qqAccountId})`
|
||||
}
|
||||
return accountState.items.length ? '正在确定当前账号' : '未绑定可用账号'
|
||||
})
|
||||
/** 只有一个账号时没有可切换项,入口降级为纯展示。 */
|
||||
const canSwitch = computed(() => accountState.items.length > 1)
|
||||
|
||||
function toggle() {
|
||||
if (!canSwitch.value) return
|
||||
if (!open.value && !accountState.loaded && !accountState.loading) loadAccounts()
|
||||
open.value = !open.value
|
||||
if (!open.value) search.value = ''
|
||||
}
|
||||
|
||||
function choose(qqAccountId) {
|
||||
if (!qqAccountId) return
|
||||
setCurrentAccount(qqAccountId)
|
||||
open.value = false
|
||||
search.value = ''
|
||||
}
|
||||
|
||||
function onDocumentClick(event) {
|
||||
if (open.value && root.value && !root.value.contains(event.target)) open.value = false
|
||||
}
|
||||
|
||||
function onKeydown(event) {
|
||||
if (event.key === 'Escape') open.value = false
|
||||
}
|
||||
|
||||
function retry() {
|
||||
loadAccounts()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', onDocumentClick)
|
||||
document.addEventListener('keydown', onKeydown)
|
||||
if (getToken() && !accountState.loaded) loadAccounts()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onDocumentClick)
|
||||
document.removeEventListener('keydown', onKeydown)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="account-switcher">
|
||||
<button
|
||||
type="button"
|
||||
class="account-trigger"
|
||||
:class="{ 'is-static': !canSwitch }"
|
||||
:aria-expanded="open"
|
||||
:aria-haspopup="canSwitch ? 'listbox' : undefined"
|
||||
v-tooltip="triggerTitle"
|
||||
@click="toggle"
|
||||
>
|
||||
<AvatarBadge
|
||||
v-if="current"
|
||||
:media-uid="current.avatarMediaUid"
|
||||
:name="current.displayName || current.qqAccountId"
|
||||
type="ACCOUNT"
|
||||
size="sm"
|
||||
/>
|
||||
<AvatarBadge v-else name="账号" type="ACCOUNT" size="sm" />
|
||||
<span class="account-meta">
|
||||
<span class="account-name">{{ current ? (current.displayName || current.qqAccountId) : '未绑定可用账号' }}</span>
|
||||
<span class="account-qq">
|
||||
{{ current ? `${current.qqAccountId} · ${statusText(current.connectionStatus)}` : (accountState.loading ? '正在加载账号目录…' : '请先在接入管理绑定账号') }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="canSwitch" class="account-switch-text">切换</span>
|
||||
</button>
|
||||
|
||||
<div v-if="open && canSwitch" class="account-popover" role="listbox" aria-label="选择 QQ 账号" @click.stop>
|
||||
<div class="account-popover-title">切换 QQ 账号</div>
|
||||
<input
|
||||
v-if="accountState.items.length > 1"
|
||||
v-model="search"
|
||||
class="account-search"
|
||||
type="search"
|
||||
placeholder="搜索昵称或 QQ 号"
|
||||
aria-label="搜索账号"
|
||||
/>
|
||||
<template v-if="accountState.items.length">
|
||||
<button
|
||||
v-for="item in filteredItems"
|
||||
:key="item.qqAccountId"
|
||||
type="button"
|
||||
class="account-option"
|
||||
:class="{ active: accountState.current === item.qqAccountId }"
|
||||
role="option"
|
||||
:aria-selected="accountState.current === item.qqAccountId"
|
||||
@click="choose(item.qqAccountId)"
|
||||
>
|
||||
<AvatarBadge
|
||||
:media-uid="item.avatarMediaUid"
|
||||
:name="item.displayName || item.qqAccountId"
|
||||
type="ACCOUNT"
|
||||
size="sm"
|
||||
/>
|
||||
<span class="account-option-meta">
|
||||
<span class="account-option-name">{{ item.displayName || item.qqAccountId }}</span>
|
||||
<span class="account-option-sub">
|
||||
{{ item.qqAccountId }} · {{ statusText(item.connectionStatus) }} · {{ item.bindingCount }} 条绑定
|
||||
</span>
|
||||
</span>
|
||||
<span class="account-status-dot" :class="String(item.connectionStatus).toLowerCase()" />
|
||||
</button>
|
||||
<p v-if="search && filteredItems.length === 0" class="account-note">没有匹配的账号</p>
|
||||
</template>
|
||||
<p v-if="accountState.loading" class="account-note">正在加载账号目录…</p>
|
||||
<p v-else-if="accountState.error" class="account-note warn">
|
||||
账号目录加载失败:{{ accountState.error }}
|
||||
<button type="button" class="account-retry" @click.stop="retry">重试</button>
|
||||
</p>
|
||||
<p v-if="accountState.unattributedBindings > 0" class="account-note">
|
||||
另有 {{ accountState.unattributedBindings }} 条启用绑定未回填 QQ 号,未计入账号列表。
|
||||
</p>
|
||||
<p v-if="accountState.message" class="account-note warn">{{ accountState.message }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="!accountState.loading && !accountState.items.length" class="account-empty-inline">
|
||||
<p>{{ accountState.error ? `账号目录加载失败:${accountState.error}` : '当前实例没有可用 QQ 账号' }}</p>
|
||||
<RouterLink v-if="!accountState.error" to="/connections" class="account-link">去接入管理绑定并上线</RouterLink>
|
||||
<button v-else type="button" class="account-retry" @click.stop="retry">重试</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.account-switcher {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.account-trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: color-mix(in srgb, var(--card-bg) 80%, transparent);
|
||||
color: var(--qk-text);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.account-trigger:hover,
|
||||
.account-trigger:focus-visible {
|
||||
border-color: var(--qk-green);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* 仅一个账号时没有可切换项,入口按展示样式处理,避免误导为可点。 */
|
||||
.account-trigger.is-static {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.account-trigger.is-static:hover {
|
||||
border-color: var(--line);
|
||||
}
|
||||
|
||||
.account-empty-inline {
|
||||
margin-top: 8px;
|
||||
padding: 8px 10px;
|
||||
border: 1px dashed var(--line);
|
||||
border-radius: 10px;
|
||||
font-size: 11px;
|
||||
line-height: 1.6;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.account-empty-inline p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.account-empty-inline .account-link {
|
||||
display: inline-block;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.account-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.account-name,
|
||||
.account-qq {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.account-name {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.account-qq {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.account-switch-text {
|
||||
flex: 0 0 auto;
|
||||
font-size: 11px;
|
||||
color: var(--qk-green);
|
||||
}
|
||||
|
||||
.account-popover {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: calc(100% + 8px);
|
||||
z-index: 40;
|
||||
width: 264px;
|
||||
max-height: 60vh;
|
||||
overflow: auto;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: var(--card-bg);
|
||||
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.account-popover-title {
|
||||
padding: 2px 6px 8px;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.account-search {
|
||||
width: 100%;
|
||||
margin-bottom: 8px;
|
||||
padding: 7px 9px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: var(--card-bg);
|
||||
color: var(--qk-text);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.account-search:focus {
|
||||
border-color: var(--qk-green);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.account-empty {
|
||||
padding: 14px 8px 6px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.account-empty strong {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.account-empty p {
|
||||
margin: 0 0 10px;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.account-link {
|
||||
font-size: 12px;
|
||||
color: var(--qk-green);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.account-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.account-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 7px 6px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: var(--qk-text);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.account-option:hover,
|
||||
.account-option:focus-visible {
|
||||
background: color-mix(in srgb, var(--qk-green) 10%, transparent);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.account-option.active {
|
||||
background: color-mix(in srgb, var(--qk-green) 16%, transparent);
|
||||
}
|
||||
|
||||
.account-option-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.account-option-name,
|
||||
.account-option-sub {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.account-option-name {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.account-option-sub {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.account-status-dot {
|
||||
flex: 0 0 7px;
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: var(--muted);
|
||||
}
|
||||
|
||||
.account-status-dot.online {
|
||||
background: var(--qk-green);
|
||||
}
|
||||
|
||||
.account-status-dot.connecting {
|
||||
background: var(--qk-amber);
|
||||
}
|
||||
|
||||
.account-status-dot.error {
|
||||
background: var(--qk-red);
|
||||
}
|
||||
|
||||
.account-note {
|
||||
margin: 8px 6px 2px;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.account-note.warn {
|
||||
color: var(--qk-amber);
|
||||
}
|
||||
|
||||
.account-retry {
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--qk-green);
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
padding: 0 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,182 @@
|
||||
<script setup>
|
||||
import AvatarBadge from '../AvatarBadge.vue'
|
||||
|
||||
defineProps({
|
||||
conversation: { type: Object, default: null },
|
||||
bindingLabel: { type: String, default: '' },
|
||||
connected: { type: Boolean, default: false },
|
||||
connectionText: { type: String, default: '未连接' },
|
||||
connectionReason: { type: String, default: '' },
|
||||
messageTotal: { type: Number, default: 0 },
|
||||
refreshing: { type: Boolean, default: false }
|
||||
})
|
||||
|
||||
defineEmits(['search', 'refresh'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header class="chat-head">
|
||||
<div v-if="conversation" class="chat-identity">
|
||||
<AvatarBadge
|
||||
:media-uid="conversation.avatarMediaUid"
|
||||
:name="conversation.nickname || conversation.name"
|
||||
:type="conversation.type"
|
||||
size="md"
|
||||
/>
|
||||
<div class="head-text">
|
||||
<div class="head-name">
|
||||
<span :class="{ unknown: !conversation.nickname }">{{ conversation.name }}</span>
|
||||
<span class="head-tag">{{ conversation.typeLabel }}</span>
|
||||
</div>
|
||||
<div class="head-sub">
|
||||
<span>{{ conversation.type === 'GROUP' ? '群号' : '账号' }} {{ conversation.account }}</span>
|
||||
<span v-if="bindingLabel"> · 绑定 {{ bindingLabel }}</span>
|
||||
<span> · 共 {{ messageTotal }} 条</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="chat-identity empty">
|
||||
<div class="head-text">
|
||||
<div class="head-name">未选择会话</div>
|
||||
<div class="head-sub">从左侧选择一个会话查看已入库消息。</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="conversation" class="chat-actions">
|
||||
<span class="conn-chip" :class="{ online: connected }" v-tooltip="connectionReason">
|
||||
<i></i>{{ connectionText }}
|
||||
</span>
|
||||
<button class="head-btn" type="button" v-tooltip="'在消息检索中查看该会话'" aria-label="消息检索" @click="$emit('search')">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="11" cy="11" r="6.5" />
|
||||
<path d="M20 20l-4-4" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="head-btn" type="button" v-tooltip="'刷新消息'" aria-label="刷新消息" :disabled="refreshing" @click="$emit('refresh')">
|
||||
<svg viewBox="0 0 24 24" :class="{ spinning: refreshing }" aria-hidden="true">
|
||||
<path d="M20 11a8 8 0 1 0-2.3 5.7" />
|
||||
<path d="M20 4v7h-7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.chat-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-shrink: 0;
|
||||
padding: 12px 18px;
|
||||
min-height: 62px;
|
||||
border-bottom: 1px solid #ebedef;
|
||||
background: #fff;
|
||||
}
|
||||
.chat-identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
min-width: 0;
|
||||
}
|
||||
.head-name .unknown {
|
||||
color: #9aa1b2;
|
||||
font-weight: 400;
|
||||
}
|
||||
.head-text {
|
||||
min-width: 0;
|
||||
}
|
||||
.head-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #1f2329;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.head-tag {
|
||||
flex-shrink: 0;
|
||||
padding: 1px 6px;
|
||||
border: 1px solid #e3e5e8;
|
||||
border-radius: 4px;
|
||||
color: #8a8f99;
|
||||
font-size: 10px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.head-sub {
|
||||
margin-top: 3px;
|
||||
font-size: 11px;
|
||||
color: #8a8f99;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.chat-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.conn-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 3px 8px;
|
||||
border-radius: 5px;
|
||||
background: #f3f4f5;
|
||||
color: #8a8f99;
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.conn-chip i {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: #c0c4ca;
|
||||
}
|
||||
.conn-chip.online {
|
||||
color: #15803d;
|
||||
background: #eefaf2;
|
||||
}
|
||||
.conn-chip.online i {
|
||||
background: #22c55e;
|
||||
}
|
||||
.head-btn {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
background: transparent;
|
||||
color: #6b7078;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.head-btn:hover:not(:disabled) {
|
||||
background: #f0f1f3;
|
||||
color: #1f2329;
|
||||
}
|
||||
.head-btn:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.head-btn svg {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.8;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
.head-btn svg.spinning {
|
||||
animation: head-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes head-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,394 @@
|
||||
<script setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
text: { type: String, default: '' },
|
||||
disabled: { type: Boolean, default: false },
|
||||
disabledReason: { type: String, default: '' },
|
||||
inputDisabled: { type: Boolean, default: false },
|
||||
preparing: { type: Boolean, default: false },
|
||||
executing: { type: Boolean, default: false },
|
||||
targetLabel: { type: String, default: '' },
|
||||
bindingLabel: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:text', 'send', 'resize'])
|
||||
|
||||
const MAX = 4000
|
||||
const AUTO_MAX = 150
|
||||
// 输入区高度是布局偏好而非会话内容,这里按全局记住:切换会话时输入框不会跳动。
|
||||
const HEIGHT_KEY = 'qlinker.composer.height'
|
||||
// 上限按容器高度计算,剩余给消息列表的最小高度取容器高度比例,避免写死与布局不符的数值。
|
||||
const LIST_FLOOR_RATIO = 0.3
|
||||
const LIST_FLOOR_MIN = 120
|
||||
|
||||
const input = ref(null)
|
||||
const composerEl = ref(null)
|
||||
const dragging = ref(false)
|
||||
// null 表示自动增高模式;数值表示用户手动拖动后的固定高度(px)。
|
||||
const manualHeight = ref(null)
|
||||
|
||||
let startY = 0
|
||||
let startHeight = 0
|
||||
let pendingHeight = 0
|
||||
let limits = { min: 42, max: AUTO_MAX }
|
||||
let rafId = 0
|
||||
|
||||
function singleLineHeight(el) {
|
||||
const style = getComputedStyle(el)
|
||||
const line = parseFloat(style.lineHeight)
|
||||
const lineHeight = Number.isFinite(line) ? line : parseFloat(style.fontSize) * 1.6
|
||||
const padding = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0)
|
||||
const border = (parseFloat(style.borderTopWidth) || 0) + (parseFloat(style.borderBottomWidth) || 0)
|
||||
return Math.ceil(lineHeight + padding + border)
|
||||
}
|
||||
|
||||
// 上限:当前消息区高度减去需要保留的阅读高度,再换算成输入框可占的高度。
|
||||
// 全部按实际 DOM 计算,窗口或错误提示出现/消失后重新计算也能对齐。
|
||||
function bounds() {
|
||||
const el = input.value
|
||||
const composer = composerEl.value
|
||||
const chat = composer?.parentElement
|
||||
const min = el ? singleLineHeight(el) : 42
|
||||
if (!el || !chat) return { min, max: Math.max(min, AUTO_MAX) }
|
||||
|
||||
const messages = chat.querySelector('.messages')
|
||||
const chatHeight = chat.clientHeight
|
||||
const composerHeight = composer.getBoundingClientRect().height
|
||||
const inputHeight = el.getBoundingClientRect().height
|
||||
const messagesHeight = messages ? messages.clientHeight : chatHeight
|
||||
const chrome = Math.max(0, composerHeight - inputHeight)
|
||||
const others = Math.max(0, chatHeight - messagesHeight - composerHeight)
|
||||
const floor = Math.max(LIST_FLOOR_MIN, Math.round(chatHeight * LIST_FLOOR_RATIO))
|
||||
const max = Math.round(chatHeight - others - chrome - floor)
|
||||
return { min: Math.round(min), max: Math.max(Math.round(min), max) }
|
||||
}
|
||||
|
||||
function clampHeight(px, range) {
|
||||
return Math.min(range.max, Math.max(range.min, Math.round(px)))
|
||||
}
|
||||
|
||||
function applyHeight(px) {
|
||||
const el = input.value
|
||||
if (!el) return
|
||||
el.style.height = `${px}px`
|
||||
emit('resize')
|
||||
}
|
||||
|
||||
function resize() {
|
||||
const el = input.value
|
||||
if (!el || manualHeight.value != null) return
|
||||
el.style.height = 'auto'
|
||||
el.style.height = `${Math.min(Math.max(el.scrollHeight, singleLineHeight(el)), AUTO_MAX)}px`
|
||||
}
|
||||
|
||||
function onPointerDown(event) {
|
||||
const el = input.value
|
||||
if (!el || event.button > 0) return
|
||||
event.preventDefault()
|
||||
limits = bounds()
|
||||
startY = event.clientY
|
||||
startHeight = el.getBoundingClientRect().height
|
||||
pendingHeight = clampHeight(startHeight, limits)
|
||||
manualHeight.value = pendingHeight
|
||||
dragging.value = true
|
||||
document.body.style.cursor = 'ns-resize'
|
||||
document.body.style.userSelect = 'none'
|
||||
window.addEventListener('pointermove', onPointerMove)
|
||||
window.addEventListener('pointerup', onPointerEnd)
|
||||
window.addEventListener('pointercancel', onPointerEnd)
|
||||
}
|
||||
|
||||
function onPointerMove(event) {
|
||||
if (!dragging.value) return
|
||||
// 向上拖动增大高度,向下拖动减小高度;每帧内都夹在上下限,到边界立即停住。
|
||||
pendingHeight = clampHeight(startHeight + (startY - event.clientY), limits)
|
||||
if (!rafId) rafId = requestAnimationFrame(flush)
|
||||
}
|
||||
|
||||
function flush() {
|
||||
rafId = 0
|
||||
if (!dragging.value || manualHeight.value === pendingHeight) return
|
||||
manualHeight.value = pendingHeight
|
||||
applyHeight(pendingHeight)
|
||||
}
|
||||
|
||||
function persistHeight() {
|
||||
try {
|
||||
localStorage.setItem(HEIGHT_KEY, String(manualHeight.value))
|
||||
} catch {
|
||||
/* 本地存储不可用时仅本次会话内生效 */
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerEnd() {
|
||||
if (!dragging.value) return
|
||||
dragging.value = false
|
||||
if (rafId) {
|
||||
cancelAnimationFrame(rafId)
|
||||
rafId = 0
|
||||
}
|
||||
manualHeight.value = pendingHeight
|
||||
applyHeight(pendingHeight)
|
||||
persistHeight()
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
window.removeEventListener('pointermove', onPointerMove)
|
||||
window.removeEventListener('pointerup', onPointerEnd)
|
||||
window.removeEventListener('pointercancel', onPointerEnd)
|
||||
}
|
||||
|
||||
function onWindowResize() {
|
||||
const el = input.value
|
||||
if (!el) return
|
||||
if (manualHeight.value != null) {
|
||||
const next = clampHeight(manualHeight.value, bounds())
|
||||
if (next !== manualHeight.value) {
|
||||
manualHeight.value = next
|
||||
applyHeight(next)
|
||||
} else {
|
||||
emit('resize')
|
||||
}
|
||||
} else {
|
||||
resize()
|
||||
emit('resize')
|
||||
}
|
||||
}
|
||||
|
||||
function readStoredHeight() {
|
||||
try {
|
||||
const value = Number(localStorage.getItem(HEIGHT_KEY))
|
||||
return Number.isFinite(value) && value > 0 ? value : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.text,
|
||||
() => nextTick(resize)
|
||||
)
|
||||
|
||||
function inputValue(event) {
|
||||
emit('update:text', event.target.value)
|
||||
resize()
|
||||
}
|
||||
|
||||
function keydown(event) {
|
||||
if (event.key !== 'Enter' || event.shiftKey || event.isComposing) return
|
||||
event.preventDefault()
|
||||
if (!props.disabled && !props.preparing && !props.executing) emit('send')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const stored = readStoredHeight()
|
||||
nextTick(() => {
|
||||
if (stored != null) {
|
||||
const next = clampHeight(stored, bounds())
|
||||
manualHeight.value = next
|
||||
applyHeight(next)
|
||||
} else {
|
||||
resize()
|
||||
}
|
||||
})
|
||||
window.addEventListener('resize', onWindowResize)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', onWindowResize)
|
||||
window.removeEventListener('pointermove', onPointerMove)
|
||||
window.removeEventListener('pointerup', onPointerEnd)
|
||||
window.removeEventListener('pointercancel', onPointerEnd)
|
||||
if (rafId) cancelAnimationFrame(rafId)
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<footer ref="composerEl" class="composer" :class="{ 'is-resizing': dragging }">
|
||||
<div
|
||||
class="composer-resizer"
|
||||
role="separator"
|
||||
aria-orientation="horizontal"
|
||||
aria-label="拖动调整输入区高度" v-tooltip="'上下拖动调整输入区高度'"
|
||||
@pointerdown="onPointerDown"
|
||||
>
|
||||
<span class="resizer-grip" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="composer-tools">
|
||||
<button class="tool" type="button" disabled v-tooltip="'表情面板暂未接入'">☺</button>
|
||||
<button class="tool" type="button" disabled v-tooltip="'附件发送由自动化规则实现,管理台暂只支持纯文本'">📎</button>
|
||||
<button class="tool" type="button" disabled v-tooltip="'暂不支持 @ 提醒'">@</button>
|
||||
<span class="tool-note">仅支持纯文本 · 发送前二次确认</span>
|
||||
</div>
|
||||
<div class="composer-box">
|
||||
<textarea
|
||||
ref="input"
|
||||
:value="text"
|
||||
:class="{ manual: manualHeight != null }"
|
||||
:maxlength="MAX"
|
||||
rows="1"
|
||||
:disabled="inputDisabled"
|
||||
placeholder="输入消息,Enter 发送,Shift + Enter 换行"
|
||||
aria-label="消息输入框"
|
||||
@input="inputValue"
|
||||
@keydown="keydown"
|
||||
></textarea>
|
||||
<button
|
||||
class="send"
|
||||
type="button"
|
||||
:disabled="disabled || preparing || executing" v-tooltip="disabled ? disabledReason : '进入两阶段确认'"
|
||||
@click="$emit('send')"
|
||||
>
|
||||
<span v-if="preparing" class="spinner light" aria-hidden="true"></span>
|
||||
{{ preparing ? '创建操作…' : executing ? '发送中…' : '发送' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="composer-foot">
|
||||
<span v-if="disabled && disabledReason" class="composer-reason">{{ disabledReason }}</span>
|
||||
<span v-else class="composer-target">
|
||||
目标 {{ targetLabel || '—' }}<span v-if="bindingLabel"> · 绑定 {{ bindingLabel }}</span>
|
||||
</span>
|
||||
<span class="composer-count">{{ text.length }}/{{ MAX }}</span>
|
||||
</div>
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.composer {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
padding: 8px 18px 10px;
|
||||
border-top: 1px solid #ebedef;
|
||||
background: #fff;
|
||||
}
|
||||
.composer-resizer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 10px;
|
||||
margin: -8px -18px 2px;
|
||||
cursor: ns-resize;
|
||||
touch-action: none;
|
||||
}
|
||||
.resizer-grip {
|
||||
width: 46px;
|
||||
height: 3px;
|
||||
border-radius: 2px;
|
||||
background: #e3e5e8;
|
||||
transition: width 0.15s ease, background-color 0.15s ease;
|
||||
}
|
||||
.composer-resizer:hover .resizer-grip,
|
||||
.composer.is-resizing .resizer-grip {
|
||||
width: 68px;
|
||||
background: #0099ff;
|
||||
}
|
||||
.composer.is-resizing {
|
||||
user-select: none;
|
||||
}
|
||||
.composer-tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.tool {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #9aa0a6;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
}
|
||||
.tool:disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.tool-note {
|
||||
margin-left: auto;
|
||||
font-size: 10px;
|
||||
color: #b6bac0;
|
||||
}
|
||||
.composer-box {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
.composer-box textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
max-height: 150px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #e3e5e8;
|
||||
border-radius: 8px;
|
||||
outline: none;
|
||||
background: #fff;
|
||||
color: #1f2329;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
resize: none;
|
||||
overflow-y: auto;
|
||||
transition: border-color 0.15s ease;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
.composer-box textarea:focus {
|
||||
border-color: #0099ff;
|
||||
}
|
||||
/* 手动高度模式下不再受自动增高的 150px 上限约束。 */
|
||||
.composer-box textarea.manual {
|
||||
max-height: none;
|
||||
}
|
||||
.composer-box textarea:disabled {
|
||||
background: #f7f8fa;
|
||||
color: #a0a4aa;
|
||||
}
|
||||
.send {
|
||||
height: 36px;
|
||||
padding: 0 20px;
|
||||
flex-shrink: 0;
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
background: #0099ff;
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: background-color 0.15s ease;
|
||||
}
|
||||
.send:hover:not(:disabled) {
|
||||
background: #0088e6;
|
||||
}
|
||||
.send:disabled {
|
||||
background: #d4d7db;
|
||||
color: #fff;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.composer-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-top: 5px;
|
||||
font-size: 10px;
|
||||
color: #a0a4aa;
|
||||
}
|
||||
.composer-reason {
|
||||
color: #b8770b;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.composer-target {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.composer-count {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,418 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { api } from '../../api'
|
||||
import { describeError } from '../../ui'
|
||||
import Pagination from '../Pagination.vue'
|
||||
import Select from '../ui/Select.vue'
|
||||
import { accountParam, accountState } from '../../account-context.js'
|
||||
|
||||
const props = defineProps({
|
||||
stats: { type: Object, default: null }
|
||||
})
|
||||
|
||||
const STORAGE_STATUS_OPTIONS = [
|
||||
{ value: '', label: '全部存储状态' },
|
||||
{ value: 'STORED', label: '已入库' },
|
||||
{ value: 'FAILED', label: '下载失败' },
|
||||
{ value: 'SOURCE_EXPIRED', label: '源已过期' },
|
||||
{ value: 'OBJECT_MISSING', label: '对象缺失' }
|
||||
]
|
||||
const MEDIA_TYPE_OPTIONS = [
|
||||
{ value: '', label: '全部类型' },
|
||||
{ value: 'image', label: '图片' },
|
||||
{ value: 'video', label: '视频' },
|
||||
{ value: 'audio', label: '语音' },
|
||||
{ value: 'file', label: '文件' }
|
||||
]
|
||||
|
||||
const rows = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const listLoading = ref(false)
|
||||
const listError = ref(null)
|
||||
|
||||
const filters = reactive({
|
||||
storageStatus: '',
|
||||
errorCode: '',
|
||||
mediaType: '',
|
||||
conversationId: '',
|
||||
from: '',
|
||||
to: ''
|
||||
})
|
||||
|
||||
const mediaUid = ref('')
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const media = ref(null)
|
||||
const accessUrl = ref('')
|
||||
const accessError = ref(null)
|
||||
|
||||
const statsCards = computed(() => [
|
||||
{ key: 'STORED', label: '已入库', dot: 'g', value: Number(props.stats?.STORED || 0) },
|
||||
{ key: 'FAILED', label: '下载失败', dot: 'r', value: Number(props.stats?.FAILED || 0) },
|
||||
{ key: 'SOURCE_EXPIRED', label: '源已过期', dot: 'a', value: Number(props.stats?.SOURCE_EXPIRED || 0) },
|
||||
{ key: 'OBJECT_MISSING', label: '对象缺失', dot: 'r', value: Number(props.stats?.OBJECT_MISSING || 0) }
|
||||
])
|
||||
|
||||
const STATUS_LABELS = {
|
||||
PENDING: '待处理',
|
||||
DOWNLOADING: '下载中',
|
||||
STORED: '已入库',
|
||||
FAILED: '下载失败',
|
||||
SOURCE_EXPIRED: '源已过期',
|
||||
OBJECT_MISSING: '对象缺失',
|
||||
SKIPPED: '已跳过'
|
||||
}
|
||||
|
||||
function statusLabel(status) {
|
||||
return STATUS_LABELS[String(status || '').toUpperCase()] || status || '—'
|
||||
}
|
||||
|
||||
function statusClass(status) {
|
||||
const text = String(status || '').toUpperCase()
|
||||
if (text === 'STORED') return 'success'
|
||||
if (text === 'FAILED' || text === 'OBJECT_MISSING') return 'error'
|
||||
if (text === 'SOURCE_EXPIRED') return 'warning'
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
function formatBytes(size) {
|
||||
const value = Number(size)
|
||||
if (!Number.isFinite(value) || value <= 0) return '—'
|
||||
if (value < 1024) return `${value}B`
|
||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)}KB`
|
||||
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)}MB`
|
||||
return `${(value / 1024 / 1024 / 1024).toFixed(2)}GB`
|
||||
}
|
||||
|
||||
function formatTime(value) {
|
||||
if (!value) return '—'
|
||||
return String(value).replace('T', ' ').replace(/\.\d+(Z|[+-].*)?$/, '').replace(/Z$/, '')
|
||||
}
|
||||
|
||||
function toIso(value) {
|
||||
if (!value) return undefined
|
||||
const date = new Date(value)
|
||||
return Number.isNaN(date.getTime()) ? undefined : date.toISOString()
|
||||
}
|
||||
|
||||
async function loadList(nextPage = page.value) {
|
||||
// 没有可用账号时不发无账号过滤的请求,列表显示空态。
|
||||
if (!accountParam()) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
listError.value = null
|
||||
listLoading.value = false
|
||||
return
|
||||
}
|
||||
listLoading.value = true
|
||||
listError.value = null
|
||||
try {
|
||||
const data = await api.mediaList({
|
||||
storageStatus: filters.storageStatus || undefined,
|
||||
errorCode: filters.errorCode.trim() || undefined,
|
||||
mediaType: filters.mediaType || undefined,
|
||||
conversationId: filters.conversationId.trim() || undefined,
|
||||
from: toIso(filters.from),
|
||||
to: toIso(filters.to),
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value,
|
||||
qqAccount: accountParam() || undefined
|
||||
})
|
||||
rows.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || nextPage
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
listError.value = describeError(e)
|
||||
} finally {
|
||||
listLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.storageStatus = ''
|
||||
filters.errorCode = ''
|
||||
filters.mediaType = ''
|
||||
filters.conversationId = ''
|
||||
filters.from = ''
|
||||
filters.to = ''
|
||||
loadList(1)
|
||||
}
|
||||
|
||||
function onPageChange({ page: nextPage, pageSize: nextSize }) {
|
||||
pageSize.value = nextSize
|
||||
loadList(nextPage)
|
||||
}
|
||||
|
||||
async function openRow(row) {
|
||||
mediaUid.value = row.mediaUid
|
||||
await lookup()
|
||||
}
|
||||
|
||||
async function lookup() {
|
||||
const uid = mediaUid.value.trim()
|
||||
if (!uid || loading.value) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
media.value = null
|
||||
accessUrl.value = ''
|
||||
accessError.value = null
|
||||
try {
|
||||
media.value = await api.media(uid)
|
||||
} catch (e) {
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAccessUrl() {
|
||||
if (!media.value?.mediaUid || accessError.value?.title === '读取中') return
|
||||
accessError.value = { title: '读取中', message: '' }
|
||||
try {
|
||||
const data = await api.mediaAccessUrl(media.value.mediaUid)
|
||||
accessUrl.value = data?.url || ''
|
||||
accessError.value = null
|
||||
} catch (e) {
|
||||
accessError.value = describeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => loadList(1))
|
||||
|
||||
// 切换 QQ 账号后回到第 1 页重新加载媒体列表。
|
||||
watch(() => accountState.current, () => loadList(1))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="media-page">
|
||||
<div class="stat-grid">
|
||||
<div v-for="card in statsCards" :key="card.key" class="stat-card">
|
||||
<div class="stat-label"><span class="badge-dot" :class="card.dot"></span>{{ card.label }}</div>
|
||||
<div class="stat-num">{{ card.value }}<small>个</small></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="split">
|
||||
<section class="card main">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<div class="card-title">媒体库</div>
|
||||
<div class="card-sub">共 {{ total }} 条 · 仅展示元数据,不返回对象存储路径</div>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="listLoading" @click="loadList(page)">刷新</button>
|
||||
</div>
|
||||
|
||||
<div class="filterbar">
|
||||
<Select
|
||||
v-model="filters.storageStatus"
|
||||
:options="STORAGE_STATUS_OPTIONS"
|
||||
aria-label="存储状态筛选"
|
||||
@update:model-value="loadList(1)"
|
||||
/>
|
||||
<Select
|
||||
v-model="filters.mediaType"
|
||||
:options="MEDIA_TYPE_OPTIONS"
|
||||
aria-label="媒体类型筛选"
|
||||
@update:model-value="loadList(1)"
|
||||
/>
|
||||
<input v-model="filters.errorCode" class="field" placeholder="错误码" @keyup.enter="loadList(1)" />
|
||||
<input v-model="filters.conversationId" class="field" placeholder="会话标识" @keyup.enter="loadList(1)" />
|
||||
<el-date-picker
|
||||
v-model="filters.from"
|
||||
type="datetime"
|
||||
placeholder="起始时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
style="width: 170px"
|
||||
aria-label="起始时间"
|
||||
v-tooltip="'起始时间'"
|
||||
/>
|
||||
<el-date-picker
|
||||
v-model="filters.to"
|
||||
type="datetime"
|
||||
placeholder="结束时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
style="width: 170px"
|
||||
aria-label="结束时间"
|
||||
v-tooltip="'结束时间'"
|
||||
/>
|
||||
<button class="btn sm primary" type="button" :disabled="listLoading" @click="loadList(1)">查询</button>
|
||||
<button class="btn sm" type="button" :disabled="listLoading" @click="resetFilters">重置</button>
|
||||
</div>
|
||||
|
||||
<div v-if="listError" class="notice danger">
|
||||
<strong>{{ listError.title }}</strong>
|
||||
<span>{{ listError.message }}</span>
|
||||
</div>
|
||||
<div v-else-if="listLoading && !rows.length" class="loading-row"><span class="spinner"></span>正在读取媒体列表…</div>
|
||||
<div v-else-if="!rows.length" class="empty-line">当前筛选条件下没有媒体记录。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>媒体标识</th>
|
||||
<th>关联消息</th>
|
||||
<th>类型</th>
|
||||
<th>文件名</th>
|
||||
<th>MIME</th>
|
||||
<th>大小</th>
|
||||
<th>存储状态</th>
|
||||
<th>错误码</th>
|
||||
<th>创建时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="row in rows"
|
||||
:key="row.mediaUid"
|
||||
:class="{ rowsel: media?.mediaUid === row.mediaUid }"
|
||||
@click="openRow(row)"
|
||||
>
|
||||
<td><code class="code">{{ row.mediaUid }}</code></td>
|
||||
<td><code class="code">{{ row.messageUid || '—' }}</code></td>
|
||||
<td>{{ row.mediaType || '—' }}</td>
|
||||
<td class="ellipsis">{{ row.fileName || '—' }}</td>
|
||||
<td class="small-muted">{{ row.mimeType || '—' }}</td>
|
||||
<td class="small-muted">{{ formatBytes(row.fileSize) }}</td>
|
||||
<td><span class="status" :class="statusClass(row.storageStatus)">{{ statusLabel(row.storageStatus) }}</span></td>
|
||||
<td><code class="code">{{ row.errorCode || '—' }}</code></td>
|
||||
<td class="small-muted">{{ formatTime(row.createdAt) }}</td>
|
||||
<td><button class="btn sm" type="button" @click.stop="openRow(row)">查看</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside class="right-col">
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<div class="card-title">媒体元数据</div>
|
||||
<span class="pill">按标识查询</span>
|
||||
</div>
|
||||
<form class="media-search" @submit.prevent="lookup">
|
||||
<input v-model="mediaUid" class="field" type="text" placeholder="输入媒体标识" aria-label="媒体标识" />
|
||||
<button class="btn sm" type="submit" :disabled="loading || !mediaUid.trim()">
|
||||
{{ loading ? '查询中…' : '查询' }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div v-if="error" class="notice danger">
|
||||
<strong>{{ error.title }}</strong>
|
||||
<span>{{ error.message }}</span>
|
||||
</div>
|
||||
<div v-else-if="loading" class="loading-row"><span class="spinner"></span>正在读取媒体元数据…</div>
|
||||
<div v-else-if="!media" class="empty-line">从列表选择一行,或输入媒体标识查看真实元数据。</div>
|
||||
<template v-else>
|
||||
<div class="media-grid">
|
||||
<span>媒体标识</span><code class="code">{{ media.mediaUid }}</code>
|
||||
<span>关联消息</span><code class="code">{{ media.messageUid || '—' }}</code>
|
||||
<span>媒体类型</span><span>{{ media.mediaType || '—' }}</span>
|
||||
<span>文件名</span><span>{{ media.fileName || '—' }}</span>
|
||||
<span>MIME</span><span>{{ media.mimeType || '—' }}</span>
|
||||
<span>文件大小</span><span>{{ formatBytes(media.fileSize) }}</span>
|
||||
<span>存储状态</span><span class="status" :class="statusClass(media.storageStatus)">{{ statusLabel(media.storageStatus) }}</span>
|
||||
<span>尝试次数</span><span>{{ media.retryCount ?? 0 }}</span>
|
||||
<span>错误码</span><code class="code">{{ media.lastErrorCode || '—' }}</code>
|
||||
<span>错误说明</span><span :class="{ 'text-danger': media.lastErrorMessage }">{{ media.lastErrorMessage || '—' }}</span>
|
||||
<span>创建时间</span><span>{{ formatTime(media.createdAt) }}</span>
|
||||
<span>更新时间</span><span>{{ formatTime(media.updatedAt) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="media-actions">
|
||||
<button class="btn sm" type="button" :disabled="accessError?.title === '读取中'" @click="loadAccessUrl">获取预签名访问地址</button>
|
||||
<a v-if="accessUrl" class="link" :href="accessUrl" target="_blank" rel="noopener noreferrer">打开媒体地址</a>
|
||||
</div>
|
||||
<div v-if="accessError" class="notice danger">
|
||||
<strong>{{ accessError.title }}</strong>
|
||||
<span>{{ accessError.message }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head"><div class="card-title">说明与限制</div></div>
|
||||
<ul class="media-notes">
|
||||
<li>列表只返回元数据,不返回对象键或可访问路径。</li>
|
||||
<li>媒体访问地址由后端签发,页面不拼接对象存储路径。</li>
|
||||
<li>下载失败原因以错误码与后端说明为准。</li>
|
||||
<li>会话筛选通过消息关联匹配,不改变媒体记录本身。</li>
|
||||
</ul>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.media-search {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.media-search .field {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.filterbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.filterbar .field {
|
||||
width: 118px;
|
||||
}
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 82px minmax(0, 1fr);
|
||||
gap: 8px 10px;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #EDF0F5;
|
||||
background: #FAFBFF;
|
||||
font-size: 10.5px;
|
||||
align-items: center;
|
||||
}
|
||||
.media-grid > span:nth-child(odd) {
|
||||
color: #9AA1B2;
|
||||
font-size: 10px;
|
||||
}
|
||||
.text-danger {
|
||||
color: #B91C1C;
|
||||
}
|
||||
.media-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.media-notes {
|
||||
margin: 0;
|
||||
padding-left: 16px;
|
||||
font-size: 10.5px;
|
||||
line-height: 1.8;
|
||||
color: #5B6172;
|
||||
}
|
||||
.media-notes li {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.ellipsis {
|
||||
max-width: 160px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.right-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,541 @@
|
||||
<script setup>
|
||||
import { nextTick, ref, watch } from 'vue'
|
||||
import AvatarBadge from '../AvatarBadge.vue'
|
||||
|
||||
const props = defineProps({
|
||||
messages: { type: Array, default: () => [] },
|
||||
loading: { type: Boolean, default: false },
|
||||
error: { type: Object, default: null },
|
||||
loadingOlder: { type: Boolean, default: false },
|
||||
hasMore: { type: Boolean, default: false },
|
||||
isGroup: { type: Boolean, default: false },
|
||||
emptyTitle: { type: String, default: '这个会话还没有消息' },
|
||||
emptyText: { type: String, default: '当前筛选范围内没有已入库的消息。' },
|
||||
imageState: { type: Object, default: () => ({}) },
|
||||
lightbox: { type: Object, default: null }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['retry', 'load-older', 'select', 'open-image', 'close-lightbox'])
|
||||
|
||||
const body = ref(null)
|
||||
// 记录用户是否停留在底部:容器高度变化时只有贴底状态才继续贴底,避免打断向上翻历史。
|
||||
const atBottom = ref(true)
|
||||
const BOTTOM_SLACK = 24
|
||||
|
||||
function onScroll() {
|
||||
const el = body.value
|
||||
if (!el) return
|
||||
atBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_SLACK
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
nextTick(() => {
|
||||
const el = body.value
|
||||
if (!el) return
|
||||
el.scrollTop = el.scrollHeight
|
||||
atBottom.value = true
|
||||
})
|
||||
}
|
||||
|
||||
// 输入区高度变化后由父组件调用:原本贴底则继续保持贴底。
|
||||
function notifyResize() {
|
||||
if (!atBottom.value) return
|
||||
nextTick(() => {
|
||||
const el = body.value
|
||||
if (el) el.scrollTop = el.scrollHeight
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ scrollToBottom, notifyResize })
|
||||
|
||||
watch(
|
||||
() => props.messages.length,
|
||||
(next, prev) => {
|
||||
if (next > prev && prev === 0) scrollToBottom()
|
||||
}
|
||||
)
|
||||
|
||||
function dayOf(value) {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return String(value || '')
|
||||
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`
|
||||
}
|
||||
|
||||
function showDay(index) {
|
||||
const current = props.messages[index]
|
||||
const prev = props.messages[index - 1]
|
||||
if (!current) return false
|
||||
return !prev || dayOf(prev.messageTime) !== dayOf(current.messageTime)
|
||||
}
|
||||
|
||||
function dayLabel(value) {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return String(value || '')
|
||||
const now = new Date()
|
||||
const sameDay = (a, b) =>
|
||||
a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
|
||||
if (sameDay(date, now)) return '今天'
|
||||
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1)
|
||||
if (sameDay(date, yesterday)) return '昨天'
|
||||
return `${date.getMonth() + 1}月${date.getDate()}日`
|
||||
}
|
||||
|
||||
function timeLabel(value) {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return ''
|
||||
const pad = (n) => String(n).padStart(2, '0')
|
||||
return `${pad(date.getHours())}:${pad(date.getMinutes())}`
|
||||
}
|
||||
|
||||
function typeOf(row) {
|
||||
return String(row?.messageType || '').toUpperCase()
|
||||
}
|
||||
|
||||
function isSystem(row) {
|
||||
return typeOf(row) === 'SYSTEM'
|
||||
}
|
||||
|
||||
function imageStateOf(row) {
|
||||
return props.imageState[row.messageUid] || null
|
||||
}
|
||||
|
||||
function activate(row) {
|
||||
if (typeOf(row) === 'IMAGE') emit('open-image', row)
|
||||
else emit('select', row)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="body" class="messages" @scroll="onScroll">
|
||||
<div v-if="loading" class="msg-state">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在读取消息…
|
||||
</div>
|
||||
|
||||
<div v-else-if="error" class="msg-state error">
|
||||
<strong>{{ error.title }}</strong>
|
||||
<span>{{ error.message }}</span>
|
||||
<span v-if="error.hint" class="msg-hint">{{ error.hint }}</span>
|
||||
<button class="msg-retry" type="button" @click="$emit('retry')">重试</button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="!messages.length" class="msg-empty">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M21 11.5a8.5 8.5 0 0 1-8.5 8.5H4l2-3.9A8.5 8.5 0 1 1 21 11.5Z" />
|
||||
</svg>
|
||||
<strong>{{ emptyTitle }}</strong>
|
||||
<p>{{ emptyText }}</p>
|
||||
<slot name="empty-action" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<button
|
||||
v-if="hasMore"
|
||||
class="load-older"
|
||||
type="button"
|
||||
:disabled="loadingOlder"
|
||||
@click="$emit('load-older')"
|
||||
>
|
||||
{{ loadingOlder ? '正在加载更早消息…' : '加载更早消息' }}
|
||||
</button>
|
||||
|
||||
<template v-for="(row, index) in messages" :key="row.messageUid || index">
|
||||
<div v-if="showDay(index)" class="day-line">{{ dayLabel(row.messageTime) }}</div>
|
||||
|
||||
<div v-if="isSystem(row)" class="system-line">
|
||||
<span>{{ row.summary || '系统消息' }}</span>
|
||||
</div>
|
||||
|
||||
<div v-else class="msg" :class="{ mine: row.direction === 'OUTBOUND' }">
|
||||
<AvatarBadge
|
||||
v-if="row.direction !== 'OUTBOUND'"
|
||||
class="msg-avatar"
|
||||
:media-uid="row.senderAvatarMediaUid"
|
||||
:name="row.senderName || row.senderId"
|
||||
type="PRIVATE"
|
||||
size="sm"
|
||||
/>
|
||||
<div class="msg-content">
|
||||
<div v-if="row.direction !== 'OUTBOUND' && isGroup" class="msg-sender">
|
||||
{{ row.senderName || row.senderId || '未知成员' }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="bubble"
|
||||
:class="{ image: typeOf(row) === 'IMAGE', file: typeOf(row) === 'FILE', voice: typeOf(row) === 'VOICE' || typeOf(row) === 'RECORD' }"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="activate(row)"
|
||||
@keydown.enter="activate(row)"
|
||||
>
|
||||
<template v-if="typeOf(row) === 'IMAGE'">
|
||||
<span v-if="imageStateOf(row)?.loading" class="image-card loading">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在获取图片…
|
||||
</span>
|
||||
<span v-else-if="imageStateOf(row)?.error" class="image-card error">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5h16v14H4z" /><path d="m4 16 5-5 4 4 3-3 4 4" /></svg>
|
||||
{{ imageStateOf(row).error }}
|
||||
</span>
|
||||
<img v-else-if="imageStateOf(row)?.url" class="image-card img" :src="imageStateOf(row).url" alt="消息图片" loading="lazy" />
|
||||
<span v-else class="image-card">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5h16v14H4z" /><path d="m4 16 5-5 4 4 3-3 4 4" /></svg>
|
||||
<span>图片消息</span>
|
||||
<span class="image-tip">点击查看</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-else-if="typeOf(row) === 'FILE'">
|
||||
<span class="file-card">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V7z" /><path d="M14 3v4h4" /></svg>
|
||||
<span class="file-text">{{ row.summary || '文件消息' }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-else-if="typeOf(row) === 'VOICE' || typeOf(row) === 'RECORD'">
|
||||
<span class="voice-card">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 10v4M9 7v10M13 5v14M17 8v8M21 11v2" /></svg>
|
||||
<span>{{ row.summary || '语音消息' }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<span class="bubble-text">{{ row.summary || '(无文本摘要,点击查看详情)' }}</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="msg-meta">
|
||||
<span>{{ timeLabel(row.messageTime) }}</span>
|
||||
<span v-if="row.direction === 'OUTBOUND'"> · 我发送</span>
|
||||
<span v-if="typeOf(row) !== 'TEXT'" class="msg-type"> · {{ typeOf(row) === 'IMAGE' ? '图片' : typeOf(row) === 'FILE' ? '文件' : typeOf(row) === 'VOICE' || typeOf(row) === 'RECORD' ? '语音' : row.messageType }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<AvatarBadge
|
||||
v-if="row.direction === 'OUTBOUND'"
|
||||
class="msg-avatar"
|
||||
:media-uid="row.senderAvatarMediaUid"
|
||||
name="我"
|
||||
type="ACCOUNT"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<div v-if="lightbox" class="lightbox" role="dialog" aria-modal="true" @click.self="$emit('close-lightbox')">
|
||||
<button class="lightbox-close" type="button" v-tooltip="'关闭'" @click="$emit('close-lightbox')">×</button>
|
||||
<div v-if="lightbox.loading" class="lightbox-state">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在获取图片地址…
|
||||
</div>
|
||||
<div v-else-if="lightbox.error" class="lightbox-state error">{{ lightbox.error }}</div>
|
||||
<img v-else :src="lightbox.url" :alt="lightbox.alt || '消息图片'" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.messages {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 14px 22px 22px;
|
||||
background: #fff;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #dcdde0 transparent;
|
||||
}
|
||||
.messages::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
.messages::-webkit-scrollbar-thumb {
|
||||
background: #dcdde0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.msg-state,
|
||||
.msg-empty {
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 40px 24px;
|
||||
color: #8a8f99;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.msg-state.error strong {
|
||||
color: #c0392b;
|
||||
font-size: 13px;
|
||||
}
|
||||
.msg-hint {
|
||||
color: #a0a4aa;
|
||||
}
|
||||
.msg-retry {
|
||||
margin-top: 4px;
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #d7d9dd;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #4b5058;
|
||||
font-size: 12px;
|
||||
}
|
||||
.msg-empty svg {
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
fill: none;
|
||||
stroke: #c6c9ce;
|
||||
stroke-width: 1.5;
|
||||
}
|
||||
.msg-empty strong {
|
||||
color: #4b5058;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.msg-empty p {
|
||||
max-width: 320px;
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.load-older {
|
||||
display: block;
|
||||
margin: 2px auto 14px;
|
||||
padding: 5px 14px;
|
||||
border: 1px solid #e3e5e8;
|
||||
border-radius: 14px;
|
||||
background: #f7f7f8;
|
||||
color: #8a8f99;
|
||||
font-size: 11px;
|
||||
}
|
||||
.load-older:hover:not(:disabled) {
|
||||
color: #0099ff;
|
||||
border-color: #bfe3ff;
|
||||
}
|
||||
.load-older:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.7;
|
||||
}
|
||||
.day-line {
|
||||
margin: 16px 0 12px;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
color: #a0a4aa;
|
||||
}
|
||||
.system-line {
|
||||
margin: 10px auto;
|
||||
text-align: center;
|
||||
}
|
||||
.system-line span {
|
||||
display: inline-block;
|
||||
max-width: 78%;
|
||||
padding: 4px 10px;
|
||||
border-radius: 5px;
|
||||
background: #f3f4f5;
|
||||
color: #8a8f99;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.msg {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 9px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.msg.mine {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.msg-avatar {
|
||||
margin-top: 2px;
|
||||
}
|
||||
.msg-content {
|
||||
min-width: 0;
|
||||
max-width: min(72%, 620px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.msg.mine .msg-content {
|
||||
align-items: flex-end;
|
||||
}
|
||||
.msg-sender {
|
||||
margin: 0 0 3px 2px;
|
||||
font-size: 11px;
|
||||
color: #a0a4aa;
|
||||
}
|
||||
.bubble {
|
||||
padding: 9px 13px;
|
||||
border-radius: 10px;
|
||||
background: #f3f4f5;
|
||||
color: #1f2329;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
word-break: break-word;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
}
|
||||
.bubble:hover {
|
||||
background: #ebedef;
|
||||
}
|
||||
.msg.mine .bubble {
|
||||
background: #e7f3fd;
|
||||
color: #1f2329;
|
||||
}
|
||||
.msg.mine .bubble:hover {
|
||||
background: #d9ecfb;
|
||||
}
|
||||
.bubble-text {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.bubble.image,
|
||||
.bubble.file,
|
||||
.bubble.voice {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
}
|
||||
.bubble.image:hover,
|
||||
.bubble.file:hover,
|
||||
.bubble.voice:hover {
|
||||
background: transparent;
|
||||
}
|
||||
.image-card {
|
||||
position: relative;
|
||||
width: 196px;
|
||||
height: 132px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e3e5e8;
|
||||
background: #f7f8fa;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
color: #8a8f99;
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.image-card svg {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
fill: none;
|
||||
stroke: #b6bac0;
|
||||
stroke-width: 1.6;
|
||||
}
|
||||
.image-card.img {
|
||||
width: auto;
|
||||
max-width: 240px;
|
||||
height: auto;
|
||||
max-height: 200px;
|
||||
border: 0;
|
||||
object-fit: cover;
|
||||
}
|
||||
.image-tip {
|
||||
font-size: 10px;
|
||||
color: #b6bac0;
|
||||
}
|
||||
.image-card.loading,
|
||||
.image-card.error {
|
||||
color: #8a8f99;
|
||||
}
|
||||
.file-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 230px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #e3e5e8;
|
||||
border-radius: 9px;
|
||||
background: #f7f8fa;
|
||||
}
|
||||
.file-card svg {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
flex-shrink: 0;
|
||||
fill: none;
|
||||
stroke: #7b8794;
|
||||
stroke-width: 1.5;
|
||||
}
|
||||
.file-text {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
color: #3d4652;
|
||||
}
|
||||
.voice-card {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 13px;
|
||||
border-radius: 9px;
|
||||
background: #f3f4f5;
|
||||
color: #4b5058;
|
||||
font-size: 12px;
|
||||
}
|
||||
.voice-card svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
.msg-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
margin-top: 4px;
|
||||
padding: 0 2px;
|
||||
font-size: 10px;
|
||||
color: #a0a4aa;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
.msg:hover .msg-meta,
|
||||
.msg:focus-within .msg-meta {
|
||||
opacity: 1;
|
||||
}
|
||||
.lightbox {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 60;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px;
|
||||
background: rgba(15, 18, 22, 0.78);
|
||||
}
|
||||
.lightbox img {
|
||||
max-width: min(86vw, 1100px);
|
||||
max-height: 86vh;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
.lightbox-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #e7e9ec;
|
||||
font-size: 13px;
|
||||
}
|
||||
.lightbox-state.error {
|
||||
color: #ffb4a8;
|
||||
}
|
||||
.lightbox-close {
|
||||
position: absolute;
|
||||
top: 18px;
|
||||
right: 22px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
color: #fff;
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
.lightbox-close:hover {
|
||||
background: rgba(255, 255, 255, 0.26);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,591 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { api } from '../../api'
|
||||
import { describeError } from '../../ui'
|
||||
import ConfirmDialog from '../ConfirmDialog.vue'
|
||||
import Pagination from '../Pagination.vue'
|
||||
import Select from '../ui/Select.vue'
|
||||
import { can, denialReason } from '../../permissions'
|
||||
import { accountParam, accountState } from '../../account-context.js'
|
||||
|
||||
const props = defineProps({
|
||||
summary: { type: Object, default: null }
|
||||
})
|
||||
|
||||
const SEND_STATUS_OPTIONS = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: 'PENDING', label: '待发送' },
|
||||
{ value: 'RUNNING', label: '发送中' },
|
||||
{ value: 'SUCCEEDED', label: '成功' },
|
||||
{ value: 'FAILED', label: '失败' },
|
||||
{ value: 'UNKNOWN', label: '结果未知' },
|
||||
{ value: 'CANCELLED', label: '已取消' },
|
||||
{ value: 'REJECTED', label: '已拒绝' }
|
||||
]
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
const operations = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const statusFilter = ref('')
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const selectedUid = ref('')
|
||||
const detail = ref(null)
|
||||
const detailLoading = ref(false)
|
||||
const detailError = ref(null)
|
||||
|
||||
const cancelDialog = reactive({ open: false, busy: false, error: null, reason: '' })
|
||||
const resolveForm = reactive({ resolution: 'DELIVERED', note: '', busy: false, error: null })
|
||||
|
||||
const STATUS_LABELS = {
|
||||
PENDING: '待发送',
|
||||
RUNNING: '发送中',
|
||||
SUCCEEDED: '上游确认成功',
|
||||
FAILED: '明确失败',
|
||||
UNKNOWN: '结果未知',
|
||||
RETRYING: '等待重试',
|
||||
CANCELLED: '已取消',
|
||||
REJECTED: '已拒绝',
|
||||
MANUAL: '人工介入'
|
||||
}
|
||||
|
||||
const STATUS_HINTS = {
|
||||
PENDING: '等待确认执行',
|
||||
RUNNING: '等待上游回执',
|
||||
SUCCEEDED: '上游已回执',
|
||||
FAILED: '未产生送达',
|
||||
UNKNOWN: '需人工核实',
|
||||
RETRYING: '等待重试',
|
||||
CANCELLED: '人工取消',
|
||||
REJECTED: '发送前被拒绝'
|
||||
}
|
||||
|
||||
const STATUS_CLASS = {
|
||||
SUCCEEDED: 'success',
|
||||
FAILED: 'error',
|
||||
UNKNOWN: 'warning',
|
||||
PENDING: 'neutral',
|
||||
RUNNING: 'info',
|
||||
RETRYING: 'warning',
|
||||
CANCELLED: 'neutral',
|
||||
REJECTED: 'error',
|
||||
MANUAL: 'warning'
|
||||
}
|
||||
|
||||
const RESOLUTION_LABELS = {
|
||||
DELIVERED: '人工确认已送达',
|
||||
NOT_DELIVERED: '人工确认未送达',
|
||||
INCONCLUSIVE: '无法确认'
|
||||
}
|
||||
|
||||
const summaryCards = computed(() => [
|
||||
{ key: 'SUCCEEDED', label: '发送成功', value: Number(props.summary?.SUCCEEDED || 0), tone: 'g' },
|
||||
{ key: 'FAILED', label: '明确失败', value: Number(props.summary?.FAILED || 0), tone: 'r' },
|
||||
{ key: 'UNKNOWN', label: '结果未知', value: Number(props.summary?.UNKNOWN || 0), tone: 'a' },
|
||||
{
|
||||
key: 'RUNNING',
|
||||
label: '发送中',
|
||||
value: Number(props.summary?.RUNNING || 0) + Number(props.summary?.PENDING || 0),
|
||||
tone: 'b'
|
||||
}
|
||||
])
|
||||
|
||||
const unresolved = computed(() =>
|
||||
operations.value.filter(
|
||||
(item) => String(item.status || '').toUpperCase() === 'UNKNOWN' && !item.manualResolution
|
||||
)
|
||||
)
|
||||
|
||||
const detailOperation = computed(() => detail.value || null)
|
||||
const canSend = computed(() => can('send.execute'))
|
||||
const sendReason = computed(() => denialReason('send.execute', '取消或核实发送记录'))
|
||||
const canCancel = computed(() => String(detailOperation.value?.status || '').toUpperCase() === 'PENDING')
|
||||
const canResolve = computed(
|
||||
() => String(detailOperation.value?.status || '').toUpperCase() === 'UNKNOWN' && !detailOperation.value?.manualResolution
|
||||
)
|
||||
|
||||
function statusLabel(status) {
|
||||
return STATUS_LABELS[String(status || '').toUpperCase()] || status || '—'
|
||||
}
|
||||
|
||||
function statusClass(status) {
|
||||
return STATUS_CLASS[String(status || '').toUpperCase()] || 'neutral'
|
||||
}
|
||||
|
||||
function statusHint(status) {
|
||||
return STATUS_HINTS[String(status || '').toUpperCase()] || ''
|
||||
}
|
||||
|
||||
function resolutionLabel(value) {
|
||||
return RESOLUTION_LABELS[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function targetLabel(item) {
|
||||
const type = String(item?.targetType || '').toUpperCase()
|
||||
return `${type === 'GROUP' ? '群聊' : type === 'PRIVATE' ? '私聊' : type || '目标'} ${item?.targetId || ''}`.trim()
|
||||
}
|
||||
|
||||
function formatTime(value) {
|
||||
if (!value) return '—'
|
||||
return String(value).replace('T', ' ').replace(/\.\d+(Z|[+-].*)?$/, '').replace(/Z$/, '')
|
||||
}
|
||||
|
||||
async function loadOperations(nextPage = page.value) {
|
||||
// 发送日志同样按账号隔离:没有可用账号时不发平台级聚合请求。
|
||||
if (!accountParam()) {
|
||||
operations.value = []
|
||||
total.value = 0
|
||||
error.value = null
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.sendOperations({
|
||||
status: statusFilter.value || undefined,
|
||||
qqAccount: accountParam() || undefined,
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value
|
||||
})
|
||||
operations.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || nextPage
|
||||
if (selectedUid.value && operations.value.some((item) => item.operationUid === selectedUid.value)) {
|
||||
await openDetail(selectedUid.value)
|
||||
}
|
||||
} catch (e) {
|
||||
operations.value = []
|
||||
total.value = 0
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openDetail(uid) {
|
||||
if (!uid || detailLoading.value) return
|
||||
selectedUid.value = uid
|
||||
resolveForm.error = null
|
||||
resolveForm.note = ''
|
||||
resolveForm.resolution = 'DELIVERED'
|
||||
detailLoading.value = true
|
||||
detailError.value = null
|
||||
try {
|
||||
detail.value = await api.sendOperation(uid)
|
||||
} catch (e) {
|
||||
detail.value = null
|
||||
detailError.value = describeError(e)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
loadOperations(page.value)
|
||||
emit('refresh')
|
||||
}
|
||||
|
||||
function onStatusChange() {
|
||||
loadOperations(1)
|
||||
}
|
||||
|
||||
function onPageChange({ page: nextPage, pageSize: nextSize }) {
|
||||
pageSize.value = nextSize
|
||||
loadOperations(nextPage)
|
||||
}
|
||||
|
||||
function openCancel() {
|
||||
if (canSend.value === false) return
|
||||
cancelDialog.open = true
|
||||
cancelDialog.reason = ''
|
||||
cancelDialog.error = null
|
||||
}
|
||||
|
||||
async function confirmCancel() {
|
||||
if (cancelDialog.busy) return
|
||||
cancelDialog.busy = true
|
||||
cancelDialog.error = null
|
||||
try {
|
||||
detail.value = await api.cancelSendOperation(selectedUid.value, cancelDialog.reason.trim() || '操作者取消发送')
|
||||
cancelDialog.open = false
|
||||
await loadOperations(page.value)
|
||||
emit('refresh')
|
||||
} catch (e) {
|
||||
cancelDialog.error = describeError(e)
|
||||
} finally {
|
||||
cancelDialog.busy = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitResolve() {
|
||||
if (resolveForm.busy || !canResolve.value) return
|
||||
resolveForm.busy = true
|
||||
resolveForm.error = null
|
||||
try {
|
||||
detail.value = await api.resolveSendOperation(selectedUid.value, resolveForm.resolution, resolveForm.note.trim() || null)
|
||||
await loadOperations(page.value)
|
||||
emit('refresh')
|
||||
} catch (e) {
|
||||
resolveForm.error = describeError(e)
|
||||
} finally {
|
||||
resolveForm.busy = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => loadOperations(1))
|
||||
// 切换账号后回到第 1 页重新加载,避免混入上一账号的发送记录。
|
||||
watch(() => accountState.current, () => loadOperations(1))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="send-page">
|
||||
<div class="notice send-notice">
|
||||
<strong>发送日志</strong>
|
||||
<span>记录平台发送结果。「上游确认成功」只表示 NapCat 已接收调用,不代表接收方已看到消息;结果未知需人工核实,不能直接重试。</span>
|
||||
<span v-if="accountState.current" class="inline-warn">
|
||||
当前只展示该 QQ 账号绑定的发送任务;跨账号记录请切换到对应账号查看。
|
||||
</span>
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="refresh">刷新</button>
|
||||
</div>
|
||||
|
||||
<div class="stat-grid">
|
||||
<div v-for="card in summaryCards" :key="card.key" class="stat-card">
|
||||
<div class="stat-label">
|
||||
<span class="badge-dot" :class="card.tone"></span>
|
||||
{{ card.label }}
|
||||
</div>
|
||||
<div class="stat-num">{{ card.value }}<small>条</small></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="split">
|
||||
<div class="main card send-main">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<div class="card-title">发送记录</div>
|
||||
<div class="card-sub">共 {{ total }} 条 · 第 {{ page }} 页 · 状态来自后端实际记录</div>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<Select
|
||||
v-model="statusFilter"
|
||||
:options="SEND_STATUS_OPTIONS"
|
||||
style="width: 120px"
|
||||
aria-label="发送状态筛选"
|
||||
@update:model-value="onStatusChange"
|
||||
/>
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="loadOperations(page)">刷新记录</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="notice danger">
|
||||
<strong>{{ error.title }}</strong>
|
||||
<span>{{ error.message }}</span>
|
||||
</div>
|
||||
<div v-else-if="loading && !operations.length" class="loading-row"><span class="spinner"></span>正在读取发送记录…</div>
|
||||
<div v-else-if="!operations.length" class="empty-line">暂无发送记录。通过消息中心确认发送后,记录会出现在这里。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl send-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作标识</th>
|
||||
<th>目标</th>
|
||||
<th>状态</th>
|
||||
<th>尝试</th>
|
||||
<th>最近时间</th>
|
||||
<th>结果 / 错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="item in operations"
|
||||
:key="item.operationUid"
|
||||
:class="{ rowsel: item.operationUid === selectedUid }"
|
||||
@click="openDetail(item.operationUid)"
|
||||
>
|
||||
<td>
|
||||
<code class="code">{{ item.operationUid }}</code>
|
||||
<div class="small-muted">{{ item.sourceType === 'RULE' ? '规则自动发送' : '人工发送' }}</div>
|
||||
</td>
|
||||
<td>
|
||||
{{ targetLabel(item) }}
|
||||
</td>
|
||||
<td>
|
||||
<span class="status" :class="statusClass(item.status)">{{ statusLabel(item.status) }}</span>
|
||||
<div class="small-muted">{{ statusHint(item.status) }}</div>
|
||||
<span v-if="item.manualResolution" class="small-muted resolved-tag">已核实</span>
|
||||
</td>
|
||||
<td>{{ item.attemptCount ?? 0 }} 次</td>
|
||||
<td class="small-muted">{{ formatTime(item.finishedAt || item.createdAt) }}</td>
|
||||
<td>
|
||||
<span v-if="item.errorCode" class="text-danger">{{ item.errorCode }}</span>
|
||||
<span v-else class="small-muted">{{ String(item.status).toUpperCase() === 'SUCCEEDED' ? '上游已回执' : '—' }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn sm" type="button" @click.stop="openDetail(item.operationUid)">查看</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="right-col send-side">
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<div class="card-title">结果未知</div>
|
||||
<span class="pill">{{ Number(summary?.UNKNOWN_UNRESOLVED || unresolved.length) }}</span>
|
||||
</div>
|
||||
<div v-if="!unresolved.length" class="empty-line">当前页没有待核实的结果未知操作。</div>
|
||||
<button
|
||||
v-for="item in unresolved"
|
||||
:key="item.operationUid"
|
||||
class="unknown-item"
|
||||
type="button"
|
||||
@click="openDetail(item.operationUid)"
|
||||
>
|
||||
<span class="unknown-id">{{ item.operationUid }}</span>
|
||||
<span class="small-muted">{{ targetLabel(item) }}</span>
|
||||
<span class="small-muted">{{ formatTime(item.createdAt) }}</span>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="card detail-card">
|
||||
<div class="card-head">
|
||||
<div class="card-title">操作详情</div>
|
||||
<code v-if="selectedUid" class="code">{{ selectedUid }}</code>
|
||||
</div>
|
||||
<div v-if="detailLoading" class="loading-row"><span class="spinner"></span>正在读取详情…</div>
|
||||
<div v-else-if="detailError" class="notice danger">
|
||||
<strong>{{ detailError.title }}</strong>
|
||||
<span>{{ detailError.message }}</span>
|
||||
</div>
|
||||
<div v-else-if="!detailOperation" class="empty-line">从左侧选择一条发送记录查看详情。</div>
|
||||
<template v-else>
|
||||
<div class="kv-row"><span>状态</span><span class="status" :class="statusClass(detailOperation.status)">{{ statusLabel(detailOperation.status) }}</span></div>
|
||||
<div class="kv-row"><span>目标</span><span>{{ targetLabel(detailOperation) }}</span></div>
|
||||
<div class="kv-row"><span>尝试次数</span><span>{{ detailOperation.attemptCount ?? 0 }}</span></div>
|
||||
<div class="kv-row"><span>创建时间</span><span>{{ formatTime(detailOperation.createdAt) }}</span></div>
|
||||
<div class="kv-row"><span>完成时间</span><span>{{ formatTime(detailOperation.finishedAt) }}</span></div>
|
||||
<div v-if="detailOperation.errorCode" class="kv-row"><span>错误码</span><code class="code">{{ detailOperation.errorCode }}</code></div>
|
||||
<div v-if="detailOperation.errorMessage" class="kv-row"><span>错误说明</span><span class="text-danger">{{ detailOperation.errorMessage }}</span></div>
|
||||
<div v-if="detailOperation.manualResolution" class="kv-row">
|
||||
<span>人工核实</span>
|
||||
<span>{{ resolutionLabel(detailOperation.manualResolution) }}<span class="small-muted"> · {{ formatTime(detailOperation.manualResolvedAt) }}</span></span>
|
||||
</div>
|
||||
<div v-if="detailOperation.manualResolutionNote" class="kv-row"><span>核实说明</span><span>{{ detailOperation.manualResolutionNote }}</span></div>
|
||||
|
||||
<div class="sub-title">发送内容</div>
|
||||
<div class="detail-text">{{ detailOperation.text || '—' }}</div>
|
||||
|
||||
<div class="sub-title">逐次尝试(send_attempt)</div>
|
||||
<div v-if="!detailOperation.attempts?.length" class="empty-line">后端未返回尝试明细(可能尚未开始发送)。</div>
|
||||
<div v-else class="attempts">
|
||||
<div v-for="attempt in detailOperation.attempts" :key="attempt.attemptNumber" class="attempt-row">
|
||||
<div class="attempt-head">
|
||||
<span>第 {{ attempt.attemptNumber }} 次</span>
|
||||
<span class="status" :class="statusClass(attempt.attemptStatus)">{{ statusLabel(attempt.attemptStatus) }}</span>
|
||||
<span class="small-muted">{{ formatTime(attempt.startedAt) }} · {{ attempt.durationMs ?? '—' }}ms</span>
|
||||
</div>
|
||||
<div v-if="attempt.errorCode" class="small-muted text-danger">{{ attempt.errorCode }}:{{ attempt.errorMessage || '—' }}</div>
|
||||
<div v-if="attempt.responseSummary" class="small-muted attempt-text">{{ attempt.responseSummary }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="canResolve" class="resolve-panel">
|
||||
<div class="sub-title">人工核实</div>
|
||||
<div class="resolve-options">
|
||||
<label><input v-model="resolveForm.resolution" type="radio" value="DELIVERED" /> 确认已送达</label>
|
||||
<label><input v-model="resolveForm.resolution" type="radio" value="NOT_DELIVERED" /> 确认未送达</label>
|
||||
<label><input v-model="resolveForm.resolution" type="radio" value="INCONCLUSIVE" /> 无法确认</label>
|
||||
</div>
|
||||
<input v-model="resolveForm.note" class="field" placeholder="核实说明(选填,不含敏感内容)" />
|
||||
<div v-if="resolveForm.error" class="inline-error">{{ resolveForm.error.title }}:{{ resolveForm.error.message }}</div>
|
||||
<button
|
||||
class="btn sm primary"
|
||||
type="button"
|
||||
:disabled="resolveForm.busy || canSend === false" v-tooltip="canSend === false ? sendReason : '只记录人工结论,不会把结果未知改写为成功'"
|
||||
@click="submitResolve"
|
||||
>
|
||||
{{ resolveForm.busy ? '提交中…' : '提交核实结论' }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="canSend === false" class="save-reason">{{ sendReason }}</div>
|
||||
|
||||
<div class="detail-actions">
|
||||
<button
|
||||
class="btn sm"
|
||||
type="button"
|
||||
:disabled="!canCancel || canSend === false" v-tooltip="canCancel ? (canSend === false ? sendReason : '只有待发送操作可以取消') : '当前状态可能已产生外部副作用,不能取消'"
|
||||
@click="openCancel"
|
||||
>
|
||||
取消发送
|
||||
</button>
|
||||
<button
|
||||
class="btn sm"
|
||||
type="button"
|
||||
disabled v-tooltip="'结果未知或已失败时禁止直接重试,需人工核实;后端未提供重试接口'"
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="cancelDialog.open"
|
||||
title="取消发送"
|
||||
message="取消只对「待发送」记录生效;已进入发送中或结果未知的记录不能取消。"
|
||||
hint="取消不会删除记录,状态会变为「已取消」并写入审计。"
|
||||
confirm-text="确认取消"
|
||||
tone="warning"
|
||||
:busy="cancelDialog.busy"
|
||||
@confirm="confirmCancel"
|
||||
@cancel="cancelDialog.open = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.send-notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.send-notice strong {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.send-notice span {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 10.5px;
|
||||
}
|
||||
.send-main {
|
||||
min-width: 0;
|
||||
}
|
||||
.head-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.send-table tbody tr {
|
||||
cursor: pointer;
|
||||
}
|
||||
.send-table tbody tr:hover {
|
||||
background: #FAFBFF;
|
||||
}
|
||||
.text-danger {
|
||||
color: #B91C1C;
|
||||
}
|
||||
.resolved-tag {
|
||||
margin-left: 6px;
|
||||
font-size: 9px;
|
||||
}
|
||||
.right-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.unknown-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
width: 100%;
|
||||
padding: 7px 10px;
|
||||
border: 0;
|
||||
border-top: 1px solid #EDF0F5;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
.unknown-item:first-of-type {
|
||||
border-top: 0;
|
||||
}
|
||||
.unknown-item:hover {
|
||||
background: #FAFBFF;
|
||||
}
|
||||
.unknown-id {
|
||||
font-family: 'Consolas', 'JetBrains Mono', monospace;
|
||||
font-size: 10px;
|
||||
color: #B45309;
|
||||
}
|
||||
.detail-card {
|
||||
min-height: 240px;
|
||||
}
|
||||
.sub-title {
|
||||
margin: 12px 0 6px;
|
||||
font-size: 10.5px;
|
||||
font-weight: 600;
|
||||
color: #6B7280;
|
||||
}
|
||||
.detail-text {
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background: #F8F9FC;
|
||||
border: 1px solid #EDF0F5;
|
||||
font-size: 11px;
|
||||
line-height: 1.65;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
.attempts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.attempt-row {
|
||||
padding: 8px;
|
||||
border: 1px solid #EDF0F5;
|
||||
border-radius: 8px;
|
||||
background: #FCFCFF;
|
||||
}
|
||||
.attempt-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 10.5px;
|
||||
}
|
||||
.attempt-text {
|
||||
margin-top: 4px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.resolve-panel {
|
||||
margin-top: 8px;
|
||||
padding: 10px;
|
||||
border: 1px solid #FDE68A;
|
||||
border-radius: 8px;
|
||||
background: #FFFBEB;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.resolve-options {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
font-size: 10.5px;
|
||||
}
|
||||
.inline-error {
|
||||
color: #B91C1C;
|
||||
font-size: 10.5px;
|
||||
}
|
||||
.save-reason {
|
||||
margin-top: 8px;
|
||||
color: #B91C1C;
|
||||
font-size: 10px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.detail-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,382 @@
|
||||
<script setup>
|
||||
import AvatarBadge from '../AvatarBadge.vue'
|
||||
|
||||
defineProps({
|
||||
conversations: { type: Array, default: () => [] },
|
||||
activeKey: { type: String, default: '' },
|
||||
search: { type: String, default: '' },
|
||||
loading: { type: Boolean, default: false },
|
||||
error: { type: Object, default: null },
|
||||
page: { type: Number, default: 1 },
|
||||
total: { type: Number, default: 0 },
|
||||
hasNext: { type: Boolean, default: false },
|
||||
hasPrev: { type: Boolean, default: false }
|
||||
})
|
||||
|
||||
defineEmits(['update:search', 'select', 'refresh', 'page-change'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="session-list">
|
||||
<header class="sl-head">
|
||||
<div class="sl-title-row">
|
||||
<span class="sl-title">消息</span>
|
||||
<span class="sl-count">{{ conversations.length }}</span>
|
||||
<button class="sl-refresh" type="button" v-tooltip="'刷新会话'" :disabled="loading" @click="$emit('refresh')">
|
||||
<svg viewBox="0 0 24 24" :class="{ spinning: loading }" aria-hidden="true">
|
||||
<path d="M20 11a8 8 0 1 0-2.3 5.7" />
|
||||
<path d="M20 4v7h-7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="sl-search">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="11" cy="11" r="6.5" />
|
||||
<path d="M20 20l-4-4" />
|
||||
</svg>
|
||||
<input
|
||||
type="search"
|
||||
:value="search"
|
||||
placeholder="搜索会话"
|
||||
aria-label="搜索会话"
|
||||
@input="$emit('update:search', $event.target.value)"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="sl-body">
|
||||
<div v-if="loading && !conversations.length" class="sl-state">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在读取会话…
|
||||
</div>
|
||||
|
||||
<div v-else-if="error" class="sl-state error">
|
||||
<strong>{{ error.title }}</strong>
|
||||
<span>{{ error.message }}</span>
|
||||
<button class="sl-retry" type="button" @click="$emit('refresh')">重试</button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="!conversations.length" class="sl-empty">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M21 11.5a8.5 8.5 0 0 1-8.5 8.5H4l2-3.9A8.5 8.5 0 1 1 21 11.5Z" />
|
||||
</svg>
|
||||
<strong>{{ search.trim() ? '没有匹配的会话' : '还没有任何会话' }}</strong>
|
||||
<p v-if="search.trim()">换个关键词,或清空搜索查看全部会话。</p>
|
||||
<p v-else>绑定 NapCat 并收到消息后,会话会按「会话类型 + 会话 ID」自动出现在这里。</p>
|
||||
<slot v-if="!search.trim()" name="empty-action" />
|
||||
</div>
|
||||
|
||||
<div v-else class="sl-items">
|
||||
<button
|
||||
v-for="item in conversations"
|
||||
:key="item.key"
|
||||
type="button"
|
||||
class="conversation"
|
||||
:class="{ active: item.key === activeKey }"
|
||||
@click="$emit('select', item)"
|
||||
>
|
||||
<AvatarBadge
|
||||
:media-uid="item.avatarMediaUid"
|
||||
:name="item.nickname || item.name"
|
||||
:type="item.type"
|
||||
size="md"
|
||||
/>
|
||||
<span class="conv-main">
|
||||
<span class="conv-top">
|
||||
<span class="conv-name" :class="{ unknown: !item.nickname }">{{ item.name }}</span>
|
||||
<span class="conv-time">{{ item.timeLabel }}</span>
|
||||
</span>
|
||||
<span class="conv-bottom">
|
||||
<span class="conv-type">{{ item.typeLabel }}</span>
|
||||
<span class="conv-meta">{{ item.type === 'GROUP' ? '群号' : '账号' }} {{ item.account }} · {{ item.countLabel }} 条</span>
|
||||
<span v-if="item.unread" class="conv-unread" v-tooltip="'有新消息'"></span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="sl-pager">
|
||||
<span>共 {{ total }} 条 · 第 {{ page }} 页</span>
|
||||
<div class="sl-pager-actions">
|
||||
<button type="button" :disabled="!hasPrev || loading" @click="$emit('page-change', page - 1)">上一页</button>
|
||||
<button type="button" :disabled="!hasNext || loading" @click="$emit('page-change', page + 1)">下一页</button>
|
||||
</div>
|
||||
</footer>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.session-list {
|
||||
width: 276px;
|
||||
flex: 0 0 276px;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #F8F9FC;
|
||||
border-right: 1px solid #EDF0F5;
|
||||
}
|
||||
.sl-head {
|
||||
flex-shrink: 0;
|
||||
padding: 12px 12px 9px;
|
||||
border-bottom: 1px solid #EDF0F5;
|
||||
}
|
||||
.sl-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.sl-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #1f2329;
|
||||
}
|
||||
.sl-count {
|
||||
font-size: 11px;
|
||||
color: #8a8f99;
|
||||
}
|
||||
.sl-refresh {
|
||||
margin-left: auto;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #8a8f99;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.sl-refresh:hover:not(:disabled) {
|
||||
background: #ebedef;
|
||||
color: #4b5058;
|
||||
}
|
||||
.sl-refresh:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.sl-refresh svg {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
.sl-refresh svg.spinning {
|
||||
animation: sl-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes sl-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.sl-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 9px;
|
||||
height: 30px;
|
||||
padding: 0 8px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #E4E7EF;
|
||||
background: #fff;
|
||||
color: #9AA1B2;
|
||||
}
|
||||
.sl-search svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex-shrink: 0;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
.sl-search input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
background: transparent;
|
||||
color: #1f2329;
|
||||
font-size: 11px;
|
||||
}
|
||||
.sl-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #d4d6da transparent;
|
||||
}
|
||||
.sl-body::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
.sl-body::-webkit-scrollbar-thumb {
|
||||
background: #d4d6da;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.sl-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 36px 18px;
|
||||
color: #8a8f99;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.sl-state.error strong {
|
||||
color: #c0392b;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sl-state.error span {
|
||||
word-break: break-all;
|
||||
}
|
||||
.sl-retry {
|
||||
margin-top: 6px;
|
||||
border: 1px solid #d7d9dd;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
padding: 5px 12px;
|
||||
font-size: 12px;
|
||||
color: #4b5058;
|
||||
}
|
||||
.sl-empty {
|
||||
padding: 44px 22px;
|
||||
text-align: center;
|
||||
color: #8a8f99;
|
||||
}
|
||||
.sl-empty svg {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin-bottom: 12px;
|
||||
fill: none;
|
||||
stroke: #c6c9ce;
|
||||
stroke-width: 1.6;
|
||||
}
|
||||
.sl-empty strong {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: #4b5058;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sl-empty p {
|
||||
margin: 0 0 14px;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.sl-items {
|
||||
padding: 4px 6px;
|
||||
}
|
||||
.conversation {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
.conversation:hover {
|
||||
background: #EEF0FE;
|
||||
}
|
||||
.conversation.active {
|
||||
background: #EEF0FE;
|
||||
}
|
||||
.conv-main {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.conv-top {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
.conv-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #171B26;
|
||||
}
|
||||
.conv-name.unknown {
|
||||
color: #9AA1B2;
|
||||
font-weight: 400;
|
||||
}
|
||||
.conv-time {
|
||||
flex-shrink: 0;
|
||||
font-size: 9px;
|
||||
color: #9AA1B2;
|
||||
}
|
||||
.conv-bottom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.conv-type {
|
||||
flex-shrink: 0;
|
||||
padding: 0 4px;
|
||||
height: 14px;
|
||||
line-height: 14px;
|
||||
border-radius: 3px;
|
||||
background: #EEF0FE;
|
||||
color: #4F5BEF;
|
||||
font-size: 9px;
|
||||
}
|
||||
.conv-meta {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 9px;
|
||||
color: #9AA1B2;
|
||||
}
|
||||
.conv-unread {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 50%;
|
||||
background: #EF4444;
|
||||
}
|
||||
.sl-pager {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
height: 40px;
|
||||
padding: 0 12px;
|
||||
border-top: 1px solid #EDF0F5;
|
||||
font-size: 10px;
|
||||
color: #9AA1B2;
|
||||
}
|
||||
.sl-pager-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
.sl-pager-actions button {
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
padding: 0 5px;
|
||||
border: 1px solid #E4E7EF;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
color: #5B6172;
|
||||
font-size: 10px;
|
||||
font-family: var(--qk-font-num);
|
||||
}
|
||||
.sl-pager-actions button:hover:not(:disabled) {
|
||||
border-color: #A9B1FF;
|
||||
color: #4F5BEF;
|
||||
}
|
||||
.sl-pager-actions button:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: default;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
/**
|
||||
* 复选框:原生 input 仅作为无障碍与表单语义载体,视觉完全自绘。
|
||||
*/
|
||||
const props = defineProps({
|
||||
modelValue: { type: Boolean, default: false },
|
||||
value: { type: [String, Number, Boolean], default: true },
|
||||
disabled: Boolean,
|
||||
indeterminate: Boolean,
|
||||
label: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
const inputRef = ref(null)
|
||||
|
||||
const checked = computed(() => Boolean(props.modelValue))
|
||||
|
||||
function onChange(event) {
|
||||
const next = event.target.checked
|
||||
emit('update:modelValue', next)
|
||||
emit('change', next)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<label class="qk-checkbox" :class="{ 'is-disabled': disabled }" @click.stop>
|
||||
<input
|
||||
ref="inputRef"
|
||||
class="qk-checkbox__input"
|
||||
type="checkbox"
|
||||
:checked="checked"
|
||||
:disabled="disabled"
|
||||
:indeterminate="indeterminate"
|
||||
@change="onChange"
|
||||
/>
|
||||
<span class="qk-checkbox__box" aria-hidden="true" />
|
||||
<span v-if="label || $slots.default" class="qk-checkbox__text">
|
||||
<slot>{{ label }}</slot>
|
||||
</span>
|
||||
</label>
|
||||
</template>
|
||||
@@ -0,0 +1,103 @@
|
||||
<script setup>
|
||||
import { computed, ref, useAttrs } from 'vue'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
/**
|
||||
* 文本输入:默认根节点就是 input(可直接放在既有 .field / .fld 容器里,不改变布局语义),
|
||||
* 仅在需要标签或字数计数时才多包一层容器。
|
||||
*/
|
||||
const props = defineProps({
|
||||
modelValue: { type: [String, Number], default: '' },
|
||||
type: { type: String, default: 'text' },
|
||||
label: { type: String, default: '' },
|
||||
placeholder: { type: String, default: '' },
|
||||
hint: { type: String, default: '' },
|
||||
error: { type: String, default: '' },
|
||||
disabled: Boolean,
|
||||
readonly: Boolean,
|
||||
invalid: Boolean,
|
||||
size: { type: String, default: 'md' },
|
||||
maxlength: { type: [String, Number], default: undefined },
|
||||
showCount: Boolean,
|
||||
numeric: Boolean
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change', 'blur', 'focus', 'enter'])
|
||||
const attrs = useAttrs()
|
||||
const inputRef = ref(null)
|
||||
|
||||
const length = computed(() => String(props.modelValue ?? '').length)
|
||||
const limit = computed(() => (props.maxlength === undefined ? null : Number(props.maxlength)))
|
||||
const hasWrap = computed(() => Boolean(props.label || props.hint || props.error || props.showCount))
|
||||
|
||||
function onInput(event) {
|
||||
const raw = event.target.value
|
||||
emit('update:modelValue', props.numeric && raw !== '' ? Number(raw) : raw)
|
||||
}
|
||||
|
||||
function onChange(event) {
|
||||
emit('change', event)
|
||||
}
|
||||
|
||||
function onBlur(event) {
|
||||
emit('blur', event)
|
||||
}
|
||||
|
||||
function onFocus(event) {
|
||||
emit('focus', event)
|
||||
}
|
||||
|
||||
function onKeydown(event) {
|
||||
if (event.key === 'Enter') emit('enter', event)
|
||||
}
|
||||
|
||||
defineExpose({ focus: () => inputRef.value?.focus() })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="hasWrap" class="qk-field-wrap">
|
||||
<span v-if="label" class="qk-field-label">{{ label }}</span>
|
||||
<input
|
||||
ref="inputRef"
|
||||
v-bind="attrs"
|
||||
class="qk-field"
|
||||
:class="[`qk-field-${size}`, { 'is-invalid': invalid || error }]"
|
||||
:type="type"
|
||||
:value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:maxlength="maxlength"
|
||||
:aria-invalid="Boolean(invalid || error) || undefined"
|
||||
@input="onInput"
|
||||
@change="onChange"
|
||||
@blur="onBlur"
|
||||
@focus="onFocus"
|
||||
@keydown="onKeydown"
|
||||
/>
|
||||
<div v-if="hint || error || showCount" class="qk-field-meta">
|
||||
<span :class="{ 'qk-field-error': Boolean(error) }">{{ error || hint }}</span>
|
||||
<span v-if="showCount" class="qk-field-count">{{ length }}{{ limit ? `/${limit}` : '' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<input
|
||||
v-else
|
||||
ref="inputRef"
|
||||
v-bind="attrs"
|
||||
class="qk-field"
|
||||
:class="[`qk-field-${size}`, { 'is-invalid': invalid }]"
|
||||
:type="type"
|
||||
:value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:maxlength="maxlength"
|
||||
:aria-invalid="invalid || undefined"
|
||||
@input="onInput"
|
||||
@change="onChange"
|
||||
@blur="onBlur"
|
||||
@focus="onFocus"
|
||||
@keydown="onKeydown"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,102 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
/**
|
||||
* 通用弹窗外壳:Element Plus `el-dialog` 的薄封装。
|
||||
* 保留原有 props/插槽契约(open/title/subtitle/size/busy/head/body/foot),
|
||||
* ESC、遮罩关闭策略、焦点捕获与锁滚动由 el-dialog 承载;关闭后焦点回到触发元素。
|
||||
*/
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
title: { type: String, default: '' },
|
||||
subtitle: { type: String, default: '' },
|
||||
ariaLabel: { type: String, default: '' },
|
||||
size: { type: String, default: 'md' },
|
||||
closable: { type: Boolean, default: true },
|
||||
closeOnMask: { type: Boolean, default: true },
|
||||
closeOnEsc: { type: Boolean, default: true },
|
||||
busy: Boolean
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'opened', 'closed'])
|
||||
|
||||
const WIDTH = { sm: '420px', md: '576px', lg: '720px' }
|
||||
const dialogWidth = computed(() => WIDTH[props.size] || WIDTH.md)
|
||||
|
||||
let lastFocused = null
|
||||
|
||||
function onOpen() {
|
||||
lastFocused = document.activeElement
|
||||
emit('opened')
|
||||
}
|
||||
|
||||
function onClosed() {
|
||||
const target = lastFocused
|
||||
lastFocused = null
|
||||
if (target && typeof target.focus === 'function') {
|
||||
requestAnimationFrame(() => {
|
||||
try { target.focus() } catch { /* 元素可能已被移除 */ }
|
||||
})
|
||||
}
|
||||
emit('closed')
|
||||
}
|
||||
|
||||
// 关闭动作统一走 before-close,保证父组件先拿到 close 事件再决定是否收起(busy 时直接拒绝)。
|
||||
function onBeforeClose() {
|
||||
if (props.busy) return
|
||||
emit('close')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
class="qk-dialog"
|
||||
:model-value="open"
|
||||
:width="dialogWidth"
|
||||
:show-close="closable && !busy"
|
||||
:close-on-click-modal="closeOnMask && !busy"
|
||||
:close-on-press-escape="closeOnEsc && !busy"
|
||||
:before-close="onBeforeClose"
|
||||
:aria-label="ariaLabel || title || '对话框'"
|
||||
append-to-body
|
||||
align-center
|
||||
:style="{ maxWidth: 'calc(100vw - 32px)' }"
|
||||
@open="onOpen"
|
||||
@closed="onClosed"
|
||||
>
|
||||
<template #header>
|
||||
<div class="qk-dialog__head">
|
||||
<h3>{{ title }}</h3>
|
||||
<p v-if="subtitle">{{ subtitle }}</p>
|
||||
<slot name="head" />
|
||||
</div>
|
||||
</template>
|
||||
<slot />
|
||||
<template #footer>
|
||||
<div class="qk-dialog__foot">
|
||||
<slot name="foot" />
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.qk-dialog__head h3 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
line-height: 20px;
|
||||
color: var(--qk-text);
|
||||
}
|
||||
.qk-dialog__head p {
|
||||
margin: 4px 0 0;
|
||||
font-size: 10px;
|
||||
line-height: 1.55;
|
||||
color: var(--qk-text-4);
|
||||
}
|
||||
.qk-dialog__foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
/**
|
||||
* 静态提示条:替代页面里零散拼接的 .notice 结构,统一 4 种语义色。
|
||||
*/
|
||||
const props = defineProps({
|
||||
tone: { type: String, default: 'info' },
|
||||
title: { type: String, default: '' },
|
||||
closable: Boolean
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close'])
|
||||
const closed = ref(false)
|
||||
|
||||
const TONE_CLASS = { success: 'is-success', warning: 'is-warning', danger: 'is-danger', error: 'is-danger' }
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="!closed"
|
||||
class="qk-notice"
|
||||
:class="TONE_CLASS[tone] || ''"
|
||||
:role="tone === 'danger' || tone === 'error' ? 'alert' : 'status'"
|
||||
>
|
||||
<div class="qk-notice__body">
|
||||
<strong v-if="title">{{ title }}</strong>
|
||||
<slot />
|
||||
</div>
|
||||
<button v-if="closable" class="btn sm ghost" type="button" aria-label="关闭提示" @click="closed = true; emit('close')">×</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,145 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
/**
|
||||
* 下拉选择器:Element Plus `el-select` 的薄封装。
|
||||
* 保留原有 options API(value/label/hint/group/disabled),因此 53 处调用点无需改写;
|
||||
* 交互(键盘导航、过滤、浮层定位、可清空)与视觉由 el-select + styles/element-theme.css 统一承载。
|
||||
* readonly 场景按不可交互展示处理(映射为 disabled),与旧行为的视觉/语义一致。
|
||||
*/
|
||||
const props = defineProps({
|
||||
modelValue: { type: [String, Number, Boolean, Object, Array], default: '' },
|
||||
options: { type: Array, default: () => [] },
|
||||
placeholder: { type: String, default: '请选择' },
|
||||
searchable: { type: Boolean, default: false },
|
||||
clearable: { type: Boolean, default: false },
|
||||
disabled: Boolean,
|
||||
readonly: Boolean,
|
||||
block: Boolean,
|
||||
size: { type: String, default: 'md' },
|
||||
id: { type: String, default: '' },
|
||||
// 校验失败态:与 .field.is-invalid 同款红描边,保持表单前后端校验的视觉一致。
|
||||
invalid: Boolean,
|
||||
ariaLabel: { type: String, default: '' },
|
||||
emptyText: { type: String, default: '没有匹配的选项' },
|
||||
// 多选:值类型为数组;配合 searchable 支持过滤,标签过多时折叠为 +N。
|
||||
multiple: Boolean,
|
||||
collapseTags: Boolean,
|
||||
maxCollapseTags: { type: Number, default: 1 }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change', 'visible-change'])
|
||||
|
||||
const elSize = computed(() => ({ sm: 'small', lg: 'large' })[props.size] || 'default')
|
||||
|
||||
// 按出现顺序聚合分组,与旧自绘下拉的分组表现一致;无 group 的选项走平铺列表。
|
||||
const groupedOptions = computed(() => {
|
||||
const buckets = []
|
||||
props.options.forEach((option, index) => {
|
||||
const group = option?.group || ''
|
||||
const last = buckets[buckets.length - 1]
|
||||
const entry = { key: `o${index}`, option }
|
||||
if (last && last.group === group) last.items.push(entry)
|
||||
else buckets.push({ group, items: [entry] })
|
||||
})
|
||||
return buckets
|
||||
})
|
||||
|
||||
const hasGroups = computed(() => groupedOptions.value.some((bucket) => bucket.group))
|
||||
|
||||
function onUpdate(value) {
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
|
||||
function onChange(value) {
|
||||
emit('change', value)
|
||||
}
|
||||
|
||||
/** 打开/收起浮层;调用方可借此在展开前刷新选项数据(如连接状态)。 */
|
||||
function onVisibleChange(visible) {
|
||||
emit('visible-change', visible)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-select
|
||||
:id="id || undefined"
|
||||
class="qk-select"
|
||||
:class="[`is-${size}`, { 'is-block': block, 'is-invalid': invalid }]"
|
||||
:model-value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
:size="elSize"
|
||||
:disabled="disabled || readonly"
|
||||
:filterable="searchable"
|
||||
:clearable="clearable"
|
||||
:multiple="multiple"
|
||||
:collapse-tags="multiple && collapseTags"
|
||||
:max-collapse-tags="maxCollapseTags"
|
||||
:collapse-tags-tooltip="multiple && collapseTags"
|
||||
:fit-input-width="false"
|
||||
:no-data-text="emptyText"
|
||||
:aria-label="ariaLabel || placeholder"
|
||||
:aria-invalid="invalid || undefined"
|
||||
:teleported="true"
|
||||
@update:model-value="onUpdate"
|
||||
@change="onChange"
|
||||
@visible-change="onVisibleChange"
|
||||
>
|
||||
<template v-if="hasGroups">
|
||||
<template v-for="bucket in groupedOptions" :key="bucket.group || 'flat'">
|
||||
<el-option-group v-if="bucket.group" :label="bucket.group">
|
||||
<el-option
|
||||
v-for="entry in bucket.items"
|
||||
:key="entry.key"
|
||||
:label="entry.option?.label ?? String(entry.option?.value ?? '')"
|
||||
:value="entry.option?.value"
|
||||
:disabled="Boolean(entry.option?.disabled)"
|
||||
>
|
||||
<span class="qk-opt-label">{{ entry.option?.label }}</span>
|
||||
<span v-if="entry.option?.hint" class="qk-opt-hint">{{ entry.option.hint }}</span>
|
||||
</el-option>
|
||||
</el-option-group>
|
||||
<template v-else>
|
||||
<el-option
|
||||
v-for="entry in bucket.items"
|
||||
:key="entry.key"
|
||||
:label="entry.option?.label ?? String(entry.option?.value ?? '')"
|
||||
:value="entry.option?.value"
|
||||
:disabled="Boolean(entry.option?.disabled)"
|
||||
>
|
||||
<span class="qk-opt-label">{{ entry.option?.label }}</span>
|
||||
<span v-if="entry.option?.hint" class="qk-opt-hint">{{ entry.option.hint }}</span>
|
||||
</el-option>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-option
|
||||
v-for="(option, index) in options"
|
||||
:key="`o${index}`"
|
||||
:label="option?.label ?? String(option?.value ?? '')"
|
||||
:value="option?.value"
|
||||
:disabled="Boolean(option?.disabled)"
|
||||
>
|
||||
<span class="qk-opt-label">{{ option?.label }}</span>
|
||||
<span v-if="option?.hint" class="qk-opt-hint">{{ option.hint }}</span>
|
||||
</el-option>
|
||||
</template>
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.qk-opt-label {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.qk-opt-hint {
|
||||
flex: none;
|
||||
margin-left: 8px;
|
||||
font-size: 10px;
|
||||
color: var(--qk-text-4);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup>
|
||||
/**
|
||||
* 开关:真实 button[role=switch],支持键盘 Space/Enter,禁用态不响应。
|
||||
*/
|
||||
const props = defineProps({
|
||||
modelValue: { type: Boolean, default: false },
|
||||
disabled: Boolean,
|
||||
ariaLabel: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
|
||||
function toggle() {
|
||||
if (props.disabled) return
|
||||
emit('update:modelValue', !props.modelValue)
|
||||
emit('change', !props.modelValue)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
class="qk-switch"
|
||||
role="switch"
|
||||
:aria-checked="modelValue"
|
||||
:aria-label="ariaLabel || '开关'"
|
||||
:disabled="disabled"
|
||||
@click="toggle"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,74 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
/**
|
||||
* 多行文本:默认根节点是 textarea,保留既有 .field 布局;仅在需要标签/计数时包裹容器。
|
||||
*/
|
||||
const props = defineProps({
|
||||
modelValue: { type: String, default: '' },
|
||||
label: { type: String, default: '' },
|
||||
placeholder: { type: String, default: '' },
|
||||
hint: { type: String, default: '' },
|
||||
error: { type: String, default: '' },
|
||||
rows: { type: [String, Number], default: 4 },
|
||||
disabled: Boolean,
|
||||
readonly: Boolean,
|
||||
invalid: Boolean,
|
||||
maxlength: { type: [String, Number], default: undefined },
|
||||
showCount: Boolean,
|
||||
autoResize: Boolean
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change', 'blur'])
|
||||
|
||||
const length = computed(() => String(props.modelValue ?? '').length)
|
||||
const limit = computed(() => (props.maxlength === undefined ? null : Number(props.maxlength)))
|
||||
const hasWrap = computed(() => Boolean(props.label || props.hint || props.error || props.showCount))
|
||||
|
||||
function onInput(event) {
|
||||
emit('update:modelValue', event.target.value)
|
||||
if (props.autoResize) {
|
||||
event.target.style.height = 'auto'
|
||||
event.target.style.height = `${event.target.scrollHeight}px`
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="hasWrap" class="qk-field-wrap">
|
||||
<span v-if="label" class="qk-field-label">{{ label }}</span>
|
||||
<textarea
|
||||
class="qk-field"
|
||||
:class="{ 'is-invalid': invalid || error }"
|
||||
:value="modelValue"
|
||||
:rows="rows"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:maxlength="maxlength"
|
||||
:aria-invalid="Boolean(invalid || error) || undefined"
|
||||
@input="onInput"
|
||||
@change="emit('change', $event)"
|
||||
@blur="emit('blur', $event)"
|
||||
/>
|
||||
<div v-if="hint || error || showCount" class="qk-field-meta">
|
||||
<span :class="{ 'qk-field-error': Boolean(error) }">{{ error || hint }}</span>
|
||||
<span v-if="showCount" class="qk-field-count">{{ length }}{{ limit ? `/${limit}` : '' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<textarea
|
||||
v-else
|
||||
class="qk-field"
|
||||
:class="{ 'is-invalid': invalid }"
|
||||
:value="modelValue"
|
||||
:rows="rows"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:maxlength="maxlength"
|
||||
:aria-invalid="invalid || undefined"
|
||||
@input="onInput"
|
||||
@change="emit('change', $event)"
|
||||
@blur="emit('blur', $event)"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,59 @@
|
||||
<script setup>
|
||||
import { nextTick, onBeforeUnmount, ref } from 'vue'
|
||||
|
||||
/**
|
||||
* 轻量 Tooltip:替代原生 title 属性。鼠标悬停、键盘聚焦都会显示,位置自动翻转。
|
||||
*/
|
||||
const props = defineProps({
|
||||
content: { type: String, default: '' },
|
||||
placement: { type: String, default: 'top' },
|
||||
delay: { type: Number, default: 120 },
|
||||
disabled: Boolean
|
||||
})
|
||||
|
||||
const rootRef = ref(null)
|
||||
const visible = ref(false)
|
||||
const style = ref({})
|
||||
let timer = 0
|
||||
|
||||
const TEXT_WIDTH = 240
|
||||
|
||||
function measure() {
|
||||
const anchor = rootRef.value
|
||||
if (!anchor) return
|
||||
const rect = anchor.getBoundingClientRect()
|
||||
const place = props.placement === 'bottom' ? 'bottom' : 'top'
|
||||
style.value = {
|
||||
left: `${Math.max(8, Math.min(rect.left + rect.width / 2 - TEXT_WIDTH / 2, window.innerWidth - TEXT_WIDTH - 8))}px`,
|
||||
minWidth: `${Math.min(rect.width, TEXT_WIDTH)}px`,
|
||||
...(place === 'bottom'
|
||||
? { top: `${rect.bottom + 6}px` }
|
||||
: { bottom: `${window.innerHeight - rect.top + 6}px` })
|
||||
}
|
||||
}
|
||||
|
||||
function show() {
|
||||
if (props.disabled || !props.content) return
|
||||
window.clearTimeout(timer)
|
||||
timer = window.setTimeout(() => {
|
||||
visible.value = true
|
||||
nextTick(measure)
|
||||
}, props.delay)
|
||||
}
|
||||
|
||||
function hide() {
|
||||
window.clearTimeout(timer)
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => window.clearTimeout(timer))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span ref="rootRef" class="qk-tooltip" @mouseenter="show" @mouseleave="hide" @focusin="show" @focusout="hide">
|
||||
<slot />
|
||||
<Teleport to="body">
|
||||
<span v-if="visible" class="qk-tooltip-pop" :style="style" role="tooltip">{{ content }}</span>
|
||||
</Teleport>
|
||||
</span>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
import { h } from 'vue'
|
||||
|
||||
/**
|
||||
* 命令式确认:基于 Element Plus `ElMessageBox`,返回 Promise<boolean>。
|
||||
* - 取消、关闭(X / ESC)都解析为 false,不产生任何变更;
|
||||
* - tone === 'danger' 时确认按钮渲染为红色实心(危险操作),其余为常规主色;
|
||||
* - 文案(title/message/hint)沿用调用方传入的中文,不在封装层改写。
|
||||
*/
|
||||
export function askConfirm(options = {}) {
|
||||
// 同一时间只处理一个确认请求:新请求先关闭上一条,避免弹窗叠层与 Promise 悬挂。
|
||||
ElMessageBox.close()
|
||||
|
||||
const {
|
||||
title = '确认操作',
|
||||
message = '',
|
||||
hint = '',
|
||||
confirmText = '确认',
|
||||
cancelText = '取消',
|
||||
tone = 'primary'
|
||||
} = options
|
||||
|
||||
return ElMessageBox.confirm(
|
||||
() =>
|
||||
h('div', { class: 'qk-confirm-body' }, [
|
||||
message ? h('div', { class: 'qk-confirm-text' }, message) : null,
|
||||
hint ? h('div', { class: 'qk-confirm-hint' }, hint) : null
|
||||
]),
|
||||
title,
|
||||
{
|
||||
confirmButtonText: confirmText,
|
||||
cancelButtonText: cancelText,
|
||||
showCancelButton: true,
|
||||
showClose: true,
|
||||
closeOnClickModal: false,
|
||||
closeOnPressEscape: true,
|
||||
confirmButtonClass: tone === 'danger' ? 'qk-btn-danger' : '',
|
||||
customClass: 'qk-confirm'
|
||||
}
|
||||
).then(
|
||||
() => true,
|
||||
() => false
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export { default as Select } from './Select.vue'
|
||||
export { default as Modal } from './Modal.vue'
|
||||
export { default as Input } from './Input.vue'
|
||||
export { default as Textarea } from './Textarea.vue'
|
||||
export { default as Switch } from './Switch.vue'
|
||||
export { default as Checkbox } from './Checkbox.vue'
|
||||
export { default as Tooltip } from './Tooltip.vue'
|
||||
export { default as Notice } from './Notice.vue'
|
||||
export { askConfirm } from './feedback'
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* v-tooltip 指令:批量替代原生 title 属性,不改变既有 DOM 结构与布局。
|
||||
* 用法:v-tooltip="'说明文字'" 或 v-tooltip="{ content: '说明', placement: 'bottom' }"
|
||||
* 与 <Tooltip> 组件共用 .qk-tooltip-pop 样式。
|
||||
*/
|
||||
const state = new WeakMap()
|
||||
const DELAY = 120
|
||||
|
||||
function clearTimer(record) {
|
||||
if (record?.timer) window.clearTimeout(record.timer)
|
||||
}
|
||||
|
||||
function removeTip(record) {
|
||||
if (record?.tip?.parentNode) record.tip.parentNode.removeChild(record.tip)
|
||||
if (record) record.tip = null
|
||||
}
|
||||
|
||||
function hide(el) {
|
||||
const record = state.get(el)
|
||||
if (!record) return
|
||||
clearTimer(record)
|
||||
removeTip(record)
|
||||
}
|
||||
|
||||
function place(el, text, placement) {
|
||||
const tip = document.createElement('div')
|
||||
tip.className = 'qk-tooltip-pop'
|
||||
tip.setAttribute('role', 'tooltip')
|
||||
tip.textContent = text
|
||||
document.body.appendChild(tip)
|
||||
const rect = el.getBoundingClientRect()
|
||||
const width = Math.min(tip.offsetWidth || 0, 240)
|
||||
const left = Math.max(8, Math.min(rect.left + rect.width / 2 - width / 2, window.innerWidth - width - 8))
|
||||
tip.style.left = `${left}px`
|
||||
if (placement === 'bottom') tip.style.top = `${rect.bottom + 6}px`
|
||||
else tip.style.bottom = `${window.innerHeight - rect.top + 6}px`
|
||||
return tip
|
||||
}
|
||||
|
||||
function show(el, binding) {
|
||||
const raw = binding.value
|
||||
const text = typeof raw === 'string' ? raw : raw?.content
|
||||
const placement = typeof raw === 'object' && raw?.placement ? raw.placement : 'top'
|
||||
if (!text) return
|
||||
hide(el)
|
||||
const record = state.get(el) || {}
|
||||
record.timer = window.setTimeout(() => {
|
||||
removeTip(record)
|
||||
record.tip = place(el, text, placement)
|
||||
state.set(el, record)
|
||||
}, DELAY)
|
||||
state.set(el, record)
|
||||
}
|
||||
|
||||
function normalize(el, binding) {
|
||||
// 原生 title 会与自绘提示重复,移除它,但保留 aria-label 语义。
|
||||
if (el.hasAttribute('title')) el.removeAttribute('title')
|
||||
show(el, binding)
|
||||
}
|
||||
|
||||
export const vTooltip = {
|
||||
mounted(el, binding) {
|
||||
el.__qkTooltipShow = () => normalize(el, binding)
|
||||
el.__qkTooltipHide = () => hide(el)
|
||||
el.addEventListener('mouseenter', el.__qkTooltipShow)
|
||||
el.addEventListener('focusin', el.__qkTooltipShow)
|
||||
el.addEventListener('mouseleave', el.__qkTooltipHide)
|
||||
el.addEventListener('focusout', el.__qkTooltipHide)
|
||||
el.addEventListener('click', el.__qkTooltipHide)
|
||||
},
|
||||
updated(el, binding) {
|
||||
if (el.hasAttribute('title')) el.removeAttribute('title')
|
||||
if (binding.value !== binding.oldValue) {
|
||||
hide(el)
|
||||
el.__qkTooltipShow = () => normalize(el, binding)
|
||||
}
|
||||
},
|
||||
unmounted(el) {
|
||||
hide(el)
|
||||
el.removeEventListener('mouseenter', el.__qkTooltipShow)
|
||||
el.removeEventListener('focusin', el.__qkTooltipShow)
|
||||
el.removeEventListener('mouseleave', el.__qkTooltipHide)
|
||||
el.removeEventListener('focusout', el.__qkTooltipHide)
|
||||
el.removeEventListener('click', el.__qkTooltipHide)
|
||||
}
|
||||
}
|
||||
|
||||
export function installTooltip(app) {
|
||||
app.directive('tooltip', vTooltip)
|
||||
}
|
||||
@@ -4,13 +4,15 @@ import App from './App.vue'
|
||||
import { getToken } from './api'
|
||||
import './styles/prototype.css'
|
||||
import './styles/app.css'
|
||||
|
||||
import './styles/ui.css'
|
||||
import { vTooltip } from './components/ui/tooltip'
|
||||
import DashboardView from './views/DashboardView.vue'
|
||||
import MessagesView from './views/MessagesView.vue'
|
||||
import ContactsView from './views/ContactsView.vue'
|
||||
import MessageSearchView from './views/MessageSearchView.vue'
|
||||
import ConnectionsView from './views/ConnectionsView.vue'
|
||||
import AutomationView from './views/AutomationView.vue'
|
||||
import AiView from './views/AiView.vue'
|
||||
import AiCenterView from './views/ai/AiCenterView.vue'
|
||||
import OpsView from './views/OpsView.vue'
|
||||
import LogsView from './views/LogsView.vue'
|
||||
import BackupView from './views/BackupView.vue'
|
||||
@@ -18,6 +20,9 @@ import SecurityView from './views/SecurityView.vue'
|
||||
import SettingsView from './views/SettingsView.vue'
|
||||
import LoginView from './views/LoginView.vue'
|
||||
import BootstrapView from './views/BootstrapView.vue'
|
||||
// Element Plus 主题覆盖:放在所有视图 import 之后,确保按需注入的 Element 组件样式先加载,
|
||||
// 这里的 --el-* 变量与组件级穿透后加载才能稳定生效。
|
||||
import './styles/element-theme.css'
|
||||
|
||||
// 使用 hash 路由:构建产物 dist/index.html 可被 file:// 直接打开预览,
|
||||
// 部署到任意子路径时也不需要额外的服务端路由重写。
|
||||
@@ -31,10 +36,11 @@ const router = createRouter({
|
||||
|
||||
{ path: '/dashboard', component: DashboardView, meta: { title: '工作台', group: '工作空间' } },
|
||||
{ path: '/messages', component: MessagesView, meta: { title: '消息中心', group: '工作空间' } },
|
||||
{ path: '/contacts', component: ContactsView, meta: { title: '联系人中心', group: '工作空间' } },
|
||||
{ path: '/message-search', component: MessageSearchView, meta: { title: '消息检索', group: '工作空间' } },
|
||||
{ path: '/connections', component: ConnectionsView, meta: { title: '接入管理', group: '工作空间' } },
|
||||
{ path: '/automation', component: AutomationView, meta: { title: '自动化规则', group: '工作空间' } },
|
||||
{ path: '/ai', component: AiView, meta: { title: 'AI 能力', group: '工作空间' } },
|
||||
{ path: '/automation', component: AutomationView, meta: { title: '自动化中心', group: '工作空间' } },
|
||||
{ path: '/ai', component: AiCenterView, meta: { title: 'AI 中心', group: '工作空间' } },
|
||||
{ path: '/ops', component: OpsView, meta: { title: '运维监控', group: '工作空间' } },
|
||||
{ path: '/logs', component: LogsView, meta: { title: '日志中心', group: '工作空间' } },
|
||||
{ path: '/backup', component: BackupView, meta: { title: '备份与恢复', group: '平台管理' } },
|
||||
@@ -51,4 +57,7 @@ router.beforeEach((to) => {
|
||||
return true
|
||||
})
|
||||
|
||||
createApp(App).use(router).mount('#app')
|
||||
const app = createApp(App)
|
||||
// 自绘 Tooltip 指令:批量替代原生 title 属性,不新增运行时依赖。
|
||||
app.directive('tooltip', vTooltip)
|
||||
app.use(router).mount('#app')
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { reactive } from 'vue'
|
||||
import { api } from './api'
|
||||
|
||||
/**
|
||||
* 当前登录账号与权限(来源 /api/v1/auth/me)。
|
||||
* can() 返回 true/false;若后端未返回 permissions 字段则返回 null,
|
||||
* 表示前端无法预判,按钮保持可用、由后端做最终校验,界面需显式说明。
|
||||
*/
|
||||
export const sessionState = reactive({
|
||||
user: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
loaded: false
|
||||
})
|
||||
|
||||
export function setSessionUser(user) {
|
||||
sessionState.user = user || null
|
||||
sessionState.loaded = true
|
||||
}
|
||||
|
||||
export async function loadMe() {
|
||||
if (sessionState.loading) return sessionState.user
|
||||
sessionState.loading = true
|
||||
sessionState.error = null
|
||||
try {
|
||||
const user = await api.me()
|
||||
setSessionUser(user)
|
||||
return user
|
||||
} catch (error) {
|
||||
sessionState.user = null
|
||||
sessionState.error = error
|
||||
throw error
|
||||
} finally {
|
||||
sessionState.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
export function can(permission) {
|
||||
if (!permission) return true
|
||||
const permissions = sessionState.user?.permissions
|
||||
if (!Array.isArray(permissions)) return null
|
||||
return permissions.includes(permission)
|
||||
}
|
||||
|
||||
export function denialReason(permission, action) {
|
||||
const allowed = can(permission)
|
||||
if (allowed === null) {
|
||||
return `后端未返回权限清单,前端无法预判;${action}仍会由后端校验,可能被拒绝。`
|
||||
}
|
||||
if (!allowed) {
|
||||
return `当前账号缺少「${permission}」权限,无法${action}。`
|
||||
}
|
||||
return ''
|
||||
}
|
||||
@@ -150,9 +150,10 @@ button:disabled { cursor: not-allowed; opacity: .55; }
|
||||
padding: 38px 34px; background: light-dark(#172554, #0b1120); color: #fff;
|
||||
display: flex; flex-direction: column; gap: 34px;
|
||||
}
|
||||
.auth-brand .brand-text strong { color: #fff; }
|
||||
.auth-brand .brand-text span { color: #9fb0d8; }
|
||||
.auth-brand .logo { background: #fff; color: var(--site-primary); box-shadow: none; }
|
||||
.auth-brand .brand { flex-direction: column; align-items: flex-start; gap: 12px; }
|
||||
.auth-brand .brand-lockup { display: block; line-height: 0; border-radius: 10px; overflow: hidden; }
|
||||
.auth-brand .brand-lockup img { display: block; width: auto; height: 54px; }
|
||||
.auth-brand .brand-tagline { font-size: 11px; color: #9fb0d8; font-weight: 500; letter-spacing: 0; }
|
||||
.auth-pitch h1 { font-size: 26px; line-height: 1.35; letter-spacing: -.6px; margin: 0 0 12px; }
|
||||
.auth-pitch p { color: #b8c6e6; line-height: 1.7; margin: 0 0 22px; font-size: 13px; }
|
||||
.auth-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
|
||||
@@ -216,3 +217,648 @@ button:disabled { cursor: not-allowed; opacity: .55; }
|
||||
.filterbar .field { flex: 1 1 120px; }
|
||||
.pager { flex-direction: column; align-items: flex-start; }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 可收起导航侧边栏 */
|
||||
.sidebar {
|
||||
transition: width .24s cubic-bezier(.4, 0, .2, 1), padding .24s cubic-bezier(.4, 0, .2, 1);
|
||||
}
|
||||
|
||||
.sidebar-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
min-height: 30px;
|
||||
padding: 0 5px 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.sidebar-head-title {
|
||||
padding-left: 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
color: #98a2b5;
|
||||
white-space: nowrap;
|
||||
transition: opacity .14s ease, max-width .2s ease;
|
||||
}
|
||||
.nav-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 7px;
|
||||
background: var(--card-bg);
|
||||
color: var(--muted-strong);
|
||||
cursor: pointer;
|
||||
transition: background .15s ease, color .15s ease, border-color .15s ease;
|
||||
}
|
||||
.nav-toggle:hover {
|
||||
background: light-dark(#f2f5ff, #1d2a40);
|
||||
border-color: var(--line-strong);
|
||||
color: var(--site-primary);
|
||||
}
|
||||
.nav-toggle:focus-visible {
|
||||
outline: 2px solid var(--site-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.nav-toggle svg {
|
||||
transition: transform .24s cubic-bezier(.4, 0, .2, 1);
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
position: relative;
|
||||
transition: gap .24s cubic-bezier(.4, 0, .2, 1), padding .24s cubic-bezier(.4, 0, .2, 1);
|
||||
}
|
||||
.nav-text {
|
||||
max-width: 170px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
transition: max-width .24s cubic-bezier(.4, 0, .2, 1), opacity .14s ease;
|
||||
}
|
||||
.nav-label {
|
||||
max-height: 40px;
|
||||
overflow: hidden;
|
||||
transition: max-height .24s cubic-bezier(.4, 0, .2, 1), opacity .14s ease,
|
||||
padding .24s cubic-bezier(.4, 0, .2, 1);
|
||||
}
|
||||
.sidebar-bottom {
|
||||
margin-top: auto;
|
||||
max-height: 220px;
|
||||
overflow: visible;
|
||||
transition: max-height .24s cubic-bezier(.4, 0, .2, 1), opacity .14s ease,
|
||||
padding .24s cubic-bezier(.4, 0, .2, 1), border-width .24s ease;
|
||||
}
|
||||
|
||||
.sidebar.collapsed {
|
||||
width: 64px;
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
.sidebar.collapsed .sidebar-head {
|
||||
justify-content: center;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
.sidebar.collapsed .sidebar-head-title {
|
||||
max-width: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
.sidebar.collapsed .nav-label {
|
||||
max-height: 0;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
.sidebar.collapsed .nav-text {
|
||||
max-width: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
.sidebar.collapsed .nav-item {
|
||||
gap: 0;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
justify-content: center;
|
||||
}
|
||||
.sidebar.collapsed .sidebar-bottom {
|
||||
max-height: 60px;
|
||||
padding: 0;
|
||||
border-width: 0;
|
||||
background: transparent;
|
||||
overflow: visible;
|
||||
opacity: 1;
|
||||
}
|
||||
/* 收起态只保留账号头像:昵称、QQ 与「切换」文字隐藏,避免挤压 64px 栏宽。 */
|
||||
.sidebar.collapsed .sidebar-bottom .account-meta,
|
||||
.sidebar.collapsed .sidebar-bottom .account-switch-text {
|
||||
display: none;
|
||||
}
|
||||
.sidebar.collapsed .sidebar-bottom .account-trigger {
|
||||
justify-content: center;
|
||||
padding: 4px;
|
||||
}
|
||||
.sidebar.collapsed .sidebar-bottom .account-popover {
|
||||
left: 0;
|
||||
width: 264px;
|
||||
}
|
||||
.sidebar.collapsed .nav-toggle svg {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
/* 收起态:悬浮 / 键盘聚焦时显示文字标签。 */
|
||||
.sidebar.collapsed .nav-item::after {
|
||||
content: attr(data-label);
|
||||
position: absolute;
|
||||
left: calc(100% + 10px);
|
||||
top: 50%;
|
||||
z-index: 30;
|
||||
padding: 5px 9px;
|
||||
border-radius: 7px;
|
||||
background: light-dark(#1f2a3d, #e6ecff);
|
||||
color: light-dark(#ffffff, #1f2a3d);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transform: translateY(-50%) translateX(-4px);
|
||||
transition: opacity .14s ease, transform .14s ease;
|
||||
box-shadow: 0 8px 22px #1018282e;
|
||||
}
|
||||
.sidebar.collapsed .nav-item:hover::after,
|
||||
.sidebar.collapsed .nav-item:focus-visible::after {
|
||||
opacity: 1;
|
||||
transform: translateY(-50%) translateX(0);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.sidebar,
|
||||
.sidebar .nav-toggle svg,
|
||||
.sidebar .nav-item,
|
||||
.sidebar .nav-text,
|
||||
.sidebar .nav-label,
|
||||
.sidebar .sidebar-bottom {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 管理台 v1 设计 token */
|
||||
/* 取值来源:docs/design/qlinker-admin-v1/设计规范与组件清单.md 1.1–1.7。 */
|
||||
:root {
|
||||
--site-primary: #4F5BEF;
|
||||
--site-background: #F6F7FB;
|
||||
--site-on-background: #171B26;
|
||||
|
||||
--qk-bg: #F6F7FB;
|
||||
--qk-card: #FFFFFF;
|
||||
--qk-line: #EDF0F5;
|
||||
--qk-line-strong: #E4E7EF;
|
||||
--qk-primary: #4F5BEF;
|
||||
--qk-primary-weak: #EEF0FE;
|
||||
--qk-primary-ink: #3B46C9;
|
||||
--qk-slate-weak: #F8F9FC;
|
||||
--qk-text: #171B26;
|
||||
--qk-text-2: #5B6172;
|
||||
--qk-text-3: #6B7280;
|
||||
--qk-text-4: #9AA1B2;
|
||||
--qk-green: #22C55E;
|
||||
--qk-green-ink: #15803D;
|
||||
--qk-green-weak: #F0FDF4;
|
||||
--qk-red: #EF4444;
|
||||
--qk-red-ink: #B91C1C;
|
||||
--qk-red-weak: #FEF2F2;
|
||||
--qk-amber: #F59E0B;
|
||||
--qk-amber-ink: #B45309;
|
||||
--qk-amber-weak: #FFFBEB;
|
||||
--qk-cyan: #0EA5E9;
|
||||
--qk-cyan-ink: #0369A1;
|
||||
--qk-cyan-weak: #F0F9FF;
|
||||
--qk-head-bg: #FAFBFD;
|
||||
--qk-font-num: 'Inter', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||
--qk-font-mono: 'Consolas', 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
body,
|
||||
.app {
|
||||
background: light-dark(var(--qk-bg), #0c1220);
|
||||
color: light-dark(var(--qk-text), #e7ecf6);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 顶栏 52px:面包屑 + 实例胶囊 + 模式 + 账号 */
|
||||
.topbar {
|
||||
height: 52px;
|
||||
padding: 0 20px;
|
||||
gap: 12px;
|
||||
background: light-dark(var(--qk-card), #121b2b);
|
||||
border-bottom: 1px solid light-dark(var(--qk-line), #253147);
|
||||
}
|
||||
.shell { min-height: calc(100vh - 52px); }
|
||||
.topbar .crumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
font-size: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
.topbar .crumb strong { color: light-dark(var(--qk-text), #e7ecf6); font-weight: 650; }
|
||||
.topbar .crumb-sep { color: light-dark(var(--qk-text-4), #6b788f); }
|
||||
.topbar .instance {
|
||||
height: 24px;
|
||||
padding: 0 8px;
|
||||
border: 1px solid light-dark(var(--qk-line-strong), #344158);
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.topbar .instance .dot-live { width: 6px; height: 6px; border-radius: 50%; background: var(--qk-green); }
|
||||
.topbar .instance span { color: light-dark(var(--qk-text-2), #b3bed0); font-family: var(--qk-font-num); }
|
||||
.topbar .mode-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
height: 24px;
|
||||
padding: 0 8px;
|
||||
border-radius: 6px;
|
||||
background: var(--qk-green-weak);
|
||||
color: var(--qk-green-ink);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.topbar .mode-chip:before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--qk-green); }
|
||||
.topbar .global-search {
|
||||
height: 30px;
|
||||
max-width: 320px;
|
||||
border-radius: 6px;
|
||||
border-color: light-dark(var(--qk-line-strong), #334057);
|
||||
background: light-dark(var(--qk-slate-weak), #192437);
|
||||
font-size: 11px;
|
||||
}
|
||||
.topbar .top-actions { gap: 8px; }
|
||||
.topbar .icon-btn {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
border-color: light-dark(var(--qk-line-strong), #344158);
|
||||
background: light-dark(var(--qk-card), #1a2638);
|
||||
}
|
||||
.topbar .avatar {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background: var(--qk-primary);
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
/* 侧栏 238 / 64 */
|
||||
.sidebar {
|
||||
position: relative;
|
||||
width: 238px;
|
||||
padding: 14px 12px;
|
||||
gap: 2px;
|
||||
background: light-dark(var(--qk-card), #121b2b);
|
||||
border-right: 1px solid light-dark(var(--qk-line), #253147);
|
||||
}
|
||||
.sidebar-head { min-height: 38px; padding: 0 6px 10px; gap: 6px; justify-content: flex-start; }
|
||||
.sidebar-brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
|
||||
.sidebar-brand .brand-logo {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 7px;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
flex-shrink: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
.sidebar-brand .brand-logo img { display: block; width: 100%; height: 100%; }
|
||||
.sidebar-brand .brand-text strong { font-size: 15px; letter-spacing: -.2px; }
|
||||
.sidebar-brand .brand-text span { font-size: 10px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.sidebar .nav-toggle {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 1px solid transparent;
|
||||
background: light-dark(var(--qk-bg), #1d2a40);
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
border-radius: 6px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.sidebar .nav-label { font-size: 11px; line-height: 16px; color: light-dark(var(--qk-text-4), #8a96aa); font-weight: 500; letter-spacing: 0; padding: 8px 10px 4px; }
|
||||
.sidebar .nav-item { height: 34px; padding: 0 10px; border-radius: 8px; gap: 9px; font-size: 13px; font-weight: 500; color: light-dark(var(--qk-text-2), #a8b3c8); }
|
||||
.sidebar .nav-item:hover { background: light-dark(var(--qk-bg), #1d2a40); color: var(--qk-primary); }
|
||||
.sidebar .nav-item.active { background: var(--qk-primary-weak); color: var(--qk-primary); font-weight: 600; }
|
||||
.sidebar .nav-icon { width: 18px; font-size: 14px; }
|
||||
.sidebar .sidebar-bottom { border: 1px solid light-dark(var(--qk-line), #2b374d); border-radius: 10px; padding: 11px 11px 10px; background: light-dark(var(--qk-slate-weak), #182337); }
|
||||
.sidebar .sidebar-bottom strong { font-size: 11px; color: light-dark(#374151, #e7ecf6); }
|
||||
.sidebar .sidebar-bottom p { font-size: 10px; line-height: 15px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.sidebar .sidebar-bottom .btn { height: 24px; font-size: 10.5px; }
|
||||
.sidebar.collapsed { width: 64px; padding: 14px 10px; }
|
||||
.sidebar.collapsed .sidebar-head { justify-content: center; gap: 2px; padding: 0 0 12px; }
|
||||
.sidebar.collapsed .sidebar-brand { flex: 0 0 auto; }
|
||||
.sidebar.collapsed .sidebar-brand .brand-logo { width: 24px; height: 24px; }
|
||||
.sidebar.collapsed .sidebar-brand .brand-text { display: none; }
|
||||
.sidebar.collapsed .sidebar-head .nav-toggle { width: 22px; height: 22px; margin-left: 0; }
|
||||
.sidebar.collapsed .nav-label { max-height: 0; padding: 0; opacity: 0; }
|
||||
.sidebar.collapsed .nav-item { height: 36px; border-radius: 8px; }
|
||||
|
||||
/* 内容区与卡片 */
|
||||
.content { padding: 20px 24px 32px; max-width: none; }
|
||||
.grid { gap: 12px; }
|
||||
.stats { gap: 12px; margin-bottom: 12px; }
|
||||
.card {
|
||||
background: light-dark(var(--qk-card), #121b2b);
|
||||
border: 1px solid light-dark(var(--qk-line), #273247);
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
}
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 46px;
|
||||
margin: -16px -16px 12px;
|
||||
padding: 0 14px;
|
||||
border-bottom: 1px solid light-dark(var(--qk-line), #253147);
|
||||
}
|
||||
.card-title { font-size: 13px; line-height: 18px; font-weight: 600; }
|
||||
.card-sub { font-size: 11px; color: light-dark(var(--qk-text-4), #8a96aa); font-weight: 400; }
|
||||
.stat-top { font-size: 11px; color: light-dark(var(--qk-text-3), #b3bed0); }
|
||||
.stat-icon { width: 30px; height: 30px; border-radius: 8px; font-size: 14px; background: var(--qk-primary-weak); color: var(--qk-primary); }
|
||||
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin: 8px 0 4px; font-family: var(--qk-font-num); font-variant-numeric: tabular-nums; }
|
||||
.stat-foot { font-size: 10px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
|
||||
/* 表格 */
|
||||
th {
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
background: light-dark(var(--qk-head-bg), #172235);
|
||||
border-bottom: 1px solid light-dark(var(--qk-line), #2b374c);
|
||||
}
|
||||
td {
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid light-dark(var(--qk-line), #253147);
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
}
|
||||
tbody tr { height: 58px; }
|
||||
.table-compact th { height: 30px; }
|
||||
.table-compact td { height: 36px; padding: 3px 10px; }
|
||||
.table-compact tbody tr { height: 36px; }
|
||||
.identity { gap: 8px; min-width: 120px; }
|
||||
.identity strong { font-size: 11.5px; line-height: 16px; font-weight: 600; }
|
||||
.identity span { font-size: 9px; line-height: 13px; color: light-dark(var(--qk-text-4), #8a96aa); margin-top: 2px; font-family: var(--qk-font-num); }
|
||||
.mini-avatar { width: 28px; height: 28px; border-radius: 7px; font-size: 12px; background: var(--qk-primary-weak); color: var(--qk-primary); }
|
||||
.table-actions { gap: 6px; align-items: center; }
|
||||
.small-muted { color: light-dark(var(--qk-text-4), #8a96aa); font-size: 10px; }
|
||||
|
||||
/* 按钮 / 输入 / 页签 / 徽标 */
|
||||
.btn {
|
||||
height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
gap: 5px;
|
||||
border-color: light-dark(var(--qk-line-strong), #3a465d);
|
||||
background: light-dark(var(--qk-card), #1a2638);
|
||||
color: inherit;
|
||||
}
|
||||
.btn:hover { border-color: #A9B1FF; }
|
||||
.btn.primary { background: var(--qk-primary); border-color: var(--qk-primary); color: #fff; }
|
||||
.btn.primary:hover { background: #4450DD; }
|
||||
.btn.danger { color: var(--qk-red-ink); border-color: #FBD5D5; }
|
||||
.btn.danger:hover { background: var(--qk-red-weak); }
|
||||
.btn.sm, .btn.xs { height: 24px; padding: 0 8px; font-size: 11px; border-radius: 6px; }
|
||||
.btn.lg { height: 36px; padding: 0 16px; font-size: 12px; }
|
||||
.btn.block { width: 100%; justify-content: center; }
|
||||
.field {
|
||||
height: 30px;
|
||||
padding: 0 9px;
|
||||
font-size: 11px;
|
||||
border-radius: 6px;
|
||||
border-color: light-dark(var(--qk-line-strong), #37445b);
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
}
|
||||
.field:focus { border-color: #8F98F5; box-shadow: 0 0 0 3px #4F5BEF1C; }
|
||||
.fld > label { font-size: 11px; font-weight: 500; color: light-dark(var(--qk-text-2), #b3bed0); }
|
||||
.fld .field.invalid { border-color: var(--qk-red); background: var(--qk-red-weak); box-shadow: none; }
|
||||
.fld .field-error { font-size: 10px; color: var(--qk-red-ink); }
|
||||
.fld .field-hint { font-size: 10px; }
|
||||
.fld textarea.field { height: auto; min-height: 80px; padding: 8px; }
|
||||
.tabs {
|
||||
gap: 2px;
|
||||
height: 40px;
|
||||
margin-bottom: 12px;
|
||||
border-bottom: 1px solid light-dark(var(--qk-line-strong), #253147);
|
||||
}
|
||||
.tab {
|
||||
position: relative;
|
||||
height: 40px;
|
||||
padding: 0 14px;
|
||||
line-height: 40px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
border-bottom: 0;
|
||||
}
|
||||
.tab.active { color: var(--qk-primary); font-weight: 600; border-bottom-color: transparent; }
|
||||
.tab.active:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 14px;
|
||||
right: 14px;
|
||||
bottom: -1px;
|
||||
height: 2px;
|
||||
border-radius: 2px;
|
||||
background: var(--qk-primary);
|
||||
}
|
||||
.tab .tab-count { color: light-dark(var(--qk-text-4), #8a96aa); font-size: 10px; margin-left: 4px; font-family: var(--qk-font-num); }
|
||||
.tab.active .tab-count { color: var(--qk-primary-ink); }
|
||||
.pill {
|
||||
height: 20px;
|
||||
padding: 0 7px;
|
||||
border-radius: 4px;
|
||||
font-size: 10px;
|
||||
border-color: light-dark(var(--qk-line-strong), #344158);
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
gap: 4px;
|
||||
}
|
||||
.status {
|
||||
height: 20px;
|
||||
padding: 0 7px;
|
||||
border-radius: 4px;
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
gap: 4px;
|
||||
}
|
||||
.status:before { width: 5px; height: 5px; }
|
||||
.success { color: var(--qk-green-ink); background: var(--qk-green-weak); }
|
||||
.warning { color: var(--qk-amber-ink); background: var(--qk-amber-weak); }
|
||||
.error { color: var(--qk-red-ink); background: var(--qk-red-weak); }
|
||||
.info { color: var(--qk-primary-ink); background: var(--qk-primary-weak); }
|
||||
.neutral { color: var(--qk-text-3); background: light-dark(#F3F4F6, #252f40); }
|
||||
.code { font-family: var(--qk-font-mono); font-size: 10px; color: light-dark(var(--qk-text-2), #b3bed0); word-break: break-all; }
|
||||
.notice { border-radius: 8px; padding: 9px 11px; font-size: 11px; line-height: 1.6; border-color: #DDE1FD; background: #F5F7FF; color: var(--qk-primary-ink); }
|
||||
.notice.warn { border-color: #FDE9C2; background: #FFF9EC; color: #8A5B12; }
|
||||
.notice.danger { border-color: #FECACA; background: var(--qk-red-weak); color: var(--qk-red-ink); }
|
||||
.notice .btn { height: 24px; font-size: 10.5px; }
|
||||
.filterbar { gap: 8px; margin-bottom: 12px; }
|
||||
.filterbar .field { min-width: 108px; }
|
||||
.filterbar .searchfield { flex: 1 1 220px; min-width: 180px; }
|
||||
.pager {
|
||||
height: 40px;
|
||||
margin-top: 0;
|
||||
padding: 0 12px;
|
||||
border-top: 1px solid light-dark(var(--qk-line), #253147);
|
||||
}
|
||||
.pager .pager-info { font-size: 10px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.pager .pager-actions { display: flex; gap: 4px; align-items: center; }
|
||||
.pager select {
|
||||
height: 24px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid light-dark(var(--qk-line), #344158);
|
||||
border-radius: 6px;
|
||||
background: light-dark(var(--qk-card), #121b2b);
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
font-size: 10px;
|
||||
}
|
||||
.pg-btn {
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
padding: 0 5px;
|
||||
border: 1px solid light-dark(var(--qk-line), #344158);
|
||||
border-radius: 4px;
|
||||
background: light-dark(var(--qk-card), #121b2b);
|
||||
color: light-dark(var(--qk-text-3), #b3bed0);
|
||||
font-size: 10px;
|
||||
font-family: var(--qk-font-num);
|
||||
}
|
||||
.pg-btn:hover:not(:disabled) { border-color: light-dark(#b9c2d6, #4a5b7a); color: light-dark(var(--qk-text-2), #dbe3f0); }
|
||||
.pg-btn.active,
|
||||
.pg-btn.active:disabled {
|
||||
border-color: light-dark(#c7ccff, #39438f);
|
||||
background: light-dark(var(--qk-primary-weak), #1c2445);
|
||||
color: var(--qk-primary);
|
||||
font-weight: 600;
|
||||
opacity: 1;
|
||||
}
|
||||
.pg-btn:disabled:not(.active) { opacity: .55; }
|
||||
.state-block { padding: 32px 16px; border-radius: 8px; background: light-dark(var(--qk-slate-weak), #182337); font-size: 11px; }
|
||||
.state-block strong { font-size: 12px; }
|
||||
|
||||
/* 弹窗统一由 Element Plus el-dialog 承载(见 styles/element-theme.css) */
|
||||
.switch { width: 28px; height: 16px; padding: 2px; border-radius: 8px; background: var(--qk-green); }
|
||||
.switch:after { width: 12px; height: 12px; }
|
||||
.switch.off { background: #E5E7EB; }
|
||||
.switch:disabled { opacity: .5; }
|
||||
.drawer { background: light-dark(var(--qk-card), #121b2b); }
|
||||
.drawer-head { padding: 14px 18px; border-color: light-dark(var(--qk-line), #273247); }
|
||||
.drawer-head h3 { font-size: 15px; }
|
||||
.drawer-body { padding: 14px 18px 28px; }
|
||||
.drawer-section { padding: 14px 0; }
|
||||
.drawer-section h4 { font-size: 12px; margin-bottom: 10px; }
|
||||
.kv-row { font-size: 11px; gap: 10px; }
|
||||
.kv-row span:first-child { color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.segment { border-radius: 8px; padding: 8px 10px; }
|
||||
.segment .seg-head, .segment .seg-body { font-size: 11px; }
|
||||
|
||||
/* 其他通用 */
|
||||
.eyebrow { font-size: 11px; color: light-dark(var(--qk-text-4), #8a96aa); margin-bottom: 4px; }
|
||||
.page-actions { margin-bottom: 12px; }
|
||||
.actions { gap: 8px; }
|
||||
.inline-warn { font-size: 10px; color: var(--qk-amber-ink); }
|
||||
.tooltip-hint { font-size: 10px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.right-col { width: 326px; flex: 0 0 326px; }
|
||||
.right-col-wide { width: 340px; flex: 0 0 340px; }
|
||||
.split { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
|
||||
.split > .main { flex: 1; min-width: 0; }
|
||||
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
|
||||
.stat-card { background: light-dark(var(--qk-card), #121b2b); border: 1px solid light-dark(var(--qk-line), #273247); border-radius: 12px; padding: 12px 14px; }
|
||||
.stat-card .stat-label { font-size: 10px; color: light-dark(var(--qk-text-3), #b3bed0); display: flex; align-items: center; gap: 6px; }
|
||||
.stat-card .stat-num { font-size: 22px; font-weight: 700; margin-top: 4px; font-family: var(--qk-font-num); font-variant-numeric: tabular-nums; }
|
||||
.stat-card .stat-num small { font-size: 10px; font-weight: 400; color: light-dark(var(--qk-text-4), #8a96aa); margin-left: 4px; }
|
||||
.segmented { display: inline-flex; padding: 2px; border-radius: 6px; background: light-dark(var(--qk-bg), #182337); border: 1px solid light-dark(var(--qk-line), #2b374d); }
|
||||
.segmented button { height: 24px; padding: 0 9px; border: 0; border-radius: 4px; background: transparent; color: light-dark(var(--qk-text-3), #b3bed0); font-size: 10.5px; }
|
||||
.segmented button.active { background: var(--qk-primary-weak); color: var(--qk-primary-ink); font-weight: 600; }
|
||||
.empty-line { padding: 24px; text-align: center; font-size: 11px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.badge-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
|
||||
.badge-dot.g { background: var(--qk-green); }
|
||||
.badge-dot.r { background: var(--qk-red); }
|
||||
.badge-dot.a { background: var(--qk-amber); }
|
||||
.badge-dot.n { background: var(--qk-text-4); }
|
||||
|
||||
/* v2 自动化规则列表右栏与通用 chip */
|
||||
.rules-layout { display: flex; gap: 12px; align-items: flex-start; }
|
||||
.rules-main { flex: 1; min-width: 0; }
|
||||
.rules-aside { width: 300px; flex: 0 0 300px; display: flex; flex-direction: column; gap: 12px; }
|
||||
.aside-body { display: flex; flex-direction: column; gap: 10px; font-size: 11px; }
|
||||
.aside-meta { display: flex; flex-direction: column; gap: 2px; color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
.aside-meta b { color: light-dark(var(--qk-text-2), #a8b3c8); font-weight: 500; word-break: break-all; }
|
||||
.aside-list { margin: 0; padding-left: 16px; line-height: 1.7; color: light-dark(var(--qk-text-3), #b3bed0); }
|
||||
.aside-body .flow-list { gap: 8px; }
|
||||
.flow-list > div { display: flex; justify-content: space-between; gap: 8px; }
|
||||
.flow-list b { font-weight: 600; }
|
||||
.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 10px;
|
||||
font-size: 10px; border: 1px solid light-dark(var(--qk-line), #273247); background: light-dark(var(--qk-bg), #182337);
|
||||
color: light-dark(var(--qk-text-3), #b3bed0); white-space: nowrap; }
|
||||
.chip.ok { color: #2e6b34; border-color: #c8e6c9; background: #f1f8f1; }
|
||||
.chip.warn { color: #8a5a12; border-color: #f0dcb4; background: #fdf8ef; }
|
||||
.chip.muted { color: light-dark(var(--qk-text-4), #8a96aa); }
|
||||
@media (max-width: 1200px) {
|
||||
.rules-layout { flex-direction: column; }
|
||||
.rules-aside { width: 100%; flex-basis: auto; }
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.content { padding: 18px 20px 32px; }
|
||||
.sidebar { width: 210px; }
|
||||
.stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.split { flex-direction: column; }
|
||||
.right-col, .right-col-wide { width: 100%; flex-basis: auto; }
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.topbar { height: 52px; padding: 0 12px; }
|
||||
.shell { min-height: calc(100vh - 52px); }
|
||||
.topbar .crumb { font-size: 11px; }
|
||||
.topbar .global-search { display: none; }
|
||||
.topbar .mode-chip { display: none; }
|
||||
.content { padding: 14px 12px 80px; }
|
||||
.card { padding: 14px; }
|
||||
.card-head { margin: -14px -14px 10px; }
|
||||
.stat-grid { grid-template-columns: 1fr 1fr; }
|
||||
}
|
||||
|
||||
/* 全局布局:导航固定一屏,页面内容在右侧内部滚动;顶栏保持可见。 */
|
||||
.app {
|
||||
height: 100vh;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
.shell {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.sidebar {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
/* 仅导航列表可滚动;账号切换浮层在 sidebar-bottom 内,不受导航滚动容器裁切。 */
|
||||
.sidebar-nav {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.sidebar-bottom {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.content {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
/* 移动端保留整页滚动与底部固定导航,避免内容被 100vh 裁切。 */
|
||||
.app {
|
||||
height: auto;
|
||||
min-height: 100vh;
|
||||
overflow: visible;
|
||||
}
|
||||
.content {
|
||||
height: auto;
|
||||
overflow-y: visible;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
/* ---------------------------------------------------------------- Element Plus 主题覆盖(唯一维护点)
|
||||
方案 B:以 Element Plus 作为底座,但视觉仍由本项目管理台设计 token 决定。
|
||||
取值来源:docs/design/qlinker-admin-v1/设计规范与组件清单.md 1.1–1.7,与 styles/app.css 的 --qk-* token 同源。
|
||||
规则:
|
||||
1) 只在这里覆盖 --el-* 变量与必要的组件级样式,页面内不再写零散的 Element 皮肤补丁。
|
||||
2) 变量选择器使用 :root:root(提高一级优先级),避免与 Element 自带 :root 定义的加载顺序耦合。
|
||||
3) 颜色统一引用 --qk-*(其内部已用 light-dark() 适配系统深浅色),Element 自身不再额外接入 dark 主题包。 */
|
||||
|
||||
:root:root {
|
||||
/* ---------- 主色阶(弱底 light-9 直接对齐 --qk-primary-weak #EEF0FE) */
|
||||
--el-color-primary: var(--qk-primary);
|
||||
--el-color-primary-light-3: color-mix(in srgb, var(--qk-primary) 70%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-primary-light-5: color-mix(in srgb, var(--qk-primary) 50%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-primary-light-7: color-mix(in srgb, var(--qk-primary) 30%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-primary-light-8: color-mix(in srgb, var(--qk-primary) 20%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-primary-light-9: var(--qk-primary-weak);
|
||||
--el-color-primary-dark-2: var(--qk-primary-ink);
|
||||
|
||||
/* ---------- 语义色 */
|
||||
--el-color-success: var(--qk-green);
|
||||
--el-color-success-light-3: color-mix(in srgb, var(--qk-green) 70%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-success-light-5: color-mix(in srgb, var(--qk-green) 50%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-success-light-8: color-mix(in srgb, var(--qk-green) 20%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-success-light-9: var(--qk-green-weak);
|
||||
--el-color-success-dark-2: var(--qk-green-ink);
|
||||
|
||||
--el-color-warning: var(--qk-amber);
|
||||
--el-color-warning-light-3: color-mix(in srgb, var(--qk-amber) 70%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-warning-light-5: color-mix(in srgb, var(--qk-amber) 50%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-warning-light-8: color-mix(in srgb, var(--qk-amber) 20%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-warning-light-9: var(--qk-amber-weak);
|
||||
--el-color-warning-dark-2: var(--qk-amber-ink);
|
||||
|
||||
--el-color-danger: var(--qk-red);
|
||||
--el-color-error: var(--qk-red);
|
||||
--el-color-danger-light-3: color-mix(in srgb, var(--qk-red) 70%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-danger-light-5: color-mix(in srgb, var(--qk-red) 50%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-danger-light-8: color-mix(in srgb, var(--qk-red) 20%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-danger-light-9: var(--qk-red-weak);
|
||||
--el-color-danger-dark-2: var(--qk-red-ink);
|
||||
--el-color-error-light-9: var(--qk-red-weak);
|
||||
|
||||
--el-color-info: var(--qk-text-3);
|
||||
--el-color-info-light-3: color-mix(in srgb, var(--qk-text-3) 70%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-info-light-5: color-mix(in srgb, var(--qk-text-3) 50%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-info-light-8: color-mix(in srgb, var(--qk-text-3) 20%, light-dark(#FFFFFF, #172235));
|
||||
--el-color-info-light-9: var(--qk-slate-weak);
|
||||
--el-color-info-dark-2: var(--qk-text);
|
||||
|
||||
/* ---------- 底色 / 填充 */
|
||||
--el-bg-color: var(--qk-card);
|
||||
--el-bg-color-page: var(--qk-bg);
|
||||
--el-bg-color-overlay: var(--qk-card);
|
||||
--el-fill-color-blank: var(--qk-card);
|
||||
--el-fill-color: light-dark(var(--qk-slate-weak), #1B2638);
|
||||
--el-fill-color-light: light-dark(#FAFBFD, #1B2638);
|
||||
--el-fill-color-lighter: light-dark(#FCFDFE, #1F2A3D);
|
||||
--el-fill-color-extra-light: light-dark(#FDFDFF, #1F2A3D);
|
||||
--el-fill-color-dark: light-dark(#F1F3F8, #16202F);
|
||||
--el-fill-color-darker: light-dark(#E9ECF3, #131C2A);
|
||||
|
||||
/* ---------- 文字 */
|
||||
--el-text-color-primary: var(--qk-text);
|
||||
--el-text-color-regular: var(--qk-text-2);
|
||||
--el-text-color-secondary: var(--qk-text-3);
|
||||
--el-text-color-placeholder: var(--qk-text-4);
|
||||
--el-text-color-disabled: var(--qk-text-4);
|
||||
--el-text-color-primary-hover: var(--qk-text);
|
||||
|
||||
/* ---------- 边框 / 分隔 */
|
||||
--el-border-color: var(--qk-line-strong);
|
||||
--el-border-color-light: var(--qk-line);
|
||||
--el-border-color-lighter: var(--qk-line);
|
||||
--el-border-color-extra-light: var(--qk-line);
|
||||
--el-border-color-dark: light-dark(#CBD2E0, #37445B);
|
||||
--el-border-color-darker: light-dark(#AEB7C9, #3D4C64);
|
||||
|
||||
/* ---------- 圆角 / 字号 / 控件尺寸 / 过渡 */
|
||||
--el-border-radius-base: 6px;
|
||||
--el-border-radius-small: 6px;
|
||||
--el-border-radius-round: 999px;
|
||||
--el-font-size-extra-large: 16px;
|
||||
--el-font-size-large: 14px;
|
||||
--el-font-size-medium: 13px;
|
||||
--el-font-size-base: 12px;
|
||||
--el-font-size-small: 11px;
|
||||
--el-font-size-extra-small: 10px;
|
||||
--el-component-size: 30px;
|
||||
--el-component-size-small: 24px;
|
||||
--el-component-size-large: 36px;
|
||||
--el-transition-duration: .16s;
|
||||
--el-transition-duration-fast: .14s;
|
||||
|
||||
/* ---------- 阴影 / 遮罩 */
|
||||
--el-box-shadow: var(--qk-shadow-pop);
|
||||
--el-box-shadow-light: 0 4px 14px rgba(23, 27, 38, .10);
|
||||
--el-box-shadow-lighter: 0 2px 8px rgba(23, 27, 38, .07);
|
||||
--el-box-shadow-dark: var(--qk-shadow-pop);
|
||||
--el-popup-modal-bg-color: #171B26;
|
||||
--el-popup-modal-opacity: .34;
|
||||
--el-mask-color: rgba(23, 27, 38, .34);
|
||||
--el-mask-color-extra-light: rgba(23, 27, 38, .18);
|
||||
|
||||
/* ---------- 弹窗(卡片 12 / 弹窗 14 / 弹窗阴影固定) */
|
||||
--el-dialog-border-radius: 14px;
|
||||
--el-dialog-box-shadow: var(--qk-shadow-modal);
|
||||
--el-dialog-bg-color: var(--qk-card);
|
||||
--el-dialog-padding-primary: 16px;
|
||||
--el-dialog-title-font-size: 14px;
|
||||
--el-dialog-content-font-size: 11px;
|
||||
--el-dialog-margin-top: 12vh;
|
||||
|
||||
--el-messagebox-width: 420px;
|
||||
--el-messagebox-border-radius: 14px;
|
||||
--el-messagebox-box-shadow: var(--qk-shadow-modal);
|
||||
--el-messagebox-padding-primary: 16px;
|
||||
--el-messagebox-font-size: 14px;
|
||||
--el-messagebox-content-font-size: 11px;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 按钮
|
||||
与自绘 .btn 一致:30px 高、6px 圆角、500 字重、160ms 以内过渡。 */
|
||||
.el-button {
|
||||
font-weight: 500;
|
||||
letter-spacing: 0;
|
||||
border-radius: 6px;
|
||||
transition: background-color .14s ease, border-color .14s ease, color .14s ease;
|
||||
}
|
||||
.el-button--primary {
|
||||
--el-button-bg-color: var(--qk-primary);
|
||||
--el-button-border-color: var(--qk-primary);
|
||||
--el-button-hover-bg-color: #5F6AF2;
|
||||
--el-button-hover-border-color: #5F6AF2;
|
||||
--el-button-active-bg-color: var(--qk-primary-ink);
|
||||
--el-button-active-border-color: var(--qk-primary-ink);
|
||||
--el-button-text-color: #FFFFFF;
|
||||
}
|
||||
.el-button--default:not(.is-text):not(.is-link):not(.is-plain) {
|
||||
--el-button-bg-color: light-dark(var(--qk-card), #172235);
|
||||
--el-button-border-color: var(--qk-line-strong);
|
||||
--el-button-text-color: var(--qk-text-2);
|
||||
--el-button-hover-bg-color: light-dark(var(--qk-slate-weak), #1F2A3D);
|
||||
--el-button-hover-border-color: light-dark(#CBD2E0, #4A5B7A);
|
||||
--el-button-hover-text-color: var(--qk-text);
|
||||
}
|
||||
.el-button--danger:not(.is-text):not(.is-link):not(.is-plain) {
|
||||
--el-button-bg-color: var(--qk-red);
|
||||
--el-button-border-color: var(--qk-red);
|
||||
--el-button-hover-bg-color: #DC2626;
|
||||
--el-button-hover-border-color: #DC2626;
|
||||
}
|
||||
.el-button.is-text,
|
||||
.el-button.is-link { font-weight: 500; }
|
||||
.el-button--small { padding: 0 10px; }
|
||||
.el-button:focus-visible { outline: none; box-shadow: var(--qk-focus-ring); }
|
||||
|
||||
/* ---------------------------------------------------------------- 输入 / 选择 / 日期
|
||||
统一为单线边框 + 3px 焦点环,避免 Element 默认的双层 inset 阴影。 */
|
||||
.el-input .el-input__wrapper,
|
||||
.el-textarea__inner,
|
||||
.qk-select .el-select__wrapper {
|
||||
border-radius: 6px;
|
||||
box-shadow: inset 0 0 0 1px var(--el-border-color);
|
||||
transition: box-shadow .14s ease, background-color .14s ease;
|
||||
}
|
||||
.el-input .el-input__wrapper { padding: 0 9px; }
|
||||
.qk-select .el-select__wrapper { padding: 2px 9px; min-height: var(--el-component-size); }
|
||||
.el-input .el-input__wrapper:hover,
|
||||
.qk-select .el-select__wrapper:hover { box-shadow: inset 0 0 0 1px var(--el-border-color-dark); }
|
||||
.el-input .el-input__wrapper.is-focus,
|
||||
.qk-select .el-select__wrapper.is-focused,
|
||||
.el-textarea__inner:focus {
|
||||
box-shadow: inset 0 0 0 1px #8F98F5, var(--qk-focus-ring);
|
||||
}
|
||||
.el-textarea__inner { padding: 7px 9px; line-height: 1.6; }
|
||||
.el-input__inner,
|
||||
.el-select__placeholder,
|
||||
.el-select__selected-item { font-size: 11px; }
|
||||
.el-input__inner::placeholder { color: var(--qk-text-4); }
|
||||
.el-input.is-disabled .el-input__wrapper,
|
||||
.qk-select .el-select__wrapper.is-disabled {
|
||||
background: light-dark(var(--qk-slate-weak), #1B2638);
|
||||
box-shadow: inset 0 0 0 1px var(--el-border-color-light);
|
||||
}
|
||||
.el-form-item__label { font-size: 11px; font-weight: 500; color: var(--qk-text-2); }
|
||||
.el-form-item__error { font-size: 10px; padding-top: 3px; }
|
||||
.el-form-item { margin-bottom: 12px; }
|
||||
|
||||
/* 日期面板:8px 圆角、11px 字号、与自绘下拉同一阴影 */
|
||||
.el-date-editor .el-range-input { font-size: 11px; }
|
||||
.el-date-editor .el-range-separator { font-size: 11px; color: var(--qk-text-4); }
|
||||
.el-picker-panel {
|
||||
border-radius: 8px;
|
||||
border-color: var(--qk-line-strong);
|
||||
box-shadow: var(--qk-shadow-pop);
|
||||
font-size: 11px;
|
||||
}
|
||||
.el-picker-panel__footer { padding: 8px 10px; }
|
||||
.el-date-table { font-size: 11px; }
|
||||
.el-date-table td { padding: 3px 0; }
|
||||
.el-date-table td .el-date-table-cell__text { width: 22px; height: 22px; line-height: 22px; border-radius: 6px; font-size: 11px; }
|
||||
.el-date-table td.current:not(.disabled) .el-date-table-cell__text { background: var(--qk-primary); }
|
||||
.el-date-table td.today .el-date-table-cell__text { color: var(--qk-primary); font-weight: 600; }
|
||||
.el-time-panel { border-radius: 8px; }
|
||||
.el-picker-panel__shortcut { font-size: 11px; }
|
||||
/* 与 .field.invalid 等价:日期控件校验失败时的红色描边 */
|
||||
.el-date-editor.invalid .el-input__wrapper,
|
||||
.qk-select.is-invalid .el-select__wrapper {
|
||||
box-shadow: inset 0 0 0 1px var(--qk-red);
|
||||
background: var(--qk-red-weak);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 下拉浮层
|
||||
与自绘 .qk-select-popup 统一:8px 圆角、统一阴影、26px 选项高度、6px 选项圆角。 */
|
||||
.el-popper.is-light {
|
||||
border: 1px solid var(--qk-line-strong);
|
||||
border-radius: 8px;
|
||||
box-shadow: var(--qk-shadow-pop);
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
}
|
||||
.el-popper.is-light .el-popper__arrow::before {
|
||||
border-color: var(--qk-line-strong);
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
}
|
||||
.el-select-dropdown .el-select-dropdown__list { padding: 4px; }
|
||||
.el-select-dropdown .el-select-dropdown__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 26px;
|
||||
line-height: 26px;
|
||||
padding: 0 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--qk-text-2);
|
||||
}
|
||||
.el-select-dropdown .el-select-dropdown__item.is-hovering {
|
||||
background: light-dark(var(--qk-primary-weak), #1C2445);
|
||||
color: var(--qk-primary-ink);
|
||||
}
|
||||
.el-select-dropdown .el-select-dropdown__item.is-selected {
|
||||
color: var(--qk-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
.el-select-dropdown .el-select-dropdown__item.is-disabled { color: var(--qk-text-4); }
|
||||
.el-select-dropdown .el-select-dropdown__empty { padding: 10px 8px; font-size: 11px; color: var(--qk-text-4); }
|
||||
.el-select-group__title { padding: 6px 8px 3px; font-size: 10px; font-weight: 600; color: var(--qk-text-4); line-height: 14px; }
|
||||
.el-select__tags-text { font-size: 11px; }
|
||||
.el-select .el-tag { border-radius: 6px; height: 22px; }
|
||||
|
||||
/* ---------------------------------------------------------------- 弹窗
|
||||
头部:14px/600 标题 + 12 分隔线;底部按钮右对齐,间距 8px。 */
|
||||
.el-dialog { padding: 16px 18px; }
|
||||
.el-dialog__header {
|
||||
padding: 0 0 12px;
|
||||
margin: 0;
|
||||
border-bottom: 1px solid var(--el-border-color-light);
|
||||
}
|
||||
.el-dialog__header.show-close { padding-right: 32px; }
|
||||
.el-dialog__title { font-size: 14px; font-weight: 600; color: var(--qk-text); line-height: 20px; }
|
||||
.el-dialog__headerbtn { width: 28px; height: 28px; top: 12px; right: 12px; border-radius: 6px; }
|
||||
.el-dialog__headerbtn:hover { background: light-dark(var(--qk-slate-weak), #1F2A3D); }
|
||||
.el-dialog__headerbtn .el-dialog__close { font-size: 14px; color: var(--qk-text-4); }
|
||||
.el-dialog__headerbtn:focus .el-dialog__close,
|
||||
.el-dialog__headerbtn:hover .el-dialog__close { color: var(--qk-primary); }
|
||||
.el-dialog__body {
|
||||
padding: 14px 0 0;
|
||||
font-size: 11px;
|
||||
color: var(--qk-text-2);
|
||||
max-height: calc(100vh - 220px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.el-dialog__footer { padding: 14px 0 0; border-top: 1px solid var(--el-border-color-light); margin-top: 14px; }
|
||||
.el-dialog__footer .el-button + .el-button { margin-left: 8px; }
|
||||
.el-overlay { backdrop-filter: none; }
|
||||
|
||||
/* 确认框:危险操作红色实心主按钮,取消为描边中性按钮 */
|
||||
.el-message-box { padding: 16px 18px; }
|
||||
.el-message-box__header { padding: 0 0 10px; }
|
||||
.el-message-box__title { font-size: 14px; font-weight: 600; color: var(--qk-text); }
|
||||
.el-message-box__content { font-size: 11px; color: var(--qk-text-2); line-height: 1.65; }
|
||||
.el-message-box__container { gap: 10px; }
|
||||
.el-message-box__btns { padding-top: 14px; gap: 8px; }
|
||||
.el-message-box__btns .el-button { min-width: 64px; }
|
||||
.el-message-box__headerbtn { width: 28px; height: 28px; top: 12px; right: 12px; }
|
||||
|
||||
/* ---------------------------------------------------------------- 轻提示
|
||||
与自绘 Toast(ui.js notify)统一的圆角/阴影/字号。 */
|
||||
.el-message {
|
||||
min-width: 0;
|
||||
padding: 9px 14px;
|
||||
border-radius: 10px;
|
||||
border-color: var(--qk-line-strong);
|
||||
box-shadow: var(--qk-shadow-pop);
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
}
|
||||
.el-message .el-message__content { font-size: 11px; line-height: 1.55; color: var(--qk-text-2); }
|
||||
.el-message .el-message__icon { font-size: 13px; }
|
||||
/* 旧 Toast 的两段式内容(标题加粗 + 次要正文)在 ElMessage 内保持一致 */
|
||||
.qk-message-body strong { display: block; font-size: 11px; font-weight: 600; line-height: 16px; color: var(--qk-text); }
|
||||
.qk-message-body .qk-message-sub { margin-top: 2px; font-size: 10px; line-height: 15px; color: var(--qk-text-3); word-break: break-word; }
|
||||
.qk-message .el-message__content { padding-right: 4px; }
|
||||
.qk-message .el-message__closeBtn { font-size: 12px; color: var(--qk-text-4); }
|
||||
|
||||
/* 命令式确认(ui/feedback.js 的 askConfirm) */
|
||||
.qk-confirm .el-message-box__message { padding-left: 0; }
|
||||
.qk-confirm-body .qk-confirm-text { font-size: 11px; line-height: 1.6; color: var(--qk-text-2); }
|
||||
.qk-confirm-body .qk-confirm-hint { margin-top: 6px; font-size: 10px; line-height: 1.55; color: var(--qk-text-3); }
|
||||
/* 危险操作的确认按钮:实心红 */
|
||||
.el-button.qk-btn-danger {
|
||||
--el-button-bg-color: var(--qk-red);
|
||||
--el-button-border-color: var(--qk-red);
|
||||
--el-button-hover-bg-color: #DC2626;
|
||||
--el-button-hover-border-color: #DC2626;
|
||||
--el-button-active-bg-color: var(--qk-red-ink);
|
||||
--el-button-active-border-color: var(--qk-red-ink);
|
||||
--el-button-text-color: #FFFFFF;
|
||||
background: var(--qk-red);
|
||||
border-color: var(--qk-red);
|
||||
color: #FFFFFF;
|
||||
}
|
||||
.el-button.qk-btn-danger:hover { background: #DC2626; border-color: #DC2626; }
|
||||
|
||||
/* ---------------------------------------------------------------- 其余常用件
|
||||
本轮仍使用自绘实现(Input/Textarea/Switch/Checkbox/Tooltip),
|
||||
这里只做 token 对齐,避免将来按需引入这些组件时出现第二套皮肤。 */
|
||||
.el-switch { --el-switch-on-color: var(--qk-primary); }
|
||||
.el-checkbox { --el-checkbox-checked-bg-color: var(--qk-primary); --el-checkbox-checked-input-border-color: var(--qk-primary); font-size: 11px; }
|
||||
.el-checkbox__label { font-size: 11px; }
|
||||
.el-radio { font-size: 11px; --el-radio-input-border-color: var(--el-border-color); }
|
||||
.el-radio__label { font-size: 11px; }
|
||||
.el-tag { border-radius: 6px; font-size: 10px; height: 20px; padding: 0 6px; }
|
||||
.el-tooltip__popper.is-dark { border-radius: 6px; font-size: 10px; }
|
||||
.el-loading-mask { background-color: rgba(246, 247, 251, .72); }
|
||||
.el-scrollbar__bar .el-scrollbar__thumb { background: light-dark(#CBD2E0, #3A465D); border-radius: 8px; }
|
||||
@@ -0,0 +1,234 @@
|
||||
/* ---------------------------------------------------------------- 基础组件层 v1
|
||||
自绘控件(下拉、弹窗、提示、Tooltip、表单)统一视觉。
|
||||
取值来源:docs/design/qlinker-admin-v1/设计规范与组件清单.md 1.1–1.7。
|
||||
不依赖任何第三方 UI / 图标 / 动画库。 */
|
||||
|
||||
:root {
|
||||
--qk-shadow-pop: 0 10px 28px rgba(23, 27, 38, .12), 0 2px 6px rgba(23, 27, 38, .06);
|
||||
--qk-shadow-modal: 0 24px 64px rgba(23, 27, 38, .22);
|
||||
--qk-focus-ring: 0 0 0 3px rgba(79, 91, 239, .16);
|
||||
--qk-popup-bg: #FFFFFF;
|
||||
--qk-popup-line: #E4E7EF;
|
||||
--qk-tone-info-bg: #F5F7FF;
|
||||
--qk-tone-info-ink: #3B46C9;
|
||||
--qk-tone-info-line: #DDE1FD;
|
||||
}
|
||||
|
||||
/* 自绘滚动条:细、圆、低调;避免浏览器默认灰块。 */
|
||||
* {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: light-dark(#CBD2E0, #3A465D) transparent;
|
||||
}
|
||||
*::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||
*::-webkit-scrollbar-track { background: transparent; }
|
||||
*::-webkit-scrollbar-thumb {
|
||||
background: light-dark(#CBD2E0, #3A465D);
|
||||
border-radius: 8px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: content-box;
|
||||
}
|
||||
*::-webkit-scrollbar-thumb:hover { background: light-dark(#AEB7C9, #4C5A73); background-clip: content-box; }
|
||||
*::-webkit-scrollbar-corner { background: transparent; }
|
||||
|
||||
/* ---------------------------------------------------------------- 表单控件 */
|
||||
.qk-field {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 30px;
|
||||
padding: 0 9px;
|
||||
border: 1px solid light-dark(var(--qk-line-strong), #37445B);
|
||||
border-radius: 6px;
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: 11px;
|
||||
outline: none;
|
||||
transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
|
||||
}
|
||||
.qk-field::placeholder { color: light-dark(var(--qk-text-4), #8A96AA); }
|
||||
.qk-field:hover:not(:disabled):not([readonly]) { border-color: light-dark(#CBD2E0, #4A5B7A); }
|
||||
.qk-field:focus { border-color: #8F98F5; box-shadow: var(--qk-focus-ring); }
|
||||
.qk-field[disabled]:disabled { opacity: .6; cursor: not-allowed; }
|
||||
.qk-field[readonly] { background: light-dark(var(--qk-slate-weak), #1B2638); }
|
||||
.qk-field.is-invalid { border-color: var(--qk-red); background: var(--qk-red-weak); box-shadow: none; }
|
||||
textarea.qk-field {
|
||||
height: auto;
|
||||
min-height: 80px;
|
||||
padding: 8px 9px;
|
||||
line-height: 1.6;
|
||||
resize: vertical;
|
||||
}
|
||||
.qk-field-sm { height: 24px; font-size: 10px; padding: 0 7px; }
|
||||
.qk-field-lg { height: 36px; font-size: 12px; padding: 0 11px; }
|
||||
.qk-field-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 0; width: 100%; }
|
||||
.qk-field-wrap > .qk-field-label { font-size: 11px; font-weight: 500; color: light-dark(var(--qk-text-2), #B3BED0); }
|
||||
.qk-field-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; color: light-dark(var(--qk-text-4), #8A96AA); }
|
||||
.qk-field-meta .qk-field-error { color: var(--qk-red-ink); }
|
||||
.qk-field-count { font-family: var(--qk-font-num); font-variant-numeric: tabular-nums; flex: none; }
|
||||
|
||||
/* ---------------------------------------------------------------- 开关 */
|
||||
.qk-switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex: none;
|
||||
width: 30px;
|
||||
height: 17px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 9px;
|
||||
background: light-dark(#E5E7EB, #33405A);
|
||||
cursor: pointer;
|
||||
transition: background .16s ease;
|
||||
}
|
||||
.qk-switch:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 2px rgba(23, 27, 38, .24);
|
||||
transition: transform .16s ease;
|
||||
}
|
||||
.qk-switch[aria-checked="true"] { background: var(--qk-primary); }
|
||||
.qk-switch[aria-checked="true"]:after { transform: translateX(13px); }
|
||||
.qk-switch:disabled { opacity: .5; cursor: not-allowed; }
|
||||
.qk-switch:focus-visible { outline: 2px solid var(--qk-primary); outline-offset: 2px; }
|
||||
|
||||
/* ---------------------------------------------------------------- 复选框 */
|
||||
.qk-checkbox {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
font-size: 11px;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
min-width: 0;
|
||||
}
|
||||
.qk-checkbox.is-disabled { opacity: .55; cursor: not-allowed; }
|
||||
.qk-checkbox__input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
|
||||
.qk-checkbox__box {
|
||||
position: relative;
|
||||
flex: none;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 1px solid light-dark(var(--qk-line-strong), #4A5B7A);
|
||||
border-radius: 4px;
|
||||
background: light-dark(var(--qk-card), #172235);
|
||||
transition: background .14s ease, border-color .14s ease;
|
||||
}
|
||||
.qk-checkbox__box:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
top: 1px;
|
||||
width: 4px;
|
||||
height: 8px;
|
||||
border: 1.5px solid transparent;
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
transform: rotate(40deg) scale(.6);
|
||||
opacity: 0;
|
||||
transition: opacity .12s ease, transform .12s ease;
|
||||
}
|
||||
.qk-checkbox__input:checked + .qk-checkbox__box,
|
||||
.qk-checkbox__input:indeterminate + .qk-checkbox__box {
|
||||
border-color: var(--qk-primary);
|
||||
background: var(--qk-primary);
|
||||
}
|
||||
.qk-checkbox__input:checked + .qk-checkbox__box:after {
|
||||
border-bottom-color: #fff;
|
||||
border-right-color: #fff;
|
||||
transform: rotate(40deg) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
.qk-checkbox__input:indeterminate + .qk-checkbox__box:after {
|
||||
left: 3px;
|
||||
top: 6px;
|
||||
width: 7px;
|
||||
height: 0;
|
||||
border: 0;
|
||||
border-top: 1.5px solid #fff;
|
||||
transform: none;
|
||||
opacity: 1;
|
||||
}
|
||||
.qk-checkbox__input:focus-visible + .qk-checkbox__box { box-shadow: var(--qk-focus-ring); }
|
||||
.qk-checkbox__text { line-height: 1.5; min-width: 0; }
|
||||
|
||||
/* ---------------------------------------------------------------- 下拉
|
||||
自绘下拉实现已替换为 Element Plus el-select 的薄封装(components/ui/Select.vue),
|
||||
键鼠交互、浮层与视觉细节统一在 styles/element-theme.css;这里只保留宽度适配。 */
|
||||
/* el-select 根节点默认 width:100%,非块级场景需要收回为内容宽度,避免在筛选行里被拉满。 */
|
||||
.qk-select:not(.is-block) { width: auto; min-width: 108px; }
|
||||
.qk-select.is-sm:not(.is-block) { min-width: 0; }
|
||||
.qk-select.is-block { width: 100%; }
|
||||
|
||||
/* 危险操作主按钮:实心红,区别于描边式 .btn.danger。 */
|
||||
.btn.danger-solid { background: var(--qk-red); border-color: var(--qk-red); color: #fff; }
|
||||
.btn.danger-solid:hover:not(:disabled) { background: #DC2626; border-color: #DC2626; }
|
||||
|
||||
/* 弹窗与轻提示已改由 Element Plus 承载(ui/Modal.vue → el-dialog,ui.js notify → ElMessage),
|
||||
对应视觉统一在 styles/element-theme.css,本节不再保留自绘实现。 */
|
||||
|
||||
/* ---------------------------------------------------------------- 静态提示条 */
|
||||
.qk-notice {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 9px;
|
||||
padding: 9px 11px;
|
||||
border: 1px solid var(--qk-tone-info-line);
|
||||
border-radius: 8px;
|
||||
background: var(--qk-tone-info-bg);
|
||||
color: var(--qk-tone-info-ink);
|
||||
font-size: 11px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.qk-notice__body { flex: 1; min-width: 0; }
|
||||
.qk-notice__body strong { display: block; font-weight: 600; }
|
||||
.qk-notice.is-success { border-color: #BBF7D0; background: var(--qk-green-weak); color: var(--qk-green-ink); }
|
||||
.qk-notice.is-warning { border-color: #FDE9C2; background: #FFF9EC; color: #8A5B12; }
|
||||
.qk-notice.is-danger { border-color: #FECACA; background: var(--qk-red-weak); color: var(--qk-red-ink); }
|
||||
|
||||
/* ---------------------------------------------------------------- Tooltip */
|
||||
.qk-tooltip { position: relative; display: inline-flex; min-width: 0; }
|
||||
.qk-tooltip-pop {
|
||||
position: fixed;
|
||||
z-index: 95;
|
||||
max-width: 240px;
|
||||
padding: 5px 8px;
|
||||
border-radius: 6px;
|
||||
background: light-dark(#1F2A3D, #E6ECFF);
|
||||
color: light-dark(#FFFFFF, #1F2A3D);
|
||||
font-size: 10.5px;
|
||||
line-height: 1.45;
|
||||
box-shadow: 0 8px 22px rgba(16, 24, 40, .22);
|
||||
pointer-events: none;
|
||||
animation: qk-tip-in .12s ease;
|
||||
}
|
||||
@keyframes qk-tip-in {
|
||||
from { opacity: 0; transform: translateY(-2px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 原生控件兜底
|
||||
日期时间已由 el-date-picker 承载;number 等仍保留原生实现,仅统一外观。 */
|
||||
input[type="number"].field {
|
||||
font-family: var(--qk-font-num);
|
||||
}
|
||||
|
||||
/* 剩余原生单选(如发送日志人工核实)统一品牌色,避免系统默认蓝。 */
|
||||
input[type="radio"] { accent-color: var(--qk-primary); }
|
||||
|
||||
.pager select { appearance: none; padding-right: 20px; background-image:
|
||||
url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239AA1B2' stroke-width='1.4' fill='none'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat; background-position: right 6px center; }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.qk-message, .qk-tooltip-pop, .el-overlay, .el-dialog, .el-popper {
|
||||
animation: none !important;
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,31 @@
|
||||
import { reactive } from 'vue'
|
||||
import { h } from 'vue'
|
||||
|
||||
/** 全局轻提示。只在真实操作返回后调用,禁止用它在请求前伪造成功。 */
|
||||
export const toastState = reactive({ visible: false, title: '', body: '', tone: 'info' })
|
||||
const TOAST_LIFE = { success: 4000, info: 4000, warning: 5200, error: 6200 }
|
||||
|
||||
let toastTimer = 0
|
||||
function normalizeTone(tone) {
|
||||
if (tone === 'danger') return 'error'
|
||||
return ['success', 'warning', 'error', 'info'].includes(tone) ? tone : 'info'
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局轻提示:由 Element Plus `ElMessage` 承载(替代自绘 Toast 队列)。
|
||||
* 标题加粗、正文次要色,文案与 tone 与旧 Toast 保持一致;只在真实操作返回后调用。
|
||||
*/
|
||||
export function notify(title, body = '', tone = 'info') {
|
||||
toastState.title = title
|
||||
toastState.body = body
|
||||
toastState.tone = tone
|
||||
toastState.visible = true
|
||||
window.clearTimeout(toastTimer)
|
||||
toastTimer = window.setTimeout(() => {
|
||||
toastState.visible = false
|
||||
}, 4200)
|
||||
const type = normalizeTone(tone)
|
||||
return ElMessage({
|
||||
message: () =>
|
||||
h('div', { class: 'qk-message-body' }, [
|
||||
h('strong', title),
|
||||
body ? h('div', { class: 'qk-message-sub' }, body) : null
|
||||
]),
|
||||
type,
|
||||
duration: TOAST_LIFE[type],
|
||||
showClose: true,
|
||||
customClass: 'qk-message'
|
||||
})
|
||||
}
|
||||
|
||||
export function hideToast() {
|
||||
toastState.visible = false
|
||||
}
|
||||
|
||||
export function describeError(error) {
|
||||
const httpStatus = error?.httpStatus
|
||||
@@ -110,6 +117,7 @@ export function statusTone(value) {
|
||||
export function connectionLabel(value) {
|
||||
const map = {
|
||||
forward_websocket: '正向 WebSocket',
|
||||
http_api: 'HTTP API',
|
||||
reverse_websocket: '反向 WebSocket',
|
||||
http_callback: 'HTTP 回调'
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, aiCalls, aiCapabilities, aiProviders } from '../demo/planned'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import PlannedNotice from '../components/PlannedNotice.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
|
||||
const tab = ref('providers')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="工作空间" title="AI 能力" desc="服务商、模型能力、调用记录与成本。后端尚未提供 AI 接口,本页内容全部为演示数据。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供 AI 服务商创建接口">新增服务商</button>
|
||||
<button class="btn primary" type="button" disabled title="后端未提供 AI 测试接口">打开测试台</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="AI 能力尚未开发"
|
||||
summary="服务商适配、能力声明、Tool Calling 与调用审计均依赖后端尚未提供的接口;关闭演示数据时页面不展示任何占位数据。"
|
||||
:deps="PLANNED_DEPS.ai"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div class="demo-banner">{{ MOCK_NOTE }}<DemoBadge /></div>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>已启用服务商<DemoBadge /></span><span class="stat-icon">✦</span></div>
|
||||
<div class="stat-value">{{ aiProviders.length }}</div>
|
||||
<div class="stat-foot">全部为 OpenAI 兼容协议</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>今日调用<DemoBadge /></span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">{{ aiProviders.reduce((sum, item) => sum + item.todayCalls, 0) }}</div>
|
||||
<div class="stat-foot">含失败与降级调用</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>本月预算使用<DemoBadge /></span><span class="stat-icon">%</span></div>
|
||||
<div class="stat-value">81%</div>
|
||||
<div class="stat-foot">超出阈值需人工确认</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>自动执行能力<DemoBadge /></span><span class="stat-icon">!</span></div>
|
||||
<div class="stat-value">0</div>
|
||||
<div class="stat-foot">高风险动作必须经人工确认</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'providers' }" type="button" @click="tab = 'providers'">服务商</button>
|
||||
<button class="tab" :class="{ active: tab === 'capabilities' }" type="button" @click="tab = 'capabilities'">能力</button>
|
||||
<button class="tab" :class="{ active: tab === 'calls' }" type="button" @click="tab = 'calls'">调用记录</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'providers'" class="grid three-col">
|
||||
<div v-for="provider in aiProviders" :key="provider.name" class="card" v-show="true">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">{{ provider.name }} <DemoBadge /></h3>
|
||||
<StatusTag value="ACTIVE" :label="provider.status" />
|
||||
</div>
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>协议</span><span>{{ provider.protocol }}</span></div>
|
||||
<div class="kv-row"><span>模型</span><span>{{ provider.model }}</span></div>
|
||||
<div class="kv-row"><span>今日调用</span><span>{{ provider.todayCalls }}</span></div>
|
||||
<div class="kv-row"><span>预算使用</span><span>{{ provider.budget }}%</span></div>
|
||||
<div class="kv-row"><span>最近测试</span><span>{{ provider.test }}</span></div>
|
||||
</div>
|
||||
<div class="progress" style="margin-top: 12px"><span :style="{ width: `${provider.budget}%` }"></span></div>
|
||||
<div class="form-actions" style="margin-top: 12px">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供 AI 服务商测试接口">测试连接</button>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供 AI 服务商编辑接口">编辑</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'capabilities'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">模型能力声明<DemoBadge /></h3>
|
||||
<span class="small-muted">服务商宣传能力不等同于项目已验证能力</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>能力</th><th>使用模型</th><th>说明</th><th>状态</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in aiCapabilities" :key="item.name">
|
||||
<td><strong>{{ item.name }}</strong></td>
|
||||
<td>{{ item.model }}</td>
|
||||
<td>{{ item.desc }}</td>
|
||||
<td><StatusTag :value="item.enabled ? 'ACTIVE' : 'DISABLED'" :label="item.enabled ? '已启用' : '未启用'" /></td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供能力开关接口">配置</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">调用记录<DemoBadge /></h3>
|
||||
<span class="small-muted">真实调用日志需后端 /ai/calls 接口</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>时间</th><th>能力</th><th>模型</th><th>耗时</th><th>Token</th><th>结果</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="call in aiCalls" :key="`${call.time}-${call.capability}`">
|
||||
<td>{{ call.time }}</td>
|
||||
<td>{{ call.capability }}</td>
|
||||
<td>{{ call.model }}</td>
|
||||
<td>{{ call.duration }}</td>
|
||||
<td>{{ call.tokens }}</td>
|
||||
<td><StatusTag :value="call.result === '成功' ? 'SUCCESS' : 'FAILED'" :label="call.result" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
@@ -1,103 +1,815 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, backupPlans, backupRecords } from '../demo/planned'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { describeError, formatTime, notify } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import PlannedNotice from '../components/PlannedNotice.vue'
|
||||
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
||||
import DetailDrawer from '../components/DetailDrawer.vue'
|
||||
import Pagination from '../components/Pagination.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import Select from '../components/ui/Select.vue'
|
||||
import { can, denialReason } from '../permissions'
|
||||
|
||||
const tab = ref('plans')
|
||||
const BACKUP_STATUS_OPTIONS = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: 'RUNNING', label: 'RUNNING · 执行中' },
|
||||
{ value: 'SUCCEEDED', label: 'SUCCEEDED · 成功' },
|
||||
{ value: 'FAILED', label: 'FAILED · 失败' }
|
||||
]
|
||||
const BACKUP_TYPE_OPTIONS = [
|
||||
{ value: 'LOGICAL_JSONL', label: 'LOGICAL_JSONL(逻辑备份 · MinIO)' },
|
||||
{ value: 'MYSQL_DUMP', label: 'MYSQL_DUMP(mysqldump 全量)' }
|
||||
]
|
||||
|
||||
const tab = ref('records')
|
||||
const rows = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const statusFilter = ref('')
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const canRead = computed(() => can('backup.read'))
|
||||
const canExecute = computed(() => can('backup.execute'))
|
||||
const executeReason = computed(() => denialReason('backup.execute', '执行备份或恢复'))
|
||||
|
||||
const createModal = ref(null)
|
||||
const createBusy = ref(false)
|
||||
const createError = ref(null)
|
||||
|
||||
const restoreModal = ref(null)
|
||||
const restoreBusy = ref(false)
|
||||
const restoreError = ref(null)
|
||||
|
||||
const confirmRow = ref(null)
|
||||
const confirmBusy = ref(false)
|
||||
const confirmError = ref(null)
|
||||
|
||||
// 运维运行模式:由后端强制,前端只做提示与禁用。
|
||||
const runtimeMode = ref(null)
|
||||
const preflightResult = ref(null)
|
||||
const preflightBusy = ref(false)
|
||||
const preflightError = ref(null)
|
||||
|
||||
const succeeded = computed(() => rows.value.filter((row) => String(row.status).toUpperCase() === 'SUCCEEDED').length)
|
||||
const failed = computed(() => rows.value.filter((row) => String(row.status).toUpperCase() === 'FAILED').length)
|
||||
const corrupt = computed(() => rows.value.filter((row) => String(row.checksumStatus).toUpperCase() === 'CORRUPT').length)
|
||||
const lastSucceeded = computed(() => rows.value.find((row) => String(row.status).toUpperCase() === 'SUCCEEDED'))
|
||||
|
||||
function formatBytes(value) {
|
||||
const size = Number(value)
|
||||
if (!Number.isFinite(size) || size <= 0) return '—'
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
let index = 0
|
||||
let current = size
|
||||
while (current >= 1024 && index < units.length - 1) {
|
||||
current /= 1024
|
||||
index += 1
|
||||
}
|
||||
return `${current.toFixed(index === 0 ? 0 : 1)} ${units[index]}`
|
||||
}
|
||||
|
||||
function checksumLabel(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'VALID') return '校验通过'
|
||||
if (text === 'CORRUPT') return '校验不一致'
|
||||
if (text === 'PENDING') return '待校验'
|
||||
return value || '—'
|
||||
}
|
||||
|
||||
function statusLabel(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'SUCCEEDED') return '成功'
|
||||
if (text === 'FAILED') return '失败'
|
||||
if (text === 'RUNNING') return '执行中'
|
||||
return value || '—'
|
||||
}
|
||||
|
||||
async function load(nextPage = page.value) {
|
||||
if (canRead.value === false) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.backups({
|
||||
status: statusFilter.value || undefined,
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value
|
||||
})
|
||||
rows.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || nextPage
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onPageChange({ page: nextPage, pageSize: nextSize }) {
|
||||
pageSize.value = nextSize
|
||||
load(nextPage)
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
createModal.value = { backupType: 'LOGICAL_JSONL', reason: '' }
|
||||
createError.value = null
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
if (!createModal.value || createBusy.value) return
|
||||
createBusy.value = true
|
||||
createError.value = null
|
||||
try {
|
||||
const data = await api.createBackup({
|
||||
backupType: createModal.value.backupType,
|
||||
reason: createModal.value.reason.trim() || null
|
||||
})
|
||||
notify('备份已创建', `${data?.backupUid || '备份记录'}:${statusLabel(data?.status)};校验 ${checksumLabel(data?.checksumStatus)}。`, 'success')
|
||||
createModal.value = null
|
||||
await load(1)
|
||||
} catch (e) {
|
||||
createError.value = describeError(e)
|
||||
} finally {
|
||||
createBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function askVerify(row) {
|
||||
confirmRow.value = row
|
||||
confirmError.value = null
|
||||
}
|
||||
|
||||
async function doVerify() {
|
||||
if (!confirmRow.value || confirmBusy.value) return
|
||||
confirmBusy.value = true
|
||||
confirmError.value = null
|
||||
try {
|
||||
const data = await api.verifyBackup(confirmRow.value.backupUid)
|
||||
notify(
|
||||
data?.verified ? '完整性校验通过' : '完整性校验失败',
|
||||
data?.verified ? '重算 SHA-256 与记录一致。' : '备份文件哈希与记录不一致,已标记 CORRUPT,禁止恢复。',
|
||||
data?.verified ? 'success' : 'error'
|
||||
)
|
||||
confirmRow.value = null
|
||||
await load(page.value)
|
||||
} catch (e) {
|
||||
confirmError.value = describeError(e)
|
||||
} finally {
|
||||
confirmBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openRestore(row) {
|
||||
restoreModal.value = {
|
||||
row,
|
||||
reason: '',
|
||||
confirmationToken: null,
|
||||
tokenInput: '',
|
||||
step: 'request'
|
||||
}
|
||||
restoreError.value = null
|
||||
}
|
||||
|
||||
async function requestRestoreToken() {
|
||||
if (!restoreModal.value || restoreBusy.value) return
|
||||
restoreBusy.value = true
|
||||
restoreError.value = null
|
||||
try {
|
||||
const data = await api.createRestoreConfirmation(
|
||||
restoreModal.value.row.backupUid,
|
||||
restoreModal.value.reason.trim() || null
|
||||
)
|
||||
restoreModal.value.confirmationToken = data
|
||||
restoreModal.value.step = 'confirm'
|
||||
} catch (e) {
|
||||
restoreError.value = describeError(e)
|
||||
} finally {
|
||||
restoreBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function executeRestore() {
|
||||
const modal = restoreModal.value
|
||||
if (!modal || restoreBusy.value) return
|
||||
restoreBusy.value = true
|
||||
restoreError.value = null
|
||||
try {
|
||||
const data = await api.restoreBackup(
|
||||
modal.row.backupUid,
|
||||
modal.tokenInput.trim(),
|
||||
modal.reason.trim() || null
|
||||
)
|
||||
notify('恢复已提交', `目标库 ${data?.databaseName || '—'};后端已完成实例身份与备份完整性校验。`, 'success')
|
||||
restoreModal.value = null
|
||||
await load(page.value)
|
||||
} catch (e) {
|
||||
restoreError.value = describeError(e)
|
||||
} finally {
|
||||
restoreBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function canRestore(row) {
|
||||
return canExecute.value &&
|
||||
runtimeMode.value?.restoreAllowed !== false &&
|
||||
String(row.status).toUpperCase() === 'SUCCEEDED' &&
|
||||
String(row.checksumStatus).toUpperCase() === 'VALID'
|
||||
}
|
||||
|
||||
// 删除备份产物属于恢复类动作,只读观察模式下后端会返回 409,这里同步禁用入口。
|
||||
const deleteBlockedByMode = computed(() => runtimeMode.value?.restoreAllowed === false)
|
||||
|
||||
async function loadRuntimeMode() {
|
||||
try {
|
||||
runtimeMode.value = await api.runtimeMode()
|
||||
} catch (e) {
|
||||
// 无系统读权限时不展示模式卡片,不阻断备份页。
|
||||
runtimeMode.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function doPreflight(row) {
|
||||
if (preflightBusy.value) return
|
||||
preflightBusy.value = true
|
||||
preflightError.value = null
|
||||
preflightResult.value = null
|
||||
try {
|
||||
preflightResult.value = await api.preflightBackup(row.backupUid)
|
||||
} catch (e) {
|
||||
preflightError.value = describeError(e)
|
||||
} finally {
|
||||
preflightBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function closePreflight() {
|
||||
preflightResult.value = null
|
||||
preflightError.value = null
|
||||
}
|
||||
|
||||
// 保存备份保留策略、清理候选与两阶段删除确认。所有数据均来自后端真实响应。
|
||||
const retention = ref(null)
|
||||
const retentionLoading = ref(false)
|
||||
const retentionError = ref(null)
|
||||
const retentionBusy = ref(false)
|
||||
const deleteModal = ref(null)
|
||||
const deleteBusy = ref(false)
|
||||
const deleteError = ref(null)
|
||||
|
||||
const PROTECTION_LABELS = {
|
||||
LATEST_SUCCEEDED: '最新成功备份',
|
||||
NOT_SUCCEEDED: '失败或状态不明',
|
||||
CHECKSUM_NOT_VALID: '校验未通过',
|
||||
RECENTLY_VERIFIED: '近期校验通过',
|
||||
RECENT_PREFLIGHT: '近期恢复预检'
|
||||
}
|
||||
const CANDIDATE_LABELS = {
|
||||
EXCEEDS_COUNT: '超出保留数量',
|
||||
EXCEEDS_AGE: '超出保留天数'
|
||||
}
|
||||
|
||||
const retentionCandidates = computed(() => (retention.value?.items || []).filter((item) => item.candidate))
|
||||
|
||||
function protectionText(list) {
|
||||
if (!list || !list.length) return '—'
|
||||
return list.map((code) => PROTECTION_LABELS[code] || code).join('、')
|
||||
}
|
||||
|
||||
function candidateText(list) {
|
||||
if (!list || !list.length) return '—'
|
||||
return list.map((code) => CANDIDATE_LABELS[code] || code).join('、')
|
||||
}
|
||||
|
||||
async function loadRetention() {
|
||||
if (canRead.value === false) return
|
||||
retentionLoading.value = true
|
||||
retentionError.value = null
|
||||
try {
|
||||
retention.value = await api.backupRetention()
|
||||
} catch (e) {
|
||||
retention.value = null
|
||||
retentionError.value = describeError(e)
|
||||
} finally {
|
||||
retentionLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function recalculateRetention() {
|
||||
if (retentionBusy.value || canExecute.value === false) return
|
||||
retentionBusy.value = true
|
||||
retentionError.value = null
|
||||
try {
|
||||
retention.value = await api.recalculateBackupRetention()
|
||||
notify('候选计算完成', '已重新计算并标记清理候选,未删除任何备份产物。', 'success')
|
||||
await load(page.value)
|
||||
} catch (e) {
|
||||
retentionError.value = describeError(e)
|
||||
} finally {
|
||||
retentionBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function switchTab(next) {
|
||||
tab.value = next
|
||||
if (next === 'retention' && !retention.value && !retentionLoading.value) {
|
||||
loadRetention()
|
||||
}
|
||||
}
|
||||
|
||||
function openDelete(row) {
|
||||
if (deleteBlockedByMode.value) return
|
||||
deleteModal.value = { row, reason: '', preflight: null, token: null, tokenInput: '', step: 'preflight' }
|
||||
deleteError.value = null
|
||||
}
|
||||
|
||||
async function runDeletePreflight() {
|
||||
const modal = deleteModal.value
|
||||
if (!modal || deleteBusy.value) return
|
||||
deleteBusy.value = true
|
||||
deleteError.value = null
|
||||
try {
|
||||
modal.preflight = await api.backupDeletePreflight(modal.row.backupUid)
|
||||
} catch (e) {
|
||||
deleteError.value = describeError(e)
|
||||
} finally {
|
||||
deleteBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function requestDeleteToken() {
|
||||
const modal = deleteModal.value
|
||||
if (!modal || deleteBusy.value) return
|
||||
deleteBusy.value = true
|
||||
deleteError.value = null
|
||||
try {
|
||||
modal.token = await api.createBackupDeleteConfirmation(modal.row.backupUid, modal.reason.trim() || null)
|
||||
modal.step = 'confirm'
|
||||
} catch (e) {
|
||||
deleteError.value = describeError(e)
|
||||
} finally {
|
||||
deleteBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function executeDelete() {
|
||||
const modal = deleteModal.value
|
||||
if (!modal || deleteBusy.value) return
|
||||
deleteBusy.value = true
|
||||
deleteError.value = null
|
||||
try {
|
||||
const data = await api.deleteBackup(modal.row.backupUid, modal.tokenInput.trim(), modal.reason.trim() || null)
|
||||
notify('备份产物已删除', `${data?.backupUid || ''} 已标记为 ${data?.retentionState || 'DELETED'};该操作不可恢复。`, 'success')
|
||||
deleteModal.value = null
|
||||
await loadRetention()
|
||||
await load(page.value)
|
||||
} catch (e) {
|
||||
deleteError.value = describeError(e)
|
||||
} finally {
|
||||
deleteBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load(1)
|
||||
loadRuntimeMode()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="平台管理" title="备份与恢复" desc="备份策略、备份记录与恢复演练。后端尚未提供备份接口,本页内容全部为演示数据。">
|
||||
<PageHead kicker="平台管理" title="备份与恢复" desc="备份记录、完整性校验与恢复前检查均来自后端;恢复会覆盖当前数据库,必须单独申请一次性确认令牌。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供恢复接口">恢复数据</button>
|
||||
<button class="btn primary" type="button" disabled title="后端未提供立即备份接口">立即备份</button>
|
||||
<button class="btn" type="button" :disabled="loading" @click="load(page)">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
<button
|
||||
class="btn primary"
|
||||
type="button"
|
||||
:disabled="canExecute === false" v-tooltip="canExecute === false ? executeReason : '立即创建数据库备份'"
|
||||
@click="openCreate"
|
||||
>
|
||||
立即备份
|
||||
</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="备份与恢复尚未开发"
|
||||
summary="备份任务、完整性校验与恢复演练依赖后端尚未提供的接口。备份属于高风险操作,未实现前不提供任何触发入口。"
|
||||
:deps="PLANNED_DEPS.backup"
|
||||
<div v-if="runtimeMode" class="notice" :class="{ warn: runtimeMode.mode !== 'READ_WRITE' }">
|
||||
<strong>运行模式:{{ runtimeMode.description || runtimeMode.mode }}</strong>
|
||||
<span>模式由后端强制:只读观察模式禁止发起恢复类动作;维护模式禁止新建备份,预检仍可执行。</span>
|
||||
</div>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>备份记录</span><span class="stat-icon">⛁</span></div>
|
||||
<div class="stat-value">{{ total }}</div>
|
||||
<div class="stat-foot">当前筛选条件下的记录数</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>本页成功</span><span class="stat-icon">✓</span></div>
|
||||
<div class="stat-value">{{ succeeded }}</div>
|
||||
<div class="stat-foot">失败 {{ failed }} · 校验不一致 {{ corrupt }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>最近成功</span><span class="stat-icon">◷</span></div>
|
||||
<div class="stat-value">{{ lastSucceeded ? formatTime(lastSucceeded.finishedAt || lastSucceeded.startedAt) : '—' }}</div>
|
||||
<div class="stat-foot">{{ lastSucceeded ? formatBytes(lastSucceeded.fileSize) : '暂无成功记录' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>恢复门槛</span><span class="stat-icon">↺</span></div>
|
||||
<div class="stat-value">校验 + 令牌</div>
|
||||
<div class="stat-foot">实例身份不一致或旧实例库一律拒绝</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'records' }" type="button" @click="switchTab('records')">备份记录</button>
|
||||
<button class="tab" :class="{ active: tab === 'restore' }" type="button" @click="switchTab('restore')">恢复与安全</button>
|
||||
<button class="tab" :class="{ active: tab === 'retention' }" type="button" @click="switchTab('retention')">保留与容量</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'records'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">备份记录</h3>
|
||||
<span class="pill">{{ total }} 条</span>
|
||||
</div>
|
||||
<div class="filterbar" style="display: flex; gap: 8px; margin-bottom: 10px">
|
||||
<Select
|
||||
v-model="statusFilter"
|
||||
:options="BACKUP_STATUS_OPTIONS"
|
||||
style="width: 140px"
|
||||
aria-label="备份状态筛选"
|
||||
@update:model-value="load(1)"
|
||||
/>
|
||||
<button class="btn sm" type="button" :disabled="loading || canRead === false" @click="load(1)">查询</button>
|
||||
</div>
|
||||
<div v-if="canRead === false" class="notice warn">
|
||||
<strong>缺少权限</strong><span>{{ denialReason('backup.read', '查询备份记录') }}</span>
|
||||
</div>
|
||||
<div v-if="error" class="notice danger">
|
||||
<strong>{{ error.title }}</strong><span>{{ error.message }}</span>
|
||||
<button class="btn sm" type="button" @click="load(page)">重试</button>
|
||||
</div>
|
||||
<div v-else-if="loading && !rows.length" class="loading-row"><span class="spinner"></span>正在读取备份记录…</div>
|
||||
<div v-else-if="!rows.length" class="empty-line">还没有备份记录。数据库备份工具未配置时,后端会拒绝创建且不写入记录。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead>
|
||||
<tr><th>开始时间</th><th>方式</th><th>文件</th><th>大小</th><th>校验</th><th>状态</th><th>错误</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.backupUid">
|
||||
<td class="small-muted">{{ formatTime(row.startedAt) }}</td>
|
||||
<td>{{ row.backupType }}</td>
|
||||
<td class="small-muted">{{ row.fileName || '—' }}</td>
|
||||
<td>{{ formatBytes(row.fileSize) }}</td>
|
||||
<td><StatusTag :value="row.checksumStatus" :label="checksumLabel(row.checksumStatus)" /></td>
|
||||
<td><StatusTag :value="row.status" :label="statusLabel(row.status)" /></td>
|
||||
<td class="small-muted">{{ row.errorMessage || '—' }}</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button
|
||||
class="btn sm"
|
||||
type="button"
|
||||
:disabled="canRead === false || String(row.status).toUpperCase() !== 'SUCCEEDED'" v-tooltip="'只读校验产物并列出将被覆盖的表与行数'"
|
||||
@click="doPreflight(row)"
|
||||
>
|
||||
预检
|
||||
</button>
|
||||
<button
|
||||
class="btn sm"
|
||||
type="button"
|
||||
:disabled="canExecute === false || String(row.status).toUpperCase() !== 'SUCCEEDED'" v-tooltip="canExecute === false ? executeReason : '重算 SHA-256 校验备份完整性'"
|
||||
@click="askVerify(row)"
|
||||
>
|
||||
校验
|
||||
</button>
|
||||
<button
|
||||
class="btn sm danger"
|
||||
type="button"
|
||||
:disabled="!canRestore(row)" v-tooltip="canRestore(row) ? '申请一次性确认令牌后恢复' : '仅成功且校验通过、且非只读观察模式允许恢复'"
|
||||
@click="openRestore(row)"
|
||||
>
|
||||
恢复
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'restore'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">恢复与安全</h3>
|
||||
<span class="pill">破坏性操作</span>
|
||||
</div>
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>备份完整性</span><span>恢复前必须为 SUCCEEDED 且 checksumStatus=VALID;可以重新校验。</span></div>
|
||||
<div class="kv-row"><span>实例身份</span><span>后端会比对 instance-state.json 的 databaseName 与当前 JDBC catalog,不一致直接拒绝。</span></div>
|
||||
<div class="kv-row"><span>旧实例保护</span><span>包含 dblhns39 的旧实例库一律拒绝,不会触碰旧实例。</span></div>
|
||||
<div class="kv-row"><span>二次确认</span><span>必须申请一次性确认令牌(10 分钟有效、仅可用一次),并在弹窗中手动输入令牌。</span></div>
|
||||
<div class="kv-row"><span>工具配置</span><span>未配置 QLINKER_MYSQL_PATH 时后端拒绝恢复,不会执行任何命令。</span></div>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">恢复会覆盖当前数据库,请先完成独立备份并确认影响范围。</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">保留策略与清理候选</h3>
|
||||
<span class="pill">默认只标记,不自动删除</span>
|
||||
<button
|
||||
class="btn sm"
|
||||
type="button"
|
||||
:disabled="retentionBusy || canExecute === false"
|
||||
v-tooltip="canExecute === false ? executeReason : '重新计算并标记清理候选'"
|
||||
@click="recalculateRetention"
|
||||
>
|
||||
{{ retentionBusy ? '计算中…' : '重新计算候选' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="canRead === false" class="notice warn">
|
||||
<strong>缺少权限</strong><span>{{ denialReason('backup.read', '查看保留策略与清洗候选') }}</span>
|
||||
</div>
|
||||
<div v-if="retentionError" class="notice danger">
|
||||
<strong>{{ retentionError.title }}</strong><span>{{ retentionError.message }}</span>
|
||||
<button class="btn sm" type="button" @click="loadRetention">重试</button>
|
||||
</div>
|
||||
<div v-else-if="retentionLoading" class="loading-row"><span class="spinner"></span>正在读取保留策略…</div>
|
||||
<template v-else-if="retention">
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>保留数量</span><span>最多保留 {{ retention.policy?.maxCount }} 份成功备份(最新一份始终受保护)</span></div>
|
||||
<div class="kv-row"><span>保留天数</span><span>{{ retention.policy?.retentionDays > 0 ? `超过 ${retention.policy.retentionDays} 天的成功备份进入候选` : '未启用按时间清理' }}</span></div>
|
||||
<div class="kv-row"><span>保护窗口</span><span>{{ retention.policy?.protectPreflightDays }} 天内被完整性校验或恢复预检引用的备份不进入候选</span></div>
|
||||
<div class="kv-row"><span>自动删除</span><span>{{ retention.policy?.autoDelete ? '开启' : '关闭(默认只计算并标记)' }}</span></div>
|
||||
<div class="kv-row"><span>容量阈值</span><span>总量 {{ formatBytes(retention.policy?.capacityWarningBytes) }} · 近 7 天增长 {{ formatBytes(retention.policy?.growthWarningBytes) }}</span></div>
|
||||
</div>
|
||||
|
||||
<div class="grid stats" style="margin-top: 12px">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>成功备份</span><span class="stat-icon">⛁</span></div>
|
||||
<div class="stat-value">{{ retention.totals?.backupCount ?? '—' }}</div>
|
||||
<div class="stat-foot">未删除的 SUCCEEDED 记录</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>备份总量</span><span class="stat-icon">∑</span></div>
|
||||
<div class="stat-value">{{ formatBytes(retention.totals?.totalBytes) }}</div>
|
||||
<div class="stat-foot">{{ retention.totals?.capacityExceeded ? '已达到容量阈值' : '低于容量阈值' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>近 7 天增长</span><span class="stat-icon">↑</span></div>
|
||||
<div class="stat-value">{{ formatBytes(retention.totals?.growthBytes7d) }}</div>
|
||||
<div class="stat-foot">{{ retention.totals?.growthExceeded ? '已达到增长阈值' : '低于增长阈值' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>清理候选</span><span class="stat-icon">⌫</span></div>
|
||||
<div class="stat-value">{{ retention.totals?.candidateCount ?? 0 }}</div>
|
||||
<div class="stat-foot">预计可释放 {{ formatBytes(retention.totals?.candidateBytes) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="retention.totals?.capacityExceeded || retention.totals?.growthExceeded" class="notice warn">
|
||||
<strong>容量告警</strong>
|
||||
<span v-if="retention.totals?.capacityExceeded">备份总量已达到容量阈值,健康聚合与告警规则(backup-capacity)会产出告警事件。</span>
|
||||
<span v-if="retention.totals?.growthExceeded">近 7 天备份增长已达到阈值,告警规则(backup-growth)会产出告警事件。</span>
|
||||
</div>
|
||||
|
||||
<div class="notice">
|
||||
<strong>{{ retention.notice }}</strong>
|
||||
<span>候选清单基于后端实时计算;真正删除必须经过预检与一次性令牌确认。</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!retentionCandidates.length" class="empty-line">当前没有可清理候选。最新成功备份、失败/状态不明、校验未通过以及保护窗口内的备份都不会成为候选。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead><tr><th>备份</th><th>创建时间</th><th>大小</th><th>候选原因</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in retentionCandidates" :key="item.backupUid">
|
||||
<td>
|
||||
<div>{{ item.backupUid }}</div>
|
||||
<div class="small-muted">{{ item.backupType }} · {{ checksumLabel(item.checksumStatus) }}</div>
|
||||
</td>
|
||||
<td class="small-muted">{{ formatTime(item.createdAt) }}</td>
|
||||
<td>{{ formatBytes(item.fileSize) }}</td>
|
||||
<td class="small-muted">{{ candidateText(item.candidateReasons) }}</td>
|
||||
<td>
|
||||
<button
|
||||
class="btn sm danger"
|
||||
type="button"
|
||||
:disabled="!item.deletable || canExecute === false || deleteBlockedByMode"
|
||||
v-tooltip="deleteBlockedByMode ? '只读观察模式下禁止删除备份产物' : (item.deletable ? '预检并通过一次性令牌删除该备份产物' : '仅 MinIO 受控前缀下的逻辑备份产物可删除')"
|
||||
@click="openDelete(item)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">
|
||||
受保护记录示例:{{ protectionText(['LATEST_SUCCEEDED', 'RECENTLY_VERIFIED', 'RECENT_PREFLIGHT']) }}。
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<DetailDrawer :open="Boolean(createModal)" title="立即备份" subtitle="数据库全量" @close="createModal = null">
|
||||
<div v-if="createModal">
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>备份方式</label>
|
||||
<Select v-model="createModal.backupType" :options="BACKUP_TYPE_OPTIONS" block aria-label="备份方式" />
|
||||
</div>
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>原因</label>
|
||||
<input v-model="createModal.reason" class="field" placeholder="写入审计,可选" />
|
||||
</div>
|
||||
<div v-if="createError" class="notice danger"><strong>{{ createError.title }}</strong><span>{{ createError.message }}</span></div>
|
||||
<div class="table-actions" style="margin-top: 16px">
|
||||
<button class="btn primary" type="button" :disabled="createBusy" @click="submitCreate">{{ createBusy ? '执行中…' : '开始备份' }}</button>
|
||||
<button class="btn" type="button" @click="createModal = null">取消</button>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 12px">
|
||||
LOGICAL_JSONL 由后端逐表导出并写入 MinIO 受控前缀,不依赖外部命令;MYSQL_DUMP 需要配置 QLINKER_MYSQLDUMP_PATH,未配置时返回 409 且不写入记录。
|
||||
</p>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
|
||||
<DetailDrawer :open="Boolean(restoreModal)" title="恢复到该备份" :subtitle="restoreModal?.row?.backupUid" @close="restoreModal = null">
|
||||
<div v-if="restoreModal">
|
||||
<div class="notice danger">
|
||||
<strong>恢复会覆盖当前数据库</strong>
|
||||
<span>这是破坏性操作。后端会校验实例身份、备份完整性与一次性令牌,但不会自动执行任何恢复。</span>
|
||||
</div>
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>恢复原因</label>
|
||||
<input v-model="restoreModal.reason" class="field" placeholder="写入审计" :disabled="restoreModal.step === 'confirm'" />
|
||||
</div>
|
||||
<template v-if="restoreModal.step === 'request'">
|
||||
<div class="table-actions">
|
||||
<button class="btn danger" type="button" :disabled="restoreBusy || canExecute === false" @click="requestRestoreToken">
|
||||
{{ restoreBusy ? '申请中…' : '申请一次性确认令牌' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="notice warn">
|
||||
<strong>确认令牌仅显示一次</strong>
|
||||
<div><code class="code">{{ restoreModal.confirmationToken?.confirmationToken }}</code></div>
|
||||
<span>{{ restoreModal.confirmationToken?.notice }}</span>
|
||||
</div>
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>输入确认令牌</label>
|
||||
<input v-model="restoreModal.tokenInput" class="field" placeholder="rc_..." />
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button
|
||||
class="btn danger"
|
||||
type="button"
|
||||
:disabled="restoreBusy || !restoreModal.tokenInput.trim()"
|
||||
@click="executeRestore"
|
||||
>
|
||||
{{ restoreBusy ? '执行中…' : '确认执行恢复' }}
|
||||
</button>
|
||||
<button class="btn" type="button" @click="restoreModal = null">取消</button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="restoreError" class="notice danger"><strong>{{ restoreError.title }}</strong><span>{{ restoreError.message }}</span></div>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
|
||||
<DetailDrawer
|
||||
:open="Boolean(preflightResult) || Boolean(preflightError)"
|
||||
title="恢复预检"
|
||||
subtitle="只读校验,不修改现网数据"
|
||||
@close="closePreflight"
|
||||
>
|
||||
<div v-if="preflightError" class="notice danger">
|
||||
<strong>{{ preflightError.title }}</strong><span>{{ preflightError.message }}</span>
|
||||
</div>
|
||||
<div v-else-if="preflightResult">
|
||||
<div class="notice" :class="preflightResult.valid ? '' : 'danger'">
|
||||
<strong>{{ preflightResult.valid ? '产物完整可用' : '产物校验未通过' }}</strong>
|
||||
<span>校验 {{ checksumLabel(preflightResult.checksumStatus) }} · 大小 {{ formatBytes(preflightResult.actualSize) }} · 库名一致 {{ preflightResult.databaseMatches ? '是' : '否' }}</span>
|
||||
</div>
|
||||
<div v-if="preflightResult.problems?.length" class="notice danger">
|
||||
<strong>问题</strong>
|
||||
<span v-for="(item, index) in preflightResult.problems" :key="`p-${index}`">{{ item }}</span>
|
||||
</div>
|
||||
<div v-if="preflightResult.warnings?.length" class="notice warn">
|
||||
<strong>提示</strong>
|
||||
<span v-for="(item, index) in preflightResult.warnings" :key="`w-${index}`">{{ item }}</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead><tr><th>表</th><th>备份行数</th><th>当前行数</th><th>当前存在</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in preflightResult.tables || []" :key="item.table">
|
||||
<td>{{ item.table }}</td>
|
||||
<td>{{ item.backupRows }}</td>
|
||||
<td>{{ item.currentRows }}</td>
|
||||
<td>{{ item.exists ? '是' : '否' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">
|
||||
真实覆盖式恢复本阶段未开放(restoreExecutionEnabled={{ preflightResult.restoreExecutionEnabled }});预检结果仅供人工确认影响范围。
|
||||
</p>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
|
||||
<DetailDrawer
|
||||
:open="Boolean(deleteModal)"
|
||||
title="删除备份产物"
|
||||
:subtitle="deleteModal?.row?.backupUid"
|
||||
@close="deleteModal = null"
|
||||
>
|
||||
<div v-if="deleteModal">
|
||||
<div class="notice danger">
|
||||
<strong>删除不可恢复</strong>
|
||||
<span>只会移除 MinIO 受控前缀下的备份产物并把记录标记为 DELETED,不会触碰实例数据库、bucket 与本地冷备份目录。</span>
|
||||
</div>
|
||||
|
||||
<template v-if="deleteModal.step === 'preflight'">
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>备份方式</span><span>{{ deleteModal.row?.backupType || '—' }}</span></div>
|
||||
<div class="kv-row"><span>创建时间</span><span>{{ formatTime(deleteModal.row?.createdAt) }}</span></div>
|
||||
<div class="kv-row"><span>大小</span><span>{{ formatBytes(deleteModal.row?.fileSize) }}</span></div>
|
||||
<div class="kv-row"><span>候选原因</span><span>{{ candidateText(deleteModal.row?.candidateReasons) }}</span></div>
|
||||
</div>
|
||||
<div v-if="deleteModal.preflight" class="notice">
|
||||
<strong>{{ deleteModal.preflight.deletable ? '预检通过' : '预检未通过' }}</strong>
|
||||
<span>{{ deleteModal.preflight.artifactScope }}</span>
|
||||
<span>{{ deleteModal.preflight.notice }}</span>
|
||||
</div>
|
||||
<div class="table-actions" style="margin-top: 12px">
|
||||
<button class="btn" type="button" :disabled="deleteBusy" @click="runDeletePreflight">
|
||||
{{ deleteBusy ? '预检中…' : '执行删除预检' }}
|
||||
</button>
|
||||
<button v-if="deleteModal.preflight" class="btn danger" type="button" :disabled="deleteBlockedByMode" @click="deleteModal.step = 'token'">下一步</button>
|
||||
<button class="btn" type="button" @click="deleteModal = null">取消</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="deleteModal.step === 'token'">
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>删除原因</label>
|
||||
<input v-model="deleteModal.reason" class="field" placeholder="写入审计,可选(最多 500 字)" />
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button class="btn danger" type="button" :disabled="deleteBusy || deleteBlockedByMode" @click="requestDeleteToken">
|
||||
{{ deleteBusy ? '申请中…' : '申请一次性确认令牌' }}
|
||||
</button>
|
||||
<button class="btn" type="button" @click="deleteModal = null">取消</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="notice warn">
|
||||
<strong>确认令牌仅显示一次</strong>
|
||||
<div><code class="code">{{ deleteModal.token?.confirmationToken }}</code></div>
|
||||
<span>{{ deleteModal.token?.notice }}</span>
|
||||
</div>
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label>输入确认令牌</label>
|
||||
<input v-model="deleteModal.tokenInput" class="field" placeholder="bd_..." />
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button
|
||||
class="btn danger"
|
||||
type="button"
|
||||
:disabled="deleteBusy || deleteBlockedByMode || !deleteModal.tokenInput.trim()"
|
||||
@click="executeDelete"
|
||||
>
|
||||
{{ deleteBusy ? '删除中…' : '确认删除备份产物' }}
|
||||
</button>
|
||||
<button class="btn" type="button" @click="deleteModal = null">取消</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="deleteError" class="notice danger"><strong>{{ deleteError.title }}</strong><span>{{ deleteError.message }}</span></div>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="Boolean(confirmRow)"
|
||||
title="校验备份完整性"
|
||||
:message="confirmRow ? `重新计算 ${confirmRow.backupUid} 的 SHA-256?` : ''"
|
||||
hint="校验不一致会把记录标记为 CORRUPT,并禁止该备份用于恢复。"
|
||||
confirm-text="开始校验"
|
||||
:busy="confirmBusy"
|
||||
@cancel="confirmRow = null"
|
||||
@confirm="doVerify"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div class="demo-banner">{{ MOCK_NOTE }}<DemoBadge /></div>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>备份策略<DemoBadge /></span><span class="stat-icon">⛁</span></div>
|
||||
<div class="stat-value">{{ backupPlans.length }}</div>
|
||||
<div class="stat-foot">全部启用</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>最近备份<DemoBadge /></span><span class="stat-icon">◷</span></div>
|
||||
<div class="stat-value">今天 08:40</div>
|
||||
<div class="stat-foot">数据库全量 · 1.8 GB</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>完整性校验<DemoBadge /></span><span class="stat-icon">✓</span></div>
|
||||
<div class="stat-value">通过</div>
|
||||
<div class="stat-foot">最近 5 次全部通过</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>恢复演练<DemoBadge /></span><span class="stat-icon">↺</span></div>
|
||||
<div class="stat-value">14 天前</div>
|
||||
<div class="stat-foot">演练结果:通过</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'plans' }" type="button" @click="tab = 'plans'">备份策略</button>
|
||||
<button class="tab" :class="{ active: tab === 'records' }" type="button" @click="tab = 'records'">备份记录</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'plans'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">备份策略<DemoBadge /></h3>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供备份策略创建接口">新建策略</button>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>策略</th><th>范围</th><th>计划</th><th>保留</th><th>状态</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="plan in backupPlans" :key="plan.name">
|
||||
<td><strong>{{ plan.name }}</strong></td>
|
||||
<td>{{ plan.scope }}</td>
|
||||
<td>{{ plan.schedule }}</td>
|
||||
<td>{{ plan.retention }}</td>
|
||||
<td><StatusTag :value="plan.enabled ? 'ACTIVE' : 'DISABLED'" :label="plan.enabled ? '启用' : '停用'" /></td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供备份策略编辑接口">编辑</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">备份记录<DemoBadge /></h3>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供备份下载接口">下载</button>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>时间</th><th>范围</th><th>方式</th><th>大小</th><th>校验</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="record in backupRecords" :key="`${record.time}-${record.scope}`">
|
||||
<td>{{ record.time }}</td>
|
||||
<td>{{ record.scope }}</td>
|
||||
<td>{{ record.type }}</td>
|
||||
<td>{{ record.size }}</td>
|
||||
<td><StatusTag value="SUCCESS" :label="record.verify" /></td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供恢复接口">恢复</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="confirmError" class="notice danger" style="margin-top: 8px">
|
||||
<strong>{{ confirmError.title }}</strong><span>{{ confirmError.message }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.filterbar .field {
|
||||
height: 30px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -95,9 +95,7 @@ onMounted(loadStatus)
|
||||
<template>
|
||||
<div class="auth-card" style="max-width: 520px">
|
||||
<div class="auth-card-head">
|
||||
<p class="eyebrow">FIRST RUN</p>
|
||||
<h1 class="auth-title">初始化管理员</h1>
|
||||
<p class="auth-sub">首次启动专用。创建第一个管理员后,引导入口会永久关闭。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="success" class="notice">
|
||||
|
||||
@@ -7,6 +7,7 @@ import PageHead from '../components/PageHead.vue'
|
||||
import StatCard from '../components/StatCard.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import AvatarBadge from '../components/AvatarBadge.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import { demoState } from '../demo/config'
|
||||
import { automationRules, automationSummary, dashboardTrend24h } from '../demo/planned'
|
||||
@@ -137,7 +138,12 @@ onMounted(load)
|
||||
<tr v-for="item in bindings" :key="item.bindingUid">
|
||||
<td>
|
||||
<div class="identity">
|
||||
<span class="mini-avatar">{{ (item.displayName || 'N').slice(0, 1) }}</span>
|
||||
<AvatarBadge
|
||||
size="sm"
|
||||
:name="item.displayName"
|
||||
:media-uid="item.avatarMediaUid"
|
||||
type="ACCOUNT"
|
||||
/>
|
||||
<div>
|
||||
<strong>{{ item.displayName || '—' }}</strong>
|
||||
<span>{{ item.endpoint || '—' }}</span>
|
||||
@@ -151,7 +157,7 @@ onMounted(load)
|
||||
<div class="small-muted" style="margin-top: 4px">{{ item.connectionStatus || '—' }}</div>
|
||||
</td>
|
||||
<td>{{ formatTime(item.lastEventAt) }}</td>
|
||||
<td class="muted" title="后端未提供按绑定的今日消息统计">—</td>
|
||||
<td class="muted" v-tooltip="'后端未提供按绑定的今日消息统计'">—</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -75,9 +75,7 @@ onMounted(loadStatus)
|
||||
<template>
|
||||
<div class="auth-card">
|
||||
<div class="auth-card-head">
|
||||
<p class="eyebrow">QLINKER ADMIN</p>
|
||||
<h1 class="auth-title">登录管理台</h1>
|
||||
<p class="auth-sub">单管理员实例。登录后可查看消息、管理连接、执行受控发送。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="statusLoading" class="loading-row">
|
||||
|
||||
@@ -1,104 +1,192 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, logRows } from '../demo/planned'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { describeError, formatTime } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import PlannedNotice from '../components/PlannedNotice.vue'
|
||||
import Pagination from '../components/Pagination.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import Select from '../components/ui/Select.vue'
|
||||
import { can, denialReason } from '../permissions'
|
||||
|
||||
const level = ref('')
|
||||
const keyword = ref('')
|
||||
const LOG_LEVEL_OPTIONS = [
|
||||
{ value: '', label: '全部级别' },
|
||||
{ value: 'TRACE', label: 'TRACE' },
|
||||
{ value: 'DEBUG', label: 'DEBUG' },
|
||||
{ value: 'INFO', label: 'INFO' },
|
||||
{ value: 'WARN', label: 'WARN' },
|
||||
{ value: 'ERROR', label: 'ERROR' },
|
||||
{ value: 'FATAL', label: 'FATAL' }
|
||||
]
|
||||
|
||||
const filtered = computed(() =>
|
||||
logRows.filter((row) =>
|
||||
(!level.value || row.level === level.value) &&
|
||||
(!keyword.value.trim() || `${row.source} ${row.summary} ${row.trace}`.includes(keyword.value.trim()))
|
||||
)
|
||||
)
|
||||
const filters = reactive({ traceId: '', level: '', keyword: '', from: '', to: '' })
|
||||
const rows = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(50)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const errorCount = computed(() => logRows.filter((row) => row.level === 'ERROR').length)
|
||||
const warnCount = computed(() => logRows.filter((row) => row.level === 'WARN').length)
|
||||
const canRead = computed(() => can('log.read'))
|
||||
const readReason = computed(() => denialReason('log.read', '查询运行日志'))
|
||||
|
||||
const levelCounts = computed(() => {
|
||||
const counts = { ERROR: 0, WARN: 0, INFO: 0 }
|
||||
for (const row of rows.value) {
|
||||
const level = String(row.level || '').toUpperCase()
|
||||
if (level in counts) counts[level] += 1
|
||||
}
|
||||
return counts
|
||||
})
|
||||
|
||||
function toIso(value) {
|
||||
if (!value) return undefined
|
||||
const date = new Date(value)
|
||||
return Number.isNaN(date.getTime()) ? undefined : date.toISOString()
|
||||
}
|
||||
|
||||
async function load(nextPage = page.value) {
|
||||
if (canRead.value === false) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.logs({
|
||||
traceId: filters.traceId.trim() || undefined,
|
||||
level: filters.level || undefined,
|
||||
keyword: filters.keyword.trim() || undefined,
|
||||
from: toIso(filters.from),
|
||||
to: toIso(filters.to),
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value
|
||||
})
|
||||
rows.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || nextPage
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onPageChange({ page: nextPage, pageSize: nextSize }) {
|
||||
pageSize.value = nextSize
|
||||
load(nextPage)
|
||||
}
|
||||
|
||||
function reset() {
|
||||
filters.traceId = ''
|
||||
filters.level = ''
|
||||
filters.keyword = ''
|
||||
filters.from = ''
|
||||
filters.to = ''
|
||||
load(1)
|
||||
}
|
||||
|
||||
onMounted(() => load(1))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="连接与运维" title="运行日志" desc="统一日志检索与链路追踪。后端尚未提供日志查询接口,本页内容全部为演示数据。">
|
||||
<PageHead kicker="连接与运维" title="运行日志" desc="日志来自后端日志文件尾部(最近 2MB、最多 500 行),输出已脱敏;未配置 QLINKER_LOG_FILE 时后端返回 409。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供日志导出接口">导出日志</button>
|
||||
<button class="btn" type="button" :disabled="loading || canRead === false" @click="load(page)">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="运行日志尚未开发"
|
||||
summary="日志检索、链路追踪与导出均依赖后端尚未提供的接口;关闭演示数据时不展示任何占位日志。"
|
||||
:deps="PLANNED_DEPS.logs"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div class="demo-banner">{{ MOCK_NOTE }}<DemoBadge /></div>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>日志条数<DemoBadge /></span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">{{ logRows.length }}</div>
|
||||
<div class="stat-foot">仅演示样本</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>错误<DemoBadge /></span><span class="stat-icon">!</span></div>
|
||||
<div class="stat-value">{{ errorCount }}</div>
|
||||
<div class="stat-foot">ERROR 级别</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>警告<DemoBadge /></span><span class="stat-icon">△</span></div>
|
||||
<div class="stat-value">{{ warnCount }}</div>
|
||||
<div class="stat-foot">WARN 级别</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>保留策略<DemoBadge /></span><span class="stat-icon">◷</span></div>
|
||||
<div class="stat-value">7 天</div>
|
||||
<div class="stat-foot">容量与保留策略待后端配置接口</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">日志检索<DemoBadge /></h3>
|
||||
<span class="small-muted">本地筛选仅作用于演示样本</span>
|
||||
</div>
|
||||
<div class="filterbar" style="display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px">
|
||||
<div class="fld">
|
||||
<label for="log-level">级别</label>
|
||||
<select id="log-level" v-model="level" class="field">
|
||||
<option value="">全部级别</option>
|
||||
<option value="INFO">INFO</option>
|
||||
<option value="WARN">WARN</option>
|
||||
<option value="ERROR">ERROR</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="fld searchfield">
|
||||
<label for="log-keyword">来源 / 内容 / 追踪号</label>
|
||||
<input id="log-keyword" v-model="keyword" class="field" placeholder="例如:object storage、trc_9f16" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>时间</th><th>级别</th><th>来源</th><th>摘要</th><th>追踪号</th><th>耗时</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="row in filtered" :key="row.trace">
|
||||
<td>{{ row.time }}</td>
|
||||
<td><StatusTag :value="row.level" :label="row.level" /></td>
|
||||
<td>{{ row.source }}</td>
|
||||
<td>{{ row.summary }}</td>
|
||||
<td>{{ row.trace }}</td>
|
||||
<td>{{ row.cost }}</td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供链路详情接口">链路详情</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-if="!filtered.length" class="state-block" style="margin-top: 12px">没有匹配的演示日志。</div>
|
||||
<p class="small-muted" style="margin-top: 12px">按用户确认,日志页不再显示「检索延迟 86ms」等无法由后端验证的指标。</p>
|
||||
<div class="stat-top"><span>匹配条数</span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">{{ total }}</div>
|
||||
<div class="stat-foot">当前筛选条件下</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>ERROR</span><span class="stat-icon">!</span></div>
|
||||
<div class="stat-value">{{ levelCounts.ERROR }}</div>
|
||||
<div class="stat-foot">仅统计当前页</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>WARN</span><span class="stat-icon">△</span></div>
|
||||
<div class="stat-value">{{ levelCounts.WARN }}</div>
|
||||
<div class="stat-foot">仅统计当前页</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>读取上限</span><span class="stat-icon">◷</span></div>
|
||||
<div class="stat-value">500 行</div>
|
||||
<div class="stat-foot">每页最多 200 行;尾部 2MB</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">日志检索</h3>
|
||||
<span class="pill">只读</span>
|
||||
</div>
|
||||
<div class="filterbar" style="display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px">
|
||||
<input v-model="filters.traceId" class="field" style="width: 180px" placeholder="traceId" @keyup.enter="load(1)" />
|
||||
<Select
|
||||
v-model="filters.level"
|
||||
:options="LOG_LEVEL_OPTIONS"
|
||||
style="width: 120px"
|
||||
aria-label="日志级别筛选"
|
||||
@update:model-value="load(1)"
|
||||
/>
|
||||
<input v-model="filters.keyword" class="field" style="width: 200px" placeholder="关键字 / logger / 内容" @keyup.enter="load(1)" />
|
||||
<el-date-picker
|
||||
v-model="filters.from"
|
||||
type="datetime"
|
||||
placeholder="起始时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
style="width: 168px"
|
||||
aria-label="起始时间"
|
||||
v-tooltip="'起始时间'"
|
||||
/>
|
||||
<el-date-picker
|
||||
v-model="filters.to"
|
||||
type="datetime"
|
||||
placeholder="结束时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
style="width: 168px"
|
||||
aria-label="结束时间"
|
||||
v-tooltip="'结束时间'"
|
||||
/>
|
||||
<button class="btn sm primary" type="button" :disabled="loading || canRead === false" v-tooltip="canRead === false ? readReason : '查询日志'" @click="load(1)">查询</button>
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="reset">重置</button>
|
||||
</div>
|
||||
<div v-if="canRead === false" class="notice warn"><strong>缺少权限</strong><span>{{ readReason }}</span></div>
|
||||
<div v-if="error" class="notice danger">
|
||||
<strong>{{ error.title }}</strong><span>{{ error.message }}</span>
|
||||
<button class="btn sm" type="button" @click="load(page)">重试</button>
|
||||
</div>
|
||||
<div v-else-if="loading && !rows.length" class="loading-row"><span class="spinner"></span>正在读取日志…</div>
|
||||
<div v-else-if="!rows.length" class="empty-line">当前条件下没有日志。页面不生成占位日志。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead>
|
||||
<tr><th>时间</th><th>级别</th><th>Logger</th><th>traceId</th><th>内容</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, index) in rows" :key="`${row.timestamp}-${row.traceId}-${index}`">
|
||||
<td class="small-muted">{{ formatTime(row.timestamp) }}</td>
|
||||
<td><StatusTag :value="row.level" :label="row.level" /></td>
|
||||
<td class="small-muted">{{ row.logger }}</td>
|
||||
<td><code class="code">{{ row.traceId || '—' }}</code></td>
|
||||
<td class="log-message">{{ row.message }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.log-message {
|
||||
max-width: 520px;
|
||||
word-break: break-word;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { describeError, directionLabel, formatNumber, formatTime, typeLabel } from '../ui'
|
||||
@@ -8,10 +8,32 @@ import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import DetailDrawer from '../components/DetailDrawer.vue'
|
||||
import Pagination from '../components/Pagination.vue'
|
||||
import Select from '../components/ui/Select.vue'
|
||||
import { accountParam, accountState } from '../account-context.js'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const CONVERSATION_TYPE_OPTIONS = [
|
||||
{ value: '', label: '全部类型' },
|
||||
{ value: 'GROUP', label: '群聊 GROUP' },
|
||||
{ value: 'FRIEND', label: '私聊 FRIEND' }
|
||||
]
|
||||
const DIRECTION_OPTIONS = [
|
||||
{ value: '', label: '全部方向' },
|
||||
{ value: 'INBOUND', label: '收到 INBOUND' },
|
||||
{ value: 'OUTBOUND', label: '发出 OUTBOUND(发送记录)' }
|
||||
]
|
||||
const PAGE_SIZE_OPTIONS = [10, 20, 50, 100].map((size) => ({ value: size, label: `${size} 条/页` }))
|
||||
const UNSUPPORTED_OPTIONS = [{ value: '', label: '后端未支持(不筛选)' }]
|
||||
const bindingOptions = computed(() => [
|
||||
{ value: '', label: '全部绑定' },
|
||||
...(bindings.value || []).map((item) => ({
|
||||
value: item.bindingUid,
|
||||
label: `${item.displayName || item.bindingUid}${item.qqAccountId ? ` · ${item.qqAccountId}` : ''}`
|
||||
}))
|
||||
])
|
||||
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
bindingUid: '',
|
||||
@@ -44,6 +66,7 @@ const appliedList = computed(() => {
|
||||
const source = applied.value
|
||||
if (source.keyword) items.push(`关键词(摘要前缀):${source.keyword}`)
|
||||
if (source.bindingUid) items.push(`绑定:${source.bindingUid}`)
|
||||
if (source.qqAccount) items.push(`QQ 账号:${source.qqAccount}`)
|
||||
if (source.conversationType) items.push(`会话类型:${source.conversationType}`)
|
||||
if (source.conversationId) items.push(`会话 ID:${source.conversationId}`)
|
||||
if (source.direction) items.push(`方向:${directionLabel(source.direction)}`)
|
||||
@@ -77,6 +100,14 @@ function validate() {
|
||||
|
||||
async function search(nextPage = 1) {
|
||||
if (!validate()) return
|
||||
// 没有可用账号时不发无账号过滤的检索请求,结果区保持空态。
|
||||
if (!accountParam()) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = null
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
page.value = nextPage
|
||||
loading.value = true
|
||||
error.value = null
|
||||
@@ -90,7 +121,8 @@ async function search(nextPage = 1) {
|
||||
from: localToIso(filters.from),
|
||||
to: localToIso(filters.to),
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value
|
||||
pageSize: pageSize.value,
|
||||
qqAccount: accountParam() || undefined
|
||||
}
|
||||
applied.value = payload
|
||||
try {
|
||||
@@ -172,12 +204,17 @@ onMounted(async () => {
|
||||
if (route.query.direction) filters.direction = String(route.query.direction)
|
||||
if (route.query.keyword || route.query.conversationId) search()
|
||||
})
|
||||
|
||||
// 切换 QQ 账号后若已有检索条件,回到第 1 页按新账号重新检索。
|
||||
watch(() => accountState.current, () => {
|
||||
if (hasApplied.value) search(1)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="工作空间" title="消息检索" desc="按后端 /api/v1/messages 支持的参数检索已入库消息。关键词只做 raw_summary 前缀匹配,不检索正文与原始 payload。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供导出接口">导出结果</button>
|
||||
<button class="btn" type="button" disabled v-tooltip="'后端未提供导出接口'">导出结果</button>
|
||||
<button class="btn" type="button" :disabled="loading" @click="search(1)">刷新结果</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
@@ -196,20 +233,18 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-binding">账号 / 绑定</label>
|
||||
<select id="ms-binding" v-model="filters.bindingUid" class="field">
|
||||
<option value="">全部绑定</option>
|
||||
<option v-for="item in bindings" :key="item.bindingUid" :value="item.bindingUid">
|
||||
{{ item.displayName || item.bindingUid }}{{ item.qqAccountId ? ` · ${item.qqAccountId}` : '' }}
|
||||
</option>
|
||||
</select>
|
||||
<Select
|
||||
id="ms-binding"
|
||||
v-model="filters.bindingUid"
|
||||
:options="bindingOptions"
|
||||
block
|
||||
searchable
|
||||
aria-label="绑定筛选"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-conv-type">会话类型</label>
|
||||
<select id="ms-conv-type" v-model="filters.conversationType" class="field">
|
||||
<option value="">全部类型</option>
|
||||
<option value="GROUP">群聊 GROUP</option>
|
||||
<option value="FRIEND">私聊 FRIEND</option>
|
||||
</select>
|
||||
<Select id="ms-conv-type" v-model="filters.conversationType" :options="CONVERSATION_TYPE_OPTIONS" block />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-conv-id">会话 ID</label>
|
||||
@@ -217,11 +252,7 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-direction">方向(发送记录)</label>
|
||||
<select id="ms-direction" v-model="filters.direction" class="field">
|
||||
<option value="">全部方向</option>
|
||||
<option value="INBOUND">收到 INBOUND</option>
|
||||
<option value="OUTBOUND">发出 OUTBOUND(发送记录)</option>
|
||||
</select>
|
||||
<Select id="ms-direction" v-model="filters.direction" :options="DIRECTION_OPTIONS" block />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-sender">发送者 ID</label>
|
||||
@@ -229,34 +260,59 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-from">起始时间</label>
|
||||
<input id="ms-from" v-model="filters.from" class="field" type="datetime-local" :class="{ invalid: validationError }" />
|
||||
<el-date-picker
|
||||
id="ms-from"
|
||||
v-model="filters.from"
|
||||
type="datetime"
|
||||
placeholder="选择起始时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
:class="{ invalid: validationError }"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-to">结束时间</label>
|
||||
<input id="ms-to" v-model="filters.to" class="field" type="datetime-local" :class="{ invalid: validationError }" />
|
||||
<el-date-picker
|
||||
id="ms-to"
|
||||
v-model="filters.to"
|
||||
type="datetime"
|
||||
placeholder="选择结束时间"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
value-format="YYYY-MM-DDTHH:mm"
|
||||
:class="{ invalid: validationError }"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-type">消息类型</label>
|
||||
<select id="ms-type" class="field" disabled title="后端 /messages 未提供 messageType 筛选参数">
|
||||
<option>后端未支持(不筛选)</option>
|
||||
</select>
|
||||
<Select
|
||||
id="ms-type"
|
||||
:model-value="''"
|
||||
:options="UNSUPPORTED_OPTIONS"
|
||||
block
|
||||
disabled
|
||||
placeholder="后端未支持(不筛选)"
|
||||
aria-label="消息类型(后端未支持)"
|
||||
/>
|
||||
<p class="field-hint">类型筛选置灰:后端列表接口不支持 messageType 参数。</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-status">处理状态</label>
|
||||
<select id="ms-status" class="field" disabled title="后端 /messages 未提供处理状态筛选参数">
|
||||
<option>后端未支持(不筛选)</option>
|
||||
</select>
|
||||
<Select
|
||||
id="ms-status"
|
||||
:model-value="''"
|
||||
:options="UNSUPPORTED_OPTIONS"
|
||||
block
|
||||
disabled
|
||||
placeholder="后端未支持(不筛选)"
|
||||
aria-label="处理状态(后端未支持)"
|
||||
/>
|
||||
<p class="field-hint">处理状态置灰:后端列表接口不支持 normalizedStatus 参数。</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-size">每页条数</label>
|
||||
<select id="ms-size" v-model.number="pageSize" class="field">
|
||||
<option :value="10">10 条/页</option>
|
||||
<option :value="20">20 条/页</option>
|
||||
<option :value="50">50 条/页</option>
|
||||
<option :value="100">100 条/页</option>
|
||||
</select>
|
||||
<Select id="ms-size" v-model="pageSize" :options="PAGE_SIZE_OPTIONS" block />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,126 +2,277 @@
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { describeError, formatNumber, formatTime } from '../ui'
|
||||
import { demoState } from '../demo/config'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import { opsAlerts, opsResources } from '../demo/planned'
|
||||
import { can, denialReason } from '../permissions'
|
||||
|
||||
const health = ref(null)
|
||||
const status = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const sendTotal = computed(() =>
|
||||
health.value ? ['PENDING', 'RUNNING', 'SUCCEEDED', 'FAILED', 'UNKNOWN'].reduce((sum, key) => sum + (Number(health.value.send?.[key]) || 0), 0) : 0
|
||||
)
|
||||
const health = ref(null)
|
||||
const healthError = ref(null)
|
||||
const alertSummary = ref(null)
|
||||
const alertRules = ref([])
|
||||
const alertEvents = ref([])
|
||||
const alertTotal = ref(0)
|
||||
const alertError = ref(null)
|
||||
const monitoringLoading = ref(false)
|
||||
const actionMessage = ref(null)
|
||||
const actionError = ref(null)
|
||||
const ruleDrafts = ref({})
|
||||
|
||||
const lastEvent = computed(() => {
|
||||
const items = health.value?.napcat?.items || []
|
||||
const times = items.map((item) => item.lastEventAt).filter(Boolean).sort()
|
||||
return times.length ? times[times.length - 1] : null
|
||||
})
|
||||
const canRead = computed(() => can('system.read'))
|
||||
const readReason = computed(() => denialReason('system.read', '查看系统状态'))
|
||||
const canUpdate = computed(() => can('system.update'))
|
||||
const updateReason = computed(() => denialReason('system.update', '处理告警与调整规则'))
|
||||
|
||||
const sendCounts = computed(() => status.value?.send?.counts || {})
|
||||
const sendTotal = computed(() => Object.values(sendCounts.value).reduce((sum, value) => sum + (Number(value) || 0), 0))
|
||||
|
||||
const rows = computed(() => {
|
||||
if (!health.value) return []
|
||||
const m = health.value.messages || {}
|
||||
const media = health.value.media || {}
|
||||
const send = health.value.send || {}
|
||||
const napcat = health.value.napcat || {}
|
||||
if (!status.value) return []
|
||||
const database = status.value.database || {}
|
||||
const storage = status.value.objectStorage || {}
|
||||
const events = status.value.events || {}
|
||||
const tasks = status.value.tasks || {}
|
||||
const send = status.value.send || {}
|
||||
return [
|
||||
{ name: '应用进程', status: health.value.application || 'UNKNOWN', detail: 'HTTP 存活仅代表进程可响应', at: '—' },
|
||||
{ name: '实例身份', status: health.value.instance ? 'INITIALIZED' : 'PENDING', detail: health.value.instance || '未取得实例标识', at: '—' },
|
||||
{
|
||||
name: 'NapCat 连接',
|
||||
status: napcat.connections?.receiverEnabled ? 'CONNECTED' : 'DISABLED',
|
||||
detail: `受管连接 ${formatNumber(napcat.connections?.managedConnections)} · 绑定 ${formatNumber(napcat.total)} · 事件接收${napcat.connections?.receiverEnabled ? '已启用' : '未启用'}`,
|
||||
at: formatTime(lastEvent.value)
|
||||
},
|
||||
{
|
||||
name: '消息入库',
|
||||
status: Number(m.failedEvents) > 0 ? 'FAILED' : Number(m.unprocessedEvents) > 0 ? 'PENDING' : 'ACTIVE',
|
||||
detail: `总量 ${formatNumber(m.totalMessages)} · 待处理 ${formatNumber(m.unprocessedEvents)} · 失败 ${formatNumber(m.failedEvents)}`,
|
||||
name: '应用进程',
|
||||
status: status.value.application?.status,
|
||||
detail: '仅代表进程可响应;依赖项单独探测',
|
||||
at: '—'
|
||||
},
|
||||
{
|
||||
name: '媒体对象存储',
|
||||
status: Number(media.FAILED) > 0 ? 'FAILED' : Number(media.OBJECT_MISSING) > 0 ? 'WARN' : 'STORED',
|
||||
detail: `已入库 ${formatNumber(media.STORED)} · 失败 ${formatNumber(media.FAILED)} · 对象缺失 ${formatNumber(media.OBJECT_MISSING)}`,
|
||||
name: 'MySQL',
|
||||
status: database.status,
|
||||
detail: database.detail || 'SELECT 1 探测',
|
||||
at: '—'
|
||||
},
|
||||
{
|
||||
name: '发送操作',
|
||||
status: Number(send.UNKNOWN) > 0 ? 'UNKNOWN' : Number(send.FAILED) > 0 ? 'FAILED' : 'ACTIVE',
|
||||
detail: `总计 ${formatNumber(sendTotal.value)} · 成功 ${formatNumber(send.SUCCEEDED)} · 结果未知 ${formatNumber(send.UNKNOWN)}`,
|
||||
name: 'MinIO 对象存储',
|
||||
status: storage.status,
|
||||
detail: storage.detail || (storage.status === 'UP' ? 'bucket 可访问' : 'bucket 不可访问'),
|
||||
at: '—'
|
||||
},
|
||||
{ name: 'MySQL 连接', status: 'UNKNOWN', detail: '后端 health-detail 未提供数据库独立探测结果', at: '—' },
|
||||
{ name: 'MinIO 连接', status: 'UNKNOWN', detail: '后端 health-detail 未提供对象存储独立探测结果', at: '—' },
|
||||
{ name: '异步任务队列', status: 'UNKNOWN', detail: '后端 health-detail 未提供队列积压指标', at: '—' }
|
||||
{
|
||||
name: '事件接收积压',
|
||||
status: events.status,
|
||||
detail: `待处理事件 ${formatNumber(events.pending)}${events.detail ? ` · ${events.detail}` : ''}`,
|
||||
at: events.oldestPendingAt ? formatTime(events.oldestPendingAt) : '—'
|
||||
},
|
||||
{
|
||||
name: '异步任务队列',
|
||||
status: tasks.status,
|
||||
detail: `PENDING ${formatNumber(tasks.pending)} · WAITING ${formatNumber(tasks.waiting)} · FAILED ${formatNumber(tasks.failed)}${tasks.detail ? ` · ${tasks.detail}` : ''}`,
|
||||
at: tasks.nextResumeAt ? formatTime(tasks.nextResumeAt) : '—'
|
||||
},
|
||||
{
|
||||
name: '发送任务',
|
||||
status: send.status,
|
||||
detail: Object.entries(sendCounts.value).map(([key, value]) => `${key} ${formatNumber(value)}`).join(' · ') || '无记录',
|
||||
at: '—'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
async function load() {
|
||||
if (canRead.value === false) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
health.value = await api.healthDetail()
|
||||
status.value = await api.systemStatus()
|
||||
} catch (e) {
|
||||
health.value = null
|
||||
status.value = null
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
function healthTone(componentStatus) {
|
||||
if (componentStatus === 'NORMAL') return 'success'
|
||||
if (componentStatus === 'DEGRADED') return 'warning'
|
||||
if (componentStatus === 'ABNORMAL') return 'error'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function alertTone(eventStatus) {
|
||||
if (eventStatus === 'FIRING') return 'error'
|
||||
if (eventStatus === 'ACKNOWLEDGED') return 'warning'
|
||||
if (eventStatus === 'RESOLVED') return 'success'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function severityTone(severity) {
|
||||
if (severity === 'CRITICAL') return 'error'
|
||||
if (severity === 'WARNING') return 'warning'
|
||||
if (severity === 'INFO') return 'info'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
async function loadMonitoring() {
|
||||
if (canRead.value === false) return
|
||||
monitoringLoading.value = true
|
||||
healthError.value = null
|
||||
alertError.value = null
|
||||
const [healthResult, summaryResult, rulesResult, eventsResult] = await Promise.allSettled([
|
||||
api.opsHealth(),
|
||||
api.opsAlertSummary(),
|
||||
api.opsAlertRules(),
|
||||
api.opsAlertEvents({ page: 1, pageSize: 20 })
|
||||
])
|
||||
if (healthResult.status === 'fulfilled') health.value = healthResult.value
|
||||
else {
|
||||
health.value = null
|
||||
healthError.value = describeError(healthResult.reason)
|
||||
}
|
||||
if (summaryResult.status === 'fulfilled') alertSummary.value = summaryResult.value
|
||||
if (rulesResult.status === 'fulfilled') {
|
||||
alertRules.value = rulesResult.value || []
|
||||
const drafts = {}
|
||||
for (const rule of alertRules.value) drafts[rule.ruleKey] = String(rule.threshold)
|
||||
ruleDrafts.value = drafts
|
||||
}
|
||||
if (eventsResult.status === 'fulfilled') {
|
||||
alertEvents.value = eventsResult.value?.items || []
|
||||
alertTotal.value = eventsResult.value?.total || 0
|
||||
}
|
||||
const firstRejected = [summaryResult, rulesResult, eventsResult].find((item) => item.status === 'rejected')
|
||||
if (firstRejected) alertError.value = describeError(firstRejected.reason)
|
||||
monitoringLoading.value = false
|
||||
}
|
||||
|
||||
async function refreshAll() {
|
||||
actionMessage.value = null
|
||||
actionError.value = null
|
||||
await Promise.all([load(), loadMonitoring()])
|
||||
}
|
||||
|
||||
async function saveRule(rule) {
|
||||
actionMessage.value = null
|
||||
actionError.value = null
|
||||
const threshold = Number(ruleDrafts.value[rule.ruleKey])
|
||||
if (!Number.isFinite(threshold)) {
|
||||
actionError.value = '阈值必须是有效数字'
|
||||
return
|
||||
}
|
||||
try {
|
||||
await api.updateOpsAlertRule(rule.ruleKey, { threshold })
|
||||
actionMessage.value = `已保存规则「${rule.name}」的阈值`
|
||||
await loadMonitoring()
|
||||
} catch (e) {
|
||||
actionError.value = describeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleRule(rule) {
|
||||
actionMessage.value = null
|
||||
actionError.value = null
|
||||
try {
|
||||
await api.updateOpsAlertRule(rule.ruleKey, { enabled: !rule.enabled })
|
||||
actionMessage.value = `规则「${rule.name}」已${rule.enabled ? '停用' : '启用'}`
|
||||
await loadMonitoring()
|
||||
} catch (e) {
|
||||
actionError.value = describeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function acknowledgeEvent(event) {
|
||||
actionMessage.value = null
|
||||
actionError.value = null
|
||||
try {
|
||||
await api.acknowledgeOpsAlert(event.eventUid)
|
||||
actionMessage.value = `已确认告警「${event.summary}」`
|
||||
await loadMonitoring()
|
||||
} catch (e) {
|
||||
actionError.value = describeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function closeEvent(event) {
|
||||
actionMessage.value = null
|
||||
actionError.value = null
|
||||
const note = window.prompt('关闭原因(可选,最多 255 字符)', '')
|
||||
if (note === null) return
|
||||
try {
|
||||
await api.closeOpsAlert(event.eventUid, note)
|
||||
actionMessage.value = `已关闭告警「${event.summary}」`
|
||||
await loadMonitoring()
|
||||
} catch (e) {
|
||||
actionError.value = describeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(refreshAll)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="连接与运维" title="运维监控" desc="健康总览分项来自后端 health-detail;数据库、对象存储独立探测与主机资源尚未提供,按实显示「未提供」。">
|
||||
<PageHead kicker="连接与运维" title="运维监控" desc="分层健康聚合与告警:未配置、正常、降级、异常分别展示,失败原因与下一步建议来自后端真实探测。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
<button class="btn" type="button" :disabled="loading || monitoringLoading" @click="refreshAll">
|
||||
{{ loading || monitoringLoading ? '刷新中…' : '刷新' }}
|
||||
</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div class="grid stats">
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>整体健康</span><span class="stat-icon">◇</span></div>
|
||||
<div class="stat-value">{{ health?.overallLabel || '—' }}</div>
|
||||
<div class="stat-foot">运行模式 {{ health?.runtimeMode || '—' }} · 未配置项不参与降级</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>应用进程</span><span class="stat-icon">◉</span></div>
|
||||
<div class="stat-value">{{ health?.application || '—' }}</div>
|
||||
<div class="stat-foot">进程存活不等于全部依赖可用</div>
|
||||
<div class="stat-value">{{ status?.application?.status || '—' }}</div>
|
||||
<div class="stat-foot">不代表依赖可用</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>NapCat 受管连接</span><span class="stat-icon">⇄</span></div>
|
||||
<div class="stat-value">{{ health ? formatNumber(health.napcat?.connections?.managedConnections) : '—' }}</div>
|
||||
<div class="stat-foot">事件接收{{ health?.napcat?.connections?.receiverEnabled ? '已启用' : '未启用' }}</div>
|
||||
<div class="stat-top"><span>MySQL</span><span class="stat-icon">⛁</span></div>
|
||||
<div class="stat-value">{{ status?.database?.status || '—' }}</div>
|
||||
<div class="stat-foot">{{ status?.database?.detail || 'SELECT 1' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>消息失败 / 待处理</span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">{{ health ? `${formatNumber(health.messages?.failedEvents)} / ${formatNumber(health.messages?.unprocessedEvents)}` : '—' }}</div>
|
||||
<div class="stat-foot">总量 {{ health ? formatNumber(health.messages?.totalMessages) : '—' }}</div>
|
||||
<div class="stat-top"><span>MinIO</span><span class="stat-icon">▤</span></div>
|
||||
<div class="stat-value">{{ status?.objectStorage?.status || '—' }}</div>
|
||||
<div class="stat-foot">{{ status?.objectStorage?.detail || 'bucket 探测' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>发送结果未知</span><span class="stat-icon">➤</span></div>
|
||||
<div class="stat-value">{{ health ? formatNumber(health.send?.UNKNOWN) : '—' }}</div>
|
||||
<div class="stat-foot">需人工核实,禁止自动重试</div>
|
||||
<div class="stat-top"><span>任务队列</span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">{{ status ? formatNumber(status.tasks?.pending) : '—' }}</div>
|
||||
<div class="stat-foot">WAITING {{ status ? formatNumber(status.tasks?.waiting) : '—' }} · FAILED {{ status ? formatNumber(status.tasks?.failed) : '—' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>事件积压</span><span class="stat-icon">◷</span></div>
|
||||
<div class="stat-value">{{ status ? formatNumber(status.events?.pending) : '—' }}</div>
|
||||
<div class="stat-foot">{{ status?.events?.oldestPendingAt ? `最早 ${formatTime(status.events.oldestPendingAt)}` : '无积压' }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>发送任务</span><span class="stat-icon">➤</span></div>
|
||||
<div class="stat-value">{{ status ? formatNumber(sendTotal) : '—' }}</div>
|
||||
<div class="stat-foot">UNKNOWN 需人工核实,禁止自动重试</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="canRead === false" class="notice warn"><strong>缺少权限</strong><span>{{ readReason }}</span></div>
|
||||
<div v-if="status?.generatedAt" class="small-muted" style="margin-bottom: 10px">探测时间 {{ formatTime(status.generatedAt) }}</div>
|
||||
|
||||
<SectionState :loading="loading" :error="error" @retry="load">
|
||||
<div class="card" style="margin-bottom: 18px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">健康总览</h3>
|
||||
<span class="small-muted">最近事件已并入本表,不另设独立列表</span>
|
||||
<h3 class="card-title">依赖探测</h3>
|
||||
<span class="small-muted">/api/v1/system/status</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>依赖项</th><th>状态</th><th>说明</th><th>最近事件</th></tr></thead>
|
||||
<table class="tbl table-compact">
|
||||
<thead><tr><th>依赖项</th><th>状态</th><th>说明</th><th>最近时间</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.name">
|
||||
<td><strong>{{ row.name }}</strong></td>
|
||||
<td><StatusTag :value="row.status" :label="row.status" /></td>
|
||||
<td class="muted">{{ row.detail }}</td>
|
||||
<td class="small-muted">{{ row.detail }}</td>
|
||||
<td>{{ row.at }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -130,31 +281,138 @@ onMounted(load)
|
||||
</div>
|
||||
</SectionState>
|
||||
|
||||
<template v-if="demoState.enabled">
|
||||
<div class="demo-banner">以下主机资源与告警为演示数据,仅用于界面预览;后端未提供对应接口。<DemoBadge /></div>
|
||||
<div class="grid two-col">
|
||||
<div class="card">
|
||||
<div class="card-head"><h3 class="card-title">主机资源<DemoBadge /></h3><span class="pill">演示</span></div>
|
||||
<div v-for="item in opsResources" :key="item.name" style="margin-bottom: 14px">
|
||||
<div class="context-line"><span>{{ item.name }}</span><span>{{ item.value }}</span></div>
|
||||
<div class="progress"><span :style="{ width: `${item.width}%` }"></span></div>
|
||||
</div>
|
||||
<p class="small-muted">CPU / 内存 / 磁盘使用率需后端主机监控接口。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3 class="card-title">告警<DemoBadge /></h3><span class="pill">演示</span></div>
|
||||
<div v-for="alert in opsAlerts" :key="alert.title" class="activity">
|
||||
<span class="activity-icon" :class="alert.level === 'error' ? 'error' : alert.level === 'warning' ? 'warning' : 'success'">!</span>
|
||||
<div>
|
||||
<p>{{ alert.title }}</p>
|
||||
<small>{{ alert.time }} · {{ alert.status }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions" style="margin-top: 10px">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供告警确认/分派/关闭接口">处理告警</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="actionMessage" class="notice" style="margin-bottom: 12px">{{ actionMessage }}</div>
|
||||
<div v-if="actionError" class="notice warn" style="margin-bottom: 12px"><strong>操作失败</strong><span>{{ actionError }}</span></div>
|
||||
|
||||
<div class="card" style="margin-bottom: 18px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">分层健康聚合</h3>
|
||||
<span class="small-muted">/api/v1/ops/health</span>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="notice">演示数据已关闭:主机资源与告警区块依赖的后端接口尚未提供,因此不显示。</div>
|
||||
<div v-if="healthError" class="notice warn"><strong>健康聚合不可用</strong><span>{{ healthError }}</span></div>
|
||||
<div v-else-if="health" class="table-wrap">
|
||||
<div class="small-muted" style="margin-bottom: 8px">
|
||||
整体 {{ health.overallLabel }}({{ health.overall }}) · 生成时间 {{ formatTime(health.generatedAt) }}
|
||||
</div>
|
||||
<table class="tbl table-compact">
|
||||
<thead><tr><th>组件</th><th>状态</th><th>说明</th><th>下一步建议</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in health.components" :key="item.key">
|
||||
<td><strong>{{ item.name }}</strong></td>
|
||||
<td><StatusTag :value="item.status" :label="item.statusLabel" :tone="healthTone(item.status)" /></td>
|
||||
<td class="small-muted">{{ item.detail || '—' }}</td>
|
||||
<td class="small-muted">{{ item.hint || '—' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else class="small-muted">暂无健康数据</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-bottom: 18px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">告警事件</h3>
|
||||
<span class="small-muted">
|
||||
FIRING {{ alertSummary?.firingCount ?? '—' }} · ACKNOWLEDGED {{ alertSummary?.acknowledgedCount ?? '—' }}
|
||||
· 活跃 {{ alertSummary?.activeCount ?? '—' }} · 共 {{ alertTotal }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="small-muted" style="margin-bottom: 8px">
|
||||
通知渠道 {{ alertSummary?.notification?.channel || '—' }},
|
||||
{{ alertSummary?.notification?.enabled ? '已启用' : '默认关闭(仅记录告警事件,不发起外部请求)' }}
|
||||
</div>
|
||||
<div v-if="alertError" class="notice warn"><strong>告警数据不可用</strong><span>{{ alertError }}</span></div>
|
||||
<div v-else-if="alertEvents.length" class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead>
|
||||
<tr><th>级别</th><th>摘要</th><th>状态</th><th>次数</th><th>最近触发</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="event in alertEvents" :key="event.eventUid">
|
||||
<td><StatusTag :value="event.severity" :label="event.severity" :tone="severityTone(event.severity)" /></td>
|
||||
<td>
|
||||
<strong>{{ event.summary }}</strong>
|
||||
<div class="small-muted">{{ event.detail?.hint || '—' }}</div>
|
||||
</td>
|
||||
<td><StatusTag :value="event.status" :label="event.status" :tone="alertTone(event.status)" /></td>
|
||||
<td>{{ event.occurrenceCount }}</td>
|
||||
<td>{{ formatTime(event.lastFiredAt) }}</td>
|
||||
<td>
|
||||
<button
|
||||
v-if="event.status === 'FIRING'"
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="!canUpdate"
|
||||
:title="canUpdate ? '' : updateReason"
|
||||
@click="acknowledgeEvent(event)"
|
||||
>确认</button>
|
||||
<button
|
||||
v-if="event.status !== 'CLOSED'"
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="!canUpdate"
|
||||
:title="canUpdate ? '' : updateReason"
|
||||
@click="closeEvent(event)"
|
||||
>关闭</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else class="small-muted">当前没有告警事件。规则命中后会在此出现,恢复后自动转为 RESOLVED。</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">告警规则</h3>
|
||||
<span class="small-muted">阈值 / 持续时长 / 静默期由后端强制执行</span>
|
||||
</div>
|
||||
<div v-if="alertRules.length" class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead>
|
||||
<tr><th>规则</th><th>指标</th><th>阈值</th><th>持续</th><th>静默</th><th>级别</th><th>状态</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="rule in alertRules" :key="rule.ruleKey">
|
||||
<td>
|
||||
<strong>{{ rule.name }}</strong>
|
||||
<div class="small-muted">{{ rule.description || '—' }}</div>
|
||||
</td>
|
||||
<td class="small-muted">{{ rule.metric }} {{ rule.comparator }}</td>
|
||||
<td>
|
||||
<input
|
||||
v-model="ruleDrafts[rule.ruleKey]"
|
||||
class="input"
|
||||
type="number"
|
||||
step="any"
|
||||
style="width: 110px"
|
||||
:disabled="!canUpdate"
|
||||
/>
|
||||
</td>
|
||||
<td>{{ rule.durationSeconds }}s</td>
|
||||
<td>{{ rule.silenceMinutes }}min</td>
|
||||
<td>{{ rule.severity }}</td>
|
||||
<td><StatusTag :value="rule.enabled ? 'ENABLED' : 'DISABLED'" :label="rule.enabled ? '启用' : '停用'" /></td>
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="!canUpdate"
|
||||
:title="canUpdate ? '' : updateReason"
|
||||
@click="saveRule(rule)"
|
||||
>保存</button>
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="!canUpdate"
|
||||
:title="canUpdate ? '' : updateReason"
|
||||
@click="toggleRule(rule)"
|
||||
>{{ rule.enabled ? '停用' : '启用' }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else class="small-muted">暂无告警规则。后端首次评估会自动写入默认规则,也可检查告警评估任务是否运行。</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,24 +1,112 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { demoState, MOCK_NOTE, setDemoEnabled } from '../demo/config'
|
||||
import { PLANNED_DEPS, settingsValues } from '../demo/planned'
|
||||
import { describeError, formatTime, notify } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import Select from '../components/ui/Select.vue'
|
||||
import { can, denialReason } from '../permissions'
|
||||
|
||||
const tab = ref('basic')
|
||||
const NOTIFY_CHANNEL_OPTIONS = [{ value: 'IN_APP', label: 'IN_APP(站内)' }]
|
||||
|
||||
const tab = ref('retention')
|
||||
const instance = ref(null)
|
||||
const instanceError = ref('')
|
||||
const dark = ref(document.documentElement.style.colorScheme === 'dark')
|
||||
|
||||
const items = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const saving = ref(false)
|
||||
|
||||
const canRead = computed(() => can('setting.read'))
|
||||
const canUpdate = computed(() => can('setting.update'))
|
||||
const updateReason = computed(() => denialReason('setting.update', '修改系统设置'))
|
||||
|
||||
const retention = computed(() => ({
|
||||
eventDays: numberValue('retention.eventDays'),
|
||||
messageDays: numberValue('retention.messageDays'),
|
||||
mediaDays: numberValue('retention.mediaDays')
|
||||
}))
|
||||
|
||||
const notifyEnabled = computed(() => boolValue('notification.enabled'))
|
||||
const notifyChannel = computed(() => textValue('notification.channel'))
|
||||
const sendConfirmEnabled = computed(() => boolValue('send.confirm.enabled'))
|
||||
|
||||
function findItem(key) {
|
||||
return items.value.find((item) => item.key === key)
|
||||
}
|
||||
|
||||
function numberValue(key) {
|
||||
return Number(findItem(key)?.value ?? 0)
|
||||
}
|
||||
|
||||
function boolValue(key) {
|
||||
return String(findItem(key)?.value ?? 'false') === 'true'
|
||||
}
|
||||
|
||||
function textValue(key) {
|
||||
return String(findItem(key)?.value ?? '')
|
||||
}
|
||||
|
||||
function updateLocal(key, value) {
|
||||
const item = findItem(key)
|
||||
if (item) item.value = value
|
||||
}
|
||||
|
||||
function setTheme(mode) {
|
||||
dark.value = mode === 'dark'
|
||||
document.documentElement.style.colorScheme = dark.value ? 'dark' : 'light'
|
||||
localStorage.setItem('qlinker.theme', dark.value ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
function toggleDemo() {
|
||||
setDemoEnabled(!demoState.enabled)
|
||||
async function loadSettings() {
|
||||
if (canRead.value === false) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.settings()
|
||||
items.value = data?.items || []
|
||||
} catch (e) {
|
||||
items.value = []
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function save(key, value) {
|
||||
if (canUpdate.value === false || saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const item = await api.updateSetting(key, value)
|
||||
updateLocal(key, item?.value ?? value)
|
||||
notify('设置已保存', `${key} = ${item?.value ?? value};后端已写入 system_setting 并记录审计。`, 'success')
|
||||
} catch (e) {
|
||||
notify('设置保存失败', describeError(e).message, 'error')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function saveRetention() {
|
||||
if (canUpdate.value === false || saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const pairs = [
|
||||
['retention.eventDays', String(retention.value.eventDays)],
|
||||
['retention.messageDays', String(retention.value.messageDays)],
|
||||
['retention.mediaDays', String(retention.value.mediaDays)]
|
||||
]
|
||||
for (const [key, value] of pairs) {
|
||||
const item = await api.updateSetting(key, value)
|
||||
updateLocal(key, item?.value ?? value)
|
||||
}
|
||||
notify('保留策略已保存', '三项保留天数已写入 system_setting 并记录审计。', 'success')
|
||||
} catch (e) {
|
||||
notify('保留策略保存失败', describeError(e).message, 'error')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -27,11 +115,15 @@ onMounted(async () => {
|
||||
} catch {
|
||||
instanceError.value = '实例初始化信息读取失败(后端可能未启动)。'
|
||||
}
|
||||
loadSettings()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="平台管理" title="系统设置" desc="实例身份来自后端;外观与演示数据开关为本地真实设置;业务配置项后端尚未提供。">
|
||||
<PageHead kicker="平台管理" title="系统设置" desc="保留策略与通知配置由后端 system_setting 提供读写接口;未知键与越界值由后端拒绝。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="loading" @click="loadSettings">{{ loading ? '刷新中…' : '刷新配置' }}</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div class="card" style="margin-bottom: 16px">
|
||||
@@ -48,77 +140,143 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'basic' }" type="button" @click="tab = 'basic'">基础</button>
|
||||
<button class="tab" :class="{ active: tab === 'notify' }" type="button" @click="tab = 'notify'">通知</button>
|
||||
<button class="tab" :class="{ active: tab === 'appearance' }" type="button" @click="tab = 'appearance'">外观与预览</button>
|
||||
<button class="tab" :class="{ active: tab === 'data' }" type="button" @click="tab = 'data'">数据</button>
|
||||
<div v-if="canRead === false" class="notice warn"><strong>缺少权限</strong><span>{{ denialReason('setting.read', '读取系统设置') }}</span></div>
|
||||
<div v-if="error" class="notice danger">
|
||||
<strong>{{ error.title }}</strong><span>{{ error.message }}</span>
|
||||
<button class="btn sm" type="button" @click="loadSettings">重试</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'basic'" class="card">
|
||||
<div class="card-head"><h3 class="card-title">基础配置<DemoBadge /></h3><span class="small-muted">后端未提供实例设置接口</span></div>
|
||||
<div class="form-grid">
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'retention' }" type="button" @click="tab = 'retention'">数据保留</button>
|
||||
<button class="tab" :class="{ active: tab === 'notify' }" type="button" @click="tab = 'notify'">通知</button>
|
||||
<button class="tab" :class="{ active: tab === 'send' }" type="button" @click="tab = 'send'">发送</button>
|
||||
<button class="tab" :class="{ active: tab === 'appearance' }" type="button" @click="tab = 'appearance'">外观</button>
|
||||
<button class="tab" :class="{ active: tab === 'catalog' }" type="button" @click="tab = 'catalog'">配置项</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'retention'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">数据保留</h3>
|
||||
<span class="pill">system_setting</span>
|
||||
</div>
|
||||
<div v-if="loading && !items.length" class="loading-row"><span class="spinner"></span>正在读取设置…</div>
|
||||
<div v-else class="form-grid">
|
||||
<div class="fld">
|
||||
<label for="set-name">实例名称</label>
|
||||
<input id="set-name" class="field" :value="settingsValues.instanceName" disabled />
|
||||
<label for="set-event-days">原始事件保留天数</label>
|
||||
<input id="set-event-days" v-model.number="retention.eventDays" class="field" type="number" min="1" max="3650" :disabled="canUpdate === false" />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="set-code">实例编号</label>
|
||||
<input id="set-code" class="field" :value="settingsValues.instanceCode" disabled />
|
||||
<label for="set-message-days">归一化消息保留天数</label>
|
||||
<input id="set-message-days" v-model.number="retention.messageDays" class="field" type="number" min="1" max="3650" :disabled="canUpdate === false" />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="set-tz">时区</label>
|
||||
<input id="set-tz" class="field" :value="settingsValues.timezone" disabled />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="set-retention">消息保留天数</label>
|
||||
<input id="set-retention" class="field" :value="settingsValues.retention" disabled />
|
||||
<label for="set-media-days">媒体对象保留天数</label>
|
||||
<input id="set-media-days" v-model.number="retention.mediaDays" class="field" type="number" min="1" max="3650" :disabled="canUpdate === false" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn primary" type="button" disabled title="后端未提供实例设置保存接口">保存设置</button>
|
||||
<button class="btn primary" type="button" :disabled="saving || canUpdate === false" v-tooltip="canUpdate === false ? updateReason : '保存保留策略'" @click="saveRetention">
|
||||
{{ saving ? '保存中…' : '保存保留策略' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">依赖:{{ PLANNED_DEPS.settings.join('、') }}</p>
|
||||
<p class="small-muted" style="margin-top: 10px">取值范围 1–3650 天;后端在写入前校验,越界返回 400。此处只保存策略值,实际清理任务由运维流程执行。</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'notify'" class="card">
|
||||
<div class="card-head"><h3 class="card-title">通知<DemoBadge /></h3><span class="small-muted">演示数据</span></div>
|
||||
<div class="context-line"><span>实时事件提醒</span><span>{{ settingsValues.realtime ? '开启' : '关闭' }}</span></div>
|
||||
<div class="context-line"><span>移动端通知</span><span>{{ settingsValues.mobileNotify ? '开启' : '关闭' }}</span></div>
|
||||
<div class="form-actions">
|
||||
<button class="btn" type="button" disabled title="后端未提供通知设置接口">保存</button>
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">通知</h3>
|
||||
<span class="pill">站内</span>
|
||||
</div>
|
||||
<div class="kv">
|
||||
<div class="kv-row">
|
||||
<span>启用站内通知</span>
|
||||
<span>
|
||||
<button
|
||||
class="btn sm"
|
||||
:class="{ primary: notifyEnabled }"
|
||||
type="button"
|
||||
:disabled="saving || canUpdate === false"
|
||||
@click="save('notification.enabled', notifyEnabled ? 'false' : 'true')"
|
||||
>
|
||||
{{ notifyEnabled ? '已开启' : '已关闭' }}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="kv-row">
|
||||
<span>通知渠道</span>
|
||||
<span>
|
||||
<Select
|
||||
:model-value="notifyChannel"
|
||||
:options="NOTIFY_CHANNEL_OPTIONS"
|
||||
style="width: 140px"
|
||||
:disabled="saving || canUpdate === false"
|
||||
aria-label="通知渠道"
|
||||
@update:model-value="(value) => save('notification.channel', value)"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div class="kv-row"><span>第三方渠道</span><span>未开放:notification.channel.manage(后端未实现外部通知渠道)</span></div>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">修改写入 system_setting 并记录 setting.update 审计。</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'send'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">发送</h3>
|
||||
<span class="pill">system_setting</span>
|
||||
</div>
|
||||
<div class="kv">
|
||||
<div class="kv-row">
|
||||
<span>手动发送二次确认</span>
|
||||
<span>
|
||||
<button
|
||||
class="btn sm"
|
||||
:class="{ primary: sendConfirmEnabled }"
|
||||
type="button"
|
||||
:disabled="saving || canUpdate === false"
|
||||
@click="save('send.confirm.enabled', sendConfirmEnabled ? 'false' : 'true')"
|
||||
>
|
||||
{{ sendConfirmEnabled ? '已开启' : '已关闭' }}
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">关闭后,消息中心手动发送不再弹出确认框,确认后直接调用统一发送服务;可在此重新开启。修改写入 system_setting 并记录 setting.update 审计。</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'appearance'" class="card">
|
||||
<div class="card-head"><h3 class="card-title">外观与预览</h3><span class="pill">本地真实设置</span></div>
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">外观</h3>
|
||||
<span class="pill">本地设置</span>
|
||||
</div>
|
||||
<div class="context-line"><span>主题</span><span>{{ dark ? '深色' : '浅色' }}</span></div>
|
||||
<div class="actions" style="margin: 10px 0 18px">
|
||||
<button class="btn sm" :class="{ primary: !dark }" type="button" @click="setTheme('light')">浅色</button>
|
||||
<button class="btn sm" :class="{ primary: dark }" type="button" @click="setTheme('dark')">深色</button>
|
||||
</div>
|
||||
<p class="small-muted">主题保存在浏览器本地(localStorage),不写入后端配置。</p>
|
||||
|
||||
<div class="drawer-section" style="margin-top: 14px">
|
||||
<h4>演示数据总开关</h4>
|
||||
<div class="context-line">
|
||||
<span>演示数据</span>
|
||||
<button class="btn sm" :class="{ primary: demoState.enabled }" type="button" @click="toggleDemo">
|
||||
{{ demoState.enabled ? '已开启' : '已关闭' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">{{ demoState.enabled ? MOCK_NOTE : '演示数据已关闭:所有未实现页面整体显示「未开发 / 规划中」,按钮保持禁用并标注原因。' }}</p>
|
||||
<p class="small-muted">默认值由构建变量 VITE_ENABLE_MOCK 决定;本地切换会覆盖默认值并持久化。</p>
|
||||
</div>
|
||||
<p class="small-muted">主题保存在浏览器 localStorage,不写入后端配置。</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="card">
|
||||
<div class="card-head"><h3 class="card-title">数据与迁移<DemoBadge /></h3><span class="small-muted">后端未提供迁移与容量接口</span></div>
|
||||
<div class="context-line"><span>数据库迁移版本</span><span>—</span></div>
|
||||
<div class="context-line"><span>对象存储使用量</span><span>—</span></div>
|
||||
<div class="context-line"><span>日志保留策略</span><span>7 天(演示)</span></div>
|
||||
<div class="form-actions">
|
||||
<button class="btn" type="button" disabled title="后端未提供迁移接口">执行迁移</button>
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">配置项目录</h3>
|
||||
<span class="pill">{{ items.length }} 项</span>
|
||||
</div>
|
||||
<div v-if="!items.length" class="empty-line">没有可读取的配置项。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table class="tbl table-compact">
|
||||
<thead><tr><th>键</th><th>当前值</th><th>默认值</th><th>类型</th><th>来源</th><th>更新时间</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in items" :key="item.key">
|
||||
<td><code class="code">{{ item.key }}</code><div class="small-muted">{{ item.description }}</div></td>
|
||||
<td>{{ item.value }}</td>
|
||||
<td class="small-muted">{{ item.defaultValue }}</td>
|
||||
<td>{{ item.valueType }}</td>
|
||||
<td><span class="status" :class="item.source === 'DATABASE' ? 'success' : 'neutral'">{{ item.source === 'DATABASE' ? '已配置' : '默认值' }}</span></td>
|
||||
<td class="small-muted">{{ item.updatedAt ? formatTime(item.updatedAt) : '—' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { aiApi } from '../../api/ai'
|
||||
import ChannelPanel from './ChannelPanel.vue'
|
||||
import CallPanel from './CallPanel.vue'
|
||||
import ToolPanel from './ToolPanel.vue'
|
||||
import GovernancePanel from './GovernancePanel.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const TABS = [
|
||||
{ key: 'channels', label: '渠道', hint: '模型服务商与模型能力合并管理' },
|
||||
{ key: 'calls', label: '调用与成本', hint: '用量、成本、耗时与错误分类' },
|
||||
{ key: 'tools', label: '工具授权', hint: '风险分级、人工确认与执行审计' },
|
||||
{ key: 'governance', label: '治理设置', hint: '脱敏、缓存与记忆保留' }
|
||||
]
|
||||
|
||||
const tab = ref(String(route.query.tab || 'channels'))
|
||||
if (!TABS.some((item) => item.key === tab.value)) tab.value = 'channels'
|
||||
|
||||
const counts = ref({ channels: null, tools: null })
|
||||
const channelMeta = ref({ reserved: 0, unverified: 0 })
|
||||
|
||||
async function loadCounts() {
|
||||
const [providerRows, modelRows, pending] = await Promise.allSettled([
|
||||
aiApi.providers(),
|
||||
aiApi.models(),
|
||||
aiApi.toolCalls({ authorizationStatus: 'APPROVAL_REQUIRED', executionStatus: 'PENDING', page: 1, pageSize: 1 })
|
||||
])
|
||||
const providers = providerRows.status === 'fulfilled' ? (providerRows.value || []) : []
|
||||
const models = modelRows.status === 'fulfilled' ? (modelRows.value || []) : []
|
||||
counts.value = {
|
||||
channels: providerRows.status === 'fulfilled' ? providers.length : null,
|
||||
tools: pending.status === 'fulfilled' ? Number(pending.value?.total || 0) : null
|
||||
}
|
||||
channelMeta.value = {
|
||||
reserved: providers.filter((item) => item.providerStatus !== 'ACTIVE').length,
|
||||
unverified: models.filter((item) => item.modelStatus === 'UNVERIFIED').length
|
||||
}
|
||||
}
|
||||
|
||||
function select(key) {
|
||||
if (tab.value === key) return
|
||||
tab.value = key
|
||||
router.replace({ query: { ...route.query, tab: key === 'channels' ? undefined : key } })
|
||||
loadCounts()
|
||||
}
|
||||
|
||||
watch(() => route.query.tab, (value) => {
|
||||
const next = value ? String(value) : 'channels'
|
||||
if (TABS.some((item) => item.key === next) && next !== tab.value) tab.value = next
|
||||
})
|
||||
|
||||
loadCounts()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="tabs-row">
|
||||
<div class="tabs">
|
||||
<button
|
||||
v-for="item in TABS"
|
||||
:key="item.key"
|
||||
class="tab"
|
||||
:class="{ active: tab === item.key }"
|
||||
type="button" v-tooltip="item.hint"
|
||||
@click="select(item.key)"
|
||||
>
|
||||
{{ item.label }}
|
||||
<span
|
||||
v-if="item.key === 'channels' && counts.channels"
|
||||
:class="tab === 'channels' ? 'tab-badge' : 'tab-count'"
|
||||
>{{ counts.channels }}</span>
|
||||
<span
|
||||
v-else-if="item.key === 'tools' && counts.tools"
|
||||
:class="tab === 'tools' ? 'tab-badge' : 'tab-count'"
|
||||
>{{ counts.tools }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="tab === 'channels'" class="tab-side">
|
||||
<span v-if="channelMeta.reserved" class="side-pill amber">预留 {{ channelMeta.reserved }}</span>
|
||||
<span v-if="channelMeta.unverified" class="side-pill">未验证 {{ channelMeta.unverified }} 项</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ChannelPanel v-if="tab === 'channels'" @changed="loadCounts" />
|
||||
<CallPanel v-else-if="tab === 'calls'" />
|
||||
<ToolPanel v-else-if="tab === 'tools'" />
|
||||
<GovernancePanel v-else />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tabs-row {
|
||||
display: flex; align-items: center; gap: 16px; border-bottom: 1px solid #edf0f5; margin-bottom: 12px;
|
||||
}
|
||||
.tabs-row .tabs { flex: 1; margin: 0; border-bottom: 0; }
|
||||
.tab-badge {
|
||||
display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px;
|
||||
margin-left: 5px; padding: 0 5px; border-radius: 8px; background: #eef0fe; color: #4f5bef;
|
||||
font-size: 9px; font-weight: 600; line-height: 1; vertical-align: 1px; font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.tab-count { margin-left: 5px; color: #9aa1b2; font-size: 9px; font-variant-numeric: tabular-nums; }
|
||||
.tab-side { display: flex; flex: none; gap: 8px; padding-right: 2px; }
|
||||
.side-pill {
|
||||
display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 4px;
|
||||
background: #f3f4f6; color: #6b7280; font-size: 10px;
|
||||
}
|
||||
.side-pill.amber { background: #fffbeb; color: #b45309; }
|
||||
</style>
|
||||
@@ -0,0 +1,820 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { aiApi } from '../../api/ai'
|
||||
import { describeError, formatNumber, formatShortTime, formatTime, notify } from '../../ui'
|
||||
import DetailDrawer from '../../components/DetailDrawer.vue'
|
||||
import Pagination from '../../components/Pagination.vue'
|
||||
import Select from '../../components/ui/Select.vue'
|
||||
import Checkbox from '../../components/ui/Checkbox.vue'
|
||||
import { accountParam, accountState } from '../../account-context.js'
|
||||
|
||||
/**
|
||||
* AI 中心 · 调用与成本(对齐 05-ai-tools 画板,即「调用与成本」页)。
|
||||
* 所有指标与记录都来自 /ai/calls 与 /ai/calls/summary;成本不可用时显示「不可用」,不推算。
|
||||
*/
|
||||
const STATUS_LABEL = {
|
||||
SUCCEEDED: '成功',
|
||||
FAILED: '失败',
|
||||
TIMEOUT: '超时',
|
||||
DEGRADED: '降级',
|
||||
UNKNOWN: '结果未知',
|
||||
PENDING: '进行中'
|
||||
}
|
||||
const SOURCE_LABEL = {
|
||||
API: '接口调用',
|
||||
RULE: '规则引擎',
|
||||
AUTOMATION: '自动化规则',
|
||||
MESSAGE: '消息中心',
|
||||
TOOL: '工具调用',
|
||||
MANUAL: '手动调用',
|
||||
TEST: '连通性测试'
|
||||
}
|
||||
const ERROR_LABEL = {
|
||||
AI_PROVIDER_UNAVAILABLE: '服务商不可用',
|
||||
AI_PROVIDER_TIMEOUT: '调用超时',
|
||||
AI_PROVIDER_RESULT_UNKNOWN: '结果未知',
|
||||
AI_MODEL_NOT_FOUND: '模型不存在',
|
||||
AI_MODEL_UNSUPPORTED: '模型能力不支持',
|
||||
AI_INPUT_REJECTED: '请求参数不合法',
|
||||
AI_STATE_CONFLICT: '状态冲突',
|
||||
AI_TOOL_NOT_ALLOWED: '工具未获授权',
|
||||
AI_TOOL_APPROVAL_REQUIRED: '待人工确认',
|
||||
AI_TOOL_ARGUMENT_INVALID: '工具参数不合法',
|
||||
AI_TOOL_RATE_LIMITED: '工具触发限流',
|
||||
AI_TOOL_EXECUTION_FAILED: '工具执行失败',
|
||||
AI_REDACTION_FORBIDDEN: '脱敏被拒绝',
|
||||
AI_DISABLED: 'AI 能力已停用'
|
||||
}
|
||||
const REDACTION_LABEL = { NONE: '不脱敏', BASIC: '基础', STRICT: '严格' }
|
||||
const OPTIONAL_COLUMNS = [
|
||||
{ key: 'source', label: '来源' },
|
||||
{ key: 'cache', label: '缓存' },
|
||||
{ key: 'redaction', label: '脱敏' }
|
||||
]
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const rows = ref([])
|
||||
const providers = ref([])
|
||||
const models = ref([])
|
||||
const summary = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const exporting = ref(false)
|
||||
|
||||
const range = ref('7d')
|
||||
const errorOptions = ref([])
|
||||
const sourceOptions = ref([])
|
||||
const filters = ref({ providerUid: '', modelUid: '', status: '', sourceType: '', errorCode: '', keyword: '' })
|
||||
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const total = ref(0)
|
||||
|
||||
const detailOpen = ref(false)
|
||||
const detail = ref(null)
|
||||
|
||||
const columnsOpen = ref(false)
|
||||
const hiddenColumns = ref(loadColumnPrefs())
|
||||
const loadedAt = ref('')
|
||||
const governance = ref(null)
|
||||
|
||||
const redactionMode = computed(() => governance.value?.defaultRedactionMode || '')
|
||||
const loadedTimeText = computed(() => (loadedAt.value ? formatTime(loadedAt.value).slice(11) : '—'))
|
||||
const retentionText = computed(() => governance.value?.memory?.defaultRetentionDays
|
||||
? `${governance.value.memory.defaultRetentionDays} 天` : '—')
|
||||
|
||||
const RANGES = [
|
||||
{ key: 'today', label: '今日' },
|
||||
{ key: '7d', label: '近 7 天' },
|
||||
{ key: '30d', label: '近 30 天' }
|
||||
]
|
||||
|
||||
function loadColumnPrefs() {
|
||||
try {
|
||||
const raw = localStorage.getItem('qlinker.ai.calls.columns')
|
||||
const parsed = raw ? JSON.parse(raw) : []
|
||||
return Array.isArray(parsed) ? parsed : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function saveColumnPrefs() {
|
||||
try {
|
||||
localStorage.setItem('qlinker.ai.calls.columns', JSON.stringify(hiddenColumns.value))
|
||||
} catch {
|
||||
/* 本地存储不可用时只影响偏好记忆,不阻断查询 */
|
||||
}
|
||||
}
|
||||
|
||||
function toggleColumn(key) {
|
||||
const list = hiddenColumns.value
|
||||
hiddenColumns.value = list.includes(key) ? list.filter((item) => item !== key) : [...list, key]
|
||||
saveColumnPrefs()
|
||||
}
|
||||
|
||||
function isHidden(key) {
|
||||
return hiddenColumns.value.includes(key)
|
||||
}
|
||||
|
||||
const period = computed(() => {
|
||||
const now = new Date()
|
||||
if (range.value === 'today') {
|
||||
const start = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
||||
return { from: start.toISOString(), to: now.toISOString() }
|
||||
}
|
||||
const days = range.value === '30d' ? 30 : 7
|
||||
return { from: new Date(now.getTime() - days * 86400000).toISOString(), to: now.toISOString() }
|
||||
})
|
||||
|
||||
const modelOptions = computed(() => {
|
||||
const list = filters.value.providerUid
|
||||
? models.value.filter((model) => model.providerUid === filters.value.providerUid)
|
||||
: models.value
|
||||
return list
|
||||
})
|
||||
|
||||
// 筛选下拉选项:把后端返回的列表转成统一 { value, label } 结构。
|
||||
const providerSelectOptions = computed(() => [
|
||||
{ value: '', label: '全部' },
|
||||
...providers.value.map((provider) => ({
|
||||
value: provider.providerUid,
|
||||
label: provider.providerName || provider.providerCode
|
||||
}))
|
||||
])
|
||||
const modelSelectOptions = computed(() => [
|
||||
{ value: '', label: '全部' },
|
||||
...modelOptions.value.map((model) => ({
|
||||
value: model.modelUid,
|
||||
label: model.displayName || model.modelCode
|
||||
}))
|
||||
])
|
||||
const sourceSelectOptions = computed(() => [
|
||||
{ value: '', label: '全部' },
|
||||
...sourceOptions.value.map((item) => ({
|
||||
value: item.sourceType,
|
||||
label: `${sourceLabel(item.sourceType)}(${formatNumber(item.calls)})`
|
||||
}))
|
||||
])
|
||||
const statusSelectOptions = computed(() => [
|
||||
{ value: '', label: '全部' },
|
||||
...Object.keys(STATUS_LABEL).map((key) => ({ value: key, label: STATUS_LABEL[key] }))
|
||||
])
|
||||
const errorSelectOptions = computed(() => [
|
||||
{ value: '', label: '全部' },
|
||||
...errorOptions.value.map((item) => ({
|
||||
value: item.errorCode,
|
||||
label: ERROR_LABEL[item.errorCode] || item.errorCode
|
||||
}))
|
||||
])
|
||||
|
||||
const kpi = computed(() => {
|
||||
const data = summary.value || {}
|
||||
const totalCalls = Number(data.totalCalls || 0)
|
||||
const failed = Number(data.failed || 0) + Number(data.timedOut || 0) + Number(data.unknownResult || 0)
|
||||
return {
|
||||
totalCalls,
|
||||
failedRate: totalCalls ? failed / totalCalls : null,
|
||||
failed,
|
||||
timedOut: Number(data.timedOut || 0),
|
||||
unknown: Number(data.unknownResult || 0),
|
||||
degraded: Number(data.degraded || 0),
|
||||
tokens: Number(data.inputTokens || 0) + Number(data.outputTokens || 0),
|
||||
inputTokens: Number(data.inputTokens || 0),
|
||||
outputTokens: Number(data.outputTokens || 0),
|
||||
cost: data.estimatedCost === null || data.estimatedCost === undefined ? null : Number(data.estimatedCost),
|
||||
costUnavailable: Number(data.costUnavailableCalls || 0),
|
||||
currency: data.currency || '',
|
||||
cacheRate: totalCalls ? Number(data.cacheHitRate || 0) : null,
|
||||
cacheHits: Number(data.cacheHits || 0),
|
||||
cacheMiss: totalCalls - Number(data.cacheHits || 0),
|
||||
avgLatency: Number(data.avgLatencyMs || 0)
|
||||
}
|
||||
})
|
||||
|
||||
const trend = computed(() => {
|
||||
const days = summary.value?.byDay || []
|
||||
const list = days.map((item) => ({
|
||||
day: String(item.day || ''),
|
||||
input: Number(item.inputTokens || 0),
|
||||
output: Number(item.outputTokens || 0),
|
||||
calls: Number(item.calls || 0),
|
||||
failed: Number(item.failed || 0),
|
||||
cost: Number(item.estimatedCost || 0)
|
||||
}))
|
||||
const max = Math.max(1, ...list.map((item) => Math.max(item.input, item.output)))
|
||||
return list.map((item) => ({
|
||||
...item,
|
||||
inputHeight: Math.round((item.input / max) * 100),
|
||||
outputHeight: Math.round((item.output / max) * 100)
|
||||
}))
|
||||
})
|
||||
|
||||
const errorRows = computed(() => {
|
||||
const rowsList = summary.value?.byError || []
|
||||
const max = Math.max(1, ...rowsList.map((item) => Number(item.calls || 0)))
|
||||
return rowsList.map((item) => ({
|
||||
code: item.errorCode || '',
|
||||
label: ERROR_LABEL[item.errorCode] || item.errorCode || '未分类错误',
|
||||
status: item.status || '',
|
||||
calls: Number(item.calls || 0),
|
||||
width: Math.round((Number(item.calls || 0) / max) * 100)
|
||||
}))
|
||||
})
|
||||
|
||||
const errorTotal = computed(() => errorRows.value.reduce((sum, item) => sum + item.calls, 0))
|
||||
|
||||
const cacheHitText = computed(() => {
|
||||
if (kpi.value.cacheRate === null) return '—'
|
||||
return `${(kpi.value.cacheRate * 100).toFixed(0)}%`
|
||||
})
|
||||
|
||||
function tokenText(value) {
|
||||
if (value >= 10000) return `${(value / 10000).toFixed(1)} 万`
|
||||
return formatNumber(value)
|
||||
}
|
||||
|
||||
function percentText(value) {
|
||||
return value === null || value === undefined ? '—' : `${(value * 100).toFixed(1)}%`
|
||||
}
|
||||
|
||||
function sourceLabel(value) {
|
||||
return SOURCE_LABEL[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function statusLabel(value) {
|
||||
return STATUS_LABEL[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function statusClass(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'SUCCEEDED') return 'success'
|
||||
if (text === 'DEGRADED' || text === 'TIMEOUT' || text === 'UNKNOWN') return 'warning'
|
||||
if (text === 'FAILED') return 'danger'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function redactionLabel(value) {
|
||||
return REDACTION_LABEL[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function costText(value, currency) {
|
||||
if (value === null || value === undefined) return '不可用'
|
||||
return `${currency || ''} ${Number(value).toFixed(2)}`.trim()
|
||||
}
|
||||
|
||||
function latencyText(value) {
|
||||
const number = Number(value)
|
||||
if (!Number.isFinite(number)) return '—'
|
||||
return `${(number / 1000).toFixed(1)} 秒`
|
||||
}
|
||||
|
||||
function errorText(err) {
|
||||
const base = describeError(err)
|
||||
return `${base.title}。${base.hint}`
|
||||
}
|
||||
|
||||
async function load() {
|
||||
// 没有可用账号时不发跨账号聚合请求,调用记录与用量显示空态。
|
||||
if (!accountParam()) {
|
||||
rows.value = []
|
||||
summary.value = null
|
||||
total.value = 0
|
||||
error.value = null
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
error.value = null
|
||||
const params = {
|
||||
providerUid: filters.value.providerUid,
|
||||
modelUid: filters.value.modelUid,
|
||||
status: filters.value.status,
|
||||
sourceType: filters.value.sourceType,
|
||||
errorCode: filters.value.errorCode,
|
||||
keyword: filters.value.keyword,
|
||||
from: period.value.from,
|
||||
to: period.value.to,
|
||||
qqAccount: accountParam() || undefined
|
||||
}
|
||||
try {
|
||||
const [pageData, summaryData] = await Promise.all([
|
||||
aiApi.calls({ ...params, page: page.value, pageSize: pageSize.value }),
|
||||
aiApi.callSummary(params)
|
||||
])
|
||||
rows.value = pageData?.items || []
|
||||
page.value = pageData?.page || page.value
|
||||
pageSize.value = pageData?.pageSize || pageSize.value
|
||||
total.value = pageData?.total || 0
|
||||
summary.value = summaryData || null
|
||||
if (!filters.value.errorCode) errorOptions.value = summaryData?.byError || []
|
||||
if (!filters.value.sourceType) sourceOptions.value = summaryData?.bySource || []
|
||||
loadedAt.value = new Date().toISOString()
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
summary.value = null
|
||||
total.value = 0
|
||||
error.value = errorText(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProviders() {
|
||||
try {
|
||||
const [providerRows, modelRows, governanceData] = await Promise.all([
|
||||
aiApi.providers(), aiApi.models(), aiApi.governance()
|
||||
])
|
||||
providers.value = providerRows || []
|
||||
models.value = modelRows || []
|
||||
governance.value = governanceData || null
|
||||
} catch {
|
||||
providers.value = []
|
||||
models.value = []
|
||||
governance.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function changeRange(key) {
|
||||
if (range.value === key) return
|
||||
range.value = key
|
||||
page.value = 1
|
||||
load()
|
||||
}
|
||||
|
||||
let keywordTimer = 0
|
||||
function onKeywordInput() {
|
||||
window.clearTimeout(keywordTimer)
|
||||
keywordTimer = window.setTimeout(() => {
|
||||
page.value = 1
|
||||
load()
|
||||
}, 350)
|
||||
}
|
||||
|
||||
function onFilterChange() {
|
||||
page.value = 1
|
||||
load()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
filters.value = { providerUid: '', modelUid: '', status: '', sourceType: '', errorCode: '', keyword: '' }
|
||||
page.value = 1
|
||||
load()
|
||||
}
|
||||
|
||||
function onPageChange(next) {
|
||||
page.value = next.page
|
||||
pageSize.value = next.pageSize
|
||||
load()
|
||||
}
|
||||
|
||||
function openDetail(row) {
|
||||
detail.value = row
|
||||
detailOpen.value = true
|
||||
}
|
||||
|
||||
async function exportCsv() {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
const base = {
|
||||
providerUid: filters.value.providerUid,
|
||||
modelUid: filters.value.modelUid,
|
||||
status: filters.value.status,
|
||||
sourceType: filters.value.sourceType,
|
||||
errorCode: filters.value.errorCode,
|
||||
keyword: filters.value.keyword,
|
||||
from: period.value.from,
|
||||
to: period.value.to
|
||||
}
|
||||
const collected = []
|
||||
const cap = 1000
|
||||
try {
|
||||
let current = 1
|
||||
while (collected.length < cap) {
|
||||
const data = await aiApi.calls({ ...base, page: current, pageSize: 100 })
|
||||
const items = data?.items || []
|
||||
collected.push(...items)
|
||||
const fetched = (data?.page || current) * (data?.pageSize || 100)
|
||||
if (!items.length || fetched >= Number(data?.total || 0)) break
|
||||
current += 1
|
||||
}
|
||||
} catch (e) {
|
||||
exporting.value = false
|
||||
error.value = errorText(e)
|
||||
return
|
||||
}
|
||||
const header = ['时间', '调用标识', '服务商', '模型', '来源', '状态', '耗时(毫秒)', '输入Token', '输出Token', '估算成本', '币种', '缓存命中', '脱敏模式', '错误码']
|
||||
const lines = collected.map((row) => [
|
||||
formatTime(row.createdAt),
|
||||
row.callUid,
|
||||
row.providerName || row.providerUid || '',
|
||||
row.modelName || row.modelCode || '',
|
||||
sourceLabel(row.sourceType),
|
||||
statusLabel(row.status),
|
||||
row.latencyMs ?? '',
|
||||
row.inputTokens ?? '',
|
||||
row.outputTokens ?? '',
|
||||
row.estimatedCost ?? '',
|
||||
row.currency || '',
|
||||
row.cacheHit ? '命中' : '未命中',
|
||||
redactionLabel(row.redactionMode),
|
||||
row.errorCode || ''
|
||||
])
|
||||
const csv = [header, ...lines]
|
||||
.map((cells) => cells.map((cell) => `"${String(cell ?? '').replace(/"/g, '""')}"`).join(','))
|
||||
.join('\r\n')
|
||||
const blob = new Blob([`\ufeff${csv}`], { type: 'text/csv;charset=utf-8' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = `ai-calls-${new Date().toISOString().slice(0, 10)}.csv`
|
||||
link.click()
|
||||
URL.revokeObjectURL(url)
|
||||
exporting.value = false
|
||||
notify('导出完成', `已导出 ${lines.length} 条调用记录(最多 ${cap} 条)。`, 'success')
|
||||
}
|
||||
|
||||
function goGovernance() {
|
||||
router.replace({ query: { ...route.query, tab: 'governance' } })
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadProviders()
|
||||
load()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.clearTimeout(keywordTimer)
|
||||
})
|
||||
|
||||
// 切换 QQ 账号后回到第 1 页重新加载调用记录与汇总。
|
||||
watch(() => accountState.current, () => {
|
||||
page.value = 1
|
||||
load()
|
||||
})
|
||||
|
||||
watch(() => filters.value.providerUid, () => {
|
||||
if (filters.value.modelUid && !modelOptions.value.some((item) => item.modelUid === filters.value.modelUid)) {
|
||||
filters.value.modelUid = ''
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="ai-calls">
|
||||
<div class="toolbar">
|
||||
<div class="range-group">
|
||||
<button
|
||||
v-for="item in RANGES"
|
||||
:key="item.key"
|
||||
class="range-btn"
|
||||
:class="{ active: range === item.key }"
|
||||
type="button"
|
||||
@click="changeRange(item.key)"
|
||||
>{{ item.label }}</button>
|
||||
</div>
|
||||
|
||||
<label class="filter-field">
|
||||
<span>服务商</span>
|
||||
<Select v-model="filters.providerUid" :options="providerSelectOptions" aria-label="服务商筛选" @update:model-value="onFilterChange" />
|
||||
</label>
|
||||
<label class="filter-field">
|
||||
<span>模型</span>
|
||||
<Select v-model="filters.modelUid" :options="modelSelectOptions" aria-label="模型筛选" @update:model-value="onFilterChange" />
|
||||
</label>
|
||||
<label class="filter-field">
|
||||
<span>来源</span>
|
||||
<Select v-model="filters.sourceType" :options="sourceSelectOptions" aria-label="调用来源筛选" @update:model-value="onFilterChange" />
|
||||
</label>
|
||||
<label class="filter-field">
|
||||
<span>状态</span>
|
||||
<Select v-model="filters.status" :options="statusSelectOptions" aria-label="调用状态筛选" @update:model-value="onFilterChange" />
|
||||
</label>
|
||||
<label class="filter-field">
|
||||
<span>错误分类</span>
|
||||
<Select v-model="filters.errorCode" :options="errorSelectOptions" aria-label="错误分类筛选" @update:model-value="onFilterChange" />
|
||||
</label>
|
||||
|
||||
<label class="search-field">
|
||||
<input v-model="filters.keyword" type="search" placeholder="搜索调用标识 / 来源标识" @input="onKeywordInput" />
|
||||
</label>
|
||||
|
||||
<div class="columns-wrap">
|
||||
<button class="btn sm" type="button" :class="{ primary: columnsOpen }" :aria-pressed="columnsOpen"
|
||||
@click="columnsOpen = !columnsOpen">列设置</button>
|
||||
<div v-if="columnsOpen" class="columns-pop">
|
||||
<Checkbox
|
||||
v-for="item in OPTIONAL_COLUMNS"
|
||||
:key="item.key"
|
||||
class="columns-item"
|
||||
:model-value="!isHidden(item.key)"
|
||||
:label="item.label"
|
||||
@update:model-value="toggleColumn(item.key)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="toolbar-meta">数据截至 {{ loadedTimeText }}</span>
|
||||
<button class="btn sm" type="button" :disabled="exporting || loading" @click="exportCsv">
|
||||
{{ exporting ? '导出中…' : '导出表格' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="inline-error">{{ error }}</p>
|
||||
|
||||
<div class="kpi-row">
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">调用量</span>
|
||||
<strong class="kpi-value">{{ formatNumber(kpi.totalCalls) }} <em>次</em></strong>
|
||||
<span class="kpi-note">按当前筛选统计</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">失败率</span>
|
||||
<strong class="kpi-value" :class="kpi.failedRate && kpi.failedRate > 0.1 ? 'danger' : ''">
|
||||
{{ percentText(kpi.failedRate) }}
|
||||
</strong>
|
||||
<span class="kpi-note">
|
||||
失败 {{ formatNumber(kpi.failed) }} 次 · 超时 {{ formatNumber(kpi.timedOut) }}
|
||||
· 结果未知 {{ formatNumber(kpi.unknown) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">全局总耗</span>
|
||||
<strong class="kpi-value">{{ tokenText(kpi.tokens) }}</strong>
|
||||
<span class="kpi-note">输入 {{ tokenText(kpi.inputTokens) }} · 输出 {{ tokenText(kpi.outputTokens) }}</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">估算成本</span>
|
||||
<strong class="kpi-value">{{ kpi.cost === null ? '不可用' : `${kpi.currency} ${kpi.cost.toFixed(2)}` }}</strong>
|
||||
<span class="kpi-note">成本不可用 {{ formatNumber(kpi.costUnavailable) }} 次 · 按服务商单价估算</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">缓存命中</span>
|
||||
<strong class="kpi-value">{{ cacheHitText }}</strong>
|
||||
<span class="kpi-note">命中 {{ formatNumber(kpi.cacheHits) }} 次 · 未命中 {{ formatNumber(kpi.cacheMiss) }} 次</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-grid">
|
||||
<div class="card table-card">
|
||||
<div class="table-head">
|
||||
<div>
|
||||
<h3>调用记录</h3>
|
||||
<p class="table-sub">仅展示元数据、用量、耗时与成本,不展示提示词与模型响应。</p>
|
||||
</div>
|
||||
<div class="table-tags">
|
||||
<span v-if="redactionMode" class="tag">脱敏:{{ redactionLabel(redactionMode) }}</span>
|
||||
<span class="tag">成本不可用时显示「不可用」</span>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="accountState.current" class="table-sub" style="margin: 0 0 8px">
|
||||
当前按 QQ 账号筛选:仅显示可经规则执行任务追溯到该账号的调用;无法归属的调用记录不计入。
|
||||
</p>
|
||||
|
||||
<div v-if="loading" class="inline-loading">正在加载调用记录…</div>
|
||||
<div v-else-if="!rows.length" class="empty-state">
|
||||
<p>当前条件下没有调用记录。</p>
|
||||
<p class="muted-text">成功、失败、超时与降级调用都会留下记录;成本不可用时显示「不可用」。</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="table-wrap">
|
||||
<table class="call-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>时间</th>
|
||||
<th>调用标识</th>
|
||||
<th>服务商 / 模型</th>
|
||||
<th v-if="!isHidden('source')">来源</th>
|
||||
<th>状态</th>
|
||||
<th>耗时</th>
|
||||
<th>输入 / 输出</th>
|
||||
<th>成本</th>
|
||||
<th v-if="!isHidden('cache')">缓存</th>
|
||||
<th v-if="!isHidden('redaction')">脱敏</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.callUid" @click="openDetail(row)">
|
||||
<td class="nowrap">{{ formatShortTime(row.createdAt) }}</td>
|
||||
<td class="mono">{{ row.callUid }}</td>
|
||||
<td>
|
||||
<strong>{{ row.modelName || row.modelCode || '—' }}</strong>
|
||||
<div class="cell-sub">{{ row.providerName || row.providerUid }}</div>
|
||||
</td>
|
||||
<td v-if="!isHidden('source')" class="cell-sub">{{ sourceLabel(row.sourceType) }}</td>
|
||||
<td>
|
||||
<span class="status-pill" :class="statusClass(row.status)">{{ statusLabel(row.status) }}</span>
|
||||
<div v-if="row.errorCode" class="cell-sub">{{ ERROR_LABEL[row.errorCode] || row.errorCode }}</div>
|
||||
</td>
|
||||
<td class="nowrap">{{ latencyText(row.latencyMs) }}</td>
|
||||
<td class="nowrap">{{ formatNumber(row.inputTokens) }} / {{ formatNumber(row.outputTokens) }}</td>
|
||||
<td class="nowrap">{{ costText(row.estimatedCost, row.currency) }}</td>
|
||||
<td v-if="!isHidden('cache')">{{ row.cacheHit ? '命中' : '未命中' }}</td>
|
||||
<td v-if="!isHidden('redaction')">{{ redactionLabel(row.redactionMode) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="table-foot">
|
||||
<span class="muted-text">共 {{ formatNumber(total) }} 条 · 每页 {{ pageSize }} 条</span>
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="side-col">
|
||||
<div class="card side-card">
|
||||
<header class="side-head">
|
||||
<h3>成本趋势 · {{ range === 'today' ? '今日' : range === '30d' ? '近 30 天' : '近 7 天' }}</h3>
|
||||
<span class="side-meta">合计 {{ kpi.cost === null ? '不可用' : `${kpi.currency} ${kpi.cost.toFixed(2)}` }}</span>
|
||||
</header>
|
||||
<div v-if="!trend.length" class="side-empty">当前时间范围内没有调用数据。</div>
|
||||
<div v-else class="bar-chart">
|
||||
<div v-for="item in trend" :key="item.day" class="bar-col" v-tooltip="`${item.day}:输入 ${formatNumber(item.input)} · 输出 ${formatNumber(item.output)} · 调用 ${item.calls} 次`">
|
||||
<div class="bar-stack">
|
||||
<span class="bar bar-input" :style="{ height: `${item.inputHeight}%` }"></span>
|
||||
<span class="bar bar-output" :style="{ height: `${item.outputHeight}%` }"></span>
|
||||
</div>
|
||||
<span class="bar-label">{{ item.day.slice(5) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-legend">
|
||||
<span><i class="dot dot-input"></i>输入 Token</span>
|
||||
<span><i class="dot dot-output"></i>输出 Token</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card side-card">
|
||||
<header class="side-head">
|
||||
<h3>错误分类</h3>
|
||||
<span class="side-meta">{{ formatNumber(errorTotal) }} 次</span>
|
||||
</header>
|
||||
<div v-if="!errorRows.length" class="side-empty">当前时间范围没有失败或超时记录。</div>
|
||||
<ul v-else class="error-list">
|
||||
<li v-for="item in errorRows" :key="`${item.code}-${item.status}`">
|
||||
<span class="error-name">{{ item.label }}</span>
|
||||
<span class="error-bar"><i :style="{ width: `${item.width}%` }"></i></span>
|
||||
<span class="error-count">{{ formatNumber(item.calls) }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="side-note">统计口径来自错误码分组;超时与限流独立计数,降级与结果未知单列,不混入成功。</p>
|
||||
</div>
|
||||
|
||||
<div class="card side-card">
|
||||
<header class="side-head">
|
||||
<h3>数据最小化</h3>
|
||||
<span class="tag success">已启用</span>
|
||||
</header>
|
||||
<p class="side-note">
|
||||
只保存调用元数据、用量、耗时、成本与失败摘要,不保存完整提示词与模型响应。
|
||||
</p>
|
||||
<dl class="mini-facts">
|
||||
<dt>脱敏模式</dt>
|
||||
<dd>{{ redactionLabel(redactionMode) }}<template v-if="redactionMode">(可切换{{ redactionLabel('STRICT') }})</template></dd>
|
||||
<dt>记忆保留</dt>
|
||||
<dd>{{ retentionText }}</dd>
|
||||
<dt>平均耗时</dt>
|
||||
<dd>{{ latencyText(kpi.avgLatency) }}</dd>
|
||||
<dt>降级调用</dt>
|
||||
<dd>{{ formatNumber(kpi.degraded) }} 次</dd>
|
||||
</dl>
|
||||
<button class="link-btn" type="button" @click="goGovernance">进入治理设置 →</button>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<DetailDrawer :open="detailOpen" title="调用详情" :subtitle="detail?.callUid || ''" @close="detailOpen = false">
|
||||
<div v-if="detail" class="detail-grid">
|
||||
<div class="fld"><label>状态</label><div>{{ statusLabel(detail.status) }}</div></div>
|
||||
<div class="fld"><label>模型</label><div>{{ detail.modelName || detail.modelCode }}({{ detail.modelUid }})</div></div>
|
||||
<div class="fld"><label>服务商</label><div>{{ detail.providerName || detail.providerUid }}</div></div>
|
||||
<div class="fld"><label>来源</label><div>{{ sourceLabel(detail.sourceType) }} / {{ detail.sourceId || '—' }}</div></div>
|
||||
<div class="fld"><label>Token(入 / 出)</label>
|
||||
<div>{{ formatNumber(detail.inputTokens) }} / {{ formatNumber(detail.outputTokens) }}({{ detail.usageSource || '—' }})</div>
|
||||
</div>
|
||||
<div class="fld"><label>估算成本</label>
|
||||
<div>{{ costText(detail.estimatedCost, detail.currency) }}({{ detail.costSource || '—' }})</div>
|
||||
</div>
|
||||
<div class="fld"><label>耗时</label><div>{{ latencyText(detail.latencyMs) }}</div></div>
|
||||
<div class="fld"><label>脱敏模式</label><div>{{ redactionLabel(detail.redactionMode) }}</div></div>
|
||||
<div class="fld"><label>缓存 / 工具调用</label>
|
||||
<div>{{ detail.cacheHit ? '命中缓存' : '未命中' }} / {{ formatNumber(detail.toolCallCount) }}</div>
|
||||
</div>
|
||||
<div class="fld"><label>降级回退模型</label><div>{{ detail.fallbackModelConfigId || '未降级' }}</div></div>
|
||||
<div class="fld"><label>开始 / 结束</label>
|
||||
<div>{{ formatTime(detail.startedAt) }} → {{ formatTime(detail.finishedAt) }}</div>
|
||||
</div>
|
||||
<div class="fld"><label>错误</label>
|
||||
<div>{{ detail.errorCode ? (ERROR_LABEL[detail.errorCode] || detail.errorCode) : '—' }} {{ detail.errorMessage || '' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ai-calls { display: flex; flex-direction: column; gap: 14px; }
|
||||
.toolbar {
|
||||
position: relative; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 12px;
|
||||
border: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247); border-radius: 8px;
|
||||
background: light-dark(var(--qk-card, #fff), #121b2b);
|
||||
}
|
||||
.range-group { display: inline-flex; border: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247); border-radius: 6px; overflow: hidden; }
|
||||
.range-btn {
|
||||
padding: 5px 12px; font-size: 12px; border: 0; background: transparent; cursor: pointer;
|
||||
color: light-dark(var(--qk-text-1, #111827), #e7ecf6);
|
||||
}
|
||||
.range-btn + .range-btn { border-left: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247); }
|
||||
.range-btn.active { background: #eef4ff; color: #2558ba; font-weight: 600; }
|
||||
.filter-field { display: flex; align-items: center; gap: 6px; font-size: 12px; }
|
||||
.filter-field span { color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.filter-field :deep(.qk-select) { min-width: 96px; }
|
||||
.filter-field :deep(.el-select__wrapper) { min-height: 28px; font-size: 12px; }
|
||||
.search-field input { width: 190px; padding: 5px 8px; font-size: 12px; border-radius: 6px; }
|
||||
.columns-wrap { position: relative; }
|
||||
.columns-pop {
|
||||
position: absolute; top: 32px; right: 0; z-index: 12; display: flex; flex-direction: column; gap: 6px;
|
||||
padding: 8px 12px; border: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247); border-radius: 8px;
|
||||
background: light-dark(var(--qk-card, #fff), #121b2b); box-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
|
||||
}
|
||||
.columns-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }
|
||||
.toolbar-meta { margin-left: auto; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
|
||||
.kpi-cell { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; }
|
||||
.kpi-label { font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-value { font-size: 24px; line-height: 1.25; font-variant-numeric: tabular-nums; }
|
||||
.kpi-value em { font-size: 12px; font-style: normal; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-value.danger { color: #b42318; }
|
||||
.kpi-note { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
|
||||
.table-card { display: flex; flex-direction: column; gap: 10px; }
|
||||
.table-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
||||
.table-head h3 { margin: 0; font-size: 15px; }
|
||||
.table-sub { margin: 3px 0 0; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.table-tags { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.tag {
|
||||
padding: 1px 7px; font-size: 11px; border-radius: 999px;
|
||||
border: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247); color: #64748b; background: #f8f9fc;
|
||||
}
|
||||
.tag.success { border-color: #b7e2c4; background: #effaf2; color: #15803d; }
|
||||
.table-wrap { overflow: auto; }
|
||||
.call-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
.call-table th {
|
||||
padding: 7px 8px; text-align: left; white-space: nowrap; font-weight: 600;
|
||||
border-bottom: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247);
|
||||
color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd);
|
||||
}
|
||||
.call-table td {
|
||||
padding: 7px 8px; border-bottom: 1px dashed light-dark(var(--qk-line, #e5e7eb), #273247); vertical-align: top;
|
||||
}
|
||||
.call-table tbody tr { cursor: pointer; }
|
||||
.call-table tbody tr:hover { background: #f7f9fd; }
|
||||
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
|
||||
.nowrap { white-space: nowrap; }
|
||||
.cell-sub { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.status-pill { padding: 1px 7px; font-size: 11px; border-radius: 999px; }
|
||||
.status-pill.success { background: #effaf2; color: #15803d; }
|
||||
.status-pill.warning { background: #fff8e6; color: #b45309; }
|
||||
.status-pill.danger { background: #fdecec; color: #b42318; }
|
||||
.status-pill.muted { background: #f4f5f8; color: #64748b; }
|
||||
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
|
||||
.side-col { display: flex; flex-direction: column; gap: 12px; }
|
||||
.side-card { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
|
||||
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.side-head h3 { margin: 0; font-size: 13px; }
|
||||
.side-meta { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.side-note { margin: 0; font-size: 11px; line-height: 1.6; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.side-empty { padding: 10px 0; font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 92px; padding-top: 6px; }
|
||||
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
|
||||
.bar-stack { display: flex; align-items: flex-end; gap: 2px; height: 72px; }
|
||||
.bar { width: 8px; border-radius: 2px 2px 0 0; min-height: 2px; }
|
||||
.bar-input { background: #93b4f5; }
|
||||
.bar-output { background: #2f5fd0; }
|
||||
.bar-label { font-size: 10px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.chart-legend { display: flex; gap: 12px; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
|
||||
.dot-input { background: #93b4f5; }
|
||||
.dot-output { background: #2f5fd0; }
|
||||
.error-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
|
||||
.error-list li { display: grid; grid-template-columns: 1fr 82px 34px; align-items: center; gap: 8px; font-size: 12px; }
|
||||
.error-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.error-bar { display: block; height: 6px; border-radius: 3px; background: #eef1f7; overflow: hidden; }
|
||||
.error-bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #f3b46b, #e2582f); }
|
||||
.error-count { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.mini-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 11px; }
|
||||
.mini-facts dt { color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.mini-facts dd { margin: 0; }
|
||||
.link-btn { align-self: flex-start; padding: 0; border: 0; background: transparent; color: #2558ba; font-size: 12px; cursor: pointer; }
|
||||
.inline-error { margin: 0; padding: 10px 12px; border: 1px solid #f0b4b4; border-radius: 8px; background: #fdecec; color: #b42318; font-size: 12px; }
|
||||
.inline-loading { padding: 16px; font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.empty-state { padding: 26px 12px; text-align: center; border: 1px dashed #d9dce6; border-radius: 8px; }
|
||||
.empty-state p { margin: 0 0 6px; font-size: 13px; }
|
||||
.muted-text { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
||||
.fld label { display: block; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); margin-bottom: 2px; }
|
||||
.fld div { font-size: 12px; }
|
||||
</style>
|
||||
@@ -0,0 +1,414 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { aiApi } from '../../api/ai'
|
||||
import { describeError, formatTime, notify } from '../../ui'
|
||||
import ConfirmDialog from '../../components/ConfirmDialog.vue'
|
||||
import Pagination from '../../components/Pagination.vue'
|
||||
import SectionState from '../../components/SectionState.vue'
|
||||
import StatusTag from '../../components/StatusTag.vue'
|
||||
import Select from '../../components/ui/Select.vue'
|
||||
|
||||
const SCOPE_TYPE_OPTIONS = [
|
||||
{ value: '', label: '全部' },
|
||||
{ value: 'CONVERSATION', label: 'CONVERSATION' },
|
||||
{ value: 'BINDING', label: 'BINDING' },
|
||||
{ value: 'INSTANCE', label: 'INSTANCE' }
|
||||
]
|
||||
const SCOPE_TYPE_FORM_OPTIONS = SCOPE_TYPE_OPTIONS.slice(1)
|
||||
const MEMORY_STATUS_OPTIONS = [
|
||||
{ value: '', label: '全部' },
|
||||
{ value: 'ACTIVE', label: 'ACTIVE' },
|
||||
{ value: 'EXPIRED', label: 'EXPIRED' },
|
||||
{ value: 'DELETED', label: 'DELETED' }
|
||||
]
|
||||
const MEMORY_TYPE_OPTIONS = [
|
||||
{ value: 'SUMMARY', label: 'SUMMARY(摘要)' },
|
||||
{ value: 'PREFERENCE', label: 'PREFERENCE(偏好)' },
|
||||
{ value: 'FACT', label: 'FACT(事实)' }
|
||||
]
|
||||
|
||||
const governance = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const memories = ref([])
|
||||
const memoryTotal = ref(0)
|
||||
const memoryPage = ref(1)
|
||||
const memoryPageSize = ref(20)
|
||||
const memoryLoading = ref(false)
|
||||
const memoryError = ref(null)
|
||||
const memoryFilter = ref({ scopeType: '', scopeId: '', status: '' })
|
||||
|
||||
const createOpen = ref(false)
|
||||
const createForm = ref(defaultMemory())
|
||||
const createSubmitting = ref(false)
|
||||
const createError = ref(null)
|
||||
|
||||
const confirmState = ref({ open: false, title: '', message: '', action: null })
|
||||
|
||||
async function loadGovernance() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
governance.value = await aiApi.governance()
|
||||
} catch (e) {
|
||||
governance.value = null
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMemories() {
|
||||
memoryLoading.value = true
|
||||
memoryError.value = null
|
||||
try {
|
||||
const pageData = await aiApi.memories({
|
||||
scopeType: memoryFilter.value.scopeType,
|
||||
scopeId: memoryFilter.value.scopeId.trim(),
|
||||
status: memoryFilter.value.status,
|
||||
page: memoryPage.value,
|
||||
pageSize: memoryPageSize.value
|
||||
})
|
||||
memories.value = pageData?.items || []
|
||||
memoryPage.value = pageData?.page || memoryPage.value
|
||||
memoryPageSize.value = pageData?.pageSize || memoryPageSize.value
|
||||
memoryTotal.value = pageData?.total || 0
|
||||
} catch (e) {
|
||||
memories.value = []
|
||||
memoryError.value = describeError(e)
|
||||
} finally {
|
||||
memoryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function defaultMemory() {
|
||||
return { scopeType: 'CONVERSATION', scopeId: '', memoryType: 'SUMMARY', content: '', retentionDays: 30 }
|
||||
}
|
||||
|
||||
function searchMemories() {
|
||||
memoryPage.value = 1
|
||||
loadMemories()
|
||||
}
|
||||
|
||||
function onPageChange(next) {
|
||||
memoryPage.value = next.page
|
||||
memoryPageSize.value = next.pageSize
|
||||
loadMemories()
|
||||
}
|
||||
|
||||
function openCreateMemory() {
|
||||
createError.value = null
|
||||
createForm.value = defaultMemory()
|
||||
createOpen.value = true
|
||||
}
|
||||
|
||||
async function submitMemory() {
|
||||
if (createSubmitting.value) return
|
||||
createError.value = null
|
||||
if (!createForm.value.scopeId.trim()) {
|
||||
createError.value = { title: '缺少作用域 ID', message: '记忆必须绑定明确作用域,不能写入无归属的全局记忆。' }
|
||||
return
|
||||
}
|
||||
createSubmitting.value = true
|
||||
try {
|
||||
await aiApi.createMemory({
|
||||
scopeType: createForm.value.scopeType,
|
||||
scopeId: createForm.value.scopeId.trim(),
|
||||
memoryType: createForm.value.memoryType,
|
||||
content: createForm.value.content,
|
||||
retentionDays: Number(createForm.value.retentionDays)
|
||||
})
|
||||
notify('记忆已写入', '内容已按 STRICT 模式脱敏并限长,到期后由定时任务清理。', 'success')
|
||||
createOpen.value = false
|
||||
await loadMemories()
|
||||
} catch (e) {
|
||||
createError.value = describeError(e)
|
||||
} finally {
|
||||
createSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function askDelete(memory) {
|
||||
confirmState.value = {
|
||||
open: true,
|
||||
title: '删除记忆',
|
||||
message: `记忆 ${memory.memoryUid}(${memory.scopeType} / ${memory.scopeId})将被软删除。`,
|
||||
action: async () => {
|
||||
await aiApi.deleteMemory(memory.memoryUid)
|
||||
notify('记忆已删除', '软删除后不会再参与上下文拼装。', 'success')
|
||||
await loadMemories()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function askPurge() {
|
||||
confirmState.value = {
|
||||
open: true,
|
||||
title: '清理过期记忆',
|
||||
message: '将扫描并清理所有已过期记忆,该操作不可恢复。',
|
||||
action: async () => {
|
||||
const result = await aiApi.purgeMemories()
|
||||
notify('清理完成', `本次清理 ${result?.expiredCount ?? 0} 条过期记忆。`, 'success')
|
||||
await loadMemories()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function askClearCache() {
|
||||
confirmState.value = {
|
||||
open: true,
|
||||
title: '清空响应缓存',
|
||||
message: '将立即清空当前进程内的 AI 响应缓存,后续调用需要重新访问模型。',
|
||||
action: async () => {
|
||||
const result = await aiApi.clearCache()
|
||||
notify('缓存已清空', `清除 ${result?.clearedEntries ?? 0} 条缓存条目。`, 'success')
|
||||
await loadGovernance()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function runConfirm() {
|
||||
const action = confirmState.value.action
|
||||
try {
|
||||
if (action) await action()
|
||||
confirmState.value.open = false
|
||||
} catch (e) {
|
||||
notify('操作失败', describeError(e).message, 'error')
|
||||
confirmState.value.open = false
|
||||
}
|
||||
}
|
||||
|
||||
function scopeLabel(memory) {
|
||||
return `${memory.scopeType} / ${memory.scopeId}`
|
||||
}
|
||||
|
||||
function contentPreview(content) {
|
||||
const text = String(content || '')
|
||||
return text.length > 80 ? `${text.slice(0, 80)}…` : (text || '—')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadGovernance()
|
||||
loadMemories()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="notice" style="margin-bottom: 16px">
|
||||
以下为后端生效的运行配置(qlinker.ai.*),页面只读展示,不提供绕过受控配置的开关;关闭脱敏等高风险变更必须在服务端配置中完成并发起调用方权限校验。
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-bottom: 16px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">数据最小化、缓存与记忆治理</h3>
|
||||
<div class="actions">
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="loadGovernance">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SectionState
|
||||
:loading="loading"
|
||||
:error="error"
|
||||
:empty="!loading && !error && !governance"
|
||||
empty-title="无法读取治理配置"
|
||||
empty-text="请确认后端已启动且当前账号具备 ai.read 权限。"
|
||||
@retry="loadGovernance"
|
||||
>
|
||||
<div v-if="governance" class="grid stats">
|
||||
<div class="card stat">
|
||||
<span class="stat-label">AI 总开关</span>
|
||||
<strong class="stat-value">{{ governance.enabled ? '已启用' : '已停用' }}</strong>
|
||||
<span class="small-muted">停用后所有生成请求都会被拒绝</span>
|
||||
</div>
|
||||
<div class="card stat">
|
||||
<span class="stat-label">默认脱敏模式</span>
|
||||
<strong class="stat-value">{{ governance.defaultRedactionMode }}</strong>
|
||||
<span class="small-muted">可选:{{ governance.redactionModes.join(' / ') }}</span>
|
||||
</div>
|
||||
<div class="card stat">
|
||||
<span class="stat-label">输入上限</span>
|
||||
<strong class="stat-value">{{ governance.maxInputChars }} 字符</strong>
|
||||
<span class="small-muted">超限自动截断,不完全外发</span>
|
||||
</div>
|
||||
<div class="card stat">
|
||||
<span class="stat-label">上下文消息</span>
|
||||
<strong class="stat-value">{{ governance.maxContextMessages }} 条</strong>
|
||||
<span class="small-muted">按需加载,不默认上传全部聊天记录</span>
|
||||
</div>
|
||||
<div class="card stat">
|
||||
<span class="stat-label">缓存</span>
|
||||
<strong class="stat-value">{{ governance.cache.enabled ? '启用' : '关闭' }}</strong>
|
||||
<span class="small-muted">TTL {{ governance.cache.ttlSeconds }}s · {{ governance.cache.currentEntries }}/{{ governance.cache.maxEntries }} 条</span>
|
||||
<button class="btn sm" type="button" style="margin-top: 6px" :disabled="!governance.cache.enabled" @click="askClearCache">清空缓存</button>
|
||||
</div>
|
||||
<div class="card stat">
|
||||
<span class="stat-label">记忆保留</span>
|
||||
<strong class="stat-value">{{ governance.memory.defaultRetentionDays }} 天</strong>
|
||||
<span class="small-muted">上限 {{ governance.memory.maxRetentionDays }} 天 · 单条 {{ governance.memory.maxContentChars }} 字符</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="governance" class="grid two-col" style="margin-top: 12px">
|
||||
<div class="fld">
|
||||
<label>重试与超时</label>
|
||||
<div>最大尝试 {{ governance.retry.maxAttempts }} 次 · 初始间隔 {{ governance.retry.backoffMs }} ms · 上限 {{ governance.retry.maxBackoffMs }} ms</div>
|
||||
<p class="field-hint">结果未知不会按普通失败无限重试,由调用记录单独标注。</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>工具限流</label>
|
||||
<div>默认 {{ governance.defaultToolRateLimitPerMinute }} 次/分钟 · 单工具上限 {{ governance.maxToolExecutionsPerMinute }} 次/分钟</div>
|
||||
<p class="field-hint">限流在进程内按工具维度统计;多实例部署时各实例独立生效。</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>输出上限</label>
|
||||
<div>默认 {{ governance.defaultMaxOutputTokens }} token · 最大 {{ governance.maxOutputTokensLimit }} token</div>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>记忆清理计划</label>
|
||||
<div>{{ governance.memory.purgeCron }}</div>
|
||||
<p class="field-hint">作用域:{{ governance.memory.scopeTypes.join(' / ') }};类型:{{ governance.memory.memoryTypes.join(' / ') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</SectionState>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">记忆记录</h3>
|
||||
<div class="actions">
|
||||
<button class="btn sm" type="button" :disabled="memoryLoading" @click="askPurge">清理过期</button>
|
||||
<button class="btn primary sm" type="button" @click="openCreateMemory">写入记忆</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filterbar">
|
||||
<label>
|
||||
作用域类型
|
||||
<Select v-model="memoryFilter.scopeType" :options="SCOPE_TYPE_OPTIONS" aria-label="作用域类型筛选" />
|
||||
</label>
|
||||
<label>
|
||||
作用域 ID
|
||||
<input v-model="memoryFilter.scopeId" class="field" placeholder="精确匹配" />
|
||||
</label>
|
||||
<label>
|
||||
状态
|
||||
<Select v-model="memoryFilter.status" :options="MEMORY_STATUS_OPTIONS" aria-label="记忆状态筛选" />
|
||||
</label>
|
||||
<button class="btn primary sm" type="button" :disabled="memoryLoading" @click="searchMemories">查询</button>
|
||||
</div>
|
||||
|
||||
<SectionState
|
||||
:loading="memoryLoading"
|
||||
:error="memoryError"
|
||||
:empty="!memoryLoading && !memoryError && !memories.length"
|
||||
empty-title="没有记忆记录"
|
||||
empty-text="记忆只在明确作用域和保留期内生效,过期或删除后不再参与上下文。"
|
||||
@retry="loadMemories"
|
||||
>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>记忆</th>
|
||||
<th>作用域</th>
|
||||
<th>类型</th>
|
||||
<th>状态</th>
|
||||
<th>过期时间</th>
|
||||
<th>内容摘要</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="memory in memories" :key="memory.memoryUid">
|
||||
<td style="font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px">{{ memory.memoryUid }}</td>
|
||||
<td>{{ scopeLabel(memory) }}</td>
|
||||
<td>{{ memory.memoryType }}</td>
|
||||
<td><StatusTag :value="memory.status" :label="memory.status" /></td>
|
||||
<td class="small-muted">{{ formatTime(memory.expiresAt) }}</td>
|
||||
<td class="small-muted">{{ contentPreview(memory.content) }}</td>
|
||||
<td>
|
||||
<button class="btn sm" type="button" :disabled="memory.status !== 'ACTIVE'" @click="askDelete(memory)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination :page="memoryPage" :page-size="memoryPageSize" :total="memoryTotal" @change="onPageChange" />
|
||||
</SectionState>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
v-model="createOpen"
|
||||
title="写入记忆"
|
||||
width="576px"
|
||||
append-to-body
|
||||
:close-on-click-modal="!createSubmitting"
|
||||
:close-on-press-escape="!createSubmitting"
|
||||
:show-close="!createSubmitting"
|
||||
:style="{ maxWidth: 'calc(100vw - 32px)' }"
|
||||
>
|
||||
<div v-if="createError" class="notice danger" style="margin-bottom: 12px">
|
||||
<div>
|
||||
<strong>{{ createError.title }}</strong>
|
||||
<div style="margin-top: 4px">{{ createError.message }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="fld">
|
||||
<label for="memory-scope-type">作用域类型<span class="req">*</span></label>
|
||||
<Select
|
||||
id="memory-scope-type"
|
||||
v-model="createForm.scopeType"
|
||||
:options="SCOPE_TYPE_FORM_OPTIONS"
|
||||
block
|
||||
aria-label="记忆作用域类型"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="memory-scope-id">作用域 ID<span class="req">*</span></label>
|
||||
<input id="memory-scope-id" v-model="createForm.scopeId" class="field" maxlength="64" />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="memory-type">记忆类型</label>
|
||||
<Select
|
||||
id="memory-type"
|
||||
v-model="createForm.memoryType"
|
||||
:options="MEMORY_TYPE_OPTIONS"
|
||||
block
|
||||
aria-label="记忆类型"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="memory-retention">保留天数</label>
|
||||
<input id="memory-retention" v-model.number="createForm.retentionDays" class="field" type="number" min="1" />
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<label for="memory-content">内容<span class="req">*</span></label>
|
||||
<textarea id="memory-content" v-model="createForm.content" class="field" rows="4" placeholder="写入前会按 STRICT 模式脱敏并限制长度" />
|
||||
<p class="field-hint">不要写入凭据、完整聊天记录或不必要的个人信息。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div style="display: flex; justify-content: flex-end; gap: 8px">
|
||||
<button class="btn" type="button" :disabled="createSubmitting" @click="createOpen = false">取消</button>
|
||||
<button class="btn primary" type="button" :disabled="createSubmitting" @click="submitMemory">
|
||||
{{ createSubmitting ? '正在写入…' : '写入记忆' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="confirmState.open"
|
||||
:title="confirmState.title"
|
||||
:message="confirmState.message"
|
||||
tone="danger"
|
||||
confirm-text="确认执行"
|
||||
@confirm="runConfirm"
|
||||
@cancel="confirmState.open = false"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,829 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { aiApi } from '../../api/ai'
|
||||
import { describeError, formatNumber, formatShortTime, formatTime, notify } from '../../ui'
|
||||
import ConfirmDialog from '../../components/ConfirmDialog.vue'
|
||||
import DetailDrawer from '../../components/DetailDrawer.vue'
|
||||
import Pagination from '../../components/Pagination.vue'
|
||||
import Select from '../../components/ui/Select.vue'
|
||||
import Checkbox from '../../components/ui/Checkbox.vue'
|
||||
|
||||
const SCOPE_OPTIONS = [
|
||||
{ value: 'GLOBAL', label: '全局(全部实例)' },
|
||||
{ value: 'INSTANCE', label: '仅当前实例' }
|
||||
]
|
||||
const POLICY_STATUS_OPTIONS = [
|
||||
{ value: 'ACTIVE', label: '启用' },
|
||||
{ value: 'DISABLED', label: '停用' }
|
||||
]
|
||||
|
||||
const toolFilterOptions = computed(() => [
|
||||
{ value: '', label: '全部工具' },
|
||||
...tools.value.map((tool) => ({ value: tool.toolCode, label: tool.toolName || tool.toolCode }))
|
||||
])
|
||||
const toolFormOptions = computed(() => tools.value.map((tool) => ({
|
||||
value: tool.toolCode,
|
||||
label: `${tool.toolName}(${tool.toolCode})`
|
||||
})))
|
||||
const authFilterOptions = computed(() => [
|
||||
{ value: '', label: '全部授权' },
|
||||
...Object.keys(AUTH_LABEL).map((key) => ({ value: key, label: AUTH_LABEL[key] }))
|
||||
])
|
||||
const execFilterOptions = computed(() => [
|
||||
{ value: '', label: '全部执行状态' },
|
||||
...Object.keys(EXEC_LABEL).map((key) => ({ value: key, label: EXEC_LABEL[key] }))
|
||||
])
|
||||
|
||||
/**
|
||||
* AI 中心 · 工具授权(对齐 04-ai-cost 画板,即「工具授权」页)。
|
||||
* 工具只能由后端注册表提供;未命中 ACTIVE 策略的工具一律拒绝执行,
|
||||
* 高风险工具无论策略如何都必须人工确认。
|
||||
*/
|
||||
const RISK_LABEL = { HIGH: '高风险', MEDIUM: '中风险', LOW: '低风险' }
|
||||
const AUTH_LABEL = { ALLOWED: '已授权', APPROVAL_REQUIRED: '待确认', DENIED: '已拒绝' }
|
||||
const APPROVAL_LABEL = { PENDING: '待确认', APPROVED: '已批准', REJECTED: '已拒绝' }
|
||||
const EXEC_LABEL = { PENDING: '待执行', RUNNING: '执行中', SUCCEEDED: '已成功', FAILED: '已失败', REJECTED: '已拒绝' }
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const tools = ref([])
|
||||
const policies = ref([])
|
||||
const governance = ref(null)
|
||||
const calls = ref([])
|
||||
const callTotal = ref(0)
|
||||
const callPage = ref(1)
|
||||
const callPageSize = ref(20)
|
||||
const pendingCalls = ref([])
|
||||
const pendingTotalCount = ref(0)
|
||||
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const actionError = ref(null)
|
||||
|
||||
const callFilters = ref({ toolCode: '', authorizationStatus: '', executionStatus: '' })
|
||||
|
||||
const policyDialog = ref(false)
|
||||
const policyEditing = ref(null)
|
||||
const policyForm = ref(defaultPolicy())
|
||||
const policySubmitting = ref(false)
|
||||
const policyFieldErrors = ref({})
|
||||
|
||||
const approvalOpen = ref(false)
|
||||
const approvalTarget = ref(null)
|
||||
const approvalReason = ref('')
|
||||
const approvalDecision = ref('APPROVED')
|
||||
const approvalSubmitting = ref(false)
|
||||
|
||||
const detailOpen = ref(false)
|
||||
const detail = ref(null)
|
||||
const busyUid = ref('')
|
||||
|
||||
let callsSeq = 0
|
||||
let pendingSeq = 0
|
||||
|
||||
function defaultPolicy() {
|
||||
return {
|
||||
policyName: '',
|
||||
toolCode: '',
|
||||
scopeType: 'GLOBAL',
|
||||
scopeId: '',
|
||||
approvalRequired: false,
|
||||
rateLimitPerMinute: 5,
|
||||
policyStatus: 'ACTIVE'
|
||||
}
|
||||
}
|
||||
|
||||
const activePolicies = computed(() => policies.value.filter((item) => item.policyStatus === 'ACTIVE'))
|
||||
const highRiskCount = computed(() => tools.value.filter((item) => String(item.riskLevel).toUpperCase() === 'HIGH').length)
|
||||
const approvalCount = computed(() => activePolicies.value.filter((item) => item.approvalRequired).length)
|
||||
const pendingTotal = computed(() => pendingTotalCount.value)
|
||||
|
||||
function policyOf(tool) {
|
||||
return policies.value.find((item) => item.toolCode === tool.toolCode) || null
|
||||
}
|
||||
|
||||
function execPolicyOf(tool) {
|
||||
const policy = policyOf(tool)
|
||||
if (!policy || policy.policyStatus !== 'ACTIVE') return '默认拒绝'
|
||||
if (policy.approvalRequired || String(tool.riskLevel).toUpperCase() === 'HIGH') return '需人工确认'
|
||||
return '自动执行'
|
||||
}
|
||||
|
||||
function rateLimitOf(tool) {
|
||||
const policy = policyOf(tool)
|
||||
return policy ? `${policy.maxPerMinute} 次/分` : '—'
|
||||
}
|
||||
|
||||
function toolStateOf(tool) {
|
||||
if (String(tool.toolStatus || '').toUpperCase() === 'DISABLED') return { label: '工具已停用', tone: 'muted' }
|
||||
const policy = policyOf(tool)
|
||||
if (!policy) return { label: '未配置策略', tone: 'warning' }
|
||||
return policy.policyStatus === 'ACTIVE'
|
||||
? { label: '启用', tone: 'success' }
|
||||
: { label: '停用', tone: 'muted' }
|
||||
}
|
||||
|
||||
function riskTone(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'HIGH') return 'danger'
|
||||
if (text === 'MEDIUM') return 'warning'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function authTone(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'ALLOWED') return 'success'
|
||||
if (text === 'APPROVAL_REQUIRED') return 'warning'
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
function execTone(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'SUCCEEDED') return 'success'
|
||||
if (text === 'FAILED' || text === 'REJECTED') return 'danger'
|
||||
if (text === 'RUNNING') return 'info'
|
||||
return 'warning'
|
||||
}
|
||||
|
||||
function gov(key, fallback = '—') {
|
||||
const value = governance.value?.[key]
|
||||
return value === null || value === undefined || value === '' ? fallback : value
|
||||
}
|
||||
|
||||
function errorText(err) {
|
||||
const base = describeError(err)
|
||||
return `${base.title}。${base.hint}`
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const [toolList, policyList, governanceData] = await Promise.all([
|
||||
aiApi.tools(), aiApi.toolPolicies(), aiApi.governance()
|
||||
])
|
||||
tools.value = toolList || []
|
||||
policies.value = policyList || []
|
||||
governance.value = governanceData || null
|
||||
await Promise.all([loadCalls(), loadPending()])
|
||||
} catch (e) {
|
||||
tools.value = []
|
||||
policies.value = []
|
||||
governance.value = null
|
||||
calls.value = []
|
||||
pendingCalls.value = []
|
||||
error.value = errorText(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCalls() {
|
||||
const seq = ++callsSeq
|
||||
const params = {
|
||||
toolCode: callFilters.value.toolCode,
|
||||
authorizationStatus: callFilters.value.authorizationStatus,
|
||||
executionStatus: callFilters.value.executionStatus,
|
||||
page: callPage.value,
|
||||
pageSize: callPageSize.value
|
||||
}
|
||||
try {
|
||||
const data = await aiApi.toolCalls(params)
|
||||
if (seq !== callsSeq) return
|
||||
calls.value = data?.items || []
|
||||
callPage.value = data?.page || callPage.value
|
||||
callPageSize.value = data?.pageSize || callPageSize.value
|
||||
callTotal.value = data?.total || 0
|
||||
} catch (e) {
|
||||
if (seq !== callsSeq) return
|
||||
calls.value = []
|
||||
callTotal.value = 0
|
||||
notify('读取工具调用失败', errorText(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPending() {
|
||||
const seq = ++pendingSeq
|
||||
try {
|
||||
const data = await aiApi.toolCalls({
|
||||
authorizationStatus: 'APPROVAL_REQUIRED',
|
||||
executionStatus: 'PENDING',
|
||||
page: 1,
|
||||
pageSize: 5
|
||||
})
|
||||
if (seq !== pendingSeq) return
|
||||
pendingCalls.value = data?.items || []
|
||||
pendingTotalCount.value = Number(data?.total || 0)
|
||||
} catch {
|
||||
if (seq !== pendingSeq) return
|
||||
pendingCalls.value = []
|
||||
pendingTotalCount.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
function onCallFilterChange() {
|
||||
callPage.value = 1
|
||||
loadCalls()
|
||||
}
|
||||
|
||||
function onCallPageChange(next) {
|
||||
callPage.value = next.page
|
||||
callPageSize.value = next.pageSize
|
||||
loadCalls()
|
||||
}
|
||||
|
||||
function openPolicyCreate(tool) {
|
||||
policyEditing.value = null
|
||||
policyFieldErrors.value = {}
|
||||
policyForm.value = {
|
||||
...defaultPolicy(),
|
||||
toolCode: tool?.toolCode || tools.value[0]?.toolCode || '',
|
||||
rateLimitPerMinute: Number(gov('defaultToolRateLimitPerMinute', 5))
|
||||
}
|
||||
policyDialog.value = true
|
||||
}
|
||||
|
||||
function openPolicyEdit(policy) {
|
||||
policyEditing.value = policy
|
||||
policyFieldErrors.value = {}
|
||||
policyForm.value = {
|
||||
policyName: policy.policyName || '',
|
||||
toolCode: policy.toolCode || '',
|
||||
scopeType: policy.scopeType || 'GLOBAL',
|
||||
scopeId: policy.scopeId || '',
|
||||
approvalRequired: Boolean(policy.approvalRequired),
|
||||
rateLimitPerMinute: policy.maxPerMinute ?? 5,
|
||||
policyStatus: policy.policyStatus || 'ACTIVE'
|
||||
}
|
||||
policyDialog.value = true
|
||||
}
|
||||
|
||||
function openToolPolicy(tool) {
|
||||
const policy = policyOf(tool)
|
||||
if (policy) openPolicyEdit(policy)
|
||||
else openPolicyCreate(tool)
|
||||
}
|
||||
|
||||
function validatePolicy() {
|
||||
const errors = {}
|
||||
if (!policyForm.value.toolCode) errors.toolCode = '请选择工具'
|
||||
if (policyForm.value.scopeType === 'INSTANCE' && !String(policyForm.value.scopeId || '').trim()) {
|
||||
errors.scopeId = '仅当前实例作用域必须填写实例标识'
|
||||
}
|
||||
const rate = Number(policyForm.value.rateLimitPerMinute)
|
||||
if (!Number.isInteger(rate) || rate < 1 || rate > 120) {
|
||||
errors.rateLimitPerMinute = '每分钟限流必须是 1 到 120 之间的整数'
|
||||
}
|
||||
policyFieldErrors.value = errors
|
||||
return Object.keys(errors).length === 0
|
||||
}
|
||||
|
||||
async function submitPolicy() {
|
||||
if (policySubmitting.value) return
|
||||
if (!validatePolicy()) return
|
||||
policySubmitting.value = true
|
||||
actionError.value = null
|
||||
try {
|
||||
if (policyEditing.value) {
|
||||
await aiApi.updateToolPolicy(policyEditing.value.policyUid, {
|
||||
policyName: policyForm.value.policyName.trim() || null,
|
||||
approvalRequired: Boolean(policyForm.value.approvalRequired),
|
||||
rateLimitPerMinute: Number(policyForm.value.rateLimitPerMinute),
|
||||
policyStatus: policyForm.value.policyStatus
|
||||
})
|
||||
notify('策略已更新', '策略变更立即影响后续执行前的授权检查。', 'success')
|
||||
} else {
|
||||
await aiApi.createToolPolicy({
|
||||
policyName: policyForm.value.policyName.trim() || null,
|
||||
toolCode: policyForm.value.toolCode,
|
||||
scopeType: policyForm.value.scopeType,
|
||||
scopeId: policyForm.value.scopeType === 'INSTANCE' ? policyForm.value.scopeId.trim() : null,
|
||||
approvalRequired: Boolean(policyForm.value.approvalRequired),
|
||||
rateLimitPerMinute: Number(policyForm.value.rateLimitPerMinute),
|
||||
policyStatus: policyForm.value.policyStatus
|
||||
})
|
||||
notify('策略已创建', '未配置有效策略的工具默认拒绝执行。', 'success')
|
||||
}
|
||||
policyDialog.value = false
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
actionError.value = describeError(e)
|
||||
} finally {
|
||||
policySubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleToolPolicy(tool) {
|
||||
const policy = policyOf(tool)
|
||||
if (!policy) {
|
||||
openPolicyCreate(tool)
|
||||
return
|
||||
}
|
||||
const next = policy.policyStatus === 'ACTIVE' ? 'DISABLED' : 'ACTIVE'
|
||||
try {
|
||||
await aiApi.updateToolPolicy(policy.policyUid, { policyStatus: next })
|
||||
notify('策略状态已更新', `工具「${tool.toolName || tool.toolCode}」当前状态:${next === 'ACTIVE' ? '启用' : '停用'}`,
|
||||
next === 'ACTIVE' ? 'success' : 'warning')
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
notify('策略更新失败', errorText(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
function openApproval(row, decision) {
|
||||
approvalTarget.value = row
|
||||
approvalDecision.value = decision
|
||||
approvalReason.value = ''
|
||||
approvalOpen.value = true
|
||||
}
|
||||
|
||||
async function confirmApproval() {
|
||||
if (approvalSubmitting.value || !approvalTarget.value) return
|
||||
approvalSubmitting.value = true
|
||||
try {
|
||||
await aiApi.approveToolCall(approvalTarget.value.toolCallUid, approvalDecision.value,
|
||||
approvalReason.value.trim() || null)
|
||||
notify('人工确认已记录',
|
||||
approvalDecision.value === 'APPROVED' ? '已批准,可继续执行。' : '已拒绝,该调用不会被自动重试。',
|
||||
approvalDecision.value === 'APPROVED' ? 'success' : 'warning')
|
||||
approvalOpen.value = false
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
notify('确认失败', errorText(e), 'error')
|
||||
} finally {
|
||||
approvalSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function execute(row) {
|
||||
if (busyUid.value) return
|
||||
busyUid.value = row.toolCallUid
|
||||
try {
|
||||
const result = await aiApi.executeToolCall(row.toolCallUid)
|
||||
notify('工具执行完成', result?.resultSummary || '执行成功,结果摘要已记录。', 'success')
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
notify('工具执行未完成', errorText(e), 'error')
|
||||
await loadAll()
|
||||
} finally {
|
||||
busyUid.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function showDetail(row) {
|
||||
detail.value = row
|
||||
detailOpen.value = true
|
||||
try {
|
||||
detail.value = await aiApi.toolCall(row.toolCallUid)
|
||||
} catch (e) {
|
||||
notify('读取详情失败', errorText(e), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
function goGovernance() {
|
||||
router.replace({ query: { ...route.query, tab: 'governance' } })
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="ai-tools">
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-title">
|
||||
<h3>工具授权</h3>
|
||||
<p>未登记工具与未命中有效策略的调用一律拒绝;高风险工具必须人工确认后才可执行。</p>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="loadAll">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
<button class="btn primary sm" type="button" @click="openPolicyCreate(null)">新增策略</button>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="inline-error">{{ error }}</p>
|
||||
<div v-if="actionError" class="inline-error">
|
||||
<strong>{{ actionError.title }}</strong>
|
||||
<div>{{ actionError.message }}</div>
|
||||
<button class="link-btn" type="button" @click="actionError = null">关闭</button>
|
||||
</div>
|
||||
|
||||
<div class="kpi-row">
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">已注册工具</span>
|
||||
<strong class="kpi-value">{{ formatNumber(tools.length) }} <em>个</em></strong>
|
||||
<span class="kpi-note">全部由后端注册表提供 · 接口不开放任意创建</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">启用策略</span>
|
||||
<strong class="kpi-value">{{ formatNumber(activePolicies.length) }} <em>条</em></strong>
|
||||
<span class="kpi-note">高风险 {{ highRiskCount }} 个 · 需人工确认 {{ approvalCount }} 条</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">待人工确认</span>
|
||||
<strong class="kpi-value" :class="pendingTotal ? 'warning' : ''">{{ formatNumber(pendingTotal) }} <em>次</em></strong>
|
||||
<span class="kpi-note">确认后仍需单独触发执行,模型输出不会自动产生副作用</span>
|
||||
</div>
|
||||
<div class="card kpi-cell">
|
||||
<span class="kpi-label">工具调用记录</span>
|
||||
<strong class="kpi-value">{{ formatNumber(callTotal) }} <em>次</em></strong>
|
||||
<span class="kpi-note">按当前筛选统计</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-grid">
|
||||
<div class="main-col">
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<h3>工具目录与执行策略</h3>
|
||||
<p class="card-sub">工具、风险等级与所需权限来自后端注册表;执行策略以 ACTIVE 策略为准。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading && !tools.length" class="inline-loading">正在加载工具目录…</div>
|
||||
<div v-else-if="!tools.length" class="empty-state">后端注册表尚未登记任何工具。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>工具</th>
|
||||
<th>风险等级</th>
|
||||
<th>所需权限</th>
|
||||
<th>执行策略</th>
|
||||
<th>限流</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="tool in tools" :key="tool.toolUid">
|
||||
<td>
|
||||
<strong>{{ tool.toolName || tool.toolCode }}</strong>
|
||||
<div class="cell-sub">{{ tool.toolCode }} · {{ tool.toolVersion }}</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="pill" :class="riskTone(tool.riskLevel)">{{ RISK_LABEL[tool.riskLevel] || tool.riskLevel }}</span>
|
||||
</td>
|
||||
<td class="mono">{{ tool.requiredPermission }}</td>
|
||||
<td>
|
||||
<span class="pill" :class="execPolicyOf(tool) === '自动执行' ? 'success' : execPolicyOf(tool) === '需人工确认' ? 'warning' : 'muted'">
|
||||
{{ execPolicyOf(tool) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="nowrap">{{ rateLimitOf(tool) }}</td>
|
||||
<td>
|
||||
<span class="pill" :class="toolStateOf(tool).tone">{{ toolStateOf(tool).label }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="row-actions">
|
||||
<button class="btn sm" type="button" @click="toggleToolPolicy(tool)">
|
||||
{{ policyOf(tool) ? (policyOf(tool).policyStatus === 'ACTIVE' ? '停用' : '启用') : '配置' }}
|
||||
</button>
|
||||
<button class="btn sm" type="button" @click="openToolPolicy(tool)">策略</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<h3>工具调用记录</h3>
|
||||
<p class="card-sub">模型提出的工具调用只登记,不自动执行;此处记录每次授权、确认与执行结果。</p>
|
||||
</div>
|
||||
<div class="call-filters">
|
||||
<Select v-model="callFilters.toolCode" :options="toolFilterOptions" aria-label="工具筛选" @update:model-value="onCallFilterChange" />
|
||||
<Select v-model="callFilters.authorizationStatus" :options="authFilterOptions" aria-label="授权状态筛选" @update:model-value="onCallFilterChange" />
|
||||
<Select v-model="callFilters.executionStatus" :options="execFilterOptions" aria-label="执行状态筛选" @update:model-value="onCallFilterChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!calls.length" class="empty-state">
|
||||
<p>当前筛选条件下没有工具调用记录。</p>
|
||||
<p class="muted-text">没有被拒绝或待确认的调用时,这里是空的;这不是错误。</p>
|
||||
</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>时间</th>
|
||||
<th>工具</th>
|
||||
<th>授权</th>
|
||||
<th>人工确认</th>
|
||||
<th>执行</th>
|
||||
<th>结果 / 错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in calls" :key="row.toolCallUid">
|
||||
<td class="nowrap">{{ formatShortTime(row.createdAt) }}</td>
|
||||
<td>
|
||||
<strong>{{ row.toolName || row.toolCode }}</strong>
|
||||
<div class="cell-sub">{{ row.toolCode }}</div>
|
||||
</td>
|
||||
<td><span class="pill" :class="authTone(row.authorizationStatus)">{{ AUTH_LABEL[row.authorizationStatus] || row.authorizationStatus }}</span></td>
|
||||
<td>
|
||||
<span class="pill" :class="row.approvalStatus === 'APPROVED' ? 'success' : row.approvalStatus === 'REJECTED' ? 'danger' : 'warning'">
|
||||
{{ APPROVAL_LABEL[row.approvalStatus] || row.approvalStatus || '—' }}
|
||||
</span>
|
||||
</td>
|
||||
<td><span class="pill" :class="execTone(row.executionStatus)">{{ EXEC_LABEL[row.executionStatus] || row.executionStatus }}</span></td>
|
||||
<td class="cell-sub">{{ row.resultSummary || row.errorCode || '—' }}</td>
|
||||
<td>
|
||||
<div class="row-actions">
|
||||
<button v-if="row.executionStatus === 'PENDING' && row.approvalStatus === 'PENDING'"
|
||||
class="btn sm" type="button" @click="openApproval(row, 'APPROVED')">批准</button>
|
||||
<button v-if="row.executionStatus === 'PENDING' && row.approvalStatus === 'PENDING'"
|
||||
class="btn sm" type="button" @click="openApproval(row, 'REJECTED')">拒绝</button>
|
||||
<button v-if="row.executionStatus === 'PENDING'"
|
||||
class="btn primary sm" type="button" :disabled="busyUid === row.toolCallUid"
|
||||
@click="execute(row)">
|
||||
{{ busyUid === row.toolCallUid ? '执行中…' : '执行' }}
|
||||
</button>
|
||||
<button class="btn sm" type="button" @click="showDetail(row)">详情</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="table-foot">
|
||||
<span class="muted-text">共 {{ formatNumber(callTotal) }} 条 · 每页 {{ callPageSize }} 条</span>
|
||||
<Pagination :page="callPage" :page-size="callPageSize" :total="callTotal" @change="onCallPageChange" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="side-col">
|
||||
<div class="card side-card">
|
||||
<header class="side-head">
|
||||
<h3>授权策略</h3>
|
||||
<button class="link-btn" type="button" @click="goGovernance">治理设置 →</button>
|
||||
</header>
|
||||
<dl class="mini-facts">
|
||||
<dt>全局默认</dt>
|
||||
<dd>默认拒绝</dd>
|
||||
<dt>未登记工具</dt>
|
||||
<dd>拒绝执行</dd>
|
||||
<dt>高风险工具</dt>
|
||||
<dd>必须人工确认</dd>
|
||||
<dt>单工具默认限流</dt>
|
||||
<dd>{{ gov('defaultToolRateLimitPerMinute') }} 次/分</dd>
|
||||
<dt>工具执行上限</dt>
|
||||
<dd>{{ gov('maxToolExecutionsPerMinute') }} 次/分(服务端固定)</dd>
|
||||
<dt>默认脱敏模式</dt>
|
||||
<dd>{{ gov('defaultRedactionMode') }}</dd>
|
||||
</dl>
|
||||
<p class="side-note">以上为服务端运行配置,页面不提供修改入口;如需调整请在受控配置中变更并重启。</p>
|
||||
</div>
|
||||
|
||||
<div class="card side-card">
|
||||
<header class="side-head">
|
||||
<h3>待人工确认</h3>
|
||||
<span class="side-meta">{{ formatNumber(pendingTotal) }} 次</span>
|
||||
</header>
|
||||
<div v-if="!pendingCalls.length" class="side-empty">当前没有待人工确认的工具调用。</div>
|
||||
<ul v-else class="pending-list">
|
||||
<li v-for="row in pendingCalls" :key="row.toolCallUid">
|
||||
<div class="pending-main">
|
||||
<strong>{{ row.toolName || row.toolCode }}</strong>
|
||||
<span class="cell-sub">{{ formatShortTime(row.createdAt) }} · {{ row.toolCallUid }}</span>
|
||||
</div>
|
||||
<div class="pending-actions">
|
||||
<button class="btn sm" type="button" @click="openApproval(row, 'APPROVED')">批准</button>
|
||||
<button class="btn sm" type="button" @click="openApproval(row, 'REJECTED')">拒绝</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="side-note">确认动作会写入审计记录;确认不等于执行,执行仍需单独触发。</p>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
v-model="policyDialog"
|
||||
:title="policyEditing ? '编辑授权策略' : '新增授权策略'"
|
||||
width="576px"
|
||||
append-to-body
|
||||
:close-on-click-modal="!policySubmitting"
|
||||
:close-on-press-escape="!policySubmitting"
|
||||
:show-close="!policySubmitting"
|
||||
:style="{ maxWidth: 'calc(100vw - 32px)' }"
|
||||
>
|
||||
<p v-if="Object.keys(policyFieldErrors).length" class="form-summary">
|
||||
{{ Object.keys(policyFieldErrors).length }} 项校验未通过:{{ Object.values(policyFieldErrors).join('、') }}。修正前无法保存。
|
||||
</p>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="fld">
|
||||
<label for="policy-tool">工具<span class="req">*</span></label>
|
||||
<Select
|
||||
id="policy-tool"
|
||||
v-model="policyForm.toolCode"
|
||||
:options="toolFormOptions"
|
||||
block
|
||||
:disabled="Boolean(policyEditing)"
|
||||
aria-label="策略工具"
|
||||
/>
|
||||
<p v-if="policyFieldErrors.toolCode" class="field-error">{{ policyFieldErrors.toolCode }}</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="policy-name">策略名称</label>
|
||||
<input id="policy-name" v-model="policyForm.policyName" class="field" maxlength="100"
|
||||
placeholder="留空则按工具自动命名" />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="policy-scope">作用域</label>
|
||||
<Select
|
||||
id="policy-scope"
|
||||
v-model="policyForm.scopeType"
|
||||
:options="SCOPE_OPTIONS"
|
||||
block
|
||||
:disabled="Boolean(policyEditing)"
|
||||
aria-label="策略作用域"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="policy-scope-id">作用域标识</label>
|
||||
<input id="policy-scope-id" v-model="policyForm.scopeId" class="field"
|
||||
:disabled="policyForm.scopeType !== 'INSTANCE' || Boolean(policyEditing)"
|
||||
placeholder="仅当前实例作用域必填" />
|
||||
<p v-if="policyFieldErrors.scopeId" class="field-error">{{ policyFieldErrors.scopeId }}</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="policy-rate">每分钟限流</label>
|
||||
<input id="policy-rate" v-model.number="policyForm.rateLimitPerMinute" class="field" type="number" min="1" max="120" />
|
||||
<p v-if="policyFieldErrors.rateLimitPerMinute" class="field-error">{{ policyFieldErrors.rateLimitPerMinute }}</p>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="policy-status">策略状态</label>
|
||||
<Select
|
||||
id="policy-status"
|
||||
v-model="policyForm.policyStatus"
|
||||
:options="POLICY_STATUS_OPTIONS"
|
||||
block
|
||||
aria-label="策略状态"
|
||||
/>
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<Checkbox v-model="policyForm.approvalRequired" label="执行前必须人工确认" />
|
||||
<p class="field-hint">高风险工具无论是否勾选,后端都会强制要求人工确认。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-foot">
|
||||
<span class="foot-hint">未配置 ACTIVE 策略的工具默认拒绝执行。</span>
|
||||
<div class="foot-actions">
|
||||
<button class="btn" type="button" :disabled="policySubmitting" @click="policyDialog = false">取消</button>
|
||||
<button class="btn primary" type="button" :disabled="policySubmitting" @click="submitPolicy">
|
||||
{{ policySubmitting ? '正在保存…' : (policyEditing ? '保存修改' : '创建策略') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="approvalOpen"
|
||||
:title="approvalDecision === 'APPROVED' ? '批准工具调用' : '拒绝工具调用'"
|
||||
:tone="approvalDecision === 'APPROVED' ? 'primary' : 'danger'"
|
||||
:message="`工具:${approvalTarget?.toolName || approvalTarget?.toolCode || '—'};调用:${approvalTarget?.toolCallUid || '—'}`"
|
||||
hint="人工确认会写入审计记录;批准后仍需单独触发执行,模型输出不会自动产生副作用。"
|
||||
:confirm-text="approvalDecision === 'APPROVED' ? '确认批准' : '确认拒绝'"
|
||||
:busy="approvalSubmitting"
|
||||
@confirm="confirmApproval"
|
||||
@cancel="approvalOpen = false"
|
||||
>
|
||||
<label class="fld" style="display: block">
|
||||
确认说明(可选)
|
||||
<textarea v-model="approvalReason" class="field" rows="3" maxlength="200" placeholder="说明批准或拒绝的依据" />
|
||||
</label>
|
||||
</ConfirmDialog>
|
||||
|
||||
<DetailDrawer :open="detailOpen" title="工具调用详情" :subtitle="detail?.toolCallUid || ''" @close="detailOpen = false">
|
||||
<div v-if="detail" class="grid two-col">
|
||||
<div class="fld">
|
||||
<label>工具</label>
|
||||
<div>{{ detail.toolName }}({{ detail.toolCode }})</div>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>风险 / 所需权限</label>
|
||||
<div>{{ RISK_LABEL[detail.riskLevel] || detail.riskLevel }} / {{ detail.requiredPermission }}</div>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>授权 / 确认 / 执行</label>
|
||||
<div>
|
||||
{{ AUTH_LABEL[detail.authorizationStatus] || detail.authorizationStatus }} /
|
||||
{{ APPROVAL_LABEL[detail.approvalStatus] || '—' }} /
|
||||
{{ EXEC_LABEL[detail.executionStatus] || detail.executionStatus }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label>确认人 / 时间</label>
|
||||
<div>{{ detail.approvedBy || '—' }} / {{ formatTime(detail.approvedAt) }}</div>
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<label>参数快照(已脱敏)</label>
|
||||
<pre class="json-box">{{ JSON.stringify(detail.arguments, null, 2) }}</pre>
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<label>结果摘要</label>
|
||||
<pre class="json-box">{{ detail.resultSummary || '—' }}</pre>
|
||||
<div v-if="detail.errorCode" class="cell-sub">错误:{{ detail.errorCode }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ai-tools { display: flex; flex-direction: column; gap: 14px; }
|
||||
.toolbar {
|
||||
display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
|
||||
border: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247);
|
||||
background: light-dark(var(--qk-card, #fff), #121b2b);
|
||||
}
|
||||
.toolbar-title { display: flex; flex-direction: column; gap: 2px; margin-right: auto; }
|
||||
.toolbar-title h3 { margin: 0; font-size: 15px; }
|
||||
.toolbar-title p { margin: 0; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
|
||||
.kpi-cell { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; }
|
||||
.kpi-label { font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-value { font-size: 24px; line-height: 1.25; font-variant-numeric: tabular-nums; }
|
||||
.kpi-value em { font-size: 12px; font-style: normal; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.kpi-value.warning { color: #b45309; }
|
||||
.kpi-note { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
|
||||
.main-col { display: flex; flex-direction: column; gap: 14px; }
|
||||
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
|
||||
.card-head h3 { margin: 0; font-size: 15px; }
|
||||
.card-sub { margin: 3px 0 0; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.call-filters { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.call-filters :deep(.el-select__wrapper) { min-height: 28px; font-size: 12px; }
|
||||
.table-wrap { overflow: auto; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
th {
|
||||
padding: 7px 8px; text-align: left; white-space: nowrap; font-weight: 600;
|
||||
border-bottom: 1px solid light-dark(var(--qk-line, #e5e7eb), #273247);
|
||||
color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd);
|
||||
}
|
||||
td { padding: 7px 8px; vertical-align: top; border-bottom: 1px dashed light-dark(var(--qk-line, #e5e7eb), #273247); }
|
||||
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
|
||||
.nowrap { white-space: nowrap; }
|
||||
.cell-sub { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.pill { padding: 1px 7px; font-size: 11px; border-radius: 999px; white-space: nowrap; }
|
||||
.pill.success { background: #effaf2; color: #15803d; }
|
||||
.pill.warning { background: #fff8e6; color: #b45309; }
|
||||
.pill.danger { background: #fdecec; color: #b42318; }
|
||||
.pill.info { background: #eef4ff; color: #2558ba; }
|
||||
.pill.muted { background: #f4f5f8; color: #64748b; }
|
||||
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
|
||||
.side-col { display: flex; flex-direction: column; gap: 12px; }
|
||||
.side-card { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
|
||||
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.side-head h3 { margin: 0; font-size: 13px; }
|
||||
.side-meta { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.side-note { margin: 0; font-size: 11px; line-height: 1.6; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.side-empty { padding: 10px 0; font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.mini-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; font-size: 11px; }
|
||||
.mini-facts dt { color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.mini-facts dd { margin: 0; }
|
||||
.pending-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
|
||||
.pending-list li {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 8px;
|
||||
border-bottom: 1px dashed light-dark(var(--qk-line, #e5e7eb), #273247);
|
||||
}
|
||||
.pending-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
||||
.pending-main strong { font-size: 12px; }
|
||||
.pending-main .cell-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.pending-actions { display: flex; gap: 6px; }
|
||||
.inline-error { margin: 0; padding: 10px 12px; border: 1px solid #f0b4b4; border-radius: 8px; background: #fdecec; color: #b42318; font-size: 12px; }
|
||||
.inline-loading { padding: 16px; font-size: 12px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.empty-state { padding: 26px 12px; text-align: center; border: 1px dashed #d9dce6; border-radius: 8px; }
|
||||
.empty-state p { margin: 0 0 6px; font-size: 13px; }
|
||||
.muted-text { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.link-btn { padding: 0; border: 0; background: transparent; color: #2558ba; font-size: 12px; cursor: pointer; }
|
||||
.form-summary {
|
||||
margin: 0 0 12px; padding: 8px 10px; border: 1px solid #f0b4b4; border-radius: 8px;
|
||||
background: #fdecec; color: #b42318; font-size: 12px;
|
||||
}
|
||||
.field-error { margin: 4px 0 0; font-size: 11px; color: #b42318; }
|
||||
.field-hint { margin: 4px 0 0; font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.check-line { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 400; }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
||||
.form-grid .full { grid-column: 1 / -1; }
|
||||
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; }
|
||||
.foot-hint { font-size: 11px; color: light-dark(var(--qk-text-3, #6b7280), #9aa7bd); }
|
||||
.foot-actions { display: flex; gap: 8px; }
|
||||
.json-box {
|
||||
margin: 0; padding: 8px; border-radius: 6px; max-height: 220px; overflow: auto;
|
||||
background: light-dark(#f7f8fb, #0d1522); white-space: pre-wrap; word-break: break-all; font-size: 11px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,306 @@
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import Input from '../../components/ui/Input.vue'
|
||||
import Select from '../../components/ui/Select.vue'
|
||||
import { askConfirm } from '../../components/ui/index'
|
||||
import { notify } from '../../ui'
|
||||
import { contactsApi } from '../../api/contacts'
|
||||
import { errorText } from './util'
|
||||
|
||||
/**
|
||||
* 批量操作面板:只允许本地操作(软删/拉黑/解除拉黑/标签)。
|
||||
* QQ 侧删除、拉黑不可逆,按口径只能单条执行;批量上限 50,限制由前端与后端共同保证。
|
||||
*/
|
||||
const props = defineProps({
|
||||
contacts: { type: Array, default: () => [] },
|
||||
qqAccount: { type: String, default: '' },
|
||||
canManage: { type: Boolean, default: true },
|
||||
tags: { type: Array, default: () => [] },
|
||||
max: { type: Number, default: 50 },
|
||||
mode: { type: String, default: 'panel' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'clear', 'remove', 'done'])
|
||||
|
||||
const action = ref('DELETE')
|
||||
const tagName = ref('')
|
||||
const tagUid = ref('')
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const result = ref(null)
|
||||
|
||||
const ACTIONS = [
|
||||
{ value: 'DELETE', label: '本地删除', hint: '从联系人索引移除,历史消息与审计保留。' },
|
||||
{ value: 'BLOCK', label: '本地拉黑', hint: '仅写入本地标记与筛选,不拦截 QQ 消息投递,QQ 关系不变。' },
|
||||
{ value: 'UNBLOCK', label: '解除本地拉黑', hint: '仅解除本地拉黑;QQ 黑名单无法由本系统解除。' },
|
||||
{ value: 'TAG_ADD', label: '添加标签', hint: '已存在的标签自动复用,不会重复创建。' },
|
||||
{ value: 'TAG_REMOVE', label: '移除标签', hint: '移除所选联系人与指定标签的关联。' }
|
||||
]
|
||||
|
||||
const selectedCount = computed(() => props.contacts.length)
|
||||
const overLimit = computed(() => selectedCount.value > props.max)
|
||||
const noAccount = computed(() => !props.qqAccount)
|
||||
const tagOptions = computed(() => props.tags.map((tag) => ({ value: tag.tagUid, label: tag.name })))
|
||||
const actionMeta = computed(() => ACTIONS.find((item) => item.value === action.value) || ACTIONS[0])
|
||||
const canApply = computed(() => {
|
||||
if (!props.canManage || noAccount.value || overLimit.value || !selectedCount.value || busy.value) return false
|
||||
if (action.value === 'TAG_ADD') return Boolean(tagName.value.trim())
|
||||
if (action.value === 'TAG_REMOVE') return Boolean(tagUid.value)
|
||||
return true
|
||||
})
|
||||
|
||||
const applyText = computed(() => {
|
||||
if (busy.value) return '执行中…'
|
||||
const count = selectedCount.value
|
||||
return {
|
||||
DELETE: `本地删除 ${count} 人`,
|
||||
BLOCK: `本地拉黑 ${count} 人`,
|
||||
UNBLOCK: `解除拉黑 ${count} 人`,
|
||||
TAG_ADD: `添加标签(${count} 人)`,
|
||||
TAG_REMOVE: `移除标签(${count} 人)`
|
||||
}[action.value] || '应用变更'
|
||||
})
|
||||
|
||||
watch(action, () => {
|
||||
error.value = ''
|
||||
result.value = null
|
||||
tagName.value = ''
|
||||
tagUid.value = ''
|
||||
})
|
||||
|
||||
function close() {
|
||||
if (busy.value) return
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function confirmOptions() {
|
||||
const count = selectedCount.value
|
||||
if (action.value === 'DELETE') {
|
||||
return {
|
||||
title: '批量本地删除',
|
||||
message: `将从本地联系人列表移除 ${count} 人。历史消息、媒体与审计记录保留;重新同步后若仍为好友可再次出现。`,
|
||||
hint: 'QQ 好友关系不受影响。该操作只能批量执行本地软删。',
|
||||
confirmText: `删除 ${count} 人`,
|
||||
tone: 'danger'
|
||||
}
|
||||
}
|
||||
if (action.value === 'BLOCK') {
|
||||
return {
|
||||
title: '批量本地拉黑',
|
||||
message: `将为 ${count} 人写入本地拉黑标记(不拦截 QQ 消息投递)。`,
|
||||
hint: 'QQ 好友与 QQ 黑名单不受影响;QQ 不可逆拉黑只能单条执行。',
|
||||
confirmText: `拉黑 ${count} 人`,
|
||||
tone: 'danger'
|
||||
}
|
||||
}
|
||||
if (action.value === 'UNBLOCK') {
|
||||
return {
|
||||
title: '批量解除本地拉黑',
|
||||
message: `将解除 ${count} 人的本地拉黑状态。`,
|
||||
hint: '仅解除本地状态;QQ 黑名单无法通过本系统解除。',
|
||||
confirmText: '确认解除'
|
||||
}
|
||||
}
|
||||
if (action.value === 'TAG_ADD') {
|
||||
return {
|
||||
title: '批量添加标签',
|
||||
message: `为 ${count} 人添加标签「${tagName.value.trim()}」。`,
|
||||
hint: '同名标签会自动复用,不会重复创建。',
|
||||
confirmText: '确认添加'
|
||||
}
|
||||
}
|
||||
const tag = props.tags.find((item) => item.tagUid === tagUid.value)
|
||||
return {
|
||||
title: '批量移除标签',
|
||||
message: `从 ${count} 人移除标签「${tag?.name || tagUid.value}」。`,
|
||||
hint: '仅解除联系人与标签的关联,不删除标签本身。',
|
||||
confirmText: '确认移除'
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
if (!canApply.value) return
|
||||
const confirmed = await askConfirm(confirmOptions())
|
||||
if (!confirmed) return
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
result.value = null
|
||||
const payload = {
|
||||
qqAccount: props.qqAccount,
|
||||
confirm: true,
|
||||
action: action.value,
|
||||
contactUids: props.contacts.map((contact) => contact.contactUid),
|
||||
mode: 'LOCAL'
|
||||
}
|
||||
if (action.value === 'TAG_ADD') payload.tagName = tagName.value.trim()
|
||||
if (action.value === 'TAG_REMOVE') payload.tagUid = tagUid.value
|
||||
try {
|
||||
const data = await contactsApi.batch(payload)
|
||||
result.value = data
|
||||
const failed = Number(data?.failed || 0)
|
||||
if (failed > 0) {
|
||||
notify('批量操作部分失败', `请求 ${data.requested} 条 · 成功 ${data.succeeded} 条 · 失败 ${failed} 条`, 'warning')
|
||||
} else {
|
||||
notify('批量操作已完成', `请求 ${data?.requested ?? selectedCount.value} 条 · 成功 ${data?.succeeded ?? selectedCount.value} 条`, 'success')
|
||||
}
|
||||
emit('done')
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function failureText(failure) {
|
||||
if (!failure) return ''
|
||||
return `${failure.contactUid || '未知联系人'}:${failure.message || '操作失败'}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="card batch-panel" :class="`mode-${mode}`" aria-label="批量操作">
|
||||
<header class="batch-head">
|
||||
<div>
|
||||
<strong>批量操作</strong>
|
||||
<span class="batch-count">已选 {{ selectedCount }} 人</span>
|
||||
</div>
|
||||
<div class="batch-head-actions">
|
||||
<button class="btn sm ghost" type="button" :disabled="busy || !selectedCount" @click="$emit('clear')">取消选择</button>
|
||||
<button class="btn sm ghost" type="button" :disabled="busy" aria-label="退出批量管理" @click="close">×</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="batch-body">
|
||||
<div v-if="!canManage" class="notice warn">当前账号缺少「contact.manage」权限,无法执行批量操作。</div>
|
||||
<div v-else-if="noAccount" class="notice warn">批量操作仅对具体 QQ 账号生效,请先在顶部选择具体账号。</div>
|
||||
<div v-else-if="overLimit" class="notice danger">已选 {{ selectedCount }} 人,超过批量上限 {{ max }} 人,请减少选择后再执行。</div>
|
||||
|
||||
<div class="notice info">
|
||||
批量仅支持本地操作。QQ 侧删除/拉黑不可逆,不能批量执行,只能在单条详情中操作。
|
||||
</div>
|
||||
|
||||
<section class="batch-section">
|
||||
<div class="batch-section-head">
|
||||
<span>已选联系人</span>
|
||||
<span class="batch-count">{{ selectedCount }} / {{ max }}</span>
|
||||
</div>
|
||||
<div class="selected-row">
|
||||
<button
|
||||
v-for="contact in contacts"
|
||||
:key="contact.contactUid"
|
||||
class="selected-chip"
|
||||
type="button"
|
||||
:disabled="busy"
|
||||
:title="`从选择中移除 ${contact.displayName || contact.nickname}`"
|
||||
@click="$emit('remove', contact.contactUid)"
|
||||
>
|
||||
{{ contact.displayName || contact.nickname || contact.contactId }}
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<span v-if="!contacts.length" class="small-muted">尚未选择联系人,请在列表中勾选,或使用「全选本页」。</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="batch-section">
|
||||
<div class="batch-section-head"><span>操作类型</span></div>
|
||||
<div class="action-grid">
|
||||
<label v-for="item in ACTIONS" :key="item.value" class="action-item" :class="{ active: action === item.value, danger: item.value === 'DELETE' || item.value === 'BLOCK' }">
|
||||
<input v-model="action" type="radio" :value="item.value" :disabled="busy" />
|
||||
<span>
|
||||
<strong>{{ item.label }}</strong>
|
||||
<em>{{ item.hint }}</em>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="action === 'TAG_ADD'" class="batch-section">
|
||||
<Input v-model="tagName" label="标签名" placeholder="输入标签名后执行" hint="同名标签会自动复用,不会重复创建。" :maxlength="32" :disabled="busy" />
|
||||
</section>
|
||||
<section v-else-if="action === 'TAG_REMOVE'" class="batch-section">
|
||||
<span class="field-label">选择要移除的标签</span>
|
||||
<Select v-model="tagUid" :options="tagOptions" placeholder="请选择标签" :disabled="busy" block />
|
||||
</section>
|
||||
|
||||
<div v-if="error" class="notice danger">{{ error }}</div>
|
||||
|
||||
<section v-if="result" class="batch-section result-section">
|
||||
<div class="batch-section-head"><span>执行结果</span></div>
|
||||
<div class="result-line">
|
||||
<span>请求 <b>{{ result.requested }}</b></span>
|
||||
<span class="ok">成功 <b>{{ result.succeeded }}</b></span>
|
||||
<span :class="{ bad: Number(result.failed) > 0 }">失败 <b>{{ result.failed }}</b></span>
|
||||
</div>
|
||||
<ul v-if="result.failures?.length" class="failure-list">
|
||||
<li v-for="(failure, index) in result.failures" :key="index">{{ failureText(failure) }}</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<footer class="batch-foot">
|
||||
<button class="btn ghost" type="button" :disabled="busy" @click="close">取消</button>
|
||||
<button class="btn" :class="action === 'DELETE' || action === 'BLOCK' ? 'danger' : 'primary'" type="button" :disabled="!canApply" @click="apply">
|
||||
{{ applyText }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.batch-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
|
||||
.mode-panel { position: sticky; top: 12px; max-height: calc(100vh - 190px); }
|
||||
.mode-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 42; max-height: 72vh; border-radius: 14px 14px 0 0; box-shadow: 0 -18px 45px rgb(15 23 42 / 18%); }
|
||||
.batch-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--qk-line); flex: none; }
|
||||
.batch-head strong { font-size: 12px; }
|
||||
.batch-count { margin-left: 8px; font-size: 10px; color: var(--qk-text-4); font-family: var(--qk-font-num); }
|
||||
.batch-head-actions { display: flex; align-items: center; gap: 4px; }
|
||||
.batch-body { padding: 10px 14px; overflow: auto; display: flex; flex-direction: column; gap: 9px; }
|
||||
.batch-section { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--qk-line); }
|
||||
.batch-section:first-of-type { border-top: 0; padding-top: 0; }
|
||||
.batch-section-head { display: flex; align-items: center; justify-content: space-between; font-size: 10px; color: var(--qk-text-3); }
|
||||
.selected-row { display: flex; flex-wrap: wrap; gap: 5px; max-height: 86px; overflow: auto; }
|
||||
.selected-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
height: 22px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid var(--qk-line-strong);
|
||||
border-radius: 4px;
|
||||
background: var(--qk-card);
|
||||
color: var(--qk-text-3);
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.selected-chip:hover:not(:disabled) { border-color: #fca5a5; color: var(--qk-red-ink); }
|
||||
.selected-chip:disabled { opacity: .6; cursor: not-allowed; }
|
||||
.action-grid { display: grid; grid-template-columns: 1fr; gap: 4px; }
|
||||
.action-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 7px;
|
||||
padding: 7px 8px;
|
||||
border: 1px solid var(--qk-line);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.action-item.active { border-color: var(--qk-primary); background: var(--qk-primary-weak); }
|
||||
.action-item.danger.active { border-color: #fca5a5; background: var(--qk-red-weak); }
|
||||
.action-item input { margin-top: 2px; accent-color: var(--qk-primary); }
|
||||
.action-item.danger input { accent-color: var(--qk-red-ink); }
|
||||
.action-item span { display: flex; flex-direction: column; gap: 2px; }
|
||||
.action-item strong { font-size: 10.5px; color: var(--qk-text-2); }
|
||||
.action-item em { font-style: normal; font-size: 9.5px; line-height: 1.5; color: var(--qk-text-4); }
|
||||
.field-label { font-size: 10px; color: var(--qk-text-3); }
|
||||
.result-section { gap: 8px; }
|
||||
.result-line { display: flex; gap: 12px; font-size: 10.5px; color: var(--qk-text-3); }
|
||||
.result-line b { font-family: var(--qk-font-num); }
|
||||
.result-line .ok { color: var(--qk-green-ink, #047857); }
|
||||
.result-line .bad { color: var(--qk-red-ink); }
|
||||
.failure-list { margin: 0; padding-left: 16px; max-height: 100px; overflow: auto; font-size: 9.5px; line-height: 1.55; color: var(--qk-red-ink); }
|
||||
.batch-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 9px 14px; border-top: 1px solid var(--qk-line); flex: none; }
|
||||
.small-muted { font-size: 10px; color: var(--qk-text-4); }
|
||||
@media (max-width: 720px) {
|
||||
.batch-body { max-height: 58vh; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,179 @@
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import Modal from '../../components/ui/Modal.vue'
|
||||
import Input from '../../components/ui/Input.vue'
|
||||
import Checkbox from '../../components/ui/Checkbox.vue'
|
||||
import { contactsApi, newIdempotencyKey } from '../../api/contacts'
|
||||
import { notify } from '../../ui'
|
||||
import { errorText } from './util'
|
||||
|
||||
/**
|
||||
* 拉黑联系人:默认仅本地拉黑;也可显式选择同时加入 QQ 黑名单。
|
||||
* QQ 黑名单加入后无法通过本系统解除,文案必须写明;只允许单条执行。
|
||||
*/
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
contact: { type: Object, default: null },
|
||||
qqAccount: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'done'])
|
||||
|
||||
const mode = ref('LOCAL')
|
||||
const reason = ref('')
|
||||
const acked = ref(false)
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const idempotencyKey = ref('')
|
||||
|
||||
const contact = computed(() => props.contact || {})
|
||||
const isPerson = computed(() => String(contact.value.contactType || '').toUpperCase() === 'PERSON')
|
||||
const displayName = computed(() => contact.value.displayName || contact.value.nickname || '该联系人')
|
||||
const qqModeDisabled = computed(() => !isPerson.value)
|
||||
const canSubmit = computed(() => !busy.value && acked.value && Boolean(props.qqAccount))
|
||||
|
||||
function reset() {
|
||||
mode.value = 'LOCAL'
|
||||
reason.value = ''
|
||||
acked.value = false
|
||||
busy.value = false
|
||||
error.value = ''
|
||||
idempotencyKey.value = newIdempotencyKey()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.open, contact.value.contactUid],
|
||||
([open]) => {
|
||||
if (open) reset()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(mode, () => {
|
||||
acked.value = false
|
||||
error.value = ''
|
||||
idempotencyKey.value = newIdempotencyKey()
|
||||
})
|
||||
|
||||
function close() {
|
||||
if (busy.value) return
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!canSubmit.value) return
|
||||
if (!props.qqAccount) {
|
||||
error.value = '请先选择具体 QQ 账号后再拉黑联系人。'
|
||||
return
|
||||
}
|
||||
if (mode.value === 'QQ' && !isPerson.value) {
|
||||
error.value = '群聊联系人不能加入 QQ 黑名单。'
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await contactsApi.block(
|
||||
contact.value.contactUid,
|
||||
{
|
||||
qqAccount: props.qqAccount,
|
||||
confirm: true,
|
||||
mode: mode.value,
|
||||
reason: reason.value.trim()
|
||||
},
|
||||
idempotencyKey.value
|
||||
)
|
||||
notify(
|
||||
mode.value === 'QQ' ? '已请求加入 QQ 黑名单' : '已本地拉黑该联系人',
|
||||
mode.value === 'QQ'
|
||||
? 'QQ 黑名单加入已由上游确认;加入后无法通过本系统解除,只能在 QQ 客户端手动处理。'
|
||||
: '已写入本地拉黑标记:不拦截 QQ 消息投递,历史会话、媒体与审计记录保留。',
|
||||
'success'
|
||||
)
|
||||
emit('done')
|
||||
emit('close')
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :open="open" size="sm" title="拉黑联系人" :subtitle="`${displayName} · QQ ${contact.contactId || '—'}`" :busy="busy" @close="close">
|
||||
<div class="block-form">
|
||||
<p class="block-intro">本地拉黑只在联系人中心打标记与筛选,不拦截 QQ 消息投递;QQ 侧加入黑名单则由 QQ 自行拦截。两种模式都不会删除已有历史记录。</p>
|
||||
|
||||
<label class="option-card" :class="{ active: mode === 'LOCAL' }">
|
||||
<input v-model="mode" type="radio" value="LOCAL" :disabled="busy" />
|
||||
<span class="option-main">
|
||||
<strong>仅本地拉黑(默认)</strong>
|
||||
<em>仅写入本地标记用于筛选与提示,不拦截 QQ 消息投递;历史会话、媒体与审计记录全部保留,可在详情中解除。QQ 侧好友关系不变。</em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label class="option-card is-danger" :class="{ active: mode === 'QQ', disabled: qqModeDisabled }">
|
||||
<input v-model="mode" type="radio" value="QQ" :disabled="busy || qqModeDisabled" />
|
||||
<span class="option-main">
|
||||
<strong>同时加入 QQ 黑名单</strong>
|
||||
<em v-if="!qqModeDisabled">将调用 NapCat 加入黑名单。加入后无法通过本系统解除,只能在 QQ 客户端手动处理;群聊联系人不可使用此选项。</em>
|
||||
<em v-else>群聊联系人不能加入 QQ 黑名单。</em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div v-if="mode === 'QQ'" class="notice danger">
|
||||
重要:QQ 黑名单加入后不可逆地脱离本系统控制,无法通过本系统解除。请确认确实需要在 QQ 侧拉黑。该操作只能单条执行。
|
||||
</div>
|
||||
|
||||
<Input
|
||||
v-model="reason"
|
||||
label="拉黑原因(可选)"
|
||||
placeholder="仅本地记录,便于后续核查"
|
||||
hint="仅保存到本地与审计,不会发送给联系人,也不会同步到 QQ。"
|
||||
:maxlength="255"
|
||||
:disabled="busy"
|
||||
show-count
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model="acked"
|
||||
:disabled="busy"
|
||||
:label="mode === 'QQ' ? '我已知晓 QQ 黑名单加入后无法通过本系统解除,只能在 QQ 客户端处理。' : '我已知晓本地拉黑只写入本地标记,不会拦截 QQ 消息投递。'"
|
||||
/>
|
||||
|
||||
<div v-if="error" class="notice danger">{{ error }}</div>
|
||||
<p class="form-footnote">拉黑与解除拉黑都会写入审计记录;QQ 黑名单状态无法由本系统解除或反查。</p>
|
||||
</div>
|
||||
|
||||
<template #foot>
|
||||
<button class="btn ghost" type="button" :disabled="busy" @click="close">取消</button>
|
||||
<button class="btn danger" type="button" :disabled="!canSubmit" @click="submit">
|
||||
{{ busy ? '执行中…' : '确认拉黑' }}
|
||||
</button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.block-form { display: flex; flex-direction: column; gap: 10px; }
|
||||
.block-intro { margin: 0; font-size: 10.5px; line-height: 1.6; color: var(--qk-text-3); }
|
||||
.option-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 9px;
|
||||
padding: 9px 10px;
|
||||
border: 1px solid var(--qk-line);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.option-card.active { border-color: var(--qk-primary); background: var(--qk-primary-weak); }
|
||||
.option-card.is-danger.active { border-color: #fca5a5; background: var(--qk-red-weak); }
|
||||
.option-card.disabled { opacity: .55; cursor: not-allowed; }
|
||||
.option-card input { margin-top: 2px; accent-color: var(--qk-primary); }
|
||||
.is-danger input { accent-color: var(--qk-red-ink); }
|
||||
.option-main { display: flex; flex-direction: column; gap: 3px; }
|
||||
.option-main strong { font-size: 11px; color: var(--qk-text-2); }
|
||||
.option-main em { font-style: normal; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-4); }
|
||||
.form-footnote { margin: 0; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-4); }
|
||||
</style>
|
||||
@@ -0,0 +1,426 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { formatNumber, formatTime } from '../../ui'
|
||||
import AvatarBadge from '../../components/AvatarBadge.vue'
|
||||
|
||||
/**
|
||||
* 联系人详情:宽屏为右列卡片,≤1280 为右侧抽屉,≤720 为底部浮动卡片。
|
||||
* 在线状态与个性签名没有真实来源,统一显示“未获取”,不推测;不展示“关联规则”。
|
||||
*/
|
||||
const props = defineProps({
|
||||
contact: { type: Object, default: null },
|
||||
mode: { type: String, default: 'panel' },
|
||||
qqAccount: { type: String, default: '' },
|
||||
canManage: { type: Boolean, default: true },
|
||||
tagBusy: { type: Boolean, default: false },
|
||||
tagError: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'edit', 'restore', 'delete', 'block', 'unblock', 'jump', 'add-tag', 'remove-tag'])
|
||||
|
||||
const SOURCE_LABELS = {
|
||||
FRIENDS_WITH_CATEGORY: '好友分组同步',
|
||||
FRIEND_LIST: '好友列表同步',
|
||||
GROUP_LIST: '群列表同步'
|
||||
}
|
||||
const SOURCE_STATUS_LABELS = {
|
||||
ACTIVE: '正常',
|
||||
REMOVED_BY_PEER: '对方已删除',
|
||||
DISMISSED: '群已解散',
|
||||
LEFT: '已退群'
|
||||
}
|
||||
const JOB_LABELS = {
|
||||
PENDING: '等待执行',
|
||||
RUNNING: '运行中',
|
||||
SUCCEEDED: '成功',
|
||||
PARTIAL: '部分成功',
|
||||
FAILED: '失败',
|
||||
STALE: '未同步'
|
||||
}
|
||||
|
||||
const tagInputOpen = ref(false)
|
||||
const tagName = ref('')
|
||||
const tagNotice = ref('')
|
||||
|
||||
const contact = computed(() => props.contact || {})
|
||||
const isPerson = computed(() => String(contact.value.contactType || '').toUpperCase() === 'PERSON')
|
||||
const typeLabel = computed(() => (isPerson.value ? '好友' : '群聊'))
|
||||
const hasAccount = computed(() => Boolean(props.qqAccount))
|
||||
const tags = computed(() => (Array.isArray(contact.value.tags) ? contact.value.tags : []))
|
||||
const commonGroups = computed(() => (Array.isArray(contact.value.commonGroups) ? contact.value.commonGroups : []))
|
||||
const syncState = computed(() => contact.value.syncState || null)
|
||||
|
||||
function deny(action) {
|
||||
if (!props.canManage) return `当前账号缺少「contact.manage」权限,无法${action}。`
|
||||
if (!hasAccount.value) return '请先选择具体 QQ 账号'
|
||||
return ''
|
||||
}
|
||||
|
||||
function sourceLabel(value) {
|
||||
return SOURCE_LABELS[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function sourceStatusLabel(value) {
|
||||
return SOURCE_STATUS_LABELS[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function sourceStatusTone(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'ACTIVE') return 'success'
|
||||
if (text === 'REMOVED_BY_PEER' || text === 'DISMISSED' || text === 'LEFT') return 'warning'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function jobLabel(value) {
|
||||
return JOB_LABELS[String(value || '').toUpperCase()] || value || '—'
|
||||
}
|
||||
|
||||
function jobTone(value) {
|
||||
const text = String(value || '').toUpperCase()
|
||||
if (text === 'SUCCEEDED') return 'success'
|
||||
if (text === 'FAILED') return 'error'
|
||||
if (text === 'PARTIAL' || text === 'RUNNING' || text === 'PENDING') return 'warning'
|
||||
return 'muted'
|
||||
}
|
||||
|
||||
function tagColor(tag) {
|
||||
const color = String(tag?.color || '')
|
||||
return /^#[0-9a-f]{3,8}$/i.test(color) ? color : ''
|
||||
}
|
||||
|
||||
function openTagInput() {
|
||||
tagNotice.value = ''
|
||||
if (tags.value.length >= 8) {
|
||||
tagNotice.value = '每个联系人最多 8 个标签,请先移除其他标签。'
|
||||
return
|
||||
}
|
||||
tagInputOpen.value = true
|
||||
}
|
||||
|
||||
function submitTag() {
|
||||
const name = tagName.value.trim()
|
||||
tagNotice.value = ''
|
||||
if (!name) return
|
||||
if (tags.value.length >= 8) {
|
||||
tagNotice.value = '每个联系人最多 8 个标签,请先移除其他标签。'
|
||||
return
|
||||
}
|
||||
if (tags.value.some((tag) => String(tag.name || '').toLowerCase() === name.toLowerCase())) {
|
||||
tagNotice.value = '该标签已存在于当前联系人。'
|
||||
return
|
||||
}
|
||||
emit('add-tag', name)
|
||||
tagName.value = ''
|
||||
tagInputOpen.value = false
|
||||
}
|
||||
|
||||
function commonGroupCount() {
|
||||
if (isPerson.value) {
|
||||
return contact.value.commonGroupCount !== undefined && contact.value.commonGroupCount !== null
|
||||
? contact.value.commonGroupCount
|
||||
: commonGroups.value.length
|
||||
}
|
||||
return null
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="card contact-detail" :class="`mode-${mode}`" aria-label="联系人详情">
|
||||
<div v-if="mode === 'sheet'" class="sheet-grab" aria-hidden="true"></div>
|
||||
|
||||
<header class="detail-head">
|
||||
<div class="detail-person">
|
||||
<AvatarBadge
|
||||
size="lg"
|
||||
:name="contact.displayName || contact.nickname"
|
||||
:media-uid="contact.avatarMediaUid"
|
||||
:type="isPerson ? 'PRIVATE' : 'GROUP'"
|
||||
/>
|
||||
<div class="detail-name">
|
||||
<div class="detail-name-line">
|
||||
<strong>{{ contact.displayName || contact.nickname || '—' }}</strong>
|
||||
<span class="status info">{{ typeLabel }}</span>
|
||||
<span v-if="contact.blocked" class="status error">已拉黑</span>
|
||||
<span v-if="contact.deletedLocal" class="status warning">本地已删除</span>
|
||||
</div>
|
||||
<div class="detail-sub">QQ {{ contact.contactId || '—' }}</div>
|
||||
<div class="detail-online">在线状态 未获取</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn sm ghost" type="button" aria-label="关闭详情" @click="$emit('close')">×</button>
|
||||
</header>
|
||||
|
||||
<div class="detail-body">
|
||||
<div class="detail-actions">
|
||||
<button class="btn primary sm" type="button" :disabled="contact.deletedLocal" v-tooltip="contact.deletedLocal ? '联系人已本地删除,恢复后可发起会话' : '跳转到消息中心并定位该会话'" @click="$emit('jump')">
|
||||
发起会话
|
||||
</button>
|
||||
<button class="btn sm" type="button" :disabled="Boolean(deny('编辑备注'))" v-tooltip="deny('编辑备注') || '修改本地备注与标签'" @click="$emit('edit')">
|
||||
编辑备注
|
||||
</button>
|
||||
<template v-if="contact.deletedLocal">
|
||||
<button class="btn sm" type="button" :disabled="Boolean(deny('恢复联系人'))" v-tooltip="deny('恢复联系人') || '清除本地删除标记,重新显示该联系人'" @click="$emit('restore')">
|
||||
恢复
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button v-if="contact.blocked" class="btn sm" type="button" :disabled="Boolean(deny('解除拉黑'))" v-tooltip="deny('解除拉黑') || '仅解除本地拉黑;QQ 黑名单需在 QQ 客户端处理'" @click="$emit('unblock')">
|
||||
解除拉黑
|
||||
</button>
|
||||
<button v-else class="btn sm danger-ghost" type="button" :disabled="Boolean(deny('拉黑'))" v-tooltip="deny('拉黑') || '选择仅本地拉黑或同时加入 QQ 黑名单'" @click="$emit('block')">
|
||||
拉黑
|
||||
</button>
|
||||
<button class="btn sm danger" type="button" :disabled="Boolean(deny('删除'))" v-tooltip="deny('删除') || '选择仅本地软删或同时删除 QQ 好友'" @click="$emit('delete')">
|
||||
删除
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-if="!hasAccount" class="notice warn detail-notice">
|
||||
未确定当前 QQ 账号,无法编辑联系人。请先在接入管理确认绑定在线。
|
||||
</div>
|
||||
<div v-if="contact.blocked" class="notice danger detail-notice">
|
||||
该联系人已被本地标记为拉黑:仅用于本地索引与筛选,不拦截 QQ 侧的私聊或群消息投递。若同时执行了 QQ 侧拉黑,好友关系已在 QQ 侧移除;历史会话、媒体与审计记录仍保留。
|
||||
</div>
|
||||
<div v-if="contact.deletedLocal" class="notice warn detail-notice">
|
||||
该联系人已被本地删除,仅从联系人索引隐藏;历史消息、媒体与审计记录保留。重新同步后若仍为好友可再次出现。
|
||||
</div>
|
||||
|
||||
<section class="detail-section">
|
||||
<div class="detail-section-head">
|
||||
<strong>资料</strong>
|
||||
<span>数据来自 NapCat 同步</span>
|
||||
</div>
|
||||
<div class="kv-grid">
|
||||
<div class="kv"><span>QQ 号</span><b class="mono">{{ contact.contactId || '—' }}</b></div>
|
||||
<div class="kv"><span>昵称</span><b>{{ contact.nickname || '—' }}</b></div>
|
||||
<div class="kv"><span>本地备注</span><b>{{ contact.remark || '—' }}</b></div>
|
||||
<div class="kv"><span>QQ 备注</span><b>{{ contact.qqRemark || '—' }}</b></div>
|
||||
<div class="kv">
|
||||
<span>分组</span>
|
||||
<b>{{ contact.groupName || '未分组' }}</b>
|
||||
<em>仅展示 QQ 同步分组,不支持本地修改</em>
|
||||
</div>
|
||||
<div class="kv"><span>来源</span><b>{{ sourceLabel(contact.source) }}</b></div>
|
||||
<div class="kv">
|
||||
<span>来源状态</span>
|
||||
<b><span class="status" :class="sourceStatusTone(contact.sourceStatus)">{{ sourceStatusLabel(contact.sourceStatus) }}</span></b>
|
||||
</div>
|
||||
<div class="kv"><span>最近同步</span><b>{{ formatTime(contact.lastSyncedAt) }}</b></div>
|
||||
<div v-if="!isPerson" class="kv"><span>成员数</span><b>{{ formatNumber(contact.memberCount) }}<template v-if="contact.maxMemberCount"> / {{ formatNumber(contact.maxMemberCount) }}</template></b></div>
|
||||
<div v-if="isPerson" class="kv"><span>共同群聊</span><b>{{ formatNumber(commonGroupCount()) }} 个</b></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="detail-section">
|
||||
<div class="detail-section-head">
|
||||
<strong>在线状态与签名</strong>
|
||||
</div>
|
||||
<div class="kv-grid">
|
||||
<div class="kv"><span>在线状态</span><b class="unavailable">未获取</b></div>
|
||||
<div class="kv"><span>个性签名</span><b class="unavailable">未获取</b></div>
|
||||
</div>
|
||||
<p class="section-hint">后端未提供真实在线状态与签名数据,本页不推测、不伪造。</p>
|
||||
</section>
|
||||
|
||||
<section class="detail-section">
|
||||
<div class="detail-section-head">
|
||||
<strong>标签</strong>
|
||||
<span>{{ tags.length }} / 8</span>
|
||||
</div>
|
||||
<div class="tag-row">
|
||||
<span v-for="tag in tags" :key="tag.tagUid" class="tag-chip">
|
||||
<i v-if="tagColor(tag)" :style="{ background: tagColor(tag) }" aria-hidden="true"></i>
|
||||
{{ tag.name }}
|
||||
<button
|
||||
class="tag-remove"
|
||||
type="button"
|
||||
:disabled="Boolean(deny('移除标签')) || tagBusy"
|
||||
v-tooltip="deny('移除标签') || `移除标签「${tag.name}」`"
|
||||
:aria-label="`移除标签 ${tag.name}`"
|
||||
@click="$emit('remove-tag', tag)"
|
||||
>×</button>
|
||||
</span>
|
||||
<span v-if="!tags.length" class="small-muted">暂无标签</span>
|
||||
<button
|
||||
v-if="!tagInputOpen"
|
||||
class="tag-add"
|
||||
type="button"
|
||||
:disabled="Boolean(deny('添加标签')) || tags.length >= 8"
|
||||
v-tooltip="deny('添加标签') || (tags.length >= 8 ? '每个联系人最多 8 个标签' : '添加本地标签')"
|
||||
@click="openTagInput"
|
||||
>+ 添加标签</button>
|
||||
</div>
|
||||
<div v-if="tagInputOpen" class="tag-input-row">
|
||||
<input
|
||||
v-model="tagName"
|
||||
class="field"
|
||||
maxlength="32"
|
||||
placeholder="输入标签名,回车添加"
|
||||
aria-label="新标签名称"
|
||||
@keydown.enter.prevent="submitTag"
|
||||
/>
|
||||
<button class="btn sm primary" type="button" :disabled="tagBusy || !tagName.trim()" @click="submitTag">
|
||||
{{ tagBusy ? '保存中…' : '添加' }}
|
||||
</button>
|
||||
<button class="btn sm ghost" type="button" @click="tagInputOpen = false; tagName = ''">取消</button>
|
||||
</div>
|
||||
<p v-if="tagNotice || tagError" class="field-error">{{ tagError || tagNotice }}</p>
|
||||
<p v-else class="section-hint">标签用于批量筛选,也会作为自动化规则的筛选条件;不会写入 QQ。</p>
|
||||
</section>
|
||||
|
||||
<section v-if="isPerson" class="detail-section">
|
||||
<div class="detail-section-head">
|
||||
<strong>共同群聊</strong>
|
||||
<span>{{ commonGroups.length }} 个</span>
|
||||
</div>
|
||||
<ul v-if="commonGroups.length" class="common-group-list">
|
||||
<li v-for="group in commonGroups" :key="group.groupId || group.groupContactUid">
|
||||
<span>{{ group.groupName || group.groupId }}</span>
|
||||
<small>{{ formatNumber(group.memberCount) }} 人</small>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="section-hint">未记录共同群聊。仅展示已同步的群成员关系,不代表完整群列表。</p>
|
||||
</section>
|
||||
|
||||
<section class="detail-section">
|
||||
<div class="detail-section-head">
|
||||
<strong>同步信息</strong>
|
||||
</div>
|
||||
<div class="kv-grid">
|
||||
<div class="kv"><span>好友同步</span><b>{{ formatTime(syncState?.friendsSyncedAt) }}</b></div>
|
||||
<div class="kv"><span>群聊同步</span><b>{{ formatTime(syncState?.groupsSyncedAt) }}</b></div>
|
||||
<div class="kv"><span>群成员同步</span><b>{{ formatTime(syncState?.membersSyncedAt) }}</b></div>
|
||||
<div class="kv">
|
||||
<span>最近任务</span>
|
||||
<b><span class="status" :class="jobTone(syncState?.lastJobStatus)">{{ jobLabel(syncState?.lastJobStatus) }}</span></b>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="syncState?.lastErrorMessage" class="field-error">同步失败原因:{{ syncState.lastErrorMessage }}</p>
|
||||
</section>
|
||||
|
||||
<p class="detail-footnote">联系人数据仅更新本地索引;除在详情中显式执行「QQ 侧删除 / 拉黑」外,不会改动 QQ 好友关系;同步不会覆盖已有备注与本地标签。</p>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.contact-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.mode-panel {
|
||||
position: sticky;
|
||||
top: 12px;
|
||||
max-height: calc(100vh - 190px);
|
||||
}
|
||||
.mode-drawer {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 41;
|
||||
width: min(420px, 94vw);
|
||||
border-radius: 0;
|
||||
border-right: 0;
|
||||
border-top: 0;
|
||||
border-bottom: 0;
|
||||
box-shadow: -18px 0 45px rgb(15 23 42 / 18%);
|
||||
}
|
||||
.mode-sheet {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 41;
|
||||
max-height: 80vh;
|
||||
border-radius: 14px 14px 0 0;
|
||||
box-shadow: 0 -18px 45px rgb(15 23 42 / 18%);
|
||||
}
|
||||
.sheet-grab {
|
||||
width: 38px;
|
||||
height: 4px;
|
||||
border-radius: 999px;
|
||||
background: var(--qk-line-strong, #d7dce8);
|
||||
margin: 7px auto 0;
|
||||
flex: none;
|
||||
}
|
||||
.detail-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
padding: 14px 16px 12px;
|
||||
border-bottom: 1px solid var(--qk-line);
|
||||
flex: none;
|
||||
}
|
||||
.detail-person { display: flex; gap: 10px; min-width: 0; }
|
||||
.detail-name { min-width: 0; }
|
||||
.detail-name-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
|
||||
.detail-name-line strong { font-size: 14px; line-height: 20px; }
|
||||
.detail-sub { margin-top: 2px; font-size: 10px; color: var(--qk-text-4); font-family: var(--qk-font-num); }
|
||||
.detail-online { margin-top: 4px; font-size: 10px; color: var(--qk-text-4); display: flex; align-items: center; gap: 4px; }
|
||||
.detail-online:before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--qk-text-4); }
|
||||
.detail-body { padding: 12px 16px 16px; overflow: auto; flex: 1; min-height: 0; }
|
||||
.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
|
||||
.detail-actions .btn { height: 26px; }
|
||||
.detail-notice { margin: 0 0 10px; font-size: 10px; }
|
||||
.detail-section { padding: 10px 0; border-top: 1px solid var(--qk-line); }
|
||||
.detail-section:first-of-type { border-top: 0; padding-top: 0; }
|
||||
.detail-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
|
||||
.detail-section-head strong { font-size: 11px; font-weight: 600; }
|
||||
.detail-section-head span { font-size: 9.5px; color: var(--qk-text-4); }
|
||||
.kv-grid { display: grid; grid-template-columns: 1fr; gap: 5px; }
|
||||
.kv { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: start; gap: 8px; font-size: 10.5px; line-height: 1.55; }
|
||||
.kv span { color: var(--qk-text-4); }
|
||||
.kv b { font-weight: 500; color: var(--qk-text-2); word-break: break-word; }
|
||||
.kv em { grid-column: 2; font-style: normal; font-size: 9.5px; color: var(--qk-text-4); }
|
||||
.kv .mono { font-family: var(--qk-font-num); }
|
||||
.unavailable { color: var(--qk-text-4) !important; }
|
||||
.section-hint { margin: 7px 0 0; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-4); }
|
||||
.tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
|
||||
.tag-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 21px;
|
||||
padding: 0 5px 0 7px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--qk-line-strong, #d7dce8);
|
||||
background: var(--qk-card);
|
||||
color: var(--qk-text-3);
|
||||
font-size: 10px;
|
||||
}
|
||||
.tag-chip i { width: 5px; height: 5px; border-radius: 50%; background: var(--qk-text-4); }
|
||||
.tag-remove { border: 0; background: none; color: var(--qk-text-4); font-size: 12px; line-height: 1; padding: 0 1px; cursor: pointer; }
|
||||
.tag-remove:hover:not(:disabled) { color: var(--qk-red-ink); }
|
||||
.tag-remove:disabled { opacity: .4; cursor: not-allowed; }
|
||||
.tag-add {
|
||||
height: 21px;
|
||||
padding: 0 6px;
|
||||
border: 1px dashed var(--qk-line-strong, #d7dce8);
|
||||
border-radius: 4px;
|
||||
background: none;
|
||||
color: var(--qk-primary);
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tag-add:disabled { opacity: .45; cursor: not-allowed; }
|
||||
.tag-input-row { display: flex; gap: 5px; margin-top: 6px; }
|
||||
.tag-input-row .field { height: 26px; font-size: 10.5px; }
|
||||
.tag-input-row .btn { height: 26px; }
|
||||
.common-group-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
|
||||
.common-group-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--qk-text-3); padding: 3px 0; border-bottom: 1px dashed var(--qk-line); }
|
||||
.common-group-list li:last-child { border-bottom: 0; }
|
||||
.common-group-list small { color: var(--qk-text-4); font-family: var(--qk-font-num); }
|
||||
.detail-footnote { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--qk-line); font-size: 9.5px; line-height: 1.6; color: var(--qk-text-4); }
|
||||
.danger-ghost { color: var(--qk-red-ink); border-color: #fecaca; background: var(--qk-red-weak); }
|
||||
@media (max-width: 720px) {
|
||||
.detail-head { padding: 8px 14px 10px; }
|
||||
.detail-body { padding: 10px 14px 14px; }
|
||||
.kv { grid-template-columns: 70px minmax(0, 1fr); }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,111 @@
|
||||
<script setup>
|
||||
import ContactDetail from './ContactDetail.vue'
|
||||
|
||||
/**
|
||||
* 详情槽位:负责未选择占位、首次加载、首次失败状态;具体资料渲染交给 ContactDetail。
|
||||
* $attrs 继续向下透传 close/edit/delete/block/... 事件,避免中间层逐项复制。
|
||||
*/
|
||||
defineProps({
|
||||
selected: { type: Boolean, default: false },
|
||||
contact: { type: Object, default: null },
|
||||
loading: { type: Boolean, default: false },
|
||||
error: { type: Object, default: null },
|
||||
mode: { type: String, default: 'panel' },
|
||||
qqAccount: { type: String, default: '' },
|
||||
canManage: { type: Boolean, default: true },
|
||||
tagBusy: { type: Boolean, default: false },
|
||||
tagError: { type: String, default: '' }
|
||||
})
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
defineEmits(['retry'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside v-if="!selected" class="card detail-placeholder">
|
||||
<div class="placeholder-icon" aria-hidden="true">◍</div>
|
||||
<h3>暂无可查看的联系人</h3>
|
||||
<p>当前分组为空,可切换到其他分组,或调整搜索与筛选条件查看其他联系人;分组由 QQ 同步,本系统不支持本地调整。</p>
|
||||
<ol class="guide-list">
|
||||
<li><b>1</b><span>查看 QQ 号、备注、来源与共同群聊</span></li>
|
||||
<li><b>2</b><span>添加本地标签,或直接发起会话</span></li>
|
||||
<li><b>3</b><span>发起会话将跳转到消息中心并定位该会话</span></li>
|
||||
</ol>
|
||||
<p class="placeholder-footnote">联系人数据由 NapCat 事件同步,暂不支持手动新建。</p>
|
||||
</aside>
|
||||
|
||||
<div v-else-if="!contact" class="card detail-placeholder">
|
||||
<div v-if="error" class="notice danger detail-error">
|
||||
<strong>{{ error.title }}:{{ error.message }}</strong>
|
||||
<p v-if="error.hint" class="small-muted">{{ error.hint }}</p>
|
||||
</div>
|
||||
<span v-else class="spinner" aria-hidden="true"></span>
|
||||
<p v-if="!error">正在读取联系人资料…</p>
|
||||
<p v-else class="small-muted">资料未加载成功,依赖详情的编辑、删除、拉黑与标签操作已停用,避免与列表数据混用。</p>
|
||||
<button v-if="error" class="btn sm" type="button" :disabled="loading" @click="$emit('retry')">
|
||||
{{ loading ? '重试中…' : '重试' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 已有资料但刷新失败:保留上一次成功加载的真实资料,并在顶部常驻错误提示,不使用列表行兜底。 -->
|
||||
<div v-else class="detail-stack">
|
||||
<div v-if="error" class="notice danger detail-error">
|
||||
<strong>{{ error.title }}:{{ error.message }}</strong>
|
||||
<p v-if="error.hint" class="small-muted">{{ error.hint }}</p>
|
||||
<p class="small-muted">当前展示的是上一次成功加载的资料,可能已过期。</p>
|
||||
<button class="btn sm" type="button" :disabled="loading" @click="$emit('retry')">
|
||||
{{ loading ? '重试中…' : '重试' }}
|
||||
</button>
|
||||
</div>
|
||||
<ContactDetail
|
||||
v-bind="$attrs"
|
||||
:contact="contact"
|
||||
:mode="mode"
|
||||
:qq-account="qqAccount"
|
||||
:can-manage="canManage"
|
||||
:tag-busy="tagBusy"
|
||||
:tag-error="tagError"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.detail-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
min-height: 320px;
|
||||
padding: 22px 18px;
|
||||
text-align: center;
|
||||
position: sticky;
|
||||
top: 12px;
|
||||
}
|
||||
.placeholder-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 10px;
|
||||
background: var(--qk-surface-2, #f8f9fc);
|
||||
border: 1px solid var(--qk-line);
|
||||
color: var(--qk-text-4);
|
||||
font-size: 18px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.detail-placeholder h3 { margin: 0; font-size: 12px; font-weight: 600; }
|
||||
.detail-placeholder p { max-width: 280px; margin: 0; font-size: 10px; line-height: 1.6; color: var(--qk-text-4); }
|
||||
.guide-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; width: 100%; max-width: 280px; text-align: left; }
|
||||
.guide-list li { display: flex; align-items: flex-start; gap: 7px; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-3); }
|
||||
.guide-list b { flex: none; width: 16px; height: 16px; display: grid; place-items: center; border-radius: 50%; background: var(--qk-primary-weak); color: var(--qk-primary); font-size: 9px; font-weight: 600; }
|
||||
.placeholder-footnote { margin-top: 12px; padding-top: 9px; border-top: 1px solid var(--qk-line); font-size: 9px; color: var(--qk-text-4); }
|
||||
.detail-placeholder .spinner { width: 18px; height: 18px; }
|
||||
.small-muted { font-size: 9.5px; color: var(--qk-text-4); }
|
||||
.detail-error { width: 100%; text-align: left; }
|
||||
.detail-error strong { display: block; font-size: 10.5px; }
|
||||
.detail-error p { margin: 4px 0 0; max-width: none; }
|
||||
.detail-error .btn { margin-top: 6px; }
|
||||
.detail-stack { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
||||
</style>
|
||||
@@ -0,0 +1,184 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
/**
|
||||
* 系统级空态:区分“未接入 NapCat”和“已接入但从未同步/同步失败”两个分支(v3-08)。
|
||||
* 账号是全局必需上下文;未确定当前账号时不触发同步。
|
||||
*/
|
||||
const props = defineProps({
|
||||
accounts: { type: Array, default: () => [] },
|
||||
current: { type: String, default: '' },
|
||||
syncState: { type: Object, default: null },
|
||||
syncError: { type: String, default: '' },
|
||||
syncLoading: { type: Boolean, default: false }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['goto-connections', 'sync', 'refresh', 'pick-account'])
|
||||
|
||||
const hasAccounts = computed(() => props.accounts.length > 0)
|
||||
const status = computed(() => String(props.syncState?.status || '').toUpperCase())
|
||||
const running = computed(() => status.value === 'RUNNING' || props.syncLoading)
|
||||
const statusLabel = computed(() => {
|
||||
return {
|
||||
RUNNING: '同步进行中',
|
||||
SUCCEEDED: '最近同步成功',
|
||||
PARTIAL: '最近同步部分成功',
|
||||
FAILED: '最近同步失败',
|
||||
OFFLINE: '账号离线',
|
||||
STALE: '未同步'
|
||||
}[status.value] || '未获取同步状态'
|
||||
})
|
||||
|
||||
const title = computed(() => {
|
||||
if (!hasAccounts.value) return '联系人中心暂无数据'
|
||||
if (!props.current) return '尚未确定当前 QQ 账号'
|
||||
if (status.value === 'RUNNING') return '正在同步联系人'
|
||||
return '尚未同步联系人'
|
||||
})
|
||||
|
||||
const description = computed(() => {
|
||||
if (!hasAccounts.value) {
|
||||
return '联系人来自 NapCat 同步,当前没有可展示的联系人。请先在接入管理绑定 NapCat 并确认连接在线。'
|
||||
}
|
||||
if (!props.current) {
|
||||
return '账号目录尚未就绪,无法确定同步对象。请刷新账号目录,或到接入管理确认绑定已上线。'
|
||||
}
|
||||
if (status.value === 'RUNNING') {
|
||||
return `账号 ${props.current} 正在同步联系人,完成后列表会自动刷新。`
|
||||
}
|
||||
if (status.value === 'OFFLINE') {
|
||||
return `账号 ${props.current} 当前离线,联系人同步已暂停。请保持账号在线后重新同步。`
|
||||
}
|
||||
if (status.value === 'FAILED') {
|
||||
return `账号 ${props.current} 最近一次同步失败,联系人索引可能不完整。请查看失败原因并重试。`
|
||||
}
|
||||
return `账号 ${props.current} 已绑定,但尚未完成首次联系人同步。请执行同步后重试。`
|
||||
})
|
||||
|
||||
const branchTwoText = computed(() => {
|
||||
if (!props.current) {
|
||||
return hasAccounts.value
|
||||
? `已绑定 ${props.accounts.length} 个 QQ 账号,但当前账号尚未确定,无法确认同步记录。`
|
||||
: '绑定 NapCat 后,未完成首次同步时使用此分支处理。'
|
||||
}
|
||||
const parts = [`QQ ${props.current}`, statusLabel.value]
|
||||
if (props.syncState?.lastJobFinishedAt) parts.push(`最近任务 ${formatShort(props.syncState.lastJobFinishedAt)}`)
|
||||
return `${parts.join(' · ')}。点「立即同步」重新拉取联系人。`
|
||||
})
|
||||
|
||||
function formatShort(value) {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return '—'
|
||||
return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="card contacts-empty">
|
||||
<header class="empty-head">
|
||||
<div>
|
||||
<strong>联系人数据</strong>
|
||||
<span class="empty-count">0 人</span>
|
||||
</div>
|
||||
<div class="empty-head-meta">
|
||||
<span class="status" :class="hasAccounts ? 'muted' : 'warning'">{{ hasAccounts ? (current ? statusLabel : '待确定账号') : '未接入' }}</span>
|
||||
<button class="btn sm ghost" type="button" @click="$emit('refresh')">刷新</button>
|
||||
<button class="btn sm" type="button" @click="$emit('goto-connections')">接入管理</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="empty-main">
|
||||
<div class="empty-icon" aria-hidden="true">◍</div>
|
||||
<h2>{{ title }}</h2>
|
||||
<p class="empty-desc">{{ description }}</p>
|
||||
<p class="empty-status">当前状态:<b>{{ hasAccounts ? (current ? statusLabel : '待确定当前账号') : '未绑定任何 NapCat 账号' }}</b></p>
|
||||
<p v-if="syncError" class="field-error">同步状态读取失败:{{ syncError }}</p>
|
||||
<p v-if="syncState?.lastErrorMessage" class="field-error">同步失败原因:{{ syncState.lastErrorMessage }}</p>
|
||||
<div class="empty-actions">
|
||||
<template v-if="!hasAccounts">
|
||||
<button class="btn primary" type="button" @click="$emit('goto-connections')">去接入管理</button>
|
||||
<button class="btn" type="button" @click="$emit('refresh')">刷新</button>
|
||||
</template>
|
||||
<template v-else-if="!current">
|
||||
<button class="btn primary" type="button" @click="$emit('goto-connections')">去接入管理</button>
|
||||
<button class="btn" type="button" @click="$emit('refresh')">刷新</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button class="btn primary" type="button" :disabled="running" @click="$emit('sync')">
|
||||
{{ running ? '同步进行中…' : '立即同步' }}
|
||||
</button>
|
||||
<button class="btn" type="button" @click="$emit('refresh')">刷新</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="branch-grid">
|
||||
<article class="branch-card" :class="{ active: !hasAccounts }">
|
||||
<span class="branch-badge">1</span>
|
||||
<div class="branch-body">
|
||||
<div class="branch-title">未绑定任何 NapCat 账号 <span class="branch-tag">{{ hasAccounts ? '另一种情况' : '当前' }}</span></div>
|
||||
<p>实例尚未绑定 NapCat,没有同步的联系人来源。绑定后保持账号在线,联系人会自动出现在列表;也可在接入管理中手动触发同步。</p>
|
||||
<div class="branch-actions">
|
||||
<button class="btn sm" type="button" @click="$emit('goto-connections')">去接入管理</button>
|
||||
<button class="btn sm ghost" type="button" @click="$emit('refresh')">查看绑定说明</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="branch-card" :class="{ active: hasAccounts }">
|
||||
<span class="branch-badge">2</span>
|
||||
<div class="branch-body">
|
||||
<div class="branch-title">已绑定,但从未同步 <span class="branch-tag">{{ hasAccounts ? '当前' : '另一种情况' }}</span></div>
|
||||
<p>{{ branchTwoText }}</p>
|
||||
<div class="branch-actions">
|
||||
<button class="btn sm" type="button" :disabled="!current || running" :title="!current ? '请先选择具体 QQ 账号' : ''" @click="$emit('sync')">立即同步</button>
|
||||
<button class="btn sm ghost" type="button" @click="$emit('goto-connections')">查看同步记录</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div class="empty-stats">
|
||||
<div class="empty-stat"><span>同步来源</span><b>NapCat 绑定账号</b></div>
|
||||
<div class="empty-stat"><span>同步范围</span><b>好友 · 群聊 · 群成员</b></div>
|
||||
<div class="empty-stat"><span>触发方式</span><b>绑定后自动 · 手动同步</b></div>
|
||||
<div class="empty-stat"><span>同步记录</span><b>接入管理可查</b></div>
|
||||
</div>
|
||||
|
||||
<p class="empty-footnote">同步只更新本地联系人索引,不改动 QQ 好友关系;已有备注、分组与标签在同步后仍保留。</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.contacts-empty { padding: 0; overflow: hidden; }
|
||||
.empty-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--qk-line); }
|
||||
.empty-head strong { font-size: 12px; }
|
||||
.empty-count { margin-left: 6px; font-size: 10px; color: var(--qk-text-4); font-family: var(--qk-font-num); }
|
||||
.empty-head-meta { display: flex; align-items: center; gap: 6px; }
|
||||
.empty-main { max-width: 560px; margin: 0 auto; padding: 28px 20px 20px; text-align: center; }
|
||||
.empty-icon { width: 46px; height: 46px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 12px; background: var(--qk-primary-weak); color: var(--qk-primary); font-size: 20px; }
|
||||
.empty-main h2 { margin: 0; font-size: 15px; font-weight: 600; }
|
||||
.empty-desc { max-width: 430px; margin: 6px auto 10px; font-size: 10.5px; line-height: 1.65; color: var(--qk-text-3); }
|
||||
.empty-status { margin: 0 0 4px; font-size: 10px; color: var(--qk-text-4); }
|
||||
.empty-status b { color: var(--qk-text-2); font-weight: 600; }
|
||||
.empty-actions { display: flex; justify-content: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
|
||||
.branch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 14px; }
|
||||
.branch-card { display: flex; gap: 8px; padding: 10px; border: 1px solid var(--qk-line); border-radius: 8px; background: var(--qk-surface-2, #f8f9fc); }
|
||||
.branch-card.active { border-color: var(--qk-primary); background: var(--qk-primary-weak); }
|
||||
.branch-badge { flex: none; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--qk-line-strong); font-size: 9px; color: var(--qk-text-4); }
|
||||
.branch-card.active .branch-badge { background: var(--qk-primary); border-color: var(--qk-primary); color: #fff; }
|
||||
.branch-body { min-width: 0; }
|
||||
.branch-title { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; font-size: 11px; font-weight: 600; }
|
||||
.branch-tag { padding: 0 4px; border-radius: 3px; border: 1px solid var(--qk-line-strong); font-size: 9px; font-weight: 400; color: var(--qk-text-4); }
|
||||
.branch-body p { margin: 4px 0 8px; font-size: 9.5px; line-height: 1.6; color: var(--qk-text-3); }
|
||||
.branch-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.empty-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 14px; border: 1px solid var(--qk-line); border-radius: 8px; overflow: hidden; background: var(--qk-line); }
|
||||
.empty-stat { display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; background: var(--qk-card); }
|
||||
.empty-stat span { font-size: 9px; color: var(--qk-text-4); }
|
||||
.empty-stat b { font-size: 10px; font-weight: 500; color: var(--qk-text-2); }
|
||||
.empty-footnote { margin: 0; padding: 0 14px 14px; font-size: 9.5px; line-height: 1.6; color: var(--qk-text-4); }
|
||||
@media (max-width: 720px) {
|
||||
.branch-grid { grid-template-columns: 1fr; }
|
||||
.empty-stats { grid-template-columns: 1fr 1fr; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,158 @@
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import Modal from '../../components/ui/Modal.vue'
|
||||
import Checkbox from '../../components/ui/Checkbox.vue'
|
||||
import { contactsApi, newIdempotencyKey } from '../../api/contacts'
|
||||
import { notify } from '../../ui'
|
||||
import { errorText } from './util'
|
||||
|
||||
/**
|
||||
* 删除联系人:默认仅本地软删;也可显式选择同时删除 QQ 好友。
|
||||
* QQ 删除不可逆,只允许单条执行;必须勾选二次确认,失败/结果未知不提示成功。
|
||||
*/
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
contact: { type: Object, default: null },
|
||||
qqAccount: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'done'])
|
||||
|
||||
const mode = ref('LOCAL')
|
||||
const acked = ref(false)
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const idempotencyKey = ref('')
|
||||
|
||||
const contact = computed(() => props.contact || {})
|
||||
const isPerson = computed(() => String(contact.value.contactType || '').toUpperCase() === 'PERSON')
|
||||
const displayName = computed(() => contact.value.displayName || contact.value.nickname || '该联系人')
|
||||
const qqModeDisabled = computed(() => !isPerson.value)
|
||||
const canSubmit = computed(() => !busy.value && acked.value && Boolean(props.qqAccount))
|
||||
|
||||
function reset() {
|
||||
mode.value = 'LOCAL'
|
||||
acked.value = false
|
||||
busy.value = false
|
||||
error.value = ''
|
||||
idempotencyKey.value = newIdempotencyKey()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.open, contact.value.contactUid],
|
||||
([open]) => {
|
||||
if (open) reset()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(mode, () => {
|
||||
acked.value = false
|
||||
error.value = ''
|
||||
idempotencyKey.value = newIdempotencyKey()
|
||||
})
|
||||
|
||||
function close() {
|
||||
if (busy.value) return
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!canSubmit.value) return
|
||||
if (!props.qqAccount) {
|
||||
error.value = '请先选择具体 QQ 账号后再删除联系人。'
|
||||
return
|
||||
}
|
||||
if (mode.value === 'QQ' && !isPerson.value) {
|
||||
error.value = '群聊联系人不能执行 QQ 删除好友操作。'
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await contactsApi.delete(
|
||||
contact.value.contactUid,
|
||||
{ qqAccount: props.qqAccount, confirm: true, mode: mode.value },
|
||||
idempotencyKey.value
|
||||
)
|
||||
notify(
|
||||
mode.value === 'QQ' ? 'QQ 好友删除已由上游确认' : '已从本地联系人列表删除',
|
||||
mode.value === 'QQ'
|
||||
? '该操作不可逆,系统不会自动恢复好友关系;历史消息与审计记录仍保留。'
|
||||
: '历史消息、媒体与审计记录保留;后续同步若仍为好友可再次出现。',
|
||||
'success'
|
||||
)
|
||||
emit('done')
|
||||
emit('close')
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :open="open" size="sm" title="删除联系人" :subtitle="`${displayName} · QQ ${contact.contactId || '—'}`" :busy="busy" @close="close">
|
||||
<div class="delete-form">
|
||||
<p class="delete-intro">请选择删除方式。删除会影响后续联系人展示,但不会自动清理历史数据。</p>
|
||||
|
||||
<label class="option-card" :class="{ active: mode === 'LOCAL' }">
|
||||
<input v-model="mode" type="radio" value="LOCAL" :disabled="busy" />
|
||||
<span class="option-main">
|
||||
<strong>仅本地删除(默认)</strong>
|
||||
<em>从联系人列表隐藏,历史消息、媒体与审计记录保留;后续同步若仍为好友可再次出现。</em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label class="option-card is-danger" :class="{ active: mode === 'QQ', disabled: qqModeDisabled }">
|
||||
<input v-model="mode" type="radio" value="QQ" :disabled="busy || qqModeDisabled" />
|
||||
<span class="option-main">
|
||||
<strong>同时删除 QQ 好友</strong>
|
||||
<em v-if="!qqModeDisabled">将调用 NapCat 删除好友。QQ 侧删除不可逆,系统不会自动恢复;群聊联系人不可使用此选项。</em>
|
||||
<em v-else>群聊联系人不能执行 QQ 删除好友操作。</em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div v-if="mode === 'QQ'" class="notice danger">
|
||||
QQ 删除不可逆,且无法保证对方客户端已即时感知;如上游超时,后端会返回「结果未知」,请先核实再决定是否重试。该操作只能单条执行。
|
||||
</div>
|
||||
|
||||
<Checkbox v-model="acked" :disabled="busy" :label="mode === 'QQ' ? '我已知晓 QQ 侧删除不可逆,且系统不会自动恢复好友关系。' : '我已知晓该联系人将从本地联系人列表移除。'" />
|
||||
|
||||
<div v-if="error" class="notice danger">{{ error }}</div>
|
||||
<p class="form-footnote">本地删除与 QQ 删除都会写入审计记录;本地软删可通过「显示已软删」筛选后恢复。</p>
|
||||
</div>
|
||||
|
||||
<template #foot>
|
||||
<button class="btn ghost" type="button" :disabled="busy" @click="close">取消</button>
|
||||
<button class="btn danger" type="button" :disabled="!canSubmit" @click="submit">
|
||||
{{ busy ? '执行中…' : '确认删除' }}
|
||||
</button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.delete-form { display: flex; flex-direction: column; gap: 10px; }
|
||||
.delete-intro { margin: 0; font-size: 10.5px; line-height: 1.6; color: var(--qk-text-3); }
|
||||
.option-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 9px;
|
||||
padding: 9px 10px;
|
||||
border: 1px solid var(--qk-line);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: border-color .15s ease, background .15s ease;
|
||||
}
|
||||
.option-card.active { border-color: var(--qk-primary); background: var(--qk-primary-weak); }
|
||||
.option-card.is-danger.active { border-color: #fca5a5; background: var(--qk-red-weak); }
|
||||
.option-card.disabled { opacity: .55; cursor: not-allowed; }
|
||||
.option-card input { margin-top: 2px; accent-color: var(--qk-primary); }
|
||||
.is-danger input { accent-color: var(--qk-red-ink); }
|
||||
.option-main { display: flex; flex-direction: column; gap: 3px; }
|
||||
.option-main strong { font-size: 11px; color: var(--qk-text-2); }
|
||||
.option-main em { font-style: normal; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-4); }
|
||||
.form-footnote { margin: 0; font-size: 9.5px; color: var(--qk-text-4); line-height: 1.55; }
|
||||
</style>
|
||||
@@ -0,0 +1,236 @@
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import Modal from '../../components/ui/Modal.vue'
|
||||
import Input from '../../components/ui/Input.vue'
|
||||
import { contactsApi } from '../../api/contacts'
|
||||
import { notify } from '../../ui'
|
||||
import { errorText } from './util'
|
||||
|
||||
/**
|
||||
* 编辑备注与标签。分组只展示 QQ 同步结果,不提供本地改分组(口径已确认)。
|
||||
* 标签的增删与备注保存属于本地写操作,均需 confirm=true;失败不做成功提示。
|
||||
*/
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
contact: { type: Object, default: null },
|
||||
qqAccount: { type: String, default: '' }
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close', 'saved'])
|
||||
|
||||
const remark = ref('')
|
||||
const visibleTags = ref([])
|
||||
const newTags = ref([])
|
||||
const removedTags = ref([])
|
||||
const tagName = ref('')
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const tagError = ref('')
|
||||
|
||||
const MAX_TAGS = 8
|
||||
const contact = computed(() => props.contact || {})
|
||||
const typeLabel = computed(() => (String(contact.value.contactType || '').toUpperCase() === 'PERSON' ? '好友' : '群聊'))
|
||||
const tagLimitReached = computed(() => visibleTags.value.length >= MAX_TAGS)
|
||||
|
||||
function reset() {
|
||||
remark.value = contact.value.remark || ''
|
||||
visibleTags.value = Array.isArray(contact.value.tags) ? contact.value.tags.map((tag) => ({ ...tag })) : []
|
||||
newTags.value = []
|
||||
removedTags.value = []
|
||||
tagName.value = ''
|
||||
error.value = ''
|
||||
tagError.value = ''
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.open, contact.value.contactUid],
|
||||
([open]) => {
|
||||
if (open) reset()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
function addTag() {
|
||||
tagError.value = ''
|
||||
const name = tagName.value.trim()
|
||||
if (!name) return
|
||||
if (tagLimitReached.value) {
|
||||
tagError.value = `每个联系人最多 ${MAX_TAGS} 个标签。`
|
||||
return
|
||||
}
|
||||
if (visibleTags.value.some((tag) => String(tag.name || '').toLowerCase() === name.toLowerCase())) {
|
||||
tagError.value = '该标签已存在于当前联系人。'
|
||||
return
|
||||
}
|
||||
visibleTags.value.push({ name, tagUid: '', pending: true })
|
||||
newTags.value.push(name)
|
||||
tagName.value = ''
|
||||
}
|
||||
|
||||
function removeTag(tag) {
|
||||
tagError.value = ''
|
||||
visibleTags.value = visibleTags.value.filter((item) => item !== tag)
|
||||
if (tag.pending) {
|
||||
newTags.value = newTags.value.filter((name) => name !== tag.name)
|
||||
} else if (tag.tagUid) {
|
||||
removedTags.value.push(tag.tagUid)
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (saving.value) return
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (!props.qqAccount) {
|
||||
error.value = '请先选择具体 QQ 账号后再保存。'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
tagError.value = ''
|
||||
const failures = []
|
||||
let remarkSaved = false
|
||||
try {
|
||||
await contactsApi.updateRemark(contact.value.contactUid, {
|
||||
qqAccount: props.qqAccount,
|
||||
confirm: true,
|
||||
remark: remark.value.trim()
|
||||
})
|
||||
remarkSaved = true
|
||||
for (const name of newTags.value) {
|
||||
try {
|
||||
await contactsApi.addTag(contact.value.contactUid, {
|
||||
qqAccount: props.qqAccount,
|
||||
confirm: true,
|
||||
name
|
||||
})
|
||||
} catch (e) {
|
||||
failures.push(`添加标签「${name}」失败:${errorText(e)}`)
|
||||
}
|
||||
}
|
||||
for (const tagUid of removedTags.value) {
|
||||
try {
|
||||
await contactsApi.removeTag(contact.value.contactUid, tagUid, {
|
||||
qqAccount: props.qqAccount,
|
||||
confirm: true
|
||||
})
|
||||
} catch (e) {
|
||||
failures.push(`移除标签失败:${errorText(e)}`)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
saving.value = false
|
||||
return
|
||||
}
|
||||
saving.value = false
|
||||
if (failures.length) {
|
||||
tagError.value = failures.join(';')
|
||||
notify('备注已保存,但标签未全部生效', tagError.value, 'warning')
|
||||
emit('saved')
|
||||
return
|
||||
}
|
||||
if (remarkSaved) notify('联系人资料已保存', '备注与标签已更新,变更已写入审计。', 'success')
|
||||
emit('saved')
|
||||
emit('close')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :open="open" size="md" title="编辑备注与标签" :subtitle="`${contact.displayName || contact.nickname || '—'} · QQ ${contact.contactId || '—'} · ${typeLabel}`" :busy="saving" @close="close">
|
||||
<div class="edit-form">
|
||||
<Input
|
||||
v-model="remark"
|
||||
label="备注名"
|
||||
placeholder="留空时显示昵称"
|
||||
hint="优先显示在联系人列表与会话消息中,留空时显示昵称。"
|
||||
:maxlength="255"
|
||||
show-count
|
||||
size="md"
|
||||
/>
|
||||
|
||||
<div class="readonly-row">
|
||||
<div class="readonly-label">好友分组</div>
|
||||
<div class="readonly-value">{{ contact.groupName || '未分组' }}</div>
|
||||
<p class="readonly-hint">分组只由 QQ 同步,不支持在本系统修改,也不改变 QQ 好友关系。</p>
|
||||
</div>
|
||||
|
||||
<div class="tag-field">
|
||||
<div class="tag-field-head">
|
||||
<span>标签</span>
|
||||
<span class="tag-count">最多 {{ MAX_TAGS }} 个 · 已选 {{ visibleTags.length }}</span>
|
||||
</div>
|
||||
<div class="tag-row">
|
||||
<span v-for="tag in visibleTags" :key="tag.tagUid || `new-${tag.name}`" class="tag-chip">
|
||||
{{ tag.name }}
|
||||
<button class="tag-remove" type="button" :aria-label="`移除标签 ${tag.name}`" @click="removeTag(tag)">×</button>
|
||||
</span>
|
||||
<span v-if="!visibleTags.length" class="small-muted">暂无标签</span>
|
||||
</div>
|
||||
<div class="tag-input-row">
|
||||
<Input
|
||||
v-model="tagName"
|
||||
placeholder="输入标签名,回车添加"
|
||||
:disabled="tagLimitReached"
|
||||
:maxlength="32"
|
||||
size="sm"
|
||||
@enter="addTag"
|
||||
/>
|
||||
<button class="btn sm" type="button" :disabled="tagLimitReached || !tagName.trim()" @click="addTag">添加</button>
|
||||
</div>
|
||||
<p v-if="tagError" class="field-error">{{ tagError }}</p>
|
||||
<p v-else class="tag-hint">建议使用「客户」「同事」「临时」等短标签;标签用于批量筛选与自动化规则筛选,不会写入 QQ。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="notice danger form-notice">{{ error }}</div>
|
||||
<p class="form-footnote">保存将写入审计记录,包含操作人、时间与变更值。</p>
|
||||
</div>
|
||||
|
||||
<template #foot>
|
||||
<button class="btn ghost" type="button" :disabled="saving" @click="close">取消</button>
|
||||
<button class="btn primary" type="button" :disabled="saving" @click="save">
|
||||
{{ saving ? '保存中…' : '保存' }}
|
||||
</button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.edit-form { display: flex; flex-direction: column; gap: 14px; }
|
||||
.readonly-row {
|
||||
padding: 9px 10px;
|
||||
border: 1px solid var(--qk-line);
|
||||
border-radius: 8px;
|
||||
background: var(--qk-surface-2, #f8f9fc);
|
||||
}
|
||||
.readonly-label { font-size: 10px; color: var(--qk-text-4); }
|
||||
.readonly-value { margin-top: 2px; font-size: 11px; font-weight: 600; color: var(--qk-text-2); }
|
||||
.readonly-hint { margin: 4px 0 0; font-size: 9.5px; line-height: 1.55; color: var(--qk-text-4); }
|
||||
.tag-field { display: flex; flex-direction: column; gap: 6px; }
|
||||
.tag-field-head { display: flex; align-items: center; justify-content: space-between; font-size: 10px; color: var(--qk-text-3); }
|
||||
.tag-count { font-size: 9.5px; color: var(--qk-text-4); font-family: var(--qk-font-num); }
|
||||
.tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
|
||||
.tag-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 22px;
|
||||
padding: 0 5px 0 7px;
|
||||
border: 1px solid var(--qk-line-strong);
|
||||
border-radius: 4px;
|
||||
background: var(--qk-card);
|
||||
color: var(--qk-text-3);
|
||||
font-size: 10px;
|
||||
}
|
||||
.tag-remove { border: 0; background: none; padding: 0 1px; color: var(--qk-text-4); font-size: 12px; line-height: 1; cursor: pointer; }
|
||||
.tag-remove:hover { color: var(--qk-red-ink); }
|
||||
.tag-input-row { display: flex; gap: 6px; align-items: center; }
|
||||
.tag-input-row :deep(.qk-field) { height: 28px; font-size: 10.5px; }
|
||||
.tag-hint, .form-footnote { margin: 0; font-size: 9.5px; line-height: 1.6; color: var(--qk-text-4); }
|
||||
.form-footnote { padding-top: 8px; border-top: 1px solid var(--qk-line); }
|
||||
.form-notice { font-size: 10px; }
|
||||
.small-muted { font-size: 10px; color: var(--qk-text-4); }
|
||||
</style>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { describeError } from '../../ui'
|
||||
|
||||
/** 联系人模块统一错误文案:保留后端 message、错误码与追踪标识,不吞异常。 */
|
||||
export function errorText(error) {
|
||||
const info = describeError(error)
|
||||
const parts = [`${info.title}:${info.message}`]
|
||||
if (info.code) parts.push(`错误码 ${info.code}`)
|
||||
if (info.requestId) parts.push(`追踪 ${info.requestId}`)
|
||||
return parts.join(';')
|
||||
}
|
||||
@@ -2,6 +2,9 @@ import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
|
||||
// 浏览器会以 CORS 为由拒绝从 file:// 加载外部 module 脚本,
|
||||
// 因此构建结束后把唯一的 JS/CSS 内联进 index.html,让 dist/index.html 可以直接双击预览。
|
||||
@@ -36,7 +39,15 @@ function inlineDistPlugin() {
|
||||
|
||||
// 开发期通过代理访问后端,避免在生产配置里写死后端地址。
|
||||
export default defineConfig({
|
||||
plugins: [vue(), inlineDistPlugin()],
|
||||
// Element Plus 按需引入:模板里出现的 el-* 组件与 ElMessage / ElMessageBox 等 API
|
||||
// 都由这两个插件在编译期按需注入组件代码与对应样式,不做全量引入。
|
||||
plugins: [
|
||||
vue(),
|
||||
AutoImport({ resolvers: [ElementPlusResolver()], dts: false }),
|
||||
// dirs 置空:src/components 下的自绘组件均由页面显式 import,避免与按需组件重名。
|
||||
Components({ resolvers: [ElementPlusResolver()], dirs: [] }),
|
||||
inlineDistPlugin()
|
||||
],
|
||||
// 相对 base:dist 资源使用 ./assets 前缀,可直接双击 dist/index.html 预览。
|
||||
base: './',
|
||||
server: {
|
||||
|
||||