feat(frontend): 管理台按原型落地,新增独立消息检索页与演示数据开关
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<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>
|
||||
@@ -0,0 +1,133 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, automationNodes, automationRules, automationRuns, automationSummary } 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('rules')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="工作空间" title="自动化" desc="规则、版本、节点编排与执行记录。后端尚未提供自动化接口,本页内容全部为演示数据。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供规则导入接口">导入规则</button>
|
||||
<button class="btn primary" type="button" disabled title="后端未提供规则创建接口">新建规则</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="自动化能力尚未开发"
|
||||
summary="规则引擎、版本隔离、节点编排与执行记录均依赖后端尚未提供的接口。关闭演示数据时不展示任何占位业务数据。"
|
||||
:deps="PLANNED_DEPS.automation"
|
||||
/>
|
||||
|
||||
<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">{{ automationSummary.successRate }}%</div>
|
||||
<div class="stat-foot">成功 {{ automationSummary.success }} · 失败 {{ automationSummary.failed }}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>已发布规则<DemoBadge /></span><span class="stat-icon">⌗</span></div>
|
||||
<div class="stat-value">{{ automationRules.length }}</div>
|
||||
<div class="stat-foot">含 1 条已停用规则</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>今日执行<DemoBadge /></span><span class="stat-icon">≡</span></div>
|
||||
<div class="stat-value">1,284</div>
|
||||
<div class="stat-foot">最近执行「{{ automationSummary.recent }}」</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>高风险动作<DemoBadge /></span><span class="stat-icon">!</span></div>
|
||||
<div class="stat-value">2</div>
|
||||
<div class="stat-foot">需人工确认后才允许执行</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'rules' }" type="button" @click="tab = 'rules'">规则</button>
|
||||
<button class="tab" :class="{ active: tab === 'canvas' }" type="button" @click="tab = 'canvas'">节点编排</button>
|
||||
<button class="tab" :class="{ active: tab === 'runs' }" type="button" @click="tab = 'runs'">执行记录</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'rules'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">规则列表<DemoBadge /></h3>
|
||||
<div class="actions">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供规则发布接口">发布</button>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供规则停用接口">停用</button>
|
||||
</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="rule in automationRules" :key="rule.name">
|
||||
<td><strong>{{ rule.name }}</strong></td>
|
||||
<td>{{ rule.trigger }}</td>
|
||||
<td>{{ rule.version }}</td>
|
||||
<td><StatusTag :value="rule.status === '运行中' ? 'ACTIVE' : 'DISABLED'" :label="rule.status" /></td>
|
||||
<td>{{ rule.successRate }}</td>
|
||||
<td>{{ rule.lastRun }}</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供规则编辑接口">编辑</button>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供规则调试接口">调试</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'canvas'" class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">节点编排 · 群消息智能分流<DemoBadge /></h3>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供编排保存接口">保存草稿</button>
|
||||
</div>
|
||||
<div class="node-canvas">
|
||||
<div v-for="node in automationNodes" :key="node.id" class="node" :style="{ left: `${node.x}px`, top: `${node.y}px` }">
|
||||
<span class="node-kind">{{ node.kind }}</span>
|
||||
<strong>{{ node.title }}</strong>
|
||||
<small>{{ node.sub }}</small>
|
||||
</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">执行记录<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><th>状态</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="run in automationRuns" :key="run.id">
|
||||
<td>{{ run.id }}</td>
|
||||
<td>{{ run.rule }}</td>
|
||||
<td>{{ run.startedAt }}</td>
|
||||
<td>{{ run.duration }}</td>
|
||||
<td>{{ run.node }}</td>
|
||||
<td><StatusTag :value="run.status" :label="run.status" /></td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供执行详情接口">查看步骤</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,103 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, backupPlans, backupRecords } 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('plans')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="平台管理" title="备份与恢复" desc="备份策略、备份记录与恢复演练。后端尚未提供备份接口,本页内容全部为演示数据。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供恢复接口">恢复数据</button>
|
||||
<button class="btn primary" type="button" disabled title="后端未提供立即备份接口">立即备份</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="备份与恢复尚未开发"
|
||||
summary="备份任务、完整性校验与恢复演练依赖后端尚未提供的接口。备份属于高风险操作,未实现前不提供任何触发入口。"
|
||||
:deps="PLANNED_DEPS.backup"
|
||||
/>
|
||||
|
||||
<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>
|
||||
</template>
|
||||
@@ -1,124 +0,0 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { api } from '../api'
|
||||
|
||||
const rows = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const notice = ref('')
|
||||
|
||||
const form = ref({ displayName: '', endpoint: '', accessToken: '' })
|
||||
const creating = ref(false)
|
||||
const createError = ref('')
|
||||
|
||||
const rotating = ref('')
|
||||
const rotateToken = ref('')
|
||||
const rotateError = ref('')
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
rows.value = await api.bindings()
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
createError.value = ''
|
||||
notice.value = ''
|
||||
creating.value = true
|
||||
try {
|
||||
await api.createBinding({ ...form.value })
|
||||
form.value = { displayName: '', endpoint: '', accessToken: '' }
|
||||
notice.value = '绑定已创建。连接与在线状态将在总览页刷新后可见。'
|
||||
await load()
|
||||
} catch (e) {
|
||||
createError.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function rotate(bindingUid) {
|
||||
rotateError.value = ''
|
||||
try {
|
||||
await api.rotateToken(bindingUid, rotateToken.value)
|
||||
rotating.value = ''
|
||||
rotateToken.value = ''
|
||||
notice.value = '访问令牌已更新。'
|
||||
await load()
|
||||
} catch (e) {
|
||||
rotateError.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
}
|
||||
}
|
||||
|
||||
async function deactivate(row) {
|
||||
if (!window.confirm(`确认解绑「${row.displayName || row.bindingUid}」?历史消息与事件会保留。`)) return
|
||||
error.value = ''
|
||||
try {
|
||||
await api.deactivateBinding(row.bindingUid)
|
||||
await load()
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="card">
|
||||
<h2>新增 NapCat 绑定</h2>
|
||||
<p class="muted">
|
||||
采用正向 WebSocket:QLinker 主动连接 NapCat 的事件上报地址。同一 NapCat 实例最多保留一条有效绑定。
|
||||
</p>
|
||||
<form @submit.prevent="create">
|
||||
<label><span>显示名称</span><input v-model="form.displayName" required /></label>
|
||||
<label><span>连接地址(ws://…)</span><input v-model="form.endpoint" placeholder="ws://127.0.0.1:3001" required /></label>
|
||||
<label><span>访问令牌</span><input v-model="form.accessToken" type="password" autocomplete="off" /></label>
|
||||
<button type="submit" :disabled="creating">{{ creating ? '提交中…' : '创建绑定' }}</button>
|
||||
<p v-if="createError" class="error">{{ createError }}</p>
|
||||
</form>
|
||||
<p v-if="notice" class="ok">{{ notice }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between;">
|
||||
<h2 style="margin: 0;">绑定列表</h2>
|
||||
<button class="ghost" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
</div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>名称</th><th>地址</th><th>绑定状态</th><th>连接状态</th><th>QQ 账号</th><th>凭据</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.bindingUid">
|
||||
<td>{{ row.displayName }}</td>
|
||||
<td class="muted">{{ row.endpoint }}</td>
|
||||
<td>{{ row.bindingStatus }}</td>
|
||||
<td>{{ row.connectionStatus }}</td>
|
||||
<td>{{ row.qqAccountId || '-' }}</td>
|
||||
<td>{{ row.hasCredential ? '已保存' : '未设置' }}</td>
|
||||
<td class="row">
|
||||
<button v-if="rotating !== row.bindingUid" class="ghost" @click="rotating = row.bindingUid">轮换令牌</button>
|
||||
<button class="ghost" @click="deactivate(row)">解绑</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!rows.length && !loading"><td colspan="7" class="muted">暂无绑定。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="rotating" class="row" style="margin-top: 12px;">
|
||||
<input v-model="rotateToken" type="password" placeholder="新的访问令牌" style="max-width: 320px;" />
|
||||
<button @click="rotate(rotating)">确认轮换</button>
|
||||
<button class="ghost" @click="rotating = ''; rotateToken = ''">取消</button>
|
||||
</div>
|
||||
<p v-if="rotateError" class="error">{{ rotateError }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,37 +1,89 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { describeError } from '../ui'
|
||||
|
||||
const USERNAME_PATTERN = /^[A-Za-z0-9_.-]{3,64}$/
|
||||
|
||||
const router = useRouter()
|
||||
const bootstrapToken = ref('')
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const confirm = ref('')
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const status = ref(null)
|
||||
const statusLoading = ref(false)
|
||||
const statusError = ref(null)
|
||||
let statusSeq = 0
|
||||
|
||||
const form = ref({ bootstrapToken: '', username: '', password: '', confirmPassword: '' })
|
||||
const errors = ref({})
|
||||
const busy = ref(false)
|
||||
const submitError = ref(null)
|
||||
const success = ref(null)
|
||||
|
||||
const formEnabled = computed(() =>
|
||||
Boolean(status.value && !status.value.administratorExists && status.value.bootstrapTokenActive)
|
||||
)
|
||||
const closed = computed(() => Boolean(status.value?.administratorExists))
|
||||
const tokenUnavailable = computed(() =>
|
||||
Boolean(status.value && !status.value.administratorExists && !status.value.bootstrapTokenActive)
|
||||
)
|
||||
const recoveryMessage = computed(() => {
|
||||
const value = status.value?.recoveryRequired
|
||||
if (!value) return ''
|
||||
return typeof value === 'string' ? value : '实例初始化状态或资源身份不一致,可能无法正常读写数据。'
|
||||
})
|
||||
|
||||
async function loadStatus() {
|
||||
const seq = ++statusSeq
|
||||
statusLoading.value = true
|
||||
statusError.value = null
|
||||
try {
|
||||
status.value = await api.initialization()
|
||||
} catch (e) {
|
||||
error.value = e.message
|
||||
const value = await api.initialization()
|
||||
if (seq !== statusSeq) return
|
||||
status.value = value || null
|
||||
} catch (error) {
|
||||
if (seq !== statusSeq) return
|
||||
statusError.value = describeError(error)
|
||||
} finally {
|
||||
if (seq === statusSeq) statusLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
error.value = ''
|
||||
if (password.value !== confirm.value) {
|
||||
error.value = '两次输入的口令不一致'
|
||||
return
|
||||
function validate() {
|
||||
const next = {}
|
||||
if (!form.value.bootstrapToken.trim()) {
|
||||
next.bootstrapToken = '请输入引导令牌。'
|
||||
}
|
||||
if (!USERNAME_PATTERN.test(form.value.username.trim())) {
|
||||
next.username = '用户名需为 3–64 位字母、数字、下划线、点或连字符。'
|
||||
}
|
||||
if (form.value.password.length < 12) {
|
||||
next.password = '口令至少 12 位。'
|
||||
}
|
||||
if (form.value.confirmPassword !== form.value.password) {
|
||||
next.confirmPassword = '两次输入的口令不一致。'
|
||||
}
|
||||
errors.value = next
|
||||
return Object.keys(next).length === 0
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (busy.value || !formEnabled.value) return
|
||||
submitError.value = null
|
||||
if (!validate()) return
|
||||
busy.value = true
|
||||
try {
|
||||
await api.bootstrap(bootstrapToken.value, username.value, password.value)
|
||||
router.push('/login')
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
const data = await api.bootstrap(
|
||||
form.value.bootstrapToken.trim(),
|
||||
form.value.username.trim(),
|
||||
form.value.password
|
||||
)
|
||||
success.value = {
|
||||
message: data?.message || '管理员已创建,引导令牌已永久失效。',
|
||||
username: form.value.username.trim()
|
||||
}
|
||||
form.value = { bootstrapToken: '', username: '', password: '', confirmPassword: '' }
|
||||
errors.value = {}
|
||||
loadStatus()
|
||||
} catch (error) {
|
||||
submitError.value = describeError(error)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
@@ -41,25 +93,159 @@ onMounted(loadStatus)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card" style="max-width: 460px; margin: 60px auto;">
|
||||
<h2>首次初始化:创建唯一管理员</h2>
|
||||
<p v-if="status && status.administratorExists" class="warn">
|
||||
本实例已存在管理员,引导流程已永久关闭。请直接登录。
|
||||
<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">
|
||||
<div>
|
||||
<strong>管理员已创建</strong>
|
||||
<p style="margin: 4px 0 0">{{ success.message }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">
|
||||
引导令牌已永久失效。请使用刚创建的管理员用户名与口令登录管理台。
|
||||
</p>
|
||||
</div>
|
||||
<RouterLink class="btn sm" to="/login">前往登录</RouterLink>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div v-if="statusLoading" class="loading-row">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在读取初始化状态…
|
||||
</div>
|
||||
|
||||
<div v-else-if="statusError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ statusError.title }}</strong>
|
||||
<p style="margin: 4px 0 0">{{ statusError.message }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">{{ statusError.hint }}</p>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="statusLoading" @click="loadStatus">重试</button>
|
||||
</div>
|
||||
|
||||
<template v-else-if="status">
|
||||
<div v-if="closed" class="notice">
|
||||
<div>
|
||||
<strong>实例已完成初始化</strong>
|
||||
<p style="margin: 4px 0 0">已存在管理员,引导入口已永久关闭,无法再次创建管理员。</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">请返回登录页使用已有账号登录。</p>
|
||||
</div>
|
||||
<RouterLink class="btn sm" to="/login">返回登录</RouterLink>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tokenUnavailable" class="notice danger">
|
||||
<div>
|
||||
<strong>当前没有有效的引导令牌</strong>
|
||||
<p style="margin: 4px 0 0">
|
||||
实例尚未创建管理员,但引导令牌未签发或已失效,本页不会接受初始化请求。
|
||||
</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">
|
||||
请查看实例启动日志或部署配置获取引导令牌,必要时按初始化流程重新签发后再刷新本页。
|
||||
</p>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="statusLoading" @click="loadStatus">刷新状态</button>
|
||||
</div>
|
||||
|
||||
<div v-if="recoveryMessage && !closed && !tokenUnavailable" class="notice danger">
|
||||
<div>
|
||||
<strong>实例需要恢复</strong>
|
||||
<p style="margin: 4px 0 0">{{ recoveryMessage }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">
|
||||
请先核实数据库与对象存储身份,不要在未确认的情况下重新初始化,以免旧数据被遗弃。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="formEnabled">
|
||||
<div class="guide-list">
|
||||
<div class="guide-step"><b>1</b><span>从实例启动日志或部署配置中获取一次性引导令牌。</span></div>
|
||||
<div class="guide-step"><b>2</b><span>设置管理员用户名与至少 12 位口令,口令需再次确认。</span></div>
|
||||
<div class="guide-step"><b>3</b><span>创建成功后令牌永久失效,返回登录页使用新账号登录。</span></div>
|
||||
</div>
|
||||
|
||||
<div v-if="submitError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ submitError.title }}</strong>
|
||||
<p style="margin: 4px 0 0">{{ submitError.message }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">{{ submitError.hint }}</p>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="statusLoading" @click="loadStatus">
|
||||
刷新初始化状态
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form class="auth-form" @submit.prevent="submit">
|
||||
<div class="fld">
|
||||
<label for="bootstrap-token">引导令牌<span class="req">*</span></label>
|
||||
<input
|
||||
id="bootstrap-token"
|
||||
v-model="form.bootstrapToken"
|
||||
class="field"
|
||||
:class="{ invalid: errors.bootstrapToken }"
|
||||
autocomplete="off"
|
||||
placeholder="粘贴一次性引导令牌"
|
||||
/>
|
||||
<p v-if="errors.bootstrapToken" class="field-error">{{ errors.bootstrapToken }}</p>
|
||||
<p v-else class="field-hint">令牌来自实例启动日志,仅在首次初始化时有效。</p>
|
||||
</div>
|
||||
|
||||
<div class="fld">
|
||||
<label for="bootstrap-username">管理员用户名<span class="req">*</span></label>
|
||||
<input
|
||||
id="bootstrap-username"
|
||||
v-model="form.username"
|
||||
class="field"
|
||||
:class="{ invalid: errors.username }"
|
||||
autocomplete="username"
|
||||
maxlength="64"
|
||||
placeholder="3–64 位字母、数字、下划线、点或连字符"
|
||||
/>
|
||||
<p v-if="errors.username" class="field-error">{{ errors.username }}</p>
|
||||
</div>
|
||||
|
||||
<div class="fld">
|
||||
<label for="bootstrap-password">管理员口令<span class="req">*</span></label>
|
||||
<input
|
||||
id="bootstrap-password"
|
||||
v-model="form.password"
|
||||
class="field"
|
||||
:class="{ invalid: errors.password }"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
placeholder="至少 12 位"
|
||||
/>
|
||||
<p v-if="errors.password" class="field-error">{{ errors.password }}</p>
|
||||
<p v-else class="field-hint">口令由后端做强校验,前端提示不替代后端规则。</p>
|
||||
</div>
|
||||
|
||||
<div class="fld">
|
||||
<label for="bootstrap-confirm">确认口令<span class="req">*</span></label>
|
||||
<input
|
||||
id="bootstrap-confirm"
|
||||
v-model="form.confirmPassword"
|
||||
class="field"
|
||||
:class="{ invalid: errors.confirmPassword }"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
placeholder="再次输入口令"
|
||||
/>
|
||||
<p v-if="errors.confirmPassword" class="field-error">{{ errors.confirmPassword }}</p>
|
||||
</div>
|
||||
|
||||
<button class="btn primary block" type="submit" :disabled="busy">
|
||||
{{ busy ? '正在创建管理员…' : '创建管理员并关闭引导入口' }}
|
||||
</button>
|
||||
</form>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<p class="auth-note">
|
||||
引导入口只允许创建第一个管理员;任何情况下都不应把真实引导令牌写入代码、日志或公开文档。
|
||||
<RouterLink to="/login">返回登录</RouterLink>
|
||||
</p>
|
||||
<p v-else-if="status && !status.bootstrapTokenActive" class="warn">
|
||||
当前没有有效引导令牌。请查看后端启动日志中的「首次初始化引导令牌」。
|
||||
</p>
|
||||
<p v-else class="muted">
|
||||
引导令牌只输出一次且不可找回;创建管理员后令牌立即失效,无法再次创建管理员。
|
||||
</p>
|
||||
<form v-if="status && !status.administratorExists" @submit.prevent="submit">
|
||||
<label><span>引导令牌</span><input v-model="bootstrapToken" required /></label>
|
||||
<label><span>管理员用户名</span><input v-model="username" autocomplete="username" required /></label>
|
||||
<label><span>口令</span><input v-model="password" type="password" autocomplete="new-password" required /></label>
|
||||
<label><span>确认口令</span><input v-model="confirm" type="password" autocomplete="new-password" required /></label>
|
||||
<button type="submit" :disabled="busy">{{ busy ? '提交中…' : '创建管理员' }}</button>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
</form>
|
||||
<p style="margin-top: 16px;"><RouterLink to="/login">返回登录</RouterLink></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { connectionLabel, describeError, formatTime, notify } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import DetailDrawer from '../components/DetailDrawer.vue'
|
||||
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
||||
|
||||
const items = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const createOpen = ref(false)
|
||||
const createForm = ref({ displayName: '', endpoint: 'ws://127.0.0.1:3001', accessToken: '' })
|
||||
const createError = ref(null)
|
||||
const creating = ref(false)
|
||||
|
||||
const rotateTarget = ref(null)
|
||||
const rotateToken = ref('')
|
||||
const rotateError = ref(null)
|
||||
const rotating = ref(false)
|
||||
|
||||
const removeTarget = ref(null)
|
||||
const removing = ref(false)
|
||||
const removeError = ref(null)
|
||||
|
||||
const detail = ref(null)
|
||||
|
||||
const online = computed(() => items.value.filter((item) => /CONNECT|ONLINE/.test(String(item.connectionStatus || '').toUpperCase())).length)
|
||||
const bound = computed(() => items.value.filter((item) => !/UNBOUND/.test(String(item.bindingStatus || '').toUpperCase())).length)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
items.value = (await api.bindings()) || []
|
||||
} catch (e) {
|
||||
items.value = []
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
createError.value = null
|
||||
createForm.value = { displayName: '', endpoint: 'ws://127.0.0.1:3001', accessToken: '' }
|
||||
createOpen.value = true
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
if (creating.value) return
|
||||
createError.value = null
|
||||
const endpoint = createForm.value.endpoint.trim()
|
||||
if (!/^wss?:\/\/[^\s]+$/i.test(endpoint)) {
|
||||
createError.value = { title: '连接地址不合法', message: '仅支持 ws:// 或 wss:// 正向 WebSocket 端点。', hint: '后端会再次校验,http/https 与本地文件协议都会被拒绝。' }
|
||||
return
|
||||
}
|
||||
creating.value = true
|
||||
try {
|
||||
await api.createBinding({
|
||||
displayName: createForm.value.displayName.trim() || null,
|
||||
endpoint,
|
||||
accessToken: createForm.value.accessToken.trim() || null
|
||||
})
|
||||
createOpen.value = false
|
||||
notify('绑定已创建', '访问令牌只写不读,接口不会回显明文。', 'success')
|
||||
await load()
|
||||
} catch (e) {
|
||||
createError.value = describeError(e)
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openRotate(item) {
|
||||
rotateTarget.value = item
|
||||
rotateToken.value = ''
|
||||
rotateError.value = null
|
||||
}
|
||||
|
||||
async function submitRotate() {
|
||||
if (rotating.value) return
|
||||
rotateError.value = null
|
||||
if (!rotateToken.value.trim()) {
|
||||
rotateError.value = { title: '访问令牌不能为空', message: '请输入新的访问令牌。', hint: '令牌不会在界面回显。' }
|
||||
return
|
||||
}
|
||||
rotating.value = true
|
||||
try {
|
||||
await api.rotateToken(rotateTarget.value.bindingUid, rotateToken.value.trim())
|
||||
rotateTarget.value = null
|
||||
notify('令牌已更新', '后端未回显明文;正向 WS 握手不校验令牌,凭据是否生效只能靠事件到达确认。', 'success')
|
||||
} catch (e) {
|
||||
rotateError.value = describeError(e)
|
||||
} finally {
|
||||
rotating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmRemove() {
|
||||
if (removing.value) return
|
||||
removeError.value = null
|
||||
removing.value = true
|
||||
try {
|
||||
await api.deactivateBinding(removeTarget.value.bindingUid)
|
||||
notify('绑定已解绑', '仅停用绑定状态,历史消息与原始事件全部保留。', 'success')
|
||||
removeTarget.value = null
|
||||
await load()
|
||||
} catch (e) {
|
||||
removeError.value = describeError(e)
|
||||
} finally {
|
||||
removing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="连接与运维" title="接入管理" desc="一个 QLinker 可绑定多个 NapCat 实例;访问令牌只写不读,任何接口都不回显明文。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
<button class="btn" type="button" disabled title="后端未提供连接测试接口">测试连接</button>
|
||||
<button class="btn" type="button" disabled title="后端未提供批量导入接口">批量导入</button>
|
||||
<button class="btn primary" type="button" @click="openCreate">新增绑定</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">{{ items.length }}</div>
|
||||
<div class="stat-foot">有效绑定 {{ bound }} 条</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="stat-top"><span>在线连接</span><span class="stat-icon">◉</span></div>
|
||||
<div class="stat-value">{{ online }}</div>
|
||||
<div class="stat-foot">连接状态由 NapCat 上报</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 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="notice" style="margin-bottom: 16px">
|
||||
绑定只支持正向 WebSocket(accessType 固定 forward_websocket)。QQ 账号、NapCat 版本、最近事件由 NapCat 上报后回填,未上报时显示「—」。
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">绑定关系</h3>
|
||||
<div class="actions">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供重命名接口">编辑名称</button>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供批量导出接口">导出</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SectionState
|
||||
:loading="loading"
|
||||
:error="error"
|
||||
:empty="!loading && !error && !items.length"
|
||||
empty-title="尚未绑定 NapCat"
|
||||
empty-text="新增一个 ws:// 或 wss:// 正向 WebSocket 端点后,事件到达即会写入原始事件与标准化消息。"
|
||||
@retry="load"
|
||||
>
|
||||
<template #empty-actions>
|
||||
<button class="btn primary sm" type="button" @click="openCreate">新增绑定</button>
|
||||
</template>
|
||||
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>绑定 / 实例</th>
|
||||
<th>QQ 账号</th>
|
||||
<th>连接</th>
|
||||
<th>状态</th>
|
||||
<th>NapCat 版本</th>
|
||||
<th>最近事件</th>
|
||||
<th>最近错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in items" :key="item.bindingUid">
|
||||
<td>
|
||||
<div class="identity">
|
||||
<span class="mini-avatar">{{ (item.displayName || 'N').slice(0, 1) }}</span>
|
||||
<div>
|
||||
<strong>{{ item.displayName || '—' }}</strong>
|
||||
<span>{{ item.endpoint || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ item.qqAccountId || '—' }}</td>
|
||||
<td>
|
||||
{{ connectionLabel(item.connectionType) }}
|
||||
<div class="small-muted">令牌{{ item.hasCredential ? '已保存' : '未保存' }}</div>
|
||||
</td>
|
||||
<td>
|
||||
<StatusTag :value="item.bindingStatus" :label="item.bindingStatus || '—'" />
|
||||
<div style="margin-top: 4px"><StatusTag :value="item.connectionStatus" :label="item.connectionStatus || '—'" /></div>
|
||||
</td>
|
||||
<td>{{ item.napcatVersion || '—' }}</td>
|
||||
<td>{{ formatTime(item.lastEventAt) }}</td>
|
||||
<td>
|
||||
<span v-if="item.lastErrorCode"> <span class="status error">{{ item.lastErrorCode }}</span></span>
|
||||
<span v-else>—</span>
|
||||
<div class="small-muted">{{ formatTime(item.lastErrorAt) }}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button class="btn sm" type="button" @click="detail = item">详情</button>
|
||||
<button class="btn sm" type="button" @click="openRotate(item)">轮换令牌</button>
|
||||
<button class="btn sm danger" type="button" @click="removeTarget = item">解绑</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</SectionState>
|
||||
</div>
|
||||
|
||||
<Teleport to="body">
|
||||
<div v-if="createOpen" class="modal-backdrop show" @click.self="!creating && (createOpen = false)">
|
||||
<div class="modal" role="dialog" aria-modal="true">
|
||||
<div class="modal-head">
|
||||
<h3>新增 NapCat 绑定</h3>
|
||||
<button class="btn sm ghost" type="button" :disabled="creating" @click="createOpen = false">×</button>
|
||||
</div>
|
||||
<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 class="small-muted" style="margin-top: 4px">{{ createError.hint }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="fld full">
|
||||
<label for="binding-name">绑定名称</label>
|
||||
<input id="binding-name" v-model="createForm.displayName" class="field" maxlength="100" placeholder="留空则使用端点主机名" />
|
||||
<p class="field-hint">仅用于界面识别,不改变 NapCat 实例身份。</p>
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<label for="binding-endpoint">连接地址<span class="req">*</span></label>
|
||||
<input id="binding-endpoint" v-model="createForm.endpoint" class="field" placeholder="ws://127.0.0.1:3001" />
|
||||
<p class="field-hint">仅支持 ws:// 或 wss://,后端会拒绝 http/https 与用户信息。</p>
|
||||
</div>
|
||||
<div class="fld full">
|
||||
<label for="binding-token">访问令牌</label>
|
||||
<input id="binding-token" v-model="createForm.accessToken" class="field" type="password" autocomplete="off" placeholder="可选,保存后不回显" />
|
||||
<p class="field-hint">令牌只写不读;正向 WS 握手不校验令牌,凭据错误只能靠事件到达确认。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-foot">
|
||||
<button class="btn" type="button" :disabled="creating" @click="createOpen = false">取消</button>
|
||||
<button class="btn primary" type="button" :disabled="creating" @click="submitCreate">
|
||||
{{ creating ? '正在创建…' : '创建绑定' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="Boolean(rotateTarget)"
|
||||
title="轮换访问令牌"
|
||||
:message="rotateTarget ? `为「${rotateTarget.displayName || rotateTarget.bindingUid}」设置新的访问令牌。` : ''"
|
||||
hint="后端不回显明文;NapCat 正向 WS 握手不校验令牌,凭据错误只能靠事件到达确认。"
|
||||
confirm-text="保存新令牌"
|
||||
:busy="rotating"
|
||||
@confirm="submitRotate"
|
||||
@cancel="rotateTarget = null"
|
||||
>
|
||||
<div class="fld" style="margin-bottom: 12px">
|
||||
<label for="rotate-token">新访问令牌<span class="req">*</span></label>
|
||||
<input id="rotate-token" v-model="rotateToken" class="field" type="password" autocomplete="off" placeholder="输入新令牌" />
|
||||
<div v-if="rotateError" class="field-error">{{ rotateError.message }}</div>
|
||||
</div>
|
||||
</ConfirmDialog>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="Boolean(removeTarget)"
|
||||
title="解绑 NapCat"
|
||||
tone="danger"
|
||||
:message="removeTarget ? `确认解绑「${removeTarget.displayName || removeTarget.bindingUid}」?` : ''"
|
||||
hint="解绑只做状态标记(UNBOUND),不删除任何历史消息与原始事件。"
|
||||
confirm-text="确认解绑"
|
||||
:busy="removing"
|
||||
@confirm="confirmRemove"
|
||||
@cancel="removeTarget = null"
|
||||
>
|
||||
<div v-if="removeError" class="notice danger">{{ removeError.message }}</div>
|
||||
</ConfirmDialog>
|
||||
|
||||
<DetailDrawer :open="Boolean(detail)" title="绑定详情" :subtitle="detail?.bindingUid" @close="detail = null">
|
||||
<div v-if="detail" class="kv">
|
||||
<div class="kv-row"><span>绑定标识</span><span>{{ detail.bindingUid }}</span></div>
|
||||
<div class="kv-row"><span>实例标识</span><span>{{ detail.instanceUid || '—' }}</span></div>
|
||||
<div class="kv-row"><span>显示名称</span><span>{{ detail.displayName || '—' }}</span></div>
|
||||
<div class="kv-row"><span>连接方式</span><span>{{ connectionLabel(detail.connectionType) }}</span></div>
|
||||
<div class="kv-row"><span>端点</span><span>{{ detail.endpoint || '—' }}</span></div>
|
||||
<div class="kv-row"><span>绑定状态</span><span>{{ detail.bindingStatus || '—' }}</span></div>
|
||||
<div class="kv-row"><span>连接状态</span><span>{{ detail.connectionStatus || '—' }}</span></div>
|
||||
<div class="kv-row"><span>QQ 账号</span><span>{{ detail.qqAccountId || '—' }}</span></div>
|
||||
<div class="kv-row"><span>NapCat 版本</span><span>{{ detail.napcatVersion || '—' }}</span></div>
|
||||
<div class="kv-row"><span>令牌</span><span>{{ detail.hasCredential ? '已保存' : '未保存' }}</span></div>
|
||||
<div class="kv-row"><span>最近连接</span><span>{{ formatTime(detail.lastConnectedAt) }}</span></div>
|
||||
<div class="kv-row"><span>最近事件</span><span>{{ formatTime(detail.lastEventAt) }}</span></div>
|
||||
<div class="kv-row"><span>最近错误</span><span>{{ detail.lastErrorCode || '—' }} · {{ formatTime(detail.lastErrorAt) }}</span></div>
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
</template>
|
||||
@@ -0,0 +1,251 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { connectionLabel, describeError, formatNumber, formatTime, statusTone } from '../ui'
|
||||
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 DemoBadge from '../components/DemoBadge.vue'
|
||||
import { demoState } from '../demo/config'
|
||||
import { automationRules, automationSummary, dashboardTrend24h } from '../demo/planned'
|
||||
|
||||
const health = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const updatedAt = ref('')
|
||||
|
||||
const bindings = computed(() => health.value?.napcat?.items || [])
|
||||
const connections = computed(() => health.value?.napcat?.connections || {})
|
||||
const messages = computed(() => health.value?.messages || {})
|
||||
const media = computed(() => health.value?.media || {})
|
||||
const send = computed(() => health.value?.send || {})
|
||||
|
||||
const sendTotal = computed(() =>
|
||||
['PENDING', 'RUNNING', 'SUCCEEDED', 'FAILED', 'UNKNOWN'].reduce((sum, key) => sum + (Number(send.value[key]) || 0), 0)
|
||||
)
|
||||
|
||||
const attention = computed(() => {
|
||||
const items = []
|
||||
if (!health.value) return items
|
||||
if (Number(messages.value.failedEvents) > 0) {
|
||||
items.push({ level: 'error', title: `原始事件处理失败 ${formatNumber(messages.value.failedEvents)} 条`, detail: '需要查看运行日志并确认是否可重新处理' })
|
||||
}
|
||||
if (Number(messages.value.unprocessedEvents) > 0) {
|
||||
items.push({ level: 'warning', title: `待处理事件 ${formatNumber(messages.value.unprocessedEvents)} 条`, detail: '事件已入库,异步处理尚未完成' })
|
||||
}
|
||||
if (Number(send.value.UNKNOWN) > 0) {
|
||||
items.push({ level: 'warning', title: `发送结果未知 ${formatNumber(send.value.UNKNOWN)} 条`, detail: '上游可能已执行,禁止自动重试,需人工核实' })
|
||||
}
|
||||
if (Number(media.value.FAILED) > 0) {
|
||||
items.push({ level: 'error', title: `媒体入库失败 ${formatNumber(media.value.FAILED)} 条`, detail: '图片/文件等媒体资源未成功保存到对象存储' })
|
||||
}
|
||||
if (Number(media.value.OBJECT_MISSING) > 0) {
|
||||
items.push({ level: 'warning', title: `对象缺失 ${formatNumber(media.value.OBJECT_MISSING)} 条`, detail: '媒体元数据存在,但对象存储中找不到对应对象' })
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
const maxTrend = computed(() => Math.max(1, ...dashboardTrend24h))
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
health.value = await api.healthDetail()
|
||||
updatedAt.value = formatTime(new Date().toISOString())
|
||||
} catch (e) {
|
||||
health.value = null
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="工作空间" title="工作台" desc="实例运行概览:绑定连接、消息入库、待处理事件与发送状态均来自后端真实接口。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
<RouterLink class="btn primary" to="/connections">接入管理</RouterLink>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div v-if="error" class="notice danger" role="alert" style="margin-bottom: 16px">
|
||||
<div>
|
||||
<strong>{{ error.title }}</strong>
|
||||
<div style="margin-top: 4px">{{ error.message }}</div>
|
||||
<div class="small-muted" style="margin-top: 4px">{{ error.hint }}</div>
|
||||
<div v-if="error.code || error.requestId" class="small-muted" style="margin-top: 4px">
|
||||
错误码 {{ error.code }}<span v-if="error.requestId"> · 请求 {{ error.requestId }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn sm" type="button" @click="load">重试</button>
|
||||
</div>
|
||||
|
||||
<SectionState :loading="loading" :error="null">
|
||||
<div class="grid stats">
|
||||
<StatCard
|
||||
label="已绑定账号"
|
||||
:value="health ? health.napcat.total : '—'"
|
||||
:foot="`受管连接 ${formatNumber(connections.managedConnections)} · ${connections.receiverEnabled ? '事件接收已启用' : '事件接收未启用'}`"
|
||||
icon="⇄"
|
||||
/>
|
||||
<StatCard
|
||||
label="消息总量"
|
||||
:value="health ? messages.totalMessages : '—'"
|
||||
:foot="`入站 ${formatNumber(messages.inboundMessages)} · 出站 ${formatNumber(messages.outboundMessages)}`"
|
||||
icon="◫"
|
||||
/>
|
||||
<StatCard
|
||||
label="待处理事件"
|
||||
:value="health ? messages.unprocessedEvents : '—'"
|
||||
:foot="`失败 ${formatNumber(messages.failedEvents)} · 未知类型 ${formatNumber(messages.unknownTypeEvents)}`"
|
||||
icon="≡"
|
||||
/>
|
||||
<StatCard
|
||||
label="发送操作"
|
||||
:value="health ? sendTotal : '—'"
|
||||
:foot="`成功 ${formatNumber(send.SUCCEEDED)} · 结果未知 ${formatNumber(send.UNKNOWN)}`"
|
||||
icon="➤"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="health" class="grid two-col" style="margin-bottom: 18px">
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">接入实例状态</h3>
|
||||
<RouterLink class="link" to="/connections">管理绑定</RouterLink>
|
||||
</div>
|
||||
<div v-if="!bindings.length" class="state-block" style="padding: 24px">暂无绑定。前往「接入管理」新增 NapCat 正向 WebSocket 连接。</div>
|
||||
<div v-else class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>绑定 / 实例</th>
|
||||
<th>QQ 账号</th>
|
||||
<th>连接方式</th>
|
||||
<th>状态</th>
|
||||
<th>最近事件</th>
|
||||
<th>今日消息</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in bindings" :key="item.bindingUid">
|
||||
<td>
|
||||
<div class="identity">
|
||||
<span class="mini-avatar">{{ (item.displayName || 'N').slice(0, 1) }}</span>
|
||||
<div>
|
||||
<strong>{{ item.displayName || '—' }}</strong>
|
||||
<span>{{ item.endpoint || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ item.qqAccountId || '—' }}</td>
|
||||
<td>{{ connectionLabel(item.connectionType) }}</td>
|
||||
<td>
|
||||
<StatusTag :value="item.bindingStatus" :label="item.bindingStatus || '—'" />
|
||||
<div class="small-muted" style="margin-top: 4px">{{ item.connectionStatus || '—' }}</div>
|
||||
</td>
|
||||
<td>{{ formatTime(item.lastEventAt) }}</td>
|
||||
<td class="muted" title="后端未提供按绑定的今日消息统计">—</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">运行提醒</h3>
|
||||
<span class="pill">后端真实状态</span>
|
||||
</div>
|
||||
<div v-if="!attention.length" class="state-block" style="padding: 28px">
|
||||
<strong>暂无异常</strong>
|
||||
<p>失败事件、待处理事件、发送结果未知与媒体异常均为 0。</p>
|
||||
</div>
|
||||
<div v-for="item in attention" :key="item.title" class="activity">
|
||||
<span class="activity-icon" :class="item.level === 'error' ? 'error' : 'warning'">{{ item.level === 'error' ? '!' : 'i' }}</span>
|
||||
<div>
|
||||
<p>{{ item.title }}</p>
|
||||
<small>{{ item.detail }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SectionState>
|
||||
|
||||
<div v-if="demoState.enabled" class="grid two-col" style="margin-bottom: 18px">
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">消息趋势(近 24 小时)<DemoBadge /></h3>
|
||||
<span class="pill">演示</span>
|
||||
</div>
|
||||
<div class="bar-chart">
|
||||
<span
|
||||
v-for="(value, index) in dashboardTrend24h"
|
||||
:key="index"
|
||||
class="bar"
|
||||
:style="{ height: `${(value / maxTrend) * 100}%` }"
|
||||
:data-label="`第 ${index + 1} 小时:${value} 条`"
|
||||
></span>
|
||||
</div>
|
||||
<div class="chart-axis"><span>0:00</span><span>6:00</span><span>12:00</span><span>18:00</span><span>24:00</span></div>
|
||||
<p class="small-muted" style="margin-top: 10px">后端 /messages/stats 只提供累计计数,暂无时间序列接口。</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">自动化概览 <DemoBadge /></h3>
|
||||
<RouterLink class="link" to="/automation">查看规则</RouterLink>
|
||||
</div>
|
||||
<div class="activity">
|
||||
<span class="activity-icon success">%</span>
|
||||
<div>
|
||||
<p>成功率 {{ automationSummary.successRate }}%</p>
|
||||
<small>成功 {{ automationSummary.success }} · 失败 {{ automationSummary.failed }} · 最近执行「{{ automationSummary.recent }}」</small>
|
||||
</div>
|
||||
</div>
|
||||
<div v-for="rule in automationRules" :key="rule.name" class="context-line">
|
||||
<span>{{ rule.name }}</span>
|
||||
<span class="muted">{{ rule.version }} · {{ rule.status }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="notice" style="margin-bottom: 18px">
|
||||
演示数据已关闭:消息趋势与自动化概览依赖的后端接口尚未提供,相关区块不显示。
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">快捷入口</h3>
|
||||
<span class="small-muted" v-if="updatedAt">数据更新于 {{ updatedAt }}</span>
|
||||
</div>
|
||||
<div class="grid stats" style="margin-bottom: 0">
|
||||
<RouterLink class="card" to="/messages" style="text-decoration: none">
|
||||
<div class="stat-top"><span>消息中心</span><span class="stat-icon">◫</span></div>
|
||||
<div class="stat-value" style="font-size: 18px">查看会话与详情</div>
|
||||
<div class="stat-foot">消息段、原始 payload、媒体与发送</div>
|
||||
</RouterLink>
|
||||
<RouterLink class="card" to="/message-search" style="text-decoration: none">
|
||||
<div class="stat-top"><span>消息检索</span><span class="stat-icon">⌕</span></div>
|
||||
<div class="stat-value" style="font-size: 18px">条件筛选与分页</div>
|
||||
<div class="stat-foot">关键词仅匹配摘要前缀</div>
|
||||
</RouterLink>
|
||||
<RouterLink class="card" to="/ops" style="text-decoration: none">
|
||||
<div class="stat-top"><span>运维监控</span><span class="stat-icon">◉</span></div>
|
||||
<div class="stat-value" style="font-size: 18px">依赖健康总览</div>
|
||||
<div class="stat-foot">真实 health-detail 分项</div>
|
||||
</RouterLink>
|
||||
<RouterLink class="card" to="/settings" style="text-decoration: none">
|
||||
<div class="stat-top"><span>系统设置</span><span class="stat-icon">◌</span></div>
|
||||
<div class="stat-value" style="font-size: 18px">外观与演示开关</div>
|
||||
<div class="stat-foot">实例设置后端未提供</div>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,35 +1,69 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { RouterLink, useRouter } from 'vue-router'
|
||||
import { api, setToken } from '../api'
|
||||
import { describeError } from '../ui'
|
||||
|
||||
const router = useRouter()
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const status = ref(null)
|
||||
const statusError = ref('')
|
||||
const statusLoading = ref(false)
|
||||
const statusError = ref(null)
|
||||
let statusSeq = 0
|
||||
|
||||
const form = ref({ username: '', password: '' })
|
||||
const errors = ref({})
|
||||
const busy = ref(false)
|
||||
const loginError = ref(null)
|
||||
|
||||
const canLogin = computed(() => Boolean(status.value?.administratorExists))
|
||||
const recoveryMessage = computed(() => {
|
||||
const value = status.value?.recoveryRequired
|
||||
if (!value) return ''
|
||||
return typeof value === 'string' ? value : '实例初始化状态或资源身份不一致,可能无法正常读写数据。'
|
||||
})
|
||||
|
||||
const bootstrapHint = computed(() =>
|
||||
status.value?.bootstrapTokenActive
|
||||
? '引导令牌当前有效,请前往初始化页创建第一个管理员。'
|
||||
: '当前没有有效的引导令牌。请查看实例启动日志或部署配置获取令牌,必要时按初始化流程重新签发。'
|
||||
)
|
||||
|
||||
async function loadStatus() {
|
||||
statusError.value = ''
|
||||
const seq = ++statusSeq
|
||||
statusLoading.value = true
|
||||
statusError.value = null
|
||||
try {
|
||||
status.value = await api.initialization()
|
||||
} catch (e) {
|
||||
statusError.value = e.message
|
||||
const value = await api.initialization()
|
||||
if (seq !== statusSeq) return
|
||||
status.value = value || null
|
||||
} catch (error) {
|
||||
if (seq !== statusSeq) return
|
||||
statusError.value = describeError(error)
|
||||
} finally {
|
||||
if (seq === statusSeq) statusLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function validate() {
|
||||
const next = {}
|
||||
if (!form.value.username.trim()) next.username = '请输入用户名。'
|
||||
if (!form.value.password) next.password = '请输入口令。'
|
||||
errors.value = next
|
||||
return Object.keys(next).length === 0
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
error.value = ''
|
||||
if (busy.value) return
|
||||
loginError.value = null
|
||||
if (!validate()) return
|
||||
busy.value = true
|
||||
try {
|
||||
const result = await api.login(username.value, password.value)
|
||||
setToken(result.token)
|
||||
router.push('/overview')
|
||||
} catch (e) {
|
||||
// 后端不区分账号不存在与口令错误,此处只展示统一提示与请求号,便于定位。
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
const data = await api.login(form.value.username.trim(), form.value.password)
|
||||
setToken(data.token)
|
||||
await router.replace('/dashboard')
|
||||
} catch (error) {
|
||||
loginError.value = describeError(error)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
@@ -39,22 +73,109 @@ onMounted(loadStatus)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card" style="max-width: 420px; margin: 60px auto;">
|
||||
<h2>登录</h2>
|
||||
<p v-if="statusError" class="warn">无法读取实例状态:{{ statusError }}</p>
|
||||
<template v-else-if="status && status.bootstrapRequired">
|
||||
<p class="warn">本实例尚未创建管理员,需要先使用启动日志中的引导令牌完成初始化。</p>
|
||||
<RouterLink to="/bootstrap">前往初始化</RouterLink>
|
||||
<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">
|
||||
<span class="spinner" aria-hidden="true"></span>
|
||||
正在读取实例状态…
|
||||
</div>
|
||||
|
||||
<div v-else-if="statusError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ statusError.title }}</strong>
|
||||
<p style="margin: 4px 0 0">{{ statusError.message }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">{{ statusError.hint }}</p>
|
||||
</div>
|
||||
<button class="btn sm" type="button" :disabled="statusLoading" @click="loadStatus">重试</button>
|
||||
</div>
|
||||
|
||||
<template v-else-if="status">
|
||||
<div v-if="recoveryMessage" class="notice danger">
|
||||
<div>
|
||||
<strong>实例需要恢复</strong>
|
||||
<p style="margin: 4px 0 0">{{ recoveryMessage }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">
|
||||
请先按部署文档核实数据库与对象存储身份,不要在未确认的情况下重新初始化。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!status.administratorExists" class="notice warn">
|
||||
<div>
|
||||
<strong>实例尚未初始化</strong>
|
||||
<p style="margin: 4px 0 0">尚未创建管理员,当前无法登录管理台。</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">{{ bootstrapHint }}</p>
|
||||
</div>
|
||||
<RouterLink class="btn sm" to="/bootstrap">
|
||||
{{ status.bootstrapTokenActive ? '前往初始化' : '查看初始化页' }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
|
||||
<div v-else-if="status.bootstrapTokenActive" class="notice warn">
|
||||
<div>
|
||||
<strong>引导入口仍然开放</strong>
|
||||
<p style="margin: 4px 0 0">实例已存在管理员,但引导令牌仍处于有效状态。</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">
|
||||
首次初始化完成后引导入口应永久关闭;如非预期,请检查实例配置。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="status && !status.administratorExists && !status.bootstrapTokenActive">
|
||||
<p class="warn">实例尚未初始化,且当前没有有效引导令牌。请检查后端启动日志或实例状态。</p>
|
||||
<p v-if="status.recoveryRequired" class="error">{{ status.recoveryRequired }}</p>
|
||||
</template>
|
||||
<form v-else @submit.prevent="submit">
|
||||
<label><span>用户名</span><input v-model="username" autocomplete="username" required /></label>
|
||||
<label><span>口令</span><input v-model="password" type="password" autocomplete="current-password" required /></label>
|
||||
<button type="submit" :disabled="busy">{{ busy ? '登录中…' : '登录' }}</button>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
|
||||
<div v-if="loginError" class="notice danger" style="margin-top: 10px">
|
||||
<div>
|
||||
<strong>{{ loginError.title }}</strong>
|
||||
<p style="margin: 4px 0 0">{{ loginError.message }}</p>
|
||||
<p class="small-muted" style="margin: 4px 0 0">{{ loginError.hint }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form v-if="canLogin" class="auth-form" @submit.prevent="submit">
|
||||
<div class="fld">
|
||||
<label for="login-username">用户名<span class="req">*</span></label>
|
||||
<input
|
||||
id="login-username"
|
||||
v-model="form.username"
|
||||
class="field"
|
||||
:class="{ invalid: errors.username }"
|
||||
autocomplete="username"
|
||||
maxlength="64"
|
||||
placeholder="例如:admin"
|
||||
/>
|
||||
<p v-if="errors.username" class="field-error">{{ errors.username }}</p>
|
||||
</div>
|
||||
|
||||
<div class="fld">
|
||||
<label for="login-password">口令<span class="req">*</span></label>
|
||||
<input
|
||||
id="login-password"
|
||||
v-model="form.password"
|
||||
class="field"
|
||||
:class="{ invalid: errors.password }"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="输入管理员口令"
|
||||
/>
|
||||
<p v-if="errors.password" class="field-error">{{ errors.password }}</p>
|
||||
</div>
|
||||
|
||||
<button class="btn primary block" type="submit" :disabled="busy">
|
||||
{{ busy ? '正在登录…' : '登录' }}
|
||||
</button>
|
||||
|
||||
<p class="auth-note">
|
||||
登录失败不会区分「账号不存在」与「口令错误」,避免泄露账号是否存在。连续失败会触发后端限流。
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<p v-else-if="status && !status.administratorExists" class="auth-note">
|
||||
管理员创建完成后,本页的登录表单才会开放。
|
||||
<RouterLink to="/bootstrap">前往初始化</RouterLink>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, logRows } 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 level = ref('')
|
||||
const keyword = ref('')
|
||||
|
||||
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 errorCount = computed(() => logRows.filter((row) => row.level === 'ERROR').length)
|
||||
const warnCount = computed(() => logRows.filter((row) => row.level === 'WARN').length)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="连接与运维" title="运行日志" desc="统一日志检索与链路追踪。后端尚未提供日志查询接口,本页内容全部为演示数据。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供日志导出接口">导出日志</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="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>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,408 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { describeError, directionLabel, formatNumber, formatTime, typeLabel } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import DetailDrawer from '../components/DetailDrawer.vue'
|
||||
import Pagination from '../components/Pagination.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
bindingUid: '',
|
||||
conversationType: '',
|
||||
conversationId: '',
|
||||
direction: '',
|
||||
senderId: '',
|
||||
from: '',
|
||||
to: ''
|
||||
})
|
||||
|
||||
const bindings = ref([])
|
||||
const rows = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const validationError = ref('')
|
||||
|
||||
const detail = ref(null)
|
||||
const detailLoading = ref(false)
|
||||
const detailError = ref(null)
|
||||
const mediaMap = reactive({})
|
||||
|
||||
const applied = ref({})
|
||||
|
||||
const appliedList = computed(() => {
|
||||
const items = []
|
||||
const source = applied.value
|
||||
if (source.keyword) items.push(`关键词(摘要前缀):${source.keyword}`)
|
||||
if (source.bindingUid) items.push(`绑定:${source.bindingUid}`)
|
||||
if (source.conversationType) items.push(`会话类型:${source.conversationType}`)
|
||||
if (source.conversationId) items.push(`会话 ID:${source.conversationId}`)
|
||||
if (source.direction) items.push(`方向:${directionLabel(source.direction)}`)
|
||||
if (source.senderId) items.push(`发送者:${source.senderId}`)
|
||||
if (source.from) items.push(`起始时间:${formatTime(source.from)}`)
|
||||
if (source.to) items.push(`结束时间:${formatTime(source.to)}`)
|
||||
return items
|
||||
})
|
||||
|
||||
const hasApplied = computed(() => appliedList.value.length > 0)
|
||||
|
||||
function localToIso(value) {
|
||||
if (!value) return ''
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return ''
|
||||
return date.toISOString()
|
||||
}
|
||||
|
||||
function validate() {
|
||||
validationError.value = ''
|
||||
if (filters.from && filters.to) {
|
||||
const from = new Date(filters.from)
|
||||
const to = new Date(filters.to)
|
||||
if (from.getTime() > to.getTime()) {
|
||||
validationError.value = '起始时间不能晚于结束时间。'
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function search(nextPage = 1) {
|
||||
if (!validate()) return
|
||||
page.value = nextPage
|
||||
loading.value = true
|
||||
error.value = null
|
||||
const payload = {
|
||||
keyword: filters.keyword.trim(),
|
||||
bindingUid: filters.bindingUid,
|
||||
conversationType: filters.conversationType,
|
||||
conversationId: filters.conversationId.trim(),
|
||||
direction: filters.direction,
|
||||
senderId: filters.senderId.trim(),
|
||||
from: localToIso(filters.from),
|
||||
to: localToIso(filters.to),
|
||||
page: nextPage,
|
||||
pageSize: pageSize.value
|
||||
}
|
||||
applied.value = payload
|
||||
try {
|
||||
const data = await api.messages(payload)
|
||||
rows.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || nextPage
|
||||
pageSize.value = data?.pageSize || pageSize.value
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onPageChange(next) {
|
||||
pageSize.value = next.pageSize
|
||||
search(next.page)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
Object.assign(filters, {
|
||||
keyword: '', bindingUid: '', conversationType: '', conversationId: '',
|
||||
direction: '', senderId: '', from: '', to: ''
|
||||
})
|
||||
applied.value = {}
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
page.value = 1
|
||||
validationError.value = ''
|
||||
router.replace({ path: '/message-search' })
|
||||
}
|
||||
|
||||
async function openDetail(row) {
|
||||
detailLoading.value = true
|
||||
detailError.value = null
|
||||
detail.value = { message: row, segments: [], rawPayload: null }
|
||||
try {
|
||||
detail.value = await api.message(row.messageUid)
|
||||
} catch (e) {
|
||||
detailError.value = describeError(e)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMedia(mediaUid) {
|
||||
if (!mediaUid || mediaMap[mediaUid]?.loading) return
|
||||
mediaMap[mediaUid] = { loading: true, url: '', error: null }
|
||||
try {
|
||||
const data = await api.mediaAccessUrl(mediaUid)
|
||||
mediaMap[mediaUid] = { loading: false, url: data?.url || '', error: null }
|
||||
} catch (e) {
|
||||
mediaMap[mediaUid] = { loading: false, url: '', error: describeError(e) }
|
||||
}
|
||||
}
|
||||
|
||||
function prettyRaw(value) {
|
||||
if (!value) return '—'
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(value), null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
bindings.value = (await api.bindings()) || []
|
||||
} catch {
|
||||
bindings.value = []
|
||||
}
|
||||
if (route.query.keyword) filters.keyword = String(route.query.keyword)
|
||||
if (route.query.conversationType) filters.conversationType = String(route.query.conversationType)
|
||||
if (route.query.conversationId) filters.conversationId = String(route.query.conversationId)
|
||||
if (route.query.bindingUid) filters.bindingUid = String(route.query.bindingUid)
|
||||
if (route.query.direction) filters.direction = String(route.query.direction)
|
||||
if (route.query.keyword || route.query.conversationId) search()
|
||||
})
|
||||
</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="loading" @click="search(1)">刷新结果</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div class="card" style="margin-bottom: 16px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">检索条件</h3>
|
||||
<span class="small-muted">时间按浏览器本地输入,提交时转换为 ISO-8601 UTC</span>
|
||||
</div>
|
||||
<form @submit.prevent="search(1)">
|
||||
<div class="filterbar" style="flex-wrap: wrap; display: flex; gap: 12px">
|
||||
<div class="fld searchfield">
|
||||
<label for="ms-keyword">关键词(仅匹配摘要前缀)</label>
|
||||
<input id="ms-keyword" v-model="filters.keyword" class="field" placeholder="raw_summary 前缀,例如:你好" />
|
||||
<p class="field-hint">后端以 LIKE '关键词%' 执行,不匹配消息正文、消息段或原始 payload。</p>
|
||||
</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>
|
||||
</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>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-conv-id">会话 ID</label>
|
||||
<input id="ms-conv-id" v-model="filters.conversationId" class="field" placeholder="群号或账号 ID" />
|
||||
</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>
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-sender">发送者 ID</label>
|
||||
<input id="ms-sender" v-model="filters.senderId" class="field" placeholder="发送者账号 / QQ 号" />
|
||||
</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 }" />
|
||||
</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 }" />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="ms-type">消息类型</label>
|
||||
<select id="ms-type" class="field" disabled title="后端 /messages 未提供 messageType 筛选参数">
|
||||
<option>后端未支持(不筛选)</option>
|
||||
</select>
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="validationError" class="field-error" style="margin-top: 10px">{{ validationError }}</div>
|
||||
|
||||
<div class="form-actions" style="justify-content: flex-start; margin-top: 14px">
|
||||
<button class="btn primary" type="submit" :disabled="loading">{{ loading ? '检索中…' : '开始检索' }}</button>
|
||||
<button class="btn" type="button" :disabled="loading" @click="clearAll">清除条件</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div v-if="hasApplied && !loading && !error" class="notice" style="margin-bottom: 14px">
|
||||
<div>
|
||||
<strong>当前生效条件</strong>
|
||||
<div style="margin-top: 4px">{{ appliedList.join(' · ') }}</div>
|
||||
<div v-if="!rows.length" class="small-muted" style="margin-top: 4px">没有匹配的消息,可清除部分条件后重试。</div>
|
||||
</div>
|
||||
<button class="btn sm" type="button" @click="clearAll">清除</button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">检索结果</h3>
|
||||
<span class="small-muted">分页按后端 PageData:items / page / pageSize / total</span>
|
||||
</div>
|
||||
|
||||
<SectionState
|
||||
:loading="loading"
|
||||
:error="error"
|
||||
:empty="!loading && !error && !hasApplied"
|
||||
empty-title="尚未设置检索条件"
|
||||
empty-text="输入关键词或选择账号、会话、方向、时间范围后开始检索。"
|
||||
loading-text="正在检索消息…"
|
||||
@retry="search(page)"
|
||||
>
|
||||
<SectionState
|
||||
:loading="false"
|
||||
:error="null"
|
||||
:empty="!rows.length"
|
||||
empty-title="没有匹配的消息"
|
||||
empty-text="当前条件未返回任何记录。清除条件或放宽时间范围后重试。"
|
||||
>
|
||||
<template #empty-actions>
|
||||
<button class="btn sm" type="button" @click="clearAll">清除条件</button>
|
||||
</template>
|
||||
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>消息时间</th>
|
||||
<th>会话</th>
|
||||
<th>发送者</th>
|
||||
<th>方向</th>
|
||||
<th>类型</th>
|
||||
<th>摘要</th>
|
||||
<th>段 / 媒体</th>
|
||||
<th>处理状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.messageUid">
|
||||
<td>{{ formatTime(row.messageTime) }}</td>
|
||||
<td>{{ row.conversationType }} · {{ row.conversationId }}</td>
|
||||
<td>{{ row.senderName || '—' }}<div class="small-muted">{{ row.senderId || '—' }}</div></td>
|
||||
<td>{{ directionLabel(row.direction) }}</td>
|
||||
<td>{{ typeLabel(row.messageType) }}<div class="small-muted">{{ row.messageType }}</div></td>
|
||||
<td style="max-width: 300px">{{ row.summary || '(无摘要)' }}</td>
|
||||
<td>{{ row.segmentCount }} / {{ row.mediaCount }}</td>
|
||||
<td><StatusTag :value="row.normalizedStatus" :label="row.normalizedStatus || '—'" /></td>
|
||||
<td><button class="btn sm" type="button" @click="openDetail(row)">详情</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
</SectionState>
|
||||
</SectionState>
|
||||
</div>
|
||||
|
||||
<DetailDrawer :open="Boolean(detail)" title="消息详情" :subtitle="detail?.message?.messageUid" @close="detail = null">
|
||||
<div v-if="detailLoading" class="state-block"><span class="spinner"></span>正在读取消息详情…</div>
|
||||
<div v-else-if="detailError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ detailError.title }}</strong>
|
||||
<div>{{ detailError.message }}</div>
|
||||
<div class="small-muted">{{ detailError.hint }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else-if="detail">
|
||||
<div class="drawer-section">
|
||||
<h4>基本信息</h4>
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>消息标识</span><span>{{ detail.message?.messageUid }}</span></div>
|
||||
<div class="kv-row"><span>来源绑定</span><span>{{ detail.message?.bindingUid || '—' }}</span></div>
|
||||
<div class="kv-row"><span>会话</span><span>{{ detail.message?.conversationType }} · {{ detail.message?.conversationId }}</span></div>
|
||||
<div class="kv-row"><span>发送者</span><span>{{ detail.message?.senderName || '—' }} ({{ detail.message?.senderId || '—' }})</span></div>
|
||||
<div class="kv-row"><span>方向 / 类型</span><span>{{ directionLabel(detail.message?.direction) }} · {{ typeLabel(detail.message?.messageType) }}</span></div>
|
||||
<div class="kv-row"><span>消息时间</span><span>{{ formatTime(detail.message?.messageTime) }}</span></div>
|
||||
<div class="kv-row"><span>归一化状态</span><span><StatusTag :value="detail.message?.normalizedStatus" :label="detail.message?.normalizedStatus || '—'" /></span></div>
|
||||
<div class="kv-row"><span>段 / 媒体</span><span>{{ detail.message?.segmentCount }} / {{ detail.message?.mediaCount }}</span></div>
|
||||
<div class="kv-row"><span>上游消息 ID</span><span>{{ detail.message?.sourceMessageId || '—' }}</span></div>
|
||||
<div class="kv-row"><span>原始事件</span><span>{{ detail.rawEventUid || '—' }} · {{ detail.rawEventType || '—' }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>消息段</h4>
|
||||
<div v-if="!detail.segments?.length" class="small-muted">该消息没有保存任何消息段。</div>
|
||||
<div v-for="segment in detail.segments" :key="segment.index" class="segment">
|
||||
<div class="seg-head">
|
||||
<span>#{{ segment.index }} · {{ typeLabel(segment.type) }} <span class="small-muted">({{ segment.type }})</span></span>
|
||||
<StatusTag :value="segment.status" :label="segment.status || '—'" />
|
||||
</div>
|
||||
<div class="seg-body">{{ segment.content || '—' }}</div>
|
||||
<div v-if="segment.mediaUid" style="margin-top: 8px">
|
||||
<button class="btn sm" type="button" @click="loadMedia(segment.mediaUid)">加载媒体预览</button>
|
||||
<span class="small-muted" style="margin-left: 8px">{{ segment.mediaUid }}</span>
|
||||
<div v-if="mediaMap[segment.mediaUid]?.loading" class="loading-row"><span class="spinner"></span>正在获取预签名地址…</div>
|
||||
<div v-else-if="mediaMap[segment.mediaUid]?.error" class="notice danger" style="margin-top: 8px">
|
||||
{{ mediaMap[segment.mediaUid].error.message }}
|
||||
</div>
|
||||
<div v-else-if="mediaMap[segment.mediaUid]?.url" style="margin-top: 8px">
|
||||
<img v-if="String(segment.type).toUpperCase() === 'IMAGE'" :src="mediaMap[segment.mediaUid].url" alt="消息媒体预览" loading="lazy" />
|
||||
<a class="link" :href="mediaMap[segment.mediaUid].url" target="_blank" rel="noopener noreferrer">打开媒体地址</a>
|
||||
<div class="small-muted">地址为短时效预签名地址,过期后需重新获取。</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>原始事件 payload</h4>
|
||||
<pre class="raw-pre">{{ prettyRaw(detail.rawPayload) }}</pre>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>发送记录</h4>
|
||||
<p class="small-muted">
|
||||
后端未提供「按消息反查发送操作」接口。方向筛选为 OUTBOUND 的消息即管理台/规则发出的记录;
|
||||
发送操作的状态、错误码与尝试次数在 /api/v1/send/operations 中查看。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</DetailDrawer>
|
||||
</template>
|
||||
+395
-106
@@ -1,145 +1,434 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { RouterLink, useRoute } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { describeError, directionLabel, formatNumber, formatShortTime, formatTime, notify, typeLabel } from '../ui'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
import DetailDrawer from '../components/DetailDrawer.vue'
|
||||
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
||||
import Pagination from '../components/Pagination.vue'
|
||||
|
||||
const filters = ref({ conversationType: '', conversationId: '', keyword: '', direction: '' })
|
||||
const route = useRoute()
|
||||
|
||||
const conversations = ref([])
|
||||
const convLoading = ref(false)
|
||||
const convError = ref(null)
|
||||
|
||||
const active = ref(null)
|
||||
const rows = ref([])
|
||||
const msgLoading = ref(false)
|
||||
const msgError = ref(null)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const data = ref({ items: [], page: 1, pageSize: 20, total: 0 })
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const pageSize = ref(30)
|
||||
const total = ref(0)
|
||||
|
||||
const detail = ref(null)
|
||||
const detailLoading = ref(false)
|
||||
const detailError = ref('')
|
||||
const accessUrl = ref('')
|
||||
const accessError = ref('')
|
||||
const detailError = ref(null)
|
||||
const mediaMap = reactive({})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
const text = ref('')
|
||||
const preparing = ref(false)
|
||||
const prepareError = ref(null)
|
||||
const pending = ref(null)
|
||||
const executing = ref(false)
|
||||
const executeError = ref(null)
|
||||
const lastResult = ref(null)
|
||||
|
||||
const activeBinding = computed(() => active.value?.bindingUid || '')
|
||||
const canSend = computed(() => Boolean(active.value && activeBinding.value && text.value.trim()) && !preparing.value && !executing.value)
|
||||
const sendTargetType = computed(() => (String(active.value?.conversationType || '').toUpperCase() === 'GROUP' ? 'group' : 'private'))
|
||||
const conversationName = (item) => `${item.conversationType || '未知类型'} · ${item.conversationId || '—'}`
|
||||
const conditionHref = computed(() =>
|
||||
active.value
|
||||
? { path: '/message-search', query: { conversationType: active.value.conversationType, conversationId: active.value.conversationId } }
|
||||
: { path: '/message-search' }
|
||||
)
|
||||
const orderedRows = computed(() => [...rows.value].reverse())
|
||||
|
||||
async function loadConversations() {
|
||||
convLoading.value = true
|
||||
convError.value = null
|
||||
try {
|
||||
const params = { page: page.value, pageSize: pageSize.value }
|
||||
for (const [key, value] of Object.entries(filters.value)) if (value) params[key] = value
|
||||
data.value = await api.messages(params)
|
||||
const data = await api.conversations(1, 50)
|
||||
conversations.value = data?.items || []
|
||||
const wanted = route.query.conversationId
|
||||
const hit = wanted && conversations.value.find((item) =>
|
||||
item.conversationId === wanted && (!route.query.conversationType || item.conversationType === route.query.conversationType))
|
||||
if (hit) active.value = hit
|
||||
else if (!active.value && conversations.value.length) active.value = conversations.value[0]
|
||||
if (active.value) await loadMessages()
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
conversations.value = []
|
||||
rows.value = []
|
||||
convError.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
convLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function open(row) {
|
||||
async function selectConversation(item) {
|
||||
active.value = item
|
||||
page.value = 1
|
||||
detail.value = null
|
||||
detailError.value = ''
|
||||
accessUrl.value = ''
|
||||
accessError.value = ''
|
||||
lastResult.value = null
|
||||
await loadMessages()
|
||||
}
|
||||
|
||||
async function loadMessages() {
|
||||
if (!active.value) return
|
||||
msgLoading.value = true
|
||||
msgError.value = null
|
||||
try {
|
||||
const data = await api.messages({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
conversationType: active.value.conversationType,
|
||||
conversationId: active.value.conversationId
|
||||
})
|
||||
rows.value = data?.items || []
|
||||
total.value = data?.total || 0
|
||||
page.value = data?.page || page.value
|
||||
} catch (e) {
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
msgError.value = describeError(e)
|
||||
} finally {
|
||||
msgLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onPageChange(next) {
|
||||
page.value = next.page
|
||||
pageSize.value = next.pageSize
|
||||
loadMessages()
|
||||
}
|
||||
|
||||
async function openDetail(row) {
|
||||
detailLoading.value = true
|
||||
detailError.value = null
|
||||
detail.value = { message: row, segments: [], rawPayload: null }
|
||||
try {
|
||||
detail.value = await api.message(row.messageUid)
|
||||
} catch (e) {
|
||||
detailError.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
detailError.value = describeError(e)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openMedia(mediaUid) {
|
||||
accessUrl.value = ''
|
||||
accessError.value = ''
|
||||
async function loadMedia(mediaUid) {
|
||||
if (!mediaUid || mediaMap[mediaUid]?.loading) return
|
||||
mediaMap[mediaUid] = { loading: true, url: '', error: null, info: mediaMap[mediaUid]?.info || null }
|
||||
try {
|
||||
const result = await api.mediaAccessUrl(mediaUid)
|
||||
accessUrl.value = result.url || ''
|
||||
accessError.value = result.note || ''
|
||||
const [urlData, info] = await Promise.all([
|
||||
api.mediaAccessUrl(mediaUid),
|
||||
api.media(mediaUid).catch(() => null)
|
||||
])
|
||||
mediaMap[mediaUid] = { loading: false, url: urlData?.url || '', error: null, info }
|
||||
} catch (e) {
|
||||
accessError.value = e.message
|
||||
mediaMap[mediaUid] = { loading: false, url: '', error: describeError(e), info: null }
|
||||
}
|
||||
}
|
||||
|
||||
function search() {
|
||||
page.value = 1
|
||||
load()
|
||||
function prettyRaw(value) {
|
||||
if (!value) return '—'
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(value), null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
function move(delta) {
|
||||
page.value = Math.max(1, page.value + delta)
|
||||
load()
|
||||
function idempotencyKey() {
|
||||
if (window.crypto?.randomUUID) return window.crypto.randomUUID()
|
||||
return `qlinker-${Date.now()}-${Math.random().toString(16).slice(2)}`
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
async function prepareSend() {
|
||||
if (!canSend.value) return
|
||||
preparing.value = true
|
||||
prepareError.value = null
|
||||
lastResult.value = null
|
||||
try {
|
||||
pending.value = await api.prepareText({
|
||||
bindingUid: activeBinding.value,
|
||||
targetType: sendTargetType.value,
|
||||
targetId: active.value.conversationId,
|
||||
text: text.value.trim(),
|
||||
reason: '管理台消息中心手动发送'
|
||||
}, idempotencyKey())
|
||||
} catch (e) {
|
||||
prepareError.value = describeError(e)
|
||||
} finally {
|
||||
preparing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmSend() {
|
||||
if (!pending.value || executing.value) return
|
||||
executing.value = true
|
||||
executeError.value = null
|
||||
try {
|
||||
const result = await api.executeSend(pending.value.operationUid, pending.value.confirmToken)
|
||||
lastResult.value = result
|
||||
pending.value = null
|
||||
text.value = ''
|
||||
notify(
|
||||
result.status === 'SUCCEEDED' ? '发送成功' : result.status === 'UNKNOWN' ? '发送结果未知' : '发送未成功',
|
||||
result.errorMessage || result.warning || `操作 ${result.operationUid} 状态 ${result.status}`,
|
||||
result.status === 'SUCCEEDED' ? 'success' : 'warning'
|
||||
)
|
||||
await loadMessages()
|
||||
} catch (e) {
|
||||
executeError.value = describeError(e)
|
||||
} finally {
|
||||
executing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadConversations)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="card">
|
||||
<h2>消息查询</h2>
|
||||
<div class="row">
|
||||
<select v-model="filters.conversationType" style="max-width: 160px;">
|
||||
<option value="">全部会话类型</option>
|
||||
<option value="group">群聊</option>
|
||||
<option value="private">私聊</option>
|
||||
</select>
|
||||
<input v-model="filters.conversationId" placeholder="会话 ID" style="max-width: 180px;" />
|
||||
<select v-model="filters.direction" style="max-width: 160px;">
|
||||
<option value="">全部方向</option>
|
||||
<option value="INBOUND">接收</option>
|
||||
<option value="OUTBOUND">发送</option>
|
||||
</select>
|
||||
<input v-model="filters.keyword" placeholder="关键词" style="max-width: 220px;" />
|
||||
<button :disabled="loading" @click="search">{{ loading ? '查询中…' : '查询' }}</button>
|
||||
</div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p class="muted">共 {{ data.total }} 条,第 {{ data.page }} 页(每页 {{ data.pageSize }} 条)。</p>
|
||||
<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 data.items" :key="row.messageUid" @click="open(row)" style="cursor: pointer;">
|
||||
<td class="muted">{{ row.messageTime }}</td>
|
||||
<td>{{ row.conversationType }}:{{ row.conversationId }}</td>
|
||||
<td>{{ row.direction }}</td>
|
||||
<td>{{ row.senderName || row.senderId || '-' }}</td>
|
||||
<td>{{ row.summary }}</td>
|
||||
<td>{{ row.segmentCount }} / {{ row.mediaCount }}</td>
|
||||
<td>{{ row.normalizedStatus }}</td>
|
||||
</tr>
|
||||
<tr v-if="!data.items.length && !loading"><td colspan="7" class="muted">没有符合条件的消息。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row" style="margin-top: 12px;">
|
||||
<button class="ghost" :disabled="loading || page <= 1" @click="move(-1)">上一页</button>
|
||||
<button class="ghost" :disabled="loading || page * pageSize >= data.total" @click="move(1)">下一页</button>
|
||||
</div>
|
||||
</div>
|
||||
<PageHead kicker="工作空间" title="消息中心" desc="会话与消息详情来自真实入库数据;发送走统一发送服务,两阶段确认,不伪造成功。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="convLoading || msgLoading" @click="loadConversations">刷新</button>
|
||||
<RouterLink class="btn primary" :to="conditionHref">消息检索</RouterLink>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div v-if="detailLoading" class="card">详情加载中…</div>
|
||||
<div v-else-if="detailError" class="card"><p class="error">{{ detailError }}</p></div>
|
||||
<div v-else-if="detail" class="card">
|
||||
<h2>消息详情 {{ detail.message.messageUid }}</h2>
|
||||
<p class="muted">
|
||||
会话 {{ detail.message.conversationType }}:{{ detail.message.conversationId }},
|
||||
来源事件 {{ detail.rawEventUid || '-' }}({{ detail.rawEventType || '-' }})
|
||||
</p>
|
||||
<table>
|
||||
<thead><tr><th>#</th><th>类型</th><th>状态</th><th>内容</th><th>媒体</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="seg in detail.segments" :key="seg.index">
|
||||
<td>{{ seg.index }}</td>
|
||||
<td>{{ seg.type }}</td>
|
||||
<td>{{ seg.status }}</td>
|
||||
<td>{{ seg.content || '-' }}</td>
|
||||
<td>
|
||||
<button v-if="seg.mediaUid" class="ghost" @click="openMedia(seg.mediaUid)">访问对象</button>
|
||||
<span v-else class="muted">-</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-if="accessUrl" class="ok">临时访问地址:<a :href="accessUrl" target="_blank" rel="noreferrer">{{ accessUrl }}</a></p>
|
||||
<p v-if="accessError" class="warn">{{ accessError }}</p>
|
||||
<h2 style="margin-top: 16px;">原始事件</h2>
|
||||
<pre>{{ detail.rawPayload }}</pre>
|
||||
<SectionState
|
||||
:loading="convLoading"
|
||||
:error="convError"
|
||||
:empty="!convLoading && !convError && !conversations.length"
|
||||
empty-title="暂无会话"
|
||||
empty-text="还没有已入库的消息。绑定 NapCat 并等待事件到达后,会话会按「会话类型 + 会话 ID」聚合展示。"
|
||||
@retry="loadConversations"
|
||||
>
|
||||
<template #empty-actions>
|
||||
<RouterLink class="btn primary sm" to="/connections">前往接入管理</RouterLink>
|
||||
</template>
|
||||
|
||||
<div class="chat-layout">
|
||||
<aside class="chat-list">
|
||||
<div class="card-head" style="padding: 2px 6px 12px">
|
||||
<h3 class="card-title">会话</h3>
|
||||
<span class="pill">{{ conversations.length }}</span>
|
||||
</div>
|
||||
<button
|
||||
v-for="item in conversations"
|
||||
:key="`${item.conversationType}-${item.conversationId}`"
|
||||
type="button"
|
||||
class="chat-person"
|
||||
:class="{ active: active && item.conversationId === active.conversationId && item.conversationType === active.conversationType }"
|
||||
style="width: 100%; border: 0; text-align: left"
|
||||
@click="selectConversation(item)"
|
||||
>
|
||||
<span class="mini-avatar">{{ (item.conversationId || '?').slice(-2) }}</span>
|
||||
<div>
|
||||
<strong>{{ conversationName(item) }}</strong>
|
||||
<span>{{ formatNumber(item.messageCount) }} 条 · {{ formatTime(item.lastMessageTime) }}</span>
|
||||
</div>
|
||||
</button>
|
||||
</aside>
|
||||
|
||||
<section class="chat-main">
|
||||
<div v-if="!active" class="state-block" style="margin: 20px">请选择左侧会话查看消息。</div>
|
||||
<template v-else>
|
||||
<div class="chat-header">
|
||||
<div>
|
||||
<h3 style="margin: 0 0 4px">{{ conversationName(active) }}</h3>
|
||||
<span class="small-muted">
|
||||
绑定 {{ active.bindingUid || '—' }} · 共 {{ formatNumber(active.messageCount) }} 条 · 最近 {{ formatTime(active.lastMessageTime) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供会话级搜索接口">会话内搜索</button>
|
||||
<button class="btn sm" type="button" disabled title="消息段组合发送由自动化规则实现,管理台仅支持纯文本">附件 / @</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SectionState
|
||||
:loading="msgLoading"
|
||||
:error="msgError"
|
||||
:empty="!msgLoading && !msgError && !rows.length"
|
||||
empty-title="该会话暂无消息"
|
||||
empty-text="切换分页或检查筛选条件。"
|
||||
@retry="loadMessages"
|
||||
>
|
||||
<div class="chat-messages">
|
||||
<div v-for="row in orderedRows" :key="row.messageUid" class="bubble-row" :class="{ mine: row.direction === 'OUTBOUND' }">
|
||||
<div class="bubble" role="button" tabindex="0" @click="openDetail(row)" @keydown.enter="openDetail(row)">
|
||||
<div>{{ row.summary || '(无摘要)' }}</div>
|
||||
<div class="bubble-meta">
|
||||
{{ formatShortTime(row.messageTime) }} · {{ directionLabel(row.direction) }} · {{ typeLabel(row.messageType) }}
|
||||
· 段 {{ row.segmentCount }} · 媒体 {{ row.mediaCount }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SectionState>
|
||||
|
||||
<Pagination :page="page" :page-size="pageSize" :total="total" @change="onPageChange" />
|
||||
|
||||
<div v-if="prepareError" class="notice danger" style="margin-top: 10px">
|
||||
<div>
|
||||
<strong>{{ prepareError.title }}</strong>
|
||||
<div>{{ prepareError.message }}</div>
|
||||
<div class="small-muted">{{ prepareError.hint }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="lastResult" class="notice" :class="lastResult.status === 'UNKNOWN' ? 'warn' : lastResult.status === 'SUCCEEDED' ? '' : 'danger'" style="margin-top: 10px">
|
||||
<div>
|
||||
<strong>发送操作 {{ lastResult.status }}</strong>
|
||||
<div>操作 {{ lastResult.operationUid }} · 尝试 {{ lastResult.attemptCount }} 次</div>
|
||||
<div v-if="lastResult.errorCode || lastResult.errorMessage">{{ lastResult.errorCode }} {{ lastResult.errorMessage }}</div>
|
||||
<div v-if="lastResult.status === 'UNKNOWN'" class="small-muted">上游可能已执行且本地未收到确认:禁止自动重试,请人工核实后再决定。</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!activeBinding" class="notice warn" style="margin-top: 10px">
|
||||
当前会话缺少绑定信息,无法确定发送账号;请先确认消息来源绑定。
|
||||
</div>
|
||||
|
||||
<form class="chat-composer" @submit.prevent="prepareSend">
|
||||
<textarea
|
||||
v-model="text"
|
||||
class="composer-input"
|
||||
placeholder="输入纯文本消息,发送前会进入两阶段确认…"
|
||||
maxlength="4000"
|
||||
:disabled="preparing || executing"
|
||||
></textarea>
|
||||
<div class="composer-bottom">
|
||||
<span class="small-muted">仅支持纯文本 · 目标 {{ sendTargetType }} · 绑定 {{ activeBinding || '—' }}</span>
|
||||
<button class="btn primary sm" type="submit" :disabled="!canSend">{{ preparing ? '创建发送操作…' : '发送' }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<aside class="context-panel">
|
||||
<div class="context-section">
|
||||
<h4>会话信息</h4>
|
||||
<div v-if="active" class="kv">
|
||||
<div class="kv-row"><span>会话类型</span><span>{{ active.conversationType || '—' }}</span></div>
|
||||
<div class="kv-row"><span>会话 ID</span><span>{{ active.conversationId || '—' }}</span></div>
|
||||
<div class="kv-row"><span>绑定</span><span>{{ active.bindingUid || '—' }}</span></div>
|
||||
<div class="kv-row"><span>消息数</span><span>{{ formatNumber(active.messageCount) }}</span></div>
|
||||
<div class="kv-row"><span>最近消息</span><span>{{ formatTime(active.lastMessageTime) }}</span></div>
|
||||
</div>
|
||||
<div v-else class="small-muted">未选择会话</div>
|
||||
</div>
|
||||
<div class="context-section">
|
||||
<h4>快捷操作</h4>
|
||||
<RouterLink class="btn sm block" :to="conditionHref">仅检索该会话</RouterLink>
|
||||
<RouterLink class="btn sm block" to="/message-search" style="margin-top: 8px">按方向筛选发送记录</RouterLink>
|
||||
<p class="small-muted" style="margin-top: 10px">发送记录并入消息中心的出站消息与「消息检索」方向筛选,不另设独立页面。</p>
|
||||
</div>
|
||||
<div class="context-section">
|
||||
<h4>媒体预览</h4>
|
||||
<p class="small-muted">在消息详情中通过 /media/{uid}/access-url 获取短时效预签名地址。</p>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</SectionState>
|
||||
|
||||
<ConfirmDialog
|
||||
:open="Boolean(pending)"
|
||||
title="确认发送消息"
|
||||
:message="pending ? `将向 ${pending.targetSummary || `${pending.targetType} ${pending.targetId}`} 发送纯文本消息。` : ''"
|
||||
:hint="pending ? `确认令牌有效期至 ${formatTime(pending.confirmExpiresAt)};执行结果可能为「结果未知」。` : ''"
|
||||
confirm-text="确认并发送"
|
||||
:busy="executing"
|
||||
@confirm="confirmSend"
|
||||
@cancel="!executing && (pending = null)"
|
||||
>
|
||||
<div v-if="pending" class="notice" style="margin-bottom: 12px">
|
||||
<div>
|
||||
<strong>待发送内容</strong>
|
||||
<div style="white-space: pre-wrap; margin-top: 6px">{{ pending.text || text }}</div>
|
||||
<div class="small-muted" style="margin-top: 6px">操作 {{ pending.operationUid }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="executeError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ executeError.title }}</strong>
|
||||
<div>{{ executeError.message }}</div>
|
||||
<div class="small-muted">{{ executeError.hint }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</ConfirmDialog>
|
||||
|
||||
<DetailDrawer :open="Boolean(detail)" title="消息详情" :subtitle="detail?.message?.messageUid" @close="detail = null">
|
||||
<div v-if="detailLoading" class="state-block"><span class="spinner"></span>正在读取消息详情…</div>
|
||||
<div v-else-if="detailError" class="notice danger">
|
||||
<div>
|
||||
<strong>{{ detailError.title }}</strong>
|
||||
<div>{{ detailError.message }}</div>
|
||||
<div class="small-muted">{{ detailError.hint }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else-if="detail">
|
||||
<div class="drawer-section">
|
||||
<h4>基本信息</h4>
|
||||
<div class="kv">
|
||||
<div class="kv-row"><span>消息标识</span><span>{{ detail.message?.messageUid }}</span></div>
|
||||
<div class="kv-row"><span>来源绑定</span><span>{{ detail.message?.bindingUid || '—' }}</span></div>
|
||||
<div class="kv-row"><span>会话</span><span>{{ detail.message?.conversationType }} · {{ detail.message?.conversationId }}</span></div>
|
||||
<div class="kv-row"><span>发送者</span><span>{{ detail.message?.senderName || '—' }} ({{ detail.message?.senderId || '—' }})</span></div>
|
||||
<div class="kv-row"><span>方向 / 类型</span><span>{{ directionLabel(detail.message?.direction) }} · {{ typeLabel(detail.message?.messageType) }}</span></div>
|
||||
<div class="kv-row"><span>消息时间</span><span>{{ formatTime(detail.message?.messageTime) }}</span></div>
|
||||
<div class="kv-row"><span>归一化状态</span><span><StatusTag :value="detail.message?.normalizedStatus" :label="detail.message?.normalizedStatus || '—'" /></span></div>
|
||||
<div class="kv-row"><span>段 / 媒体</span><span>{{ detail.message?.segmentCount }} / {{ detail.message?.mediaCount }}</span></div>
|
||||
<div class="kv-row"><span>上游消息 ID</span><span>{{ detail.message?.sourceMessageId || '—' }}</span></div>
|
||||
<div class="kv-row"><span>原始事件</span><span>{{ detail.rawEventUid || '—' }} · {{ detail.rawEventType || '—' }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>消息段</h4>
|
||||
<div v-if="!detail.segments?.length" class="small-muted">该消息没有保存任何消息段。</div>
|
||||
<div v-for="segment in detail.segments" :key="segment.index" class="segment">
|
||||
<div class="seg-head">
|
||||
<span>#{{ segment.index }} · {{ typeLabel(segment.type) }} <span class="small-muted">({{ segment.type }})</span></span>
|
||||
<StatusTag :value="segment.status" :label="segment.status || '—'" />
|
||||
</div>
|
||||
<div class="seg-body">{{ segment.content || '—' }}</div>
|
||||
<div v-if="segment.mediaUid" style="margin-top: 8px">
|
||||
<button class="btn sm" type="button" @click="loadMedia(segment.mediaUid)">加载媒体预览</button>
|
||||
<span class="small-muted" style="margin-left: 8px">{{ segment.mediaUid }}</span>
|
||||
<div v-if="mediaMap[segment.mediaUid]?.loading" class="loading-row"><span class="spinner"></span>正在获取预签名地址…</div>
|
||||
<div v-else-if="mediaMap[segment.mediaUid]?.error" class="notice danger" style="margin-top: 8px">
|
||||
{{ mediaMap[segment.mediaUid].error.message }}
|
||||
</div>
|
||||
<div v-else-if="mediaMap[segment.mediaUid]?.url" style="margin-top: 8px">
|
||||
<img
|
||||
v-if="String(segment.type).toUpperCase() === 'IMAGE'"
|
||||
:src="mediaMap[segment.mediaUid].url"
|
||||
alt="消息媒体预览"
|
||||
loading="lazy"
|
||||
/>
|
||||
<a class="link" :href="mediaMap[segment.mediaUid].url" target="_blank" rel="noopener noreferrer">打开媒体地址</a>
|
||||
<div class="small-muted">地址为短时效预签名地址,过期后需重新获取。</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>原始事件 payload</h4>
|
||||
<pre class="raw-pre">{{ prettyRaw(detail.rawPayload) }}</pre>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<h4>媒体与发送记录</h4>
|
||||
<p class="small-muted">媒体通过 /api/v1/media/{uid}/access-url 按需获取;后端未提供按消息反查发送记录,发送记录请使用「消息检索」的方向筛选查看出站消息与发送操作列表。</p>
|
||||
<RouterLink class="btn sm" :to="conditionHref">在消息检索中查看</RouterLink>
|
||||
</div>
|
||||
</template>
|
||||
</DetailDrawer>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup>
|
||||
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'
|
||||
|
||||
const health = 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 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 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 || {}
|
||||
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)}`,
|
||||
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)}`,
|
||||
at: '—'
|
||||
},
|
||||
{
|
||||
name: '发送操作',
|
||||
status: Number(send.UNKNOWN) > 0 ? 'UNKNOWN' : Number(send.FAILED) > 0 ? 'FAILED' : 'ACTIVE',
|
||||
detail: `总计 ${formatNumber(sendTotal.value)} · 成功 ${formatNumber(send.SUCCEEDED)} · 结果未知 ${formatNumber(send.UNKNOWN)}`,
|
||||
at: '—'
|
||||
},
|
||||
{ name: 'MySQL 连接', status: 'UNKNOWN', detail: '后端 health-detail 未提供数据库独立探测结果', at: '—' },
|
||||
{ name: 'MinIO 连接', status: 'UNKNOWN', detail: '后端 health-detail 未提供对象存储独立探测结果', at: '—' },
|
||||
{ name: '异步任务队列', status: 'UNKNOWN', detail: '后端 health-detail 未提供队列积压指标', at: '—' }
|
||||
]
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
health.value = await api.healthDetail()
|
||||
} catch (e) {
|
||||
health.value = null
|
||||
error.value = describeError(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="连接与运维" title="运维监控" desc="健康总览分项来自后端 health-detail;数据库、对象存储独立探测与主机资源尚未提供,按实显示「未提供」。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</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?.application || '—' }}</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>
|
||||
<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>
|
||||
<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>
|
||||
</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>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<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>{{ row.at }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</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>
|
||||
</template>
|
||||
<div v-else class="notice">演示数据已关闭:主机资源与告警区块依赖的后端接口尚未提供,因此不显示。</div>
|
||||
</template>
|
||||
@@ -1,87 +0,0 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { api } from '../api'
|
||||
|
||||
const detail = ref(null)
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
detail.value = await api.healthDetail()
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between;">
|
||||
<h2 style="margin: 0;">系统总览</h2>
|
||||
<button class="ghost" :disabled="loading" @click="load">{{ loading ? '刷新中…' : '刷新' }}</button>
|
||||
</div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="!detail && !loading" class="muted">暂无数据。</p>
|
||||
</div>
|
||||
|
||||
<template v-if="detail">
|
||||
<div class="card">
|
||||
<h2>实例与依赖</h2>
|
||||
<div class="grid">
|
||||
<div class="stat"><div class="value">{{ detail.instance || '-' }}</div><div class="label">实例标识</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.napcat?.total ?? '-' }}</div><div class="label">NapCat 绑定数</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.messages?.totalMessages ?? '-' }}</div><div class="label">已入库消息</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.messages?.unprocessedEvents ?? '-' }}</div><div class="label">待处理事件</div></div>
|
||||
</div>
|
||||
<p class="muted">
|
||||
事件处理失败 {{ detail.messages?.failedEvents ?? 0 }} 条,未知类型事件 {{ detail.messages?.unknownTypeEvents ?? 0 }} 条。
|
||||
未知类型不会被丢弃,但也不会被强行归一化为已知消息。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>NapCat 连接状态</h2>
|
||||
<p class="muted">在线状态以收到 lifecycle 或有效事件为准,握手成功不代表在线。</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>绑定</th><th>绑定状态</th><th>连接状态</th><th>QQ 账号</th><th>最近事件</th><th>最近错误</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in detail.napcat?.items || []" :key="item.bindingUid">
|
||||
<td>{{ item.displayName || item.bindingUid }}</td>
|
||||
<td>{{ item.bindingStatus }}</td>
|
||||
<td>{{ item.connectionStatus }}</td>
|
||||
<td>{{ item.qqAccountId || '-' }}</td>
|
||||
<td>{{ item.lastEventAt || '-' }}</td>
|
||||
<td>{{ item.lastErrorCode || '-' }}</td>
|
||||
</tr>
|
||||
<tr v-if="!(detail.napcat?.items || []).length">
|
||||
<td colspan="6" class="muted">尚未绑定 NapCat 实例。</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>媒体与发送</h2>
|
||||
<div class="grid">
|
||||
<div class="stat"><div class="value">{{ detail.media?.STORED ?? 0 }}</div><div class="label">媒体已入库</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.media?.FAILED ?? 0 }}</div><div class="label">媒体下载失败</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.media?.SOURCE_EXPIRED ?? 0 }}</div><div class="label">媒体源已过期</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.send?.SUCCEEDED ?? 0 }}</div><div class="label">发送成功</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.send?.UNKNOWN ?? 0 }}</div><div class="label">发送结果未知</div></div>
|
||||
<div class="stat"><div class="value">{{ detail.send?.FAILED ?? 0 }}</div><div class="label">发送失败</div></div>
|
||||
</div>
|
||||
<p class="warn">「结果未知」表示上游可能已执行但本地未收到确认,不会自动重试,需要人工核实。</p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,155 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { describeError, formatTime } from '../ui'
|
||||
import { demoState, MOCK_NOTE } from '../demo/config'
|
||||
import { PLANNED_DEPS, securityApprovals, securityRoles, securityTokens, securityUsers } from '../demo/planned'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
import PlannedNotice from '../components/PlannedNotice.vue'
|
||||
import SectionState from '../components/SectionState.vue'
|
||||
import StatusTag from '../components/StatusTag.vue'
|
||||
|
||||
const tab = ref('users')
|
||||
const me = ref(null)
|
||||
const meLoading = ref(false)
|
||||
const meError = ref(null)
|
||||
|
||||
const permissions = computed(() => me.value?.permissions || [])
|
||||
|
||||
async function loadMe() {
|
||||
meLoading.value = true
|
||||
meError.value = null
|
||||
try {
|
||||
me.value = await api.me()
|
||||
} catch (e) {
|
||||
me.value = null
|
||||
meError.value = describeError(e)
|
||||
} finally {
|
||||
meLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadMe)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="平台管理" title="安全审计" desc="当前账号与权限来自后端 /auth/me;用户、角色、令牌与审批的后端接口尚未提供,相关页签为演示数据。">
|
||||
<template #actions>
|
||||
<button class="btn" type="button" disabled title="后端未提供紧急停止接口">紧急停止</button>
|
||||
<button class="btn danger" type="button" disabled title="后端未提供用户管理接口">新增用户</button>
|
||||
</template>
|
||||
</PageHead>
|
||||
|
||||
<div class="card" style="margin-bottom: 16px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">当前会话(真实)</h3>
|
||||
<span class="pill">/auth/me</span>
|
||||
</div>
|
||||
<SectionState :loading="meLoading" :error="meError" @retry="loadMe">
|
||||
<div v-if="me" class="kv">
|
||||
<div class="kv-row"><span>账号</span><span>{{ me.username || '—' }}</span></div>
|
||||
<div class="kv-row"><span>显示名称</span><span>{{ me.displayName || '—' }}</span></div>
|
||||
<div class="kv-row"><span>用户标识</span><span>{{ me.userId || '—' }}</span></div>
|
||||
<div class="kv-row"><span>管理员</span><span>{{ me.hasAdministrator ? '是' : '否' }}</span></div>
|
||||
<div class="kv-row"><span>权限</span><span>{{ permissions.length ? permissions.join('、') : '—' }}</span></div>
|
||||
</div>
|
||||
</SectionState>
|
||||
</div>
|
||||
|
||||
<PlannedNotice
|
||||
v-if="!demoState.enabled"
|
||||
title="用户、角色、令牌与审批尚未开发"
|
||||
summary="后端仅提供单管理员认证与权限声明,未提供用户管理、角色、API 令牌、审批与审计事件接口。关闭演示数据时不展示占位数据。"
|
||||
:deps="PLANNED_DEPS.security"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div class="demo-banner">{{ MOCK_NOTE }}<DemoBadge /></div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ active: tab === 'users' }" type="button" @click="tab = 'users'">用户</button>
|
||||
<button class="tab" :class="{ active: tab === 'roles' }" type="button" @click="tab = 'roles'">角色</button>
|
||||
<button class="tab" :class="{ active: tab === 'tokens' }" type="button" @click="tab = 'tokens'">API 令牌</button>
|
||||
<button class="tab" :class="{ active: tab === 'approvals' }" type="button" @click="tab = 'approvals'">审批</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'users'" 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><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="user in securityUsers" :key="user.account">
|
||||
<td><strong>{{ user.name }}</strong></td>
|
||||
<td>{{ user.account }}</td>
|
||||
<td>{{ user.role }}</td>
|
||||
<td><StatusTag value="ACTIVE" :label="user.status" /></td>
|
||||
<td>{{ user.lastLogin }}</td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供用户编辑接口">编辑</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'roles'" 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="role in securityRoles" :key="role.name">
|
||||
<td><strong>{{ role.name }}</strong></td>
|
||||
<td>{{ role.members }}</td>
|
||||
<td>{{ role.scope }}</td>
|
||||
<td>{{ role.changed }}</td>
|
||||
<td><button class="btn sm" type="button" disabled title="后端未提供角色编辑接口">配置权限</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="tab === 'tokens'" class="card">
|
||||
<div class="card-head"><h3 class="card-title">API 令牌<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="token in securityTokens" :key="token.name">
|
||||
<td><strong>{{ token.name }}</strong></td>
|
||||
<td>{{ token.scope }}</td>
|
||||
<td>{{ token.expires }}</td>
|
||||
<td><StatusTag :value="token.status === '有效' ? 'ACTIVE' : token.status === '临期' ? 'WARN' : 'EXPIRED'" :label="token.status" /></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">演示数据</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 securityApprovals" :key="item.title">
|
||||
<td>{{ item.title }}</td>
|
||||
<td>{{ item.submitter }}</td>
|
||||
<td>{{ item.time }}</td>
|
||||
<td><StatusTag :value="item.risk === '高' ? 'FAILED' : 'WARN'" :label="item.risk" /></td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button class="btn sm" type="button" disabled title="后端未提供审批接口">通过</button>
|
||||
<button class="btn sm" type="button" disabled title="后端未提供审批接口">驳回</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
@@ -1,152 +0,0 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { api } from '../api'
|
||||
|
||||
const bindings = ref([])
|
||||
const form = ref({ bindingUid: '', targetType: 'group', targetId: '', text: '', reason: '' })
|
||||
const phase = ref('idle')
|
||||
const prepared = ref(null)
|
||||
const operations = ref([])
|
||||
const summary = ref(null)
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const notice = ref('')
|
||||
|
||||
function newIdempotencyKey() {
|
||||
return typeof crypto !== 'undefined' && crypto.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: `idem_${Date.now()}_${Math.random().toString(36).slice(2)}`
|
||||
}
|
||||
|
||||
let idempotencyKey = newIdempotencyKey()
|
||||
|
||||
async function loadAll() {
|
||||
error.value = ''
|
||||
try {
|
||||
const [list, ops, sum] = await Promise.all([api.bindings(), api.sendOperations(), api.sendSummary()])
|
||||
bindings.value = list.filter((b) => b.bindingStatus === 'ACTIVE')
|
||||
operations.value = ops
|
||||
summary.value = sum
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
}
|
||||
}
|
||||
|
||||
async function prepare() {
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
busy.value = true
|
||||
try {
|
||||
prepared.value = await api.prepareText({ ...form.value }, idempotencyKey)
|
||||
phase.value = 'prepared'
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function execute() {
|
||||
error.value = ''
|
||||
busy.value = true
|
||||
try {
|
||||
const result = await api.executeSend(prepared.value.operationUid, prepared.value.confirmToken)
|
||||
phase.value = 'done'
|
||||
if (result.status === 'SUCCEEDED') {
|
||||
notice.value = `发送成功(操作号 ${result.operationUid})。「上游确认成功」不必然代表接收方已看到消息。`
|
||||
} else if (result.status === 'UNKNOWN') {
|
||||
error.value = `结果未知(操作号 ${result.operationUid}):上游可能已执行,系统不会自动重试,请人工核实。`
|
||||
} else {
|
||||
error.value = `发送未完成(操作号 ${result.operationUid},状态 ${result.status},错误 ${result.errorCode || '-'})`
|
||||
}
|
||||
// 一次操作只允许一次确认执行,之后重新开始,避免重复提交。
|
||||
idempotencyKey = newIdempotencyKey()
|
||||
prepared.value = null
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
error.value = `${e.message}${e.requestId ? `(请求号 ${e.requestId})` : ''}`
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
prepared.value = null
|
||||
phase.value = 'idle'
|
||||
idempotencyKey = newIdempotencyKey()
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="card">
|
||||
<h2>发送文本消息(两阶段确认)</h2>
|
||||
<p class="muted">第一步只创建发送操作,不产生任何外部副作用;第二步携带确认令牌才真正调用 NapCat。</p>
|
||||
<template v-if="phase !== 'prepared'">
|
||||
<label>
|
||||
<span>NapCat 绑定</span>
|
||||
<select v-model="form.bindingUid" required>
|
||||
<option value="" disabled>请选择绑定</option>
|
||||
<option v-for="b in bindings" :key="b.bindingUid" :value="b.bindingUid">
|
||||
{{ b.displayName }}({{ b.connectionStatus }})
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="row">
|
||||
<label style="max-width: 160px;">
|
||||
<span>目标类型</span>
|
||||
<select v-model="form.targetType">
|
||||
<option value="group">群</option>
|
||||
<option value="private">个人</option>
|
||||
</select>
|
||||
</label>
|
||||
<label style="flex: 1;"><span>目标 ID</span><input v-model="form.targetId" required /></label>
|
||||
</div>
|
||||
<label><span>消息正文</span><textarea v-model="form.text" rows="4" required></textarea></label>
|
||||
<label><span>操作原因(写入审计)</span><input v-model="form.reason" /></label>
|
||||
<button :disabled="busy || !form.bindingUid || !form.targetId || !form.text" @click="prepare">
|
||||
{{ busy ? '处理中…' : '第一步:创建发送操作' }}
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p class="warn">
|
||||
即将向 <b>{{ prepared.targetSummary }}</b> 发送消息。确认令牌有效期很短,过期后需要重新创建操作。
|
||||
</p>
|
||||
<pre>{{ form.text }}</pre>
|
||||
<div class="row">
|
||||
<button :disabled="busy" @click="execute">{{ busy ? '发送中…' : '第二步:确认并发送' }}</button>
|
||||
<button class="ghost" :disabled="busy" @click="cancel">取消</button>
|
||||
</div>
|
||||
</template>
|
||||
<p v-if="notice" class="ok">{{ notice }}</p>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>发送操作记录</h2>
|
||||
<p class="muted" v-if="summary">
|
||||
待发送 {{ summary.PENDING ?? 0 }},发送中 {{ summary.RUNNING ?? 0 }},成功 {{ summary.SUCCEEDED ?? 0 }},
|
||||
失败 {{ summary.FAILED ?? 0 }},结果未知 {{ summary.UNKNOWN ?? 0 }}
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>操作号</th><th>目标</th><th>状态</th><th>尝试</th><th>错误</th><th>创建时间</th><th>完成时间</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="op in operations" :key="op.operationUid">
|
||||
<td class="muted">{{ op.operationUid }}</td>
|
||||
<td>{{ op.targetType }}:{{ op.targetId }}</td>
|
||||
<td>{{ op.status }}</td>
|
||||
<td>{{ op.attemptCount }}</td>
|
||||
<td>{{ op.errorCode || '-' }}</td>
|
||||
<td class="muted">{{ op.createdAt }}</td>
|
||||
<td class="muted">{{ op.finishedAt || '-' }}</td>
|
||||
</tr>
|
||||
<tr v-if="!operations.length"><td colspan="7" class="muted">暂无发送操作。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,124 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { api } from '../api'
|
||||
import { demoState, MOCK_NOTE, setDemoEnabled } from '../demo/config'
|
||||
import { PLANNED_DEPS, settingsValues } from '../demo/planned'
|
||||
import PageHead from '../components/PageHead.vue'
|
||||
import DemoBadge from '../components/DemoBadge.vue'
|
||||
|
||||
const tab = ref('basic')
|
||||
const instance = ref(null)
|
||||
const instanceError = ref('')
|
||||
const dark = ref(document.documentElement.style.colorScheme === 'dark')
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
instance.value = await api.initialization()
|
||||
} catch {
|
||||
instanceError.value = '实例初始化信息读取失败(后端可能未启动)。'
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PageHead kicker="平台管理" title="系统设置" desc="实例身份来自后端;外观与演示数据开关为本地真实设置;业务配置项后端尚未提供。">
|
||||
</PageHead>
|
||||
|
||||
<div class="card" style="margin-bottom: 16px">
|
||||
<div class="card-head">
|
||||
<h3 class="card-title">实例信息</h3>
|
||||
<span class="pill">后端真实</span>
|
||||
</div>
|
||||
<div v-if="instanceError" class="notice danger">{{ instanceError }}</div>
|
||||
<div v-else class="kv">
|
||||
<div class="kv-row"><span>实例标识</span><span>{{ instance?.instanceUid || '—' }}</span></div>
|
||||
<div class="kv-row"><span>初始化状态</span><span>{{ instance ? (instance.initialized ? '已初始化' : '未初始化') : '读取中…' }}</span></div>
|
||||
<div class="kv-row"><span>数据库</span><span>{{ instance?.databaseName || '—' }}</span></div>
|
||||
<div class="kv-row"><span>对象存储 Bucket</span><span>{{ instance?.bucketName || '—' }}</span></div>
|
||||
</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>
|
||||
|
||||
<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="fld">
|
||||
<label for="set-name">实例名称</label>
|
||||
<input id="set-name" class="field" :value="settingsValues.instanceName" disabled />
|
||||
</div>
|
||||
<div class="fld">
|
||||
<label for="set-code">实例编号</label>
|
||||
<input id="set-code" class="field" :value="settingsValues.instanceCode" disabled />
|
||||
</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 />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn primary" type="button" disabled title="后端未提供实例设置保存接口">保存设置</button>
|
||||
</div>
|
||||
<p class="small-muted" style="margin-top: 10px">依赖:{{ PLANNED_DEPS.settings.join('、') }}</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>
|
||||
</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="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>
|
||||
</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>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user