Files
QLinker/frontend/src/views/ai/AiCenterView.vue
T

111 lines
4.2 KiB
Vue
Raw Normal View History

<script setup>
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { aiApi } from '../../api/ai'
import ChannelPanel from './ChannelPanel.vue'
import CallPanel from './CallPanel.vue'
import ToolPanel from './ToolPanel.vue'
import GovernancePanel from './GovernancePanel.vue'
const route = useRoute()
const router = useRouter()
const TABS = [
{ key: 'channels', label: '渠道', hint: '模型服务商与模型能力合并管理' },
{ key: 'calls', label: '调用与成本', hint: '用量、成本、耗时与错误分类' },
{ key: 'tools', label: '工具授权', hint: '风险分级、人工确认与执行审计' },
{ key: 'governance', label: '治理设置', hint: '脱敏、缓存与记忆保留' }
]
const tab = ref(String(route.query.tab || 'channels'))
if (!TABS.some((item) => item.key === tab.value)) tab.value = 'channels'
const counts = ref({ channels: null, tools: null })
const channelMeta = ref({ reserved: 0, unverified: 0 })
async function loadCounts() {
const [providerRows, modelRows, pending] = await Promise.allSettled([
aiApi.providers(),
aiApi.models(),
aiApi.toolCalls({ authorizationStatus: 'APPROVAL_REQUIRED', executionStatus: 'PENDING', page: 1, pageSize: 1 })
])
const providers = providerRows.status === 'fulfilled' ? (providerRows.value || []) : []
const models = modelRows.status === 'fulfilled' ? (modelRows.value || []) : []
counts.value = {
channels: providerRows.status === 'fulfilled' ? providers.length : null,
tools: pending.status === 'fulfilled' ? Number(pending.value?.total || 0) : null
}
channelMeta.value = {
reserved: providers.filter((item) => item.providerStatus !== 'ACTIVE').length,
unverified: models.filter((item) => item.modelStatus === 'UNVERIFIED').length
}
}
function select(key) {
if (tab.value === key) return
tab.value = key
router.replace({ query: { ...route.query, tab: key === 'channels' ? undefined : key } })
loadCounts()
}
watch(() => route.query.tab, (value) => {
const next = value ? String(value) : 'channels'
if (TABS.some((item) => item.key === next) && next !== tab.value) tab.value = next
})
loadCounts()
</script>
<template>
<div class="tabs-row">
<div class="tabs">
<button
v-for="item in TABS"
:key="item.key"
class="tab"
:class="{ active: tab === item.key }"
type="button" v-tooltip="item.hint"
@click="select(item.key)"
>
{{ item.label }}
<span
v-if="item.key === 'channels' && counts.channels"
:class="tab === 'channels' ? 'tab-badge' : 'tab-count'"
>{{ counts.channels }}</span>
<span
v-else-if="item.key === 'tools' && counts.tools"
:class="tab === 'tools' ? 'tab-badge' : 'tab-count'"
>{{ counts.tools }}</span>
</button>
</div>
<div v-if="tab === 'channels'" class="tab-side">
<span v-if="channelMeta.reserved" class="side-pill amber">预留 {{ channelMeta.reserved }}</span>
<span v-if="channelMeta.unverified" class="side-pill">未验证 {{ channelMeta.unverified }} 项</span>
</div>
</div>
<ChannelPanel v-if="tab === 'channels'" @changed="loadCounts" />
<CallPanel v-else-if="tab === 'calls'" />
<ToolPanel v-else-if="tab === 'tools'" />
<GovernancePanel v-else />
</template>
<style scoped>
.tabs-row {
display: flex; align-items: center; gap: 16px; border-bottom: 1px solid #edf0f5; margin-bottom: 12px;
}
.tabs-row .tabs { flex: 1; margin: 0; border-bottom: 0; }
.tab-badge {
display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px;
margin-left: 5px; padding: 0 5px; border-radius: 8px; background: #eef0fe; color: #4f5bef;
font-size: 9px; font-weight: 600; line-height: 1; vertical-align: 1px; font-variant-numeric: tabular-nums;
}
.tab-count { margin-left: 5px; color: #9aa1b2; font-size: 9px; font-variant-numeric: tabular-nums; }
.tab-side { display: flex; flex: none; gap: 8px; padding-right: 2px; }
.side-pill {
display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 4px;
background: #f3f4f6; color: #6b7280; font-size: 10px;
}
.side-pill.amber { background: #fffbeb; color: #b45309; }
</style>