## 主要变更 ### UI 重构(基于 Gemini) - 引入 Tailwind CSS 设计系统,替换原有样式 - 重构所有主要页面组件(Dashboard、AgentChat、Sources 等) - 新增 CommandPalette 和 ToolCallDisplay 组件 - 优化布局和交互体验 ### 关键问题修复 1. 修复 AI 对话页面 TypeError 错误 - 问题:后端 conversations API 返回格式不标准,导致前端访问 res.data 为 undefined - 修复:agent.ts 中使用 `res.data ?? res as any ?? []` 兼容两种响应格式 2. 修复 Tailwind CSS 样式未加载 - 问题:main.ts 中缺少 style.css 导入 - 修复:添加 `import './style.css'` 3. 安装缺失依赖 - 新增 @vueuse/core(MessageItem.vue 使用 useClipboard) - 新增 Tailwind CSS 相关依赖 ### 新增配置 - postcss.config.js - PostCSS 配置 - tailwind.config.js - Tailwind 主题配置 - user.ts store - 用户状态管理 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
170 lines
7.5 KiB
Vue
170 lines
7.5 KiB
Vue
<template>
|
|
<div class="space-y-8 animate-in fade-in duration-500">
|
|
<div class="flex flex-col gap-2">
|
|
<h2 class="text-3xl font-bold tracking-tight">概览 (Insights)</h2>
|
|
<p class="text-muted-foreground text-sm">系统当前运行状态与资讯采集实时汇总</p>
|
|
</div>
|
|
|
|
<!-- Bento Grid Stats -->
|
|
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
|
<div v-for="stat in statsCards" :key="stat.label" class="rounded-xl border bg-card p-6 shadow-sm transition-all hover:shadow-md group">
|
|
<div class="flex items-center justify-between">
|
|
<div class="space-y-1">
|
|
<p class="text-xs font-bold text-muted-foreground uppercase tracking-wider">{{ stat.label }}</p>
|
|
<h3 class="text-2xl font-bold tabular-nums">{{ stat.value }}</h3>
|
|
</div>
|
|
<div :class="['rounded-lg p-2.5 transition-colors group-hover:scale-110 duration-300', stat.bgClass]">
|
|
<component :is="stat.icon" :class="['h-5 w-5', stat.iconClass]" />
|
|
</div>
|
|
</div>
|
|
<div class="mt-4 flex items-center text-[10px] text-muted-foreground">
|
|
<TrendingUp class="mr-1 h-3 w-3 text-green-500" />
|
|
<span>较上周增长 12%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Content Area -->
|
|
<div class="grid gap-6 md:grid-cols-7">
|
|
<!-- Recent Reports (4 cols) -->
|
|
<div class="col-span-4 rounded-xl border bg-card shadow-sm overflow-hidden flex flex-col">
|
|
<div class="flex items-center justify-between border-b px-6 py-4 bg-muted/30">
|
|
<h3 class="font-semibold flex items-center gap-2">
|
|
<FileText class="h-4 w-4 text-blue-500" />
|
|
最近生成的报告
|
|
</h3>
|
|
<button @click="$router.push('/reports')" class="text-xs font-medium text-blue-600 hover:underline">全部</button>
|
|
</div>
|
|
<div class="flex-1 overflow-y-auto max-h-[400px]">
|
|
<div v-if="recentReports.length === 0" class="p-12 text-center text-muted-foreground italic text-sm">
|
|
暂无报告生成
|
|
</div>
|
|
<div
|
|
v-for="report in recentReports"
|
|
:key="report.id"
|
|
@click="$router.push(`/reports/${report.id}`)"
|
|
class="flex items-center justify-between px-6 py-4 border-b last:border-0 hover:bg-muted/50 cursor-pointer transition-colors"
|
|
>
|
|
<div class="space-y-1 overflow-hidden pr-4">
|
|
<p class="text-sm font-medium truncate">{{ report.title }}</p>
|
|
<div class="flex items-center gap-2 text-[10px] text-muted-foreground">
|
|
<span class="px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-600 font-bold uppercase">{{ report.topic?.name }}</span>
|
|
<span>•</span>
|
|
<span>{{ formatTime(report.createdAt) }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center gap-3">
|
|
<span :class="['text-[10px] px-2 py-0.5 rounded-full font-semibold', getStatusClass(report.status)]">
|
|
{{ getStatusText(report.status) }}
|
|
</span>
|
|
<ChevronRight class="h-4 w-4 text-muted-foreground/50" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Collection Health (3 cols) -->
|
|
<div class="col-span-3 rounded-xl border bg-card shadow-sm flex flex-col">
|
|
<div class="flex items-center justify-between border-b px-6 py-4 bg-muted/30">
|
|
<h3 class="font-semibold flex items-center gap-2">
|
|
<Activity class="h-4 w-4 text-green-500" />
|
|
采集健康度
|
|
</h3>
|
|
<button @click="$router.push('/monitoring')" class="text-xs font-medium text-blue-600 hover:underline">监控详情</button>
|
|
</div>
|
|
<div class="p-6 space-y-6">
|
|
<div v-for="stat in collectionStats" :key="stat.id" class="space-y-3">
|
|
<div class="flex items-center justify-between text-sm">
|
|
<span class="font-medium text-foreground/80">{{ stat.name }}</span>
|
|
<span :class="['text-[10px] px-2 py-0.5 rounded uppercase font-bold', stat.lastLog?.status === 'success' ? 'bg-green-500/10 text-green-600' : 'bg-red-500/10 text-red-600']">
|
|
{{ stat.lastLog?.status === 'success' ? '正常' : '异常' }}
|
|
</span>
|
|
</div>
|
|
<div class="h-1.5 w-full rounded-full bg-muted overflow-hidden">
|
|
<div
|
|
class="h-full bg-blue-500 transition-all duration-1000"
|
|
:style="{ width: `${Math.min((stat.totalArticles / 100) * 100, 100)}%` }"
|
|
></div>
|
|
</div>
|
|
<div class="flex justify-between text-[10px] text-muted-foreground">
|
|
<span>共采集 {{ stat.totalArticles }} 条</span>
|
|
<span>最后运行: {{ stat.lastCollectedAt ? formatTime(stat.lastCollectedAt) : '从未' }}</span>
|
|
</div>
|
|
</div>
|
|
<div v-if="collectionStats.length === 0" class="text-center py-8 opacity-50 italic text-sm">
|
|
暂无监控数据
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, computed, onMounted } from 'vue'
|
|
import {
|
|
Link, Library, FileText, Newspaper,
|
|
Activity, TrendingUp, ChevronRight
|
|
} from 'lucide-vue-next'
|
|
import request from '@/api/request'
|
|
import type { Report, CollectionStats } from '@/api/types'
|
|
|
|
const stats = ref({ sources: 0, topics: 0, reports: 0, articles: 0 })
|
|
const recentReports = ref<Report[]>([])
|
|
const collectionStats = ref<CollectionStats[]>([])
|
|
|
|
const statsCards = computed(() => [
|
|
{ label: '数据源', value: stats.value.sources, icon: Link, bgClass: 'bg-blue-500/10', iconClass: 'text-blue-600' },
|
|
{ label: '订阅主题', value: stats.value.topics, icon: Library, bgClass: 'bg-green-500/10', iconClass: 'text-green-600' },
|
|
{ label: '资讯快报', value: stats.value.reports, icon: FileText, bgClass: 'bg-amber-500/10', iconClass: 'text-amber-600' },
|
|
{ label: '采集文章', value: stats.value.articles, icon: Newspaper, bgClass: 'bg-purple-500/10', iconClass: 'text-purple-600' },
|
|
])
|
|
|
|
const loadData = async () => {
|
|
try {
|
|
const [s, t, r, a] = await Promise.all([
|
|
request.get('/sources', { params: { limit: 1 } }),
|
|
request.get('/topics', { params: { limit: 1 } }),
|
|
request.get('/reports', { params: { limit: 1 } }),
|
|
request.get('/articles', { params: { limit: 1 } }),
|
|
])
|
|
stats.value = {
|
|
sources: s.pagination?.total || 0,
|
|
topics: t.pagination?.total || 0,
|
|
reports: r.pagination?.total || 0,
|
|
articles: a.pagination?.total || 0,
|
|
}
|
|
|
|
const reportsRes = await request.get('/reports', { params: { limit: 5 } })
|
|
recentReports.value = reportsRes.data || []
|
|
|
|
const statsRes = await request.get('/collection-logs/stats')
|
|
collectionStats.value = (statsRes.data || []).slice(0, 4)
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
}
|
|
|
|
const getStatusText = (status: string) => {
|
|
const map: any = { pending: '等待中', generating: '生成中', completed: '已就绪', failed: '失败' }
|
|
return map[status] || status
|
|
}
|
|
|
|
const getStatusClass = (status: string) => {
|
|
const map: any = {
|
|
pending: 'bg-muted text-muted-foreground',
|
|
generating: 'bg-amber-500/10 text-amber-600',
|
|
completed: 'bg-green-500/10 text-green-600',
|
|
failed: 'bg-red-500/10 text-red-600'
|
|
}
|
|
return map[status] || ''
|
|
}
|
|
|
|
const formatTime = (time: string) => {
|
|
const date = new Date(time)
|
|
return `${date.getMonth()+1}/${date.getDate()} ${date.getHours()}:${date.getMinutes().toString().padStart(2, '0')}`
|
|
}
|
|
|
|
onMounted(loadData)
|
|
</script>
|