重构前端 UI 并修复关键问题
## 主要变更 ### 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>
This commit is contained in:
1 parent
dad4087bca
commit
311f09fb0c
19 files changed
+2500
-1491
No files matched your search
+128
-235
@@ -1,276 +1,169 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#409eff"><Connection /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.sources }}</div>
|
||||
<div class="stat-label">数据源</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<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>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#67c23a"><Collection /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.topics }}</div>
|
||||
<div class="stat-label">主题</div>
|
||||
</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>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#e6a23c"><Document /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.reports }}</div>
|
||||
<div class="stat-label">报告</div>
|
||||
</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>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</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>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#f56c6c"><Reading /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.articles }}</div>
|
||||
<div class="stat-label">资讯</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>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20" style="margin-top: 20px">
|
||||
<el-col :span="12">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>最近报告</span>
|
||||
<el-button type="primary" link @click="$router.push('/reports')">
|
||||
查看更多
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-empty v-if="recentReports.length === 0" description="暂无报告" />
|
||||
<div v-else class="report-list">
|
||||
<div
|
||||
v-for="report in recentReports"
|
||||
:key="report.id"
|
||||
class="report-item"
|
||||
@click="$router.push(`/reports/${report.id}`)"
|
||||
>
|
||||
<div class="report-title">{{ report.title }}</div>
|
||||
<div class="report-meta">
|
||||
<el-tag :type="getStatusType(report.status)" size="small">
|
||||
{{ getStatusText(report.status) }}
|
||||
</el-tag>
|
||||
<span class="report-time">
|
||||
{{ formatTime(report.createdAt) }}
|
||||
</span>
|
||||
<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>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>采集状态</span>
|
||||
<el-button type="primary" link @click="$router.push('/monitoring')">
|
||||
查看详情
|
||||
</el-button>
|
||||
<!-- 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>
|
||||
</template>
|
||||
<el-empty v-if="collectionStats.length === 0" description="暂无数据" />
|
||||
<div v-else class="collection-list">
|
||||
<div
|
||||
v-for="stat in collectionStats"
|
||||
:key="stat.id"
|
||||
class="collection-item"
|
||||
>
|
||||
<div class="collection-name">{{ stat.name }}</div>
|
||||
<div class="collection-meta">
|
||||
<el-tag
|
||||
:type="stat.lastLog?.status === 'success' ? 'success' : (stat.lastLog ? 'danger' : 'info')"
|
||||
size="small"
|
||||
>
|
||||
{{ stat.lastLog?.status === 'success' ? '成功' : (stat.lastLog ? '失败' : '未采集') }}
|
||||
</el-tag>
|
||||
<span class="collection-time">
|
||||
{{ stat.lastCollectedAt ? formatTime(stat.lastCollectedAt) : '从未采集' }}
|
||||
</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>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<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, onMounted } from 'vue'
|
||||
import { Connection, Collection, Document, Reading } from '@element-plus/icons-vue'
|
||||
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 stats = ref({ sources: 0, topics: 0, reports: 0, articles: 0 })
|
||||
const recentReports = ref<Report[]>([])
|
||||
const collectionStats = ref<CollectionStats[]>([])
|
||||
|
||||
const loadStats = async () => {
|
||||
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 [sourcesRes, topicsRes, reportsRes, articlesRes] = await Promise.all([
|
||||
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: sourcesRes.pagination?.total || 0,
|
||||
topics: topicsRes.pagination?.total || 0,
|
||||
reports: reportsRes.pagination?.total || 0,
|
||||
articles: articlesRes.pagination?.total || 0,
|
||||
sources: s.pagination?.total || 0,
|
||||
topics: t.pagination?.total || 0,
|
||||
reports: r.pagination?.total || 0,
|
||||
articles: a.pagination?.total || 0,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败', error)
|
||||
|
||||
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 loadRecentReports = async () => {
|
||||
try {
|
||||
const res = await request.get('/reports', { params: { limit: 5 } })
|
||||
recentReports.value = res.data || []
|
||||
} catch (error) {
|
||||
console.error('加载最近报告失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadCollectionStats = async () => {
|
||||
try {
|
||||
const res = await request.get('/collection-logs/stats')
|
||||
collectionStats.value = (res.data || []).slice(0, 5)
|
||||
} catch (error) {
|
||||
console.error('加载采集状态失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusType = (status: string) => {
|
||||
const map: Record<string, 'info' | 'warning' | 'success' | 'danger'> = {
|
||||
pending: 'info',
|
||||
generating: 'warning',
|
||||
completed: 'success',
|
||||
failed: 'danger',
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
pending: '待处理',
|
||||
generating: '生成中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
const map: any = { pending: '等待中', generating: '生成中', completed: '已就绪', failed: '失败' }
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
const formatTime = (time: string | null) => {
|
||||
if (!time) return '未知'
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
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] || ''
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStats()
|
||||
loadRecentReports()
|
||||
loadCollectionStats()
|
||||
})
|
||||
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>
|
||||
|
||||
<style scoped>
|
||||
.stat-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
margin-top: 5px;
|
||||
color: #909399;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.report-item,
|
||||
.collection-item {
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.report-item:last-child,
|
||||
.collection-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.report-item:hover,
|
||||
.collection-item:hover {
|
||||
background-color: #f5f7fa;
|
||||
margin: 0 -20px;
|
||||
padding: 12px 20px;
|
||||
}
|
||||
|
||||
.report-title,
|
||||
.collection-name {
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.report-meta,
|
||||
.collection-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user