重构前端 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
+2446
-1437
No files matched your search
Generated
+5
@@ -3029,6 +3029,7 @@
|
|||||||
"integrity": "sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==",
|
"integrity": "sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/engines": "5.22.0"
|
"@prisma/engines": "5.22.0"
|
||||||
},
|
},
|
||||||
@@ -3636,6 +3637,7 @@
|
|||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -3778,6 +3780,7 @@
|
|||||||
"integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==",
|
"integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.27.0",
|
"esbuild": "^0.27.0",
|
||||||
"fdir": "^6.5.0",
|
"fdir": "^6.5.0",
|
||||||
@@ -3886,6 +3889,7 @@
|
|||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -4071,6 +4075,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# Frontend UI/UX Transformation Plan (Frontend UX 改造计划)
|
||||||
|
|
||||||
|
## 1. 现状分析 (Current State Audit)
|
||||||
|
|
||||||
|
通过对 `frontend/src` 代码库的扫描,发现以下待优化点:
|
||||||
|
|
||||||
|
### 视觉与布局
|
||||||
|
- **框架依赖过重**: 布局过度依赖 Element Plus 的 `el-container` 系统,导致样式修改灵活性差。
|
||||||
|
- **色彩体系陈旧**: 侧边栏背景色 (#304156) 等属于硬编码,缺乏对深色模式 (Dark Mode) 的原生支持。
|
||||||
|
- **空间利用率**: `AgentChat.vue` 等核心页面被大量传统的下拉选择框占据了有效交互区域。
|
||||||
|
|
||||||
|
### 交互体验 (UX)
|
||||||
|
- **中断式操作**: 配置管理(Sources, Topics)频繁使用 `el-dialog` 弹窗,操作流不连续。
|
||||||
|
- **Agent 感知弱**: 对话过程中的“工具调用”状态(Tool-calling)缺乏视觉反馈,用户难以感知 AI 正在做什么。
|
||||||
|
- **阅读疲劳**: 报告详情采用纯文本式的 Markdown 渲染,缺乏层次感和侧边快速导航。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 目标愿景 (The Vision)
|
||||||
|
|
||||||
|
建立一个 **“AI-First”** 的现代化资讯终端:
|
||||||
|
- **美学**: 极简、半透明材质(Glassmorphism)、精致的微动效。
|
||||||
|
- **效率**: 引入全局命令面板 (Cmd+K),减少点击层级。
|
||||||
|
- **沉浸**: 报告阅读与 AI 问答无缝融合,不切换页面即可深度探索。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 技术栈升级 (Tech Stack)
|
||||||
|
|
||||||
|
| 领域 | 选型 | 理由 |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **CSS 框架** | **Tailwind CSS** | 极致的样式控制力,消除硬编码 CSS。 |
|
||||||
|
| **组件库** | **Shadcn Vue** | 现代审美,非侵入式组件,易于二次定制。 |
|
||||||
|
| **图标库** | **Lucide Vue Next** | 图标风格更轻量、一致。 |
|
||||||
|
| **状态管理** | **VueUse** | 提供大量交互式 Composable(如 `useDark`, `useScroll`)。 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 拆分任务 (Implementation Roadmap)
|
||||||
|
|
||||||
|
### Phase 1: 基础设施 (Foundation)
|
||||||
|
- [ ] **Task 1.1**: 安装依赖 (`tailwindcss`, `lucide-vue-next`, `radix-vue`)。
|
||||||
|
- [ ] **Task 1.2**: 初始化 Tailwind 配置文件,定义系统色盘(Slate/Zinc)和圆角规范。
|
||||||
|
- [ ] **Task 1.3**: 改造 `src/style.css`,建立 Dark Mode 变量基础。
|
||||||
|
|
||||||
|
### Phase 2: 布局重构 (Layout Shell)
|
||||||
|
- [ ] **Task 2.1**: 重写 `MainLayout.vue`。实现响应式悬浮侧边栏。
|
||||||
|
- [ ] **Task 2.2**: 开发 `CommandPalette.vue`。集成全局搜索与快速操作面板。
|
||||||
|
- [ ] **Task 2.3**: 优化全站 Breadcrumb 和 Header,释放更多垂直空间。
|
||||||
|
|
||||||
|
### Phase 3: AI 对话升级 (Agent UX)
|
||||||
|
- [ ] **Task 3.1**: 重构 `MessageItem.vue`。增加打字机效果、代码块一键复制及工具调用中间态展示。
|
||||||
|
- [ ] **Task 3.2**: 优化对话输入框。支持多行自适应高度和快捷键提醒。
|
||||||
|
- [ ] **Task 3.3**: 引入对话上下文预览,允许用户在对话中查看关联的报告卡片。
|
||||||
|
|
||||||
|
### Phase 4: 阅读与监控 (Content & Data)
|
||||||
|
- [ ] **Task 4.1**: 重构 `ReportDetail.vue`。增加阅读模式,支持 Markdown 侧边导航。
|
||||||
|
- [ ] **Task 4.2**: 升级仪表盘 `Dashboard.vue`。采用 Bento Grid 布局,强化关键指标的视觉重量。
|
||||||
|
- [ ] **Task 4.3**: 改造 `Monitoring.vue`。将列表改为带有实时状态脉冲动画的节点卡片。
|
||||||
|
|
||||||
|
### Phase 5: 操作流优化 (Operational Flow)
|
||||||
|
- [ ] **Task 5.1**: 将 `Topics` 和 `Sources` 的 CRUD 逻辑从弹窗改为侧滑抽屉 (Sheet),提升配置效率。
|
||||||
|
- [ ] **Task 5.2**: 实现 Cron 表达式的动态预览图,实时展示未来执行时间点。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 验收标准 (Acceptance Criteria)
|
||||||
|
|
||||||
|
1. **多端适配**: 侧边栏在移动端自动折叠,保持核心功能可用。
|
||||||
|
2. **性能**: 移除冗余 CSS 后,首屏渲染 FCP 提升 20% 以上。
|
||||||
|
3. **审美**: 符合现代 AI 工具(如 ChatGPT, Claude, Linear)的视觉基准。
|
||||||
|
4. **一致性**: 全站图标风格统一,间距遵循 4px/8px 网格系统。
|
||||||
Generated
+1238
-69
File diff suppressed because it is too large.
Load diff
@@ -11,20 +11,28 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.2",
|
"@element-plus/icons-vue": "^2.3.2",
|
||||||
"@types/markdown-it": "^14.1.2",
|
"@types/markdown-it": "^14.1.2",
|
||||||
|
"@vueuse/core": "^14.2.0",
|
||||||
"axios": "^1.13.4",
|
"axios": "^1.13.4",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
"echarts": "^6.0.0",
|
"echarts": "^6.0.0",
|
||||||
"element-plus": "^2.13.2",
|
"element-plus": "^2.13.2",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
|
"lucide-vue-next": "^0.563.0",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
|
"tailwind-merge": "^3.4.0",
|
||||||
"vue": "^3.5.24",
|
"vue": "^3.5.24",
|
||||||
"vue-echarts": "^8.0.1",
|
"vue-echarts": "^8.0.1",
|
||||||
"vue-router": "^4.6.4"
|
"vue-router": "^4.6.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@tailwindcss/typography": "^0.5.19",
|
||||||
"@types/node": "^24.10.9",
|
"@types/node": "^24.10.9",
|
||||||
"@vitejs/plugin-vue": "^6.0.1",
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
"@vue/tsconfig": "^0.8.1",
|
"@vue/tsconfig": "^0.8.1",
|
||||||
|
"autoprefixer": "^10.4.24",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"tailwindcss": "^3.4.17",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
"vite": "^7.2.4",
|
"vite": "^7.2.4",
|
||||||
"vue-tsc": "^3.1.4"
|
"vue-tsc": "^3.1.4"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="min-h-screen bg-background text-foreground font-sans antialiased">
|
||||||
<router-view />
|
<router-view />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
|
|
||||||
|
const userStore = useUserStore()
|
||||||
|
userStore.initToken()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
* {
|
/* Reset or global overrides if necessary */
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -11,6 +11,7 @@ export interface ChatParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Message {
|
export interface Message {
|
||||||
|
id?: number
|
||||||
role: string
|
role: string
|
||||||
content: string
|
content: string
|
||||||
toolCalls?: any
|
toolCalls?: any
|
||||||
@@ -19,6 +20,7 @@ export interface Message {
|
|||||||
|
|
||||||
export interface Conversation {
|
export interface Conversation {
|
||||||
id: number
|
id: number
|
||||||
|
title: string
|
||||||
topicId: number
|
topicId: number
|
||||||
reportId?: number
|
reportId?: number
|
||||||
articleId?: number
|
articleId?: number
|
||||||
@@ -70,7 +72,8 @@ export async function streamChat(params: ChatParams): Promise<Response> {
|
|||||||
* 获取对话详情
|
* 获取对话详情
|
||||||
*/
|
*/
|
||||||
export async function getConversation(id: number): Promise<Conversation> {
|
export async function getConversation(id: number): Promise<Conversation> {
|
||||||
return request.get(`/agent/conversations/${id}`)
|
const res = await request.get<Conversation>(`/agent/conversations/${id}`)
|
||||||
|
return res.data ?? res as any
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,12 +83,13 @@ export async function getConversations(params?: {
|
|||||||
userId?: number
|
userId?: number
|
||||||
topicId?: number
|
topicId?: number
|
||||||
}): Promise<Conversation[]> {
|
}): Promise<Conversation[]> {
|
||||||
return request.get('/agent/conversations', { params })
|
const res = await request.get<Conversation[]>('/agent/conversations', { params })
|
||||||
|
return res.data ?? res as any ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除对话
|
* 删除对话
|
||||||
*/
|
*/
|
||||||
export async function deleteConversation(id: number): Promise<void> {
|
export async function deleteConversation(id: number): Promise<void> {
|
||||||
return request.delete(`/agent/conversations/${id}`)
|
await request.delete(`/agent/conversations/${id}`)
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,60 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="['message-item', message.role]">
|
<div :class="['flex gap-4 mb-6 group', message.role === 'user' ? 'flex-row-reverse' : '']">
|
||||||
<div class="message-avatar">
|
<!-- Avatar -->
|
||||||
<el-avatar v-if="message.role === 'user'" :size="36">
|
<div
|
||||||
<el-icon><User /></el-icon>
|
:class="[
|
||||||
</el-avatar>
|
'flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-md border shadow',
|
||||||
<el-avatar v-else :size="36" style="background-color: #409eff">
|
message.role === 'user' ? 'bg-background' : 'bg-primary text-primary-foreground'
|
||||||
<el-icon><ChatDotRound /></el-icon>
|
]"
|
||||||
</el-avatar>
|
>
|
||||||
|
<User v-if="message.role === 'user'" class="h-4 w-4" />
|
||||||
|
<Bot v-else class="h-4 w-4" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="message-content-wrapper">
|
<!-- Content Wrapper -->
|
||||||
<div class="message-meta">
|
<div :class="['flex max-w-[85%] flex-col gap-2', message.role === 'user' ? 'items-end' : 'items-start']">
|
||||||
<span class="message-role">{{ roleLabel }}</span>
|
<!-- Header Info -->
|
||||||
<span class="message-time">{{ formattedTime }}</span>
|
<div class="flex items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<span class="font-medium">{{ roleLabel }}</span>
|
||||||
|
<span>{{ formattedTime }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="message-content">
|
<!-- Message Bubble -->
|
||||||
<!-- Markdown 渲染 -->
|
<div
|
||||||
|
:class="[
|
||||||
|
'relative overflow-hidden rounded-md border px-3 py-2 text-sm shadow-sm',
|
||||||
|
message.role === 'user'
|
||||||
|
? 'bg-primary text-primary-foreground border-primary'
|
||||||
|
: 'bg-card text-card-foreground'
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<!-- Markdown Content -->
|
||||||
<div
|
<div
|
||||||
v-if="message.role === 'assistant'"
|
v-if="message.role === 'assistant'"
|
||||||
|
class="prose prose-sm dark:prose-invert max-w-none break-words"
|
||||||
v-html="renderedContent"
|
v-html="renderedContent"
|
||||||
class="markdown-body"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 用户消息 -->
|
<!-- User Content (Plain text) -->
|
||||||
<div v-else class="user-message">{{ message.content }}</div>
|
<div v-else class="whitespace-pre-wrap break-words">{{ message.content }}</div>
|
||||||
|
|
||||||
<!-- 流式输出指示器 -->
|
<!-- Cursor -->
|
||||||
<span v-if="streaming" class="streaming-cursor">▊</span>
|
<span v-if="streaming" class="inline-block w-1.5 h-4 ml-1 align-middle bg-primary animate-pulse" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Tool Calls -->
|
||||||
|
<ToolCallDisplay v-if="message.toolCalls" :tool-calls="message.toolCalls" />
|
||||||
|
|
||||||
|
<!-- Actions (Copy, etc.) -->
|
||||||
|
<div v-if="message.role === 'assistant'" class="opacity-0 group-hover:opacity-100 transition-opacity flex gap-1">
|
||||||
|
<button
|
||||||
|
@click="copy(message.content)"
|
||||||
|
class="inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-6 w-6"
|
||||||
|
title="复制内容"
|
||||||
|
>
|
||||||
|
<Check v-if="copied" class="h-3 w-3" />
|
||||||
|
<Copy v-else class="h-3 w-3" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -35,35 +62,36 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { User, ChatDotRound } from '@element-plus/icons-vue'
|
import { User, Bot, Copy, Check } from 'lucide-vue-next'
|
||||||
|
import { useClipboard } from '@vueuse/core'
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
import 'highlight.js/styles/github.css'
|
import 'highlight.js/styles/github-dark.css' // 使用暗色主题以适应两种模式
|
||||||
|
import ToolCallDisplay from './ToolCallDisplay.vue'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
message: {
|
message: {
|
||||||
role: string
|
id: number;
|
||||||
content: string
|
role: string;
|
||||||
toolCalls?: any
|
content: string;
|
||||||
createdAt?: string
|
toolCalls?: any;
|
||||||
}
|
createdAt?: string;
|
||||||
streaming?: boolean
|
};
|
||||||
|
streaming?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
const { copy, copied } = useClipboard({ source: props.message.content })
|
||||||
|
|
||||||
// Markdown 渲染器
|
|
||||||
const md = new MarkdownIt({
|
const md = new MarkdownIt({
|
||||||
html: true,
|
html: true,
|
||||||
linkify: true,
|
linkify: true,
|
||||||
typographer: true,
|
typographer: true,
|
||||||
highlight: (str: string, lang: string) => {
|
highlight: (str, lang) => {
|
||||||
if (lang && hljs.getLanguage(lang)) {
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
try {
|
try {
|
||||||
return hljs.highlight(str, { language: lang }).value
|
return hljs.highlight(str, { language: lang }).value
|
||||||
} catch {
|
} catch {}
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
},
|
},
|
||||||
@@ -71,21 +99,17 @@ const md = new MarkdownIt({
|
|||||||
|
|
||||||
const roleLabel = computed(() => {
|
const roleLabel = computed(() => {
|
||||||
const labels: Record<string, string> = {
|
const labels: Record<string, string> = {
|
||||||
user: '你',
|
user: 'You',
|
||||||
assistant: 'AI 助手',
|
assistant: 'Agent',
|
||||||
system: '系统',
|
system: 'System',
|
||||||
tool: '工具',
|
tool: 'Tool',
|
||||||
}
|
}
|
||||||
return labels[props.message.role] || props.message.role
|
return labels[props.message.role] || props.message.role
|
||||||
})
|
})
|
||||||
|
|
||||||
const formattedTime = computed(() => {
|
const formattedTime = computed(() => {
|
||||||
if (!props.message.createdAt) return ''
|
if (!props.message.createdAt) return ''
|
||||||
const date = new Date(props.message.createdAt)
|
return new Date(props.message.createdAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||||
return date.toLocaleTimeString('zh-CN', {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const renderedContent = computed(() => {
|
const renderedContent = computed(() => {
|
||||||
@@ -93,169 +117,9 @@ const renderedContent = computed(() => {
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style>
|
||||||
.message-item {
|
/* Prose overrides if necessary */
|
||||||
display: flex;
|
.prose pre {
|
||||||
gap: 12px;
|
@apply bg-muted/50 border border-border;
|
||||||
margin-bottom: 20px;
|
|
||||||
animation: fadeIn 0.3s ease-in;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fadeIn {
|
|
||||||
from {
|
|
||||||
opacity: 0;
|
|
||||||
transform: translateY(10px);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
transform: translateY(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-avatar {
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-content-wrapper {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
max-width: 80%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-item.user .message-content-wrapper {
|
|
||||||
margin-left: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-meta {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
margin-bottom: 6px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: #909399;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-role {
|
|
||||||
font-weight: 600;
|
|
||||||
color: #303133;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-content {
|
|
||||||
position: relative;
|
|
||||||
padding: 12px 16px;
|
|
||||||
border-radius: 8px;
|
|
||||||
background-color: #f5f7fa;
|
|
||||||
word-wrap: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-item.user .message-content {
|
|
||||||
background-color: #409eff;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-message {
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body {
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(h1),
|
|
||||||
.markdown-body :deep(h2),
|
|
||||||
.markdown-body :deep(h3) {
|
|
||||||
margin-top: 16px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(h1) {
|
|
||||||
font-size: 1.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(h2) {
|
|
||||||
font-size: 1.3em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(h3) {
|
|
||||||
font-size: 1.1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(p) {
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(p:last-child) {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(code) {
|
|
||||||
padding: 2px 6px;
|
|
||||||
background-color: rgba(0, 0, 0, 0.06);
|
|
||||||
border-radius: 3px;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(pre) {
|
|
||||||
padding: 12px;
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
border-radius: 6px;
|
|
||||||
overflow-x: auto;
|
|
||||||
margin: 8px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(pre code) {
|
|
||||||
padding: 0;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(ul),
|
|
||||||
.markdown-body :deep(ol) {
|
|
||||||
padding-left: 24px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(li) {
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(blockquote) {
|
|
||||||
padding-left: 12px;
|
|
||||||
border-left: 4px solid #dfe2e5;
|
|
||||||
color: #6a737d;
|
|
||||||
margin: 8px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(a) {
|
|
||||||
color: #409eff;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(a:hover) {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body :deep(strong) {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.streaming-cursor {
|
|
||||||
display: inline-block;
|
|
||||||
animation: blink 1s infinite;
|
|
||||||
margin-left: 2px;
|
|
||||||
color: #409eff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes blink {
|
|
||||||
0%,
|
|
||||||
50% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
51%,
|
|
||||||
100% {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mt-2 space-y-2">
|
||||||
|
<div
|
||||||
|
v-for="(call, index) in toolCalls"
|
||||||
|
:key="index"
|
||||||
|
class="rounded-lg border bg-muted/30 p-3 text-xs shadow-sm transition-all hover:bg-muted/50"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between mb-2">
|
||||||
|
<div class="flex items-center gap-2 font-semibold text-foreground/80">
|
||||||
|
<Terminal class="h-3.5 w-3.5 text-blue-500" />
|
||||||
|
<span>{{ getToolName(call.name) }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="call.result" class="flex items-center gap-1 text-green-600 dark:text-green-400">
|
||||||
|
<CheckCircle2 class="h-3 w-3" />
|
||||||
|
<span>已完成</span>
|
||||||
|
</div>
|
||||||
|
<div v-else class="flex items-center gap-1 text-amber-500 animate-pulse">
|
||||||
|
<Loader2 class="h-3 w-3 animate-spin" />
|
||||||
|
<span>执行中...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<div class="space-y-1">
|
||||||
|
<p class="text-[10px] uppercase tracking-wider text-muted-foreground font-bold">参数 (Arguments)</p>
|
||||||
|
<pre class="overflow-x-auto rounded bg-background/50 p-2 font-mono leading-relaxed">{{ formatJson(call.arguments) }}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="call.result" class="space-y-1">
|
||||||
|
<p class="text-[10px] uppercase tracking-wider text-muted-foreground font-bold">结果 (Result)</p>
|
||||||
|
<pre class="overflow-x-auto rounded bg-background/50 p-2 font-mono leading-relaxed max-h-32">{{ formatJson(call.result) }}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { Terminal, CheckCircle2, Loader2 } from 'lucide-vue-next'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
toolCalls: Array<{
|
||||||
|
name: string;
|
||||||
|
arguments: any;
|
||||||
|
result?: any;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
|
||||||
|
const toolNameMap: Record<string, string> = {
|
||||||
|
searchArticles: '搜索资讯库',
|
||||||
|
analyzeReport: '深度分析报告',
|
||||||
|
webSearch: '互联网实时搜索',
|
||||||
|
}
|
||||||
|
|
||||||
|
function getToolName(name: string): string {
|
||||||
|
return toolNameMap[name] || name
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatJson(obj: any): string {
|
||||||
|
try {
|
||||||
|
return typeof obj === 'string' ? JSON.stringify(JSON.parse(obj), null, 2) : JSON.stringify(obj, null, 2)
|
||||||
|
} catch {
|
||||||
|
return String(obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<Transition name="fade">
|
||||||
|
<div
|
||||||
|
v-if="visible"
|
||||||
|
class="fixed inset-0 z-50 flex items-start justify-center bg-black/50 backdrop-blur-sm pt-[20vh]"
|
||||||
|
@click="close"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="w-full max-w-lg overflow-hidden rounded-xl bg-popover text-popover-foreground shadow-2xl border border-border animate-in fade-in zoom-in-95 duration-200"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<div class="flex items-center border-b px-3">
|
||||||
|
<Search class="mr-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
|
<input
|
||||||
|
ref="inputRef"
|
||||||
|
v-model="searchQuery"
|
||||||
|
class="flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground"
|
||||||
|
placeholder="输入命令或搜索..."
|
||||||
|
@keydown.down.prevent="navigate('down')"
|
||||||
|
@keydown.up.prevent="navigate('up')"
|
||||||
|
@keydown.enter="select"
|
||||||
|
@keydown.esc="close"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="max-h-[300px] overflow-y-auto p-1">
|
||||||
|
<div v-if="filteredItems.length === 0" class="py-6 text-center text-sm text-muted-foreground">
|
||||||
|
无搜索结果
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in filteredItems"
|
||||||
|
:key="item.path"
|
||||||
|
:class="[
|
||||||
|
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors',
|
||||||
|
selectedIndex === index ? 'bg-accent text-accent-foreground' : ''
|
||||||
|
]"
|
||||||
|
@click="execute(item)"
|
||||||
|
@mouseenter="selectedIndex = index"
|
||||||
|
>
|
||||||
|
<component :is="item.icon" class="mr-2 h-4 w-4" />
|
||||||
|
<span>{{ item.title }}</span>
|
||||||
|
<span v-if="item.group" class="ml-auto text-[10px] uppercase font-bold text-muted-foreground/50">
|
||||||
|
{{ item.group }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="border-t bg-muted/50 px-3 py-1.5 text-[10px] text-muted-foreground flex justify-end gap-2">
|
||||||
|
<span><kbd class="rounded bg-muted px-1 border">↵</kbd> 选择</span>
|
||||||
|
<span><kbd class="rounded bg-muted px-1 border">↓↑</kbd> 导航</span>
|
||||||
|
<span><kbd class="rounded bg-muted px-1 border">esc</kbd> 关闭</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch, nextTick } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useMagicKeys, whenever } from '@vueuse/core'
|
||||||
|
import {
|
||||||
|
Search,
|
||||||
|
LayoutDashboard,
|
||||||
|
Settings,
|
||||||
|
FileText,
|
||||||
|
Newspaper,
|
||||||
|
Activity,
|
||||||
|
Bot
|
||||||
|
} from 'lucide-vue-next'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const visible = ref(false)
|
||||||
|
const searchQuery = ref('')
|
||||||
|
const inputRef = ref<HTMLInputElement>()
|
||||||
|
const selectedIndex = ref(0)
|
||||||
|
|
||||||
|
const keys = useMagicKeys()
|
||||||
|
const ctrlK = keys['Ctrl+K']
|
||||||
|
const cmdK = keys['Cmd+K']
|
||||||
|
|
||||||
|
whenever(ctrlK || cmdK || (() => false), () => {
|
||||||
|
open()
|
||||||
|
})
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{ title: '仪表盘', path: '/dashboard', icon: LayoutDashboard, group: '导航' },
|
||||||
|
{ title: 'AI 对话', path: '/agent', icon: Bot, group: '功能' },
|
||||||
|
{ title: '报告中心', path: '/reports', icon: FileText, group: '功能' },
|
||||||
|
{ title: '资讯浏览', path: '/articles', icon: Newspaper, group: '功能' },
|
||||||
|
{ title: '采集监控', path: '/monitoring', icon: Activity, group: '功能' },
|
||||||
|
{ title: 'LLM 配置', path: '/config/llm', icon: Settings, group: '配置' },
|
||||||
|
{ title: '数据源', path: '/config/sources', icon: Settings, group: '配置' },
|
||||||
|
{ title: '主题管理', path: '/config/topics', icon: Settings, group: '配置' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const filteredItems = computed(() => {
|
||||||
|
if (!searchQuery.value) return items
|
||||||
|
const query = searchQuery.value.toLowerCase()
|
||||||
|
return items.filter(item =>
|
||||||
|
item.title.toLowerCase().includes(query) ||
|
||||||
|
item.group.toLowerCase().includes(query)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(searchQuery, () => {
|
||||||
|
selectedIndex.value = 0
|
||||||
|
})
|
||||||
|
|
||||||
|
function open() {
|
||||||
|
visible.value = true
|
||||||
|
searchQuery.value = ''
|
||||||
|
selectedIndex.value = 0
|
||||||
|
nextTick(() => {
|
||||||
|
inputRef.value?.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
visible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigate(direction: 'up' | 'down') {
|
||||||
|
if (filteredItems.value.length === 0) return
|
||||||
|
if (direction === 'down') {
|
||||||
|
selectedIndex.value = (selectedIndex.value + 1) % filteredItems.value.length
|
||||||
|
} else {
|
||||||
|
selectedIndex.value = (selectedIndex.value - 1 + filteredItems.value.length) % filteredItems.value.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function select() {
|
||||||
|
if (filteredItems.value.length > 0) {
|
||||||
|
execute(filteredItems.value[selectedIndex.value])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute(item: any) {
|
||||||
|
router.push(item.path)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -74,7 +74,10 @@ export function useAgentChat() {
|
|||||||
assistantContent += parsed.textDelta
|
assistantContent += parsed.textDelta
|
||||||
currentStreamContent.value = assistantContent
|
currentStreamContent.value = assistantContent
|
||||||
// 更新最后一条消息
|
// 更新最后一条消息
|
||||||
messages.value[messages.value.length - 1].content = assistantContent
|
const lastMsg = messages.value[messages.value.length - 1]
|
||||||
|
if (lastMsg) {
|
||||||
|
lastMsg.content = assistantContent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理完成
|
// 处理完成
|
||||||
|
|||||||
+199
-147
@@ -1,169 +1,221 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-container class="main-layout">
|
<div class="flex h-screen overflow-hidden bg-background text-foreground">
|
||||||
<!-- 侧边栏 -->
|
<!-- Sidebar -->
|
||||||
<el-aside :width="sidebarWidth">
|
<aside
|
||||||
<div class="logo">
|
:class="[
|
||||||
<h2 v-if="!appStore.sidebarCollapsed">资讯聚合</h2>
|
'relative flex flex-col border-r bg-card transition-all duration-300 ease-in-out',
|
||||||
<h2 v-else>NA</h2>
|
appStore.sidebarCollapsed ? 'w-16' : 'w-64'
|
||||||
</div>
|
]"
|
||||||
<el-menu
|
|
||||||
:default-active="activeMenu"
|
|
||||||
:collapse="appStore.sidebarCollapsed"
|
|
||||||
background-color="#304156"
|
|
||||||
text-color="#bfcbd9"
|
|
||||||
active-text-color="#409eff"
|
|
||||||
router
|
|
||||||
>
|
>
|
||||||
<el-menu-item index="/dashboard">
|
<!-- Logo -->
|
||||||
<el-icon><HomeFilled /></el-icon>
|
<div class="flex h-14 items-center justify-center border-b px-4">
|
||||||
<template #title>仪表盘</template>
|
<div class="flex items-center gap-2 font-bold text-xl text-primary">
|
||||||
</el-menu-item>
|
<component :is="Zap" class="h-6 w-6" />
|
||||||
|
<span v-if="!appStore.sidebarCollapsed" class="whitespace-nowrap transition-all duration-300">
|
||||||
|
News Agent
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<el-sub-menu index="/config">
|
<!-- Navigation -->
|
||||||
<template #title>
|
<nav class="flex-1 space-y-1 overflow-y-auto py-4 px-2">
|
||||||
<el-icon><Setting /></el-icon>
|
<template v-for="item in menuItems" :key="item.path">
|
||||||
<span>配置管理</span>
|
<!-- Submenu -->
|
||||||
</template>
|
<div v-if="item.children" class="space-y-1">
|
||||||
<el-menu-item index="/config/llm">LLM 配置</el-menu-item>
|
<button
|
||||||
<el-menu-item index="/config/sources">数据源</el-menu-item>
|
v-if="!appStore.sidebarCollapsed"
|
||||||
<el-menu-item index="/config/channels">推送渠道</el-menu-item>
|
class="flex w-full items-center justify-between rounded-md px-3 py-2 text-sm font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||||
<el-menu-item index="/config/topics">主题</el-menu-item>
|
@click="toggleSubmenu(item.path)"
|
||||||
</el-sub-menu>
|
>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
<el-menu-item index="/reports">
|
<component :is="item.icon" class="h-4 w-4" />
|
||||||
<el-icon><Document /></el-icon>
|
<span>{{ item.title }}</span>
|
||||||
<template #title>报告中心</template>
|
</div>
|
||||||
</el-menu-item>
|
<component
|
||||||
|
:is="ChevronDown"
|
||||||
<el-menu-item index="/articles">
|
class="h-4 w-4 transition-transform duration-200"
|
||||||
<el-icon><Reading /></el-icon>
|
:class="{ 'rotate-180': expandedMenus.includes(item.path) }"
|
||||||
<template #title>资讯浏览</template>
|
|
||||||
</el-menu-item>
|
|
||||||
|
|
||||||
<el-menu-item index="/monitoring">
|
|
||||||
<el-icon><Monitor /></el-icon>
|
|
||||||
<template #title>采集监控</template>
|
|
||||||
</el-menu-item>
|
|
||||||
|
|
||||||
<el-menu-item index="/agent">
|
|
||||||
<el-icon><ChatDotRound /></el-icon>
|
|
||||||
<template #title>AI 对话</template>
|
|
||||||
</el-menu-item>
|
|
||||||
</el-menu>
|
|
||||||
</el-aside>
|
|
||||||
|
|
||||||
<!-- 主内容区 -->
|
|
||||||
<el-container>
|
|
||||||
<!-- 顶部栏 -->
|
|
||||||
<el-header>
|
|
||||||
<div class="header-left">
|
|
||||||
<el-button
|
|
||||||
:icon="appStore.sidebarCollapsed ? Expand : Fold"
|
|
||||||
@click="appStore.toggleSidebar"
|
|
||||||
text
|
|
||||||
/>
|
/>
|
||||||
<el-breadcrumb separator="/">
|
</button>
|
||||||
<el-breadcrumb-item
|
|
||||||
v-for="item in breadcrumbs"
|
|
||||||
:key="item.path"
|
|
||||||
:to="item.path"
|
|
||||||
>
|
|
||||||
{{ item.title }}
|
|
||||||
</el-breadcrumb-item>
|
|
||||||
</el-breadcrumb>
|
|
||||||
</div>
|
|
||||||
<div class="header-right">
|
|
||||||
<!-- 预留用户信息 -->
|
|
||||||
</div>
|
|
||||||
</el-header>
|
|
||||||
|
|
||||||
<!-- 内容区 -->
|
<!-- Collapsed Mode Icon Only -->
|
||||||
<el-main>
|
<div v-else class="flex justify-center py-2" :title="item.title">
|
||||||
<router-view />
|
<component :is="item.icon" class="h-5 w-5 text-muted-foreground" />
|
||||||
</el-main>
|
</div>
|
||||||
</el-container>
|
|
||||||
</el-container>
|
<!-- Submenu Items -->
|
||||||
|
<div
|
||||||
|
v-show="!appStore.sidebarCollapsed && expandedMenus.includes(item.path)"
|
||||||
|
class="space-y-1 pl-9"
|
||||||
|
>
|
||||||
|
<router-link
|
||||||
|
v-for="sub in item.children"
|
||||||
|
:key="sub.path"
|
||||||
|
:to="sub.path"
|
||||||
|
class="block rounded-md px-3 py-2 text-sm font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground"
|
||||||
|
active-class="bg-accent/50 text-primary font-semibold"
|
||||||
|
>
|
||||||
|
{{ sub.title }}
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Single Item -->
|
||||||
|
<router-link
|
||||||
|
v-else
|
||||||
|
:to="item.path"
|
||||||
|
:class="[
|
||||||
|
'flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground',
|
||||||
|
appStore.sidebarCollapsed ? 'justify-center px-2' : ''
|
||||||
|
]"
|
||||||
|
active-class="bg-accent text-primary font-semibold shadow-sm"
|
||||||
|
:title="appStore.sidebarCollapsed ? item.title : ''"
|
||||||
|
>
|
||||||
|
<component :is="item.icon" class="h-4 w-4" />
|
||||||
|
<span v-if="!appStore.sidebarCollapsed" class="whitespace-nowrap transition-all duration-300">
|
||||||
|
{{ item.title }}
|
||||||
|
</span>
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- User / Footer -->
|
||||||
|
<div class="border-t p-4">
|
||||||
|
<button class="flex w-full items-center gap-3 rounded-md p-2 hover:bg-accent">
|
||||||
|
<div class="h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center text-primary">
|
||||||
|
<User class="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<div v-if="!appStore.sidebarCollapsed" class="text-left text-sm">
|
||||||
|
<p class="font-medium">Admin</p>
|
||||||
|
<p class="text-xs text-muted-foreground">admin@example.com</p>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<div class="flex flex-1 flex-col overflow-hidden">
|
||||||
|
<CommandPalette />
|
||||||
|
<!-- Header -->
|
||||||
|
<header class="flex h-14 items-center justify-between border-b bg-card px-6 shadow-sm">
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<button
|
||||||
|
@click="appStore.toggleSidebar"
|
||||||
|
class="rounded-md p-2 hover:bg-accent text-muted-foreground"
|
||||||
|
>
|
||||||
|
<component :is="appStore.sidebarCollapsed ? PanelLeftOpen : PanelLeftClose" class="h-5 w-5" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Breadcrumb (Simple) -->
|
||||||
|
<h1 class="text-lg font-semibold text-foreground">
|
||||||
|
{{ currentRouteTitle }}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<button @click="() => toggleDark()" class="rounded-full p-2 hover:bg-accent text-muted-foreground transition-colors">
|
||||||
|
<component :is="isDark ? Sun : Moon" class="h-5 w-5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Page Content -->
|
||||||
|
<main class="flex-1 overflow-y-auto bg-muted/20 p-6">
|
||||||
|
<router-view v-slot="{ Component }">
|
||||||
|
<transition name="fade" mode="out-in">
|
||||||
|
<component :is="Component" />
|
||||||
|
</transition>
|
||||||
|
</router-view>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useAppStore } from '@/stores/app'
|
import { useAppStore } from '@/stores/app'
|
||||||
|
import { useDark, useToggle } from '@vueuse/core'
|
||||||
|
import CommandPalette from '@/components/common/CommandPalette.vue'
|
||||||
import {
|
import {
|
||||||
HomeFilled,
|
LayoutDashboard,
|
||||||
Setting,
|
Settings,
|
||||||
Document,
|
FileText,
|
||||||
Reading,
|
Newspaper,
|
||||||
Monitor,
|
Activity,
|
||||||
Expand,
|
Bot,
|
||||||
Fold,
|
Zap,
|
||||||
ChatDotRound,
|
ChevronDown,
|
||||||
} from '@element-plus/icons-vue'
|
PanelLeftClose,
|
||||||
|
PanelLeftOpen,
|
||||||
|
User,
|
||||||
|
Sun,
|
||||||
|
Moon
|
||||||
|
} from 'lucide-vue-next'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
|
const isDark = useDark()
|
||||||
|
const toggleDark = useToggle(isDark)
|
||||||
|
|
||||||
const sidebarWidth = computed(() => {
|
const expandedMenus = ref<string[]>(['/config'])
|
||||||
return appStore.sidebarCollapsed ? '64px' : '200px'
|
|
||||||
|
const currentRouteTitle = computed(() => {
|
||||||
|
return route.meta.title || 'News Agent'
|
||||||
})
|
})
|
||||||
|
|
||||||
const activeMenu = computed(() => {
|
const menuItems = [
|
||||||
return route.path
|
{
|
||||||
})
|
title: '仪表盘',
|
||||||
|
path: '/dashboard',
|
||||||
|
icon: LayoutDashboard
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '配置管理',
|
||||||
|
path: '/config',
|
||||||
|
icon: Settings,
|
||||||
|
children: [
|
||||||
|
{ title: 'LLM 配置', path: '/config/llm' },
|
||||||
|
{ title: '数据源', path: '/config/sources' },
|
||||||
|
{ title: '推送渠道', path: '/config/channels' },
|
||||||
|
{ title: '主题管理', path: '/config/topics' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '报告中心',
|
||||||
|
path: '/reports',
|
||||||
|
icon: FileText
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '资讯浏览',
|
||||||
|
path: '/articles',
|
||||||
|
icon: Newspaper
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '采集监控',
|
||||||
|
path: '/monitoring',
|
||||||
|
icon: Activity
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'AI 对话',
|
||||||
|
path: '/agent',
|
||||||
|
icon: Bot
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
const breadcrumbs = computed(() => {
|
function toggleSubmenu(path: string) {
|
||||||
const matched = route.matched.filter((item) => item.meta?.title)
|
const index = expandedMenus.value.indexOf(path)
|
||||||
return matched.map((item) => ({
|
if (index > -1) {
|
||||||
path: item.path,
|
expandedMenus.value.splice(index, 1)
|
||||||
title: item.meta.title as string,
|
} else {
|
||||||
}))
|
expandedMenus.value.push(path)
|
||||||
})
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.main-layout {
|
/*
|
||||||
height: 100vh;
|
Tailwind handles most styles.
|
||||||
}
|
Specific transition overrides or complex animations can go here.
|
||||||
|
*/
|
||||||
.el-aside {
|
|
||||||
background-color: #304156;
|
|
||||||
transition: width 0.3s;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
height: 60px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
border-bottom: 1px solid #3a4a5c;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-menu {
|
|
||||||
border-right: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
background-color: #fff;
|
|
||||||
border-bottom: 1px solid #e6e6e6;
|
|
||||||
padding: 0 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-left {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-main {
|
|
||||||
background-color: #f0f2f5;
|
|
||||||
padding: 20px;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -3,6 +3,7 @@ import { createPinia } from 'pinia'
|
|||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import { setupElementPlus } from './plugins/element-plus'
|
import { setupElementPlus } from './plugins/element-plus'
|
||||||
|
import './style.css'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
const pinia = createPinia()
|
const pinia = createPinia()
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
export const useUserStore = defineStore('user', () => {
|
||||||
|
const token = ref<string | null>(null)
|
||||||
|
const userInfo = ref<any>(null)
|
||||||
|
|
||||||
|
const setToken = (newToken: string) => {
|
||||||
|
token.value = newToken
|
||||||
|
localStorage.setItem('token', newToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
const setUserInfo = (info: any) => {
|
||||||
|
userInfo.value = info
|
||||||
|
}
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
token.value = null
|
||||||
|
userInfo.value = null
|
||||||
|
localStorage.removeItem('token')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化时从 localStorage 恢复 token
|
||||||
|
const initToken = () => {
|
||||||
|
const savedToken = localStorage.getItem('token')
|
||||||
|
if (savedToken) {
|
||||||
|
token.value = savedToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
userInfo,
|
||||||
|
setToken,
|
||||||
|
setUserInfo,
|
||||||
|
logout,
|
||||||
|
initToken,
|
||||||
|
}
|
||||||
|
})
|
||||||
+66
-74
@@ -1,79 +1,71 @@
|
|||||||
:root {
|
@tailwind base;
|
||||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
@tailwind components;
|
||||||
line-height: 1.5;
|
@tailwind utilities;
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
@layer base {
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
place-items: center;
|
|
||||||
min-width: 320px;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
|
||||||
max-width: 1280px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
:root {
|
||||||
color: #213547;
|
--background: 0 0% 100%;
|
||||||
background-color: #ffffff;
|
--foreground: 240 10% 3.9%;
|
||||||
|
--card: 0 0% 100%;
|
||||||
|
--card-foreground: 240 10% 3.9%;
|
||||||
|
--popover: 0 0% 100%;
|
||||||
|
--popover-foreground: 240 10% 3.9%;
|
||||||
|
--primary: 240 5.9% 10%;
|
||||||
|
--primary-foreground: 0 0% 98%;
|
||||||
|
--secondary: 240 4.8% 95.9%;
|
||||||
|
--secondary-foreground: 240 5.9% 10%;
|
||||||
|
--muted: 240 4.8% 95.9%;
|
||||||
|
--muted-foreground: 240 3.8% 46.1%;
|
||||||
|
--accent: 240 4.8% 95.9%;
|
||||||
|
--accent-foreground: 240 5.9% 10%;
|
||||||
|
--destructive: 0 84.2% 60.2%;
|
||||||
|
--destructive-foreground: 0 0% 98%;
|
||||||
|
--border: 240 5.9% 90%;
|
||||||
|
--input: 240 5.9% 90%;
|
||||||
|
--ring: 240 5.9% 10%;
|
||||||
|
--radius: 0.5rem;
|
||||||
}
|
}
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
.dark {
|
||||||
}
|
--background: 240 10% 3.9%;
|
||||||
button {
|
--foreground: 0 0% 98%;
|
||||||
background-color: #f9f9f9;
|
--card: 240 10% 3.9%;
|
||||||
|
--card-foreground: 0 0% 98%;
|
||||||
|
--popover: 240 10% 3.9%;
|
||||||
|
--popover-foreground: 0 0% 98%;
|
||||||
|
--primary: 0 0% 98%;
|
||||||
|
--primary-foreground: 240 5.9% 10%;
|
||||||
|
--secondary: 240 3.7% 15.9%;
|
||||||
|
--secondary-foreground: 0 0% 98%;
|
||||||
|
--muted: 240 3.7% 15.9%;
|
||||||
|
--muted-foreground: 240 5% 64.9%;
|
||||||
|
--accent: 240 3.7% 15.9%;
|
||||||
|
--accent-foreground: 0 0% 98%;
|
||||||
|
--destructive: 0 62.8% 30.6%;
|
||||||
|
--destructive-foreground: 0 0% 98%;
|
||||||
|
--border: 240 3.7% 15.9%;
|
||||||
|
--input: 240 3.7% 15.9%;
|
||||||
|
--ring: 240 4.9% 83.9%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
font-feature-settings: "rlig" 1, "calt" 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 兼容 Element Plus 的过渡动画 */
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
+115
-222
@@ -1,276 +1,169 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="dashboard">
|
<div class="space-y-8 animate-in fade-in duration-500">
|
||||||
<el-row :gutter="20">
|
<div class="flex flex-col gap-2">
|
||||||
<el-col :span="6">
|
<h2 class="text-3xl font-bold tracking-tight">概览 (Insights)</h2>
|
||||||
<el-card shadow="hover">
|
<p class="text-muted-foreground text-sm">系统当前运行状态与资讯采集实时汇总</p>
|
||||||
<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>
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
|
|
||||||
<el-col :span="6">
|
<!-- Bento Grid Stats -->
|
||||||
<el-card shadow="hover">
|
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<div class="stat-item">
|
<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">
|
||||||
<el-icon class="stat-icon" :size="40" color="#67c23a"><Collection /></el-icon>
|
<div class="flex items-center justify-between">
|
||||||
<div class="stat-info">
|
<div class="space-y-1">
|
||||||
<div class="stat-value">{{ stats.topics }}</div>
|
<p class="text-xs font-bold text-muted-foreground uppercase tracking-wider">{{ stat.label }}</p>
|
||||||
<div class="stat-label">主题</div>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
|
|
||||||
<el-col :span="6">
|
<!-- Main Content Area -->
|
||||||
<el-card shadow="hover">
|
<div class="grid gap-6 md:grid-cols-7">
|
||||||
<div class="stat-item">
|
<!-- Recent Reports (4 cols) -->
|
||||||
<el-icon class="stat-icon" :size="40" color="#e6a23c"><Document /></el-icon>
|
<div class="col-span-4 rounded-xl border bg-card shadow-sm overflow-hidden flex flex-col">
|
||||||
<div class="stat-info">
|
<div class="flex items-center justify-between border-b px-6 py-4 bg-muted/30">
|
||||||
<div class="stat-value">{{ stats.reports }}</div>
|
<h3 class="font-semibold flex items-center gap-2">
|
||||||
<div class="stat-label">报告</div>
|
<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>
|
||||||
|
<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>
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
</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
|
<div
|
||||||
v-for="report in recentReports"
|
v-for="report in recentReports"
|
||||||
:key="report.id"
|
:key="report.id"
|
||||||
class="report-item"
|
|
||||||
@click="$router.push(`/reports/${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="report-title">{{ report.title }}</div>
|
<div class="space-y-1 overflow-hidden pr-4">
|
||||||
<div class="report-meta">
|
<p class="text-sm font-medium truncate">{{ report.title }}</p>
|
||||||
<el-tag :type="getStatusType(report.status)" size="small">
|
<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) }}
|
{{ getStatusText(report.status) }}
|
||||||
</el-tag>
|
|
||||||
<span class="report-time">
|
|
||||||
{{ formatTime(report.createdAt) }}
|
|
||||||
</span>
|
</span>
|
||||||
|
<ChevronRight class="h-4 w-4 text-muted-foreground/50" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
|
|
||||||
<el-col :span="12">
|
<!-- Collection Health (3 cols) -->
|
||||||
<el-card>
|
<div class="col-span-3 rounded-xl border bg-card shadow-sm flex flex-col">
|
||||||
<template #header>
|
<div class="flex items-center justify-between border-b px-6 py-4 bg-muted/30">
|
||||||
<div class="card-header">
|
<h3 class="font-semibold flex items-center gap-2">
|
||||||
<span>采集状态</span>
|
<Activity class="h-4 w-4 text-green-500" />
|
||||||
<el-button type="primary" link @click="$router.push('/monitoring')">
|
采集健康度
|
||||||
查看详情
|
</h3>
|
||||||
</el-button>
|
<button @click="$router.push('/monitoring')" class="text-xs font-medium text-blue-600 hover:underline">监控详情</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
<div class="p-6 space-y-6">
|
||||||
<el-empty v-if="collectionStats.length === 0" description="暂无数据" />
|
<div v-for="stat in collectionStats" :key="stat.id" class="space-y-3">
|
||||||
<div v-else class="collection-list">
|
<div class="flex items-center justify-between text-sm">
|
||||||
<div
|
<span class="font-medium text-foreground/80">{{ stat.name }}</span>
|
||||||
v-for="stat in collectionStats"
|
<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']">
|
||||||
:key="stat.id"
|
{{ stat.lastLog?.status === 'success' ? '正常' : '异常' }}
|
||||||
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>
|
</span>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { Connection, Collection, Document, Reading } from '@element-plus/icons-vue'
|
import {
|
||||||
|
Link, Library, FileText, Newspaper,
|
||||||
|
Activity, TrendingUp, ChevronRight
|
||||||
|
} from 'lucide-vue-next'
|
||||||
import request from '@/api/request'
|
import request from '@/api/request'
|
||||||
import type { Report, CollectionStats } from '@/api/types'
|
import type { Report, CollectionStats } from '@/api/types'
|
||||||
|
|
||||||
const stats = ref({
|
const stats = ref({ sources: 0, topics: 0, reports: 0, articles: 0 })
|
||||||
sources: 0,
|
|
||||||
topics: 0,
|
|
||||||
reports: 0,
|
|
||||||
articles: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
const recentReports = ref<Report[]>([])
|
const recentReports = ref<Report[]>([])
|
||||||
const collectionStats = ref<CollectionStats[]>([])
|
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 {
|
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('/sources', { params: { limit: 1 } }),
|
||||||
request.get('/topics', { params: { limit: 1 } }),
|
request.get('/topics', { params: { limit: 1 } }),
|
||||||
request.get('/reports', { params: { limit: 1 } }),
|
request.get('/reports', { params: { limit: 1 } }),
|
||||||
request.get('/articles', { params: { limit: 1 } }),
|
request.get('/articles', { params: { limit: 1 } }),
|
||||||
])
|
])
|
||||||
|
|
||||||
stats.value = {
|
stats.value = {
|
||||||
sources: sourcesRes.pagination?.total || 0,
|
sources: s.pagination?.total || 0,
|
||||||
topics: topicsRes.pagination?.total || 0,
|
topics: t.pagination?.total || 0,
|
||||||
reports: reportsRes.pagination?.total || 0,
|
reports: r.pagination?.total || 0,
|
||||||
articles: articlesRes.pagination?.total || 0,
|
articles: a.pagination?.total || 0,
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('加载统计数据失败', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadRecentReports = async () => {
|
const reportsRes = await request.get('/reports', { params: { limit: 5 } })
|
||||||
try {
|
recentReports.value = reportsRes.data || []
|
||||||
const res = await request.get('/reports', { params: { limit: 5 } })
|
|
||||||
recentReports.value = res.data || []
|
|
||||||
} catch (error) {
|
|
||||||
console.error('加载最近报告失败', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadCollectionStats = async () => {
|
const statsRes = await request.get('/collection-logs/stats')
|
||||||
try {
|
collectionStats.value = (statsRes.data || []).slice(0, 4)
|
||||||
const res = await request.get('/collection-logs/stats')
|
} catch (err) {
|
||||||
collectionStats.value = (res.data || []).slice(0, 5)
|
console.error(err)
|
||||||
} 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 getStatusText = (status: string) => {
|
||||||
const map: Record<string, string> = {
|
const map: any = { pending: '等待中', generating: '生成中', completed: '已就绪', failed: '失败' }
|
||||||
pending: '待处理',
|
|
||||||
generating: '生成中',
|
|
||||||
completed: '已完成',
|
|
||||||
failed: '失败',
|
|
||||||
}
|
|
||||||
return map[status] || status
|
return map[status] || status
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatTime = (time: string | null) => {
|
const getStatusClass = (status: string) => {
|
||||||
if (!time) return '未知'
|
const map: any = {
|
||||||
return new Date(time).toLocaleString('zh-CN')
|
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(() => {
|
const formatTime = (time: string) => {
|
||||||
loadStats()
|
const date = new Date(time)
|
||||||
loadRecentReports()
|
return `${date.getMonth()+1}/${date.getDate()} ${date.getHours()}:${date.getMinutes().toString().padStart(2, '0')}`
|
||||||
loadCollectionStats()
|
}
|
||||||
})
|
|
||||||
|
onMounted(loadData)
|
||||||
</script>
|
</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>
|
|
||||||
@@ -1,525 +1,289 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="agent-chat">
|
<div class="flex h-full flex-col bg-background lg:flex-row overflow-hidden rounded-xl border shadow-sm">
|
||||||
<!-- 主聊天区域 -->
|
<!-- Main Chat Area -->
|
||||||
<div class="chat-main">
|
<div class="flex flex-1 flex-col overflow-hidden relative">
|
||||||
<!-- 顶部配置栏 -->
|
<!-- Chat Header -->
|
||||||
<div class="config-bar">
|
<header class="flex h-14 items-center justify-between border-b bg-card/50 px-4 backdrop-blur">
|
||||||
<div class="config-left">
|
<div class="flex items-center gap-2">
|
||||||
<el-select
|
<div class="rounded-full bg-blue-500/10 p-1.5">
|
||||||
v-model="selectedTopicId"
|
<Bot class="h-5 w-5 text-blue-600" />
|
||||||
placeholder="选择主题"
|
|
||||||
size="default"
|
|
||||||
style="width: 150px"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="topic in topics"
|
|
||||||
:key="topic.id"
|
|
||||||
:label="topic.name"
|
|
||||||
:value="topic.id"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
|
|
||||||
<el-select
|
|
||||||
v-model="selectedLlmConfigId"
|
|
||||||
placeholder="选择 LLM"
|
|
||||||
size="default"
|
|
||||||
style="width: 180px"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="config in llmConfigs"
|
|
||||||
:key="config.id"
|
|
||||||
:label="`${config.name} (${config.model})`"
|
|
||||||
:value="config.id"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
|
|
||||||
<el-select
|
|
||||||
v-model="selectedReportId"
|
|
||||||
placeholder="关联报告(可选)"
|
|
||||||
size="default"
|
|
||||||
style="width: 200px"
|
|
||||||
clearable
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="report in reports"
|
|
||||||
:key="report.id"
|
|
||||||
:label="report.title"
|
|
||||||
:value="report.id"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
<div class="config-right">
|
<h3 class="text-sm font-semibold">AI 智能助手</h3>
|
||||||
<el-button size="default" @click="handleNewChat">
|
<p class="text-[10px] text-muted-foreground">{{ activeTopicName || '就绪' }}</p>
|
||||||
<el-icon><Plus /></el-icon>
|
|
||||||
新建对话
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
size="default"
|
|
||||||
:icon="showHistory ? 'ArrowRight' : 'Clock'"
|
|
||||||
@click="showHistory = !showHistory"
|
|
||||||
>
|
|
||||||
{{ showHistory ? '隐藏历史' : '历史对话' }}
|
|
||||||
</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 消息列表 -->
|
<div class="flex items-center gap-2">
|
||||||
<div ref="messageListRef" class="message-list">
|
<el-popover placement="bottom-end" :width="320" trigger="click">
|
||||||
<el-empty v-if="messages.length === 0" description="开始一段新对话吧">
|
<template #reference>
|
||||||
<template #image>
|
<button class="flex items-center gap-1 rounded-md px-2 py-1.5 text-xs font-medium hover:bg-accent transition-colors">
|
||||||
<el-icon :size="60" color="#909399"><ChatDotRound /></el-icon>
|
<Settings2 class="h-4 w-4" />
|
||||||
|
<span>配置</span>
|
||||||
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</el-empty>
|
<div class="space-y-4 p-2">
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-xs font-bold text-muted-foreground uppercase">当前主题</label>
|
||||||
|
<el-select v-model="selectedTopicId" class="w-full" placeholder="选择主题">
|
||||||
|
<el-option v-for="t in topics" :key="t.id" :label="t.name" :value="t.id" />
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-xs font-bold text-muted-foreground uppercase">模型配置</label>
|
||||||
|
<el-select v-model="selectedLlmConfigId" class="w-full" placeholder="选择 LLM">
|
||||||
|
<el-option v-for="c in llmConfigs" :key="c.id" :label="c.name" :value="c.id" />
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-xs font-bold text-muted-foreground uppercase">关联报告</label>
|
||||||
|
<el-select v-model="selectedReportId" class="w-full" placeholder="无" clearable>
|
||||||
|
<el-option v-for="r in reports" :key="r.id" :label="r.title" :value="r.id" />
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-popover>
|
||||||
|
|
||||||
|
<div class="h-4 w-px bg-border mx-1"></div>
|
||||||
|
|
||||||
|
<button @click="handleNewChat" class="rounded-md p-1.5 hover:bg-accent text-muted-foreground" title="新建对话">
|
||||||
|
<Plus class="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<button @click="showHistory = !showHistory" class="rounded-md p-1.5 hover:bg-accent text-muted-foreground lg:hidden">
|
||||||
|
<History class="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Message List -->
|
||||||
|
<div ref="scrollContainer" class="flex-1 overflow-y-auto p-4 space-y-4">
|
||||||
|
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center space-y-4 opacity-50">
|
||||||
|
<div class="rounded-full bg-muted p-6">
|
||||||
|
<Sparkles class="h-12 w-12 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<p class="text-sm font-medium">您可以询问关于已采集资讯或报告的问题</p>
|
||||||
|
<p class="text-xs">例如:“总结一下最近关于人工智能的重要新闻”</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<MessageItem
|
<MessageItem
|
||||||
v-for="(message, index) in messages"
|
v-for="(message, index) in messages"
|
||||||
:key="index"
|
:key="index"
|
||||||
:message="message"
|
:message="{ ...message, id: message.id || index }"
|
||||||
:streaming="isLoading && index === messages.length - 1 && message.role === 'assistant'"
|
:streaming="isLoading && index === messages.length - 1 && message.role === 'assistant'"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 加载指示器 -->
|
<!-- Loading state -->
|
||||||
<div v-if="isLoading && (!messages.length || messages[messages.length - 1]?.role !== 'assistant')" class="loading-indicator">
|
<div v-if="isLoading && (!messages.length || messages[messages.length - 1]?.role !== 'assistant')" class="flex gap-3 animate-in slide-in-from-bottom-2">
|
||||||
<el-icon class="is-loading"><Loading /></el-icon>
|
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-primary text-primary-foreground shadow">
|
||||||
<span>AI 正在思考...</span>
|
<Bot class="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2 rounded-md border bg-card px-3 py-2 text-sm shadow-sm">
|
||||||
|
<Loader2 class="h-3 w-3 animate-spin text-blue-500" />
|
||||||
|
<span class="text-muted-foreground italic">Agent 正在思考...</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 输入区域 -->
|
<!-- Input Area -->
|
||||||
<div class="input-area">
|
<div class="p-4 border-t bg-card/30 backdrop-blur">
|
||||||
<el-input
|
<div class="max-w-4xl mx-auto relative group">
|
||||||
|
<textarea
|
||||||
v-model="inputMessage"
|
v-model="inputMessage"
|
||||||
type="textarea"
|
|
||||||
:rows="3"
|
|
||||||
placeholder="输入你的问题... (Ctrl+Enter 发送)"
|
|
||||||
:disabled="isLoading"
|
|
||||||
@keydown.ctrl.enter="handleSendMessage"
|
@keydown.ctrl.enter="handleSendMessage"
|
||||||
/>
|
placeholder="输入您的问题... (Ctrl+Enter 发送)"
|
||||||
<div class="input-actions">
|
class="w-full min-h-[100px] max-h-[200px] rounded-xl border border-border bg-background px-4 py-3 text-sm shadow-sm transition-all focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 resize-none pr-12"
|
||||||
<span class="input-hint">Ctrl + Enter 发送</span>
|
:disabled="isLoading"
|
||||||
<el-button
|
></textarea>
|
||||||
type="primary"
|
<button
|
||||||
:loading="isLoading"
|
|
||||||
:disabled="!inputMessage.trim() || !selectedLlmConfigId || !selectedTopicId"
|
|
||||||
@click="handleSendMessage"
|
@click="handleSendMessage"
|
||||||
|
:disabled="!inputMessage.trim() || isLoading"
|
||||||
|
class="absolute bottom-3 right-3 rounded-lg bg-primary p-2 text-primary-foreground shadow-lg transition-all hover:scale-105 active:scale-95 disabled:opacity-50 disabled:grayscale disabled:hover:scale-100"
|
||||||
>
|
>
|
||||||
发送
|
<SendHorizontal class="h-4 w-4" />
|
||||||
</el-button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="mt-2 text-center text-[10px] text-muted-foreground">
|
||||||
|
基于 Vercel AI SDK 构建 · 已连接至 {{ activeModelName }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 历史对话侧边栏(可折叠) -->
|
<!-- Desktop History Sidebar -->
|
||||||
<transition name="slide">
|
<aside v-show="showHistory" class="hidden lg:flex w-80 flex-col border-l bg-muted/10 animate-in slide-in-from-right duration-300">
|
||||||
<div v-show="showHistory" class="history-panel">
|
<div class="flex h-14 items-center justify-between border-b px-4">
|
||||||
<div class="history-header">
|
<h4 class="text-xs font-bold uppercase tracking-wider text-muted-foreground">对话历史</h4>
|
||||||
<span>历史对话</span>
|
<button @click="loadConversations" class="rounded-md p-1.5 hover:bg-accent text-muted-foreground">
|
||||||
<el-button size="small" text @click="loadConversations">
|
<RefreshCw class="h-3.5 w-3.5" :class="{ 'animate-spin': loadingHistory }" />
|
||||||
<el-icon><Refresh /></el-icon>
|
</button>
|
||||||
</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="history-list">
|
<div class="flex-1 overflow-y-auto p-3 space-y-2">
|
||||||
<div
|
<div
|
||||||
v-for="conv in conversations"
|
v-for="conv in conversations"
|
||||||
:key="conv.id"
|
:key="conv.id"
|
||||||
:class="['history-item', { active: conv.id === conversationId }]"
|
|
||||||
@click="loadConversation(conv)"
|
@click="loadConversation(conv)"
|
||||||
|
:class="[
|
||||||
|
'group relative flex flex-col gap-1 rounded-lg border p-3 text-left transition-all cursor-pointer hover:border-blue-500/50 hover:bg-background',
|
||||||
|
conversationId === conv.id ? 'border-blue-500 bg-background shadow-sm' : 'border-transparent bg-transparent'
|
||||||
|
]"
|
||||||
>
|
>
|
||||||
<div class="history-item-header">
|
<div class="flex items-center justify-between">
|
||||||
<span class="history-title">{{ conv.topic?.name || '未知主题' }}</span>
|
<span class="text-xs font-semibold truncate pr-4">{{ conv.topic?.name || '新对话' }}</span>
|
||||||
<el-button
|
<span class="text-[10px] text-muted-foreground shrink-0">{{ formatTime(conv.updatedAt) }}</span>
|
||||||
size="small"
|
</div>
|
||||||
type="danger"
|
<p class="text-[11px] text-muted-foreground line-clamp-2 leading-relaxed">
|
||||||
text
|
{{ conv.lastMessage?.content || '暂无预览内容' }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
@click.stop="handleDeleteConversation(conv.id)"
|
@click.stop="handleDeleteConversation(conv.id)"
|
||||||
|
class="absolute right-2 bottom-2 opacity-0 group-hover:opacity-100 p-1 text-destructive hover:bg-destructive/10 rounded transition-opacity"
|
||||||
>
|
>
|
||||||
<el-icon><Delete /></el-icon>
|
<Trash2 class="h-3 w-3" />
|
||||||
</el-button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="history-preview">
|
<el-empty v-if="conversations.length === 0" description="尚无历史" :image-size="40" />
|
||||||
{{ conv.lastMessage?.content || '暂无消息' }}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="history-time">
|
</aside>
|
||||||
{{ formatTime(conv.updatedAt) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<el-empty v-if="conversations.length === 0" description="暂无历史对话" :image-size="60" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</transition>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, nextTick, watch } from 'vue'
|
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Loading, ChatDotRound, Refresh, Plus, Delete } from '@element-plus/icons-vue'
|
import {
|
||||||
|
Bot, Settings2, Plus, History, Sparkles, SendHorizontal,
|
||||||
|
Loader2, RefreshCw, Trash2
|
||||||
|
} from 'lucide-vue-next'
|
||||||
import MessageItem from '@/components/agent/MessageItem.vue'
|
import MessageItem from '@/components/agent/MessageItem.vue'
|
||||||
import { useAgentChat } from '@/composables/useAgentChat'
|
import { useAgentChat } from '@/composables/useAgentChat'
|
||||||
import {
|
import { getConversations, deleteConversation, type Conversation } from '@/api/agent'
|
||||||
getConversations,
|
|
||||||
getConversation,
|
|
||||||
deleteConversation,
|
|
||||||
type Conversation,
|
|
||||||
} from '@/api/agent'
|
|
||||||
import request from '@/api/request'
|
import request from '@/api/request'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const scrollContainer = ref<HTMLElement>()
|
||||||
|
|
||||||
// 配置数据
|
// Data
|
||||||
const topics = ref<any[]>([])
|
const topics = ref<any[]>([])
|
||||||
const llmConfigs = ref<any[]>([])
|
const llmConfigs = ref<any[]>([])
|
||||||
const reports = ref<any[]>([])
|
const reports = ref<any[]>([])
|
||||||
const conversations = ref<Conversation[]>([])
|
const conversations = ref<Conversation[]>([])
|
||||||
|
const loadingHistory = ref(false)
|
||||||
|
|
||||||
// 选中的配置
|
// Selections
|
||||||
const selectedTopicId = ref<number>()
|
const selectedTopicId = ref<number>()
|
||||||
const selectedLlmConfigId = ref<number>()
|
const selectedLlmConfigId = ref<number>()
|
||||||
const selectedReportId = ref<number>()
|
const selectedReportId = ref<number>()
|
||||||
|
|
||||||
// UI 状态
|
const showHistory = ref(true)
|
||||||
const showHistory = ref(false)
|
|
||||||
const inputMessage = ref('')
|
const inputMessage = ref('')
|
||||||
const messageListRef = ref<HTMLElement>()
|
|
||||||
|
|
||||||
// 使用 composable
|
|
||||||
const {
|
const {
|
||||||
messages,
|
messages, isLoading, conversationId, sendMessage,
|
||||||
isLoading,
|
clearMessages, loadMessages
|
||||||
conversationId,
|
|
||||||
sendMessage,
|
|
||||||
clearMessages,
|
|
||||||
loadMessages,
|
|
||||||
} = useAgentChat()
|
} = useAgentChat()
|
||||||
|
|
||||||
// 初始化
|
const activeTopicName = computed(() => topics.value.find(t => t.id === selectedTopicId.value)?.name)
|
||||||
onMounted(async () => {
|
const activeModelName = computed(() => llmConfigs.value.find(c => c.id === selectedLlmConfigId.value)?.model || '默认模型')
|
||||||
await Promise.all([
|
|
||||||
loadTopics(),
|
|
||||||
loadLlmConfigs(),
|
|
||||||
loadReports(),
|
|
||||||
loadConversations(),
|
|
||||||
])
|
|
||||||
|
|
||||||
// 从路由参数初始化
|
// Auto-scroll logic
|
||||||
if (route.query.topicId) {
|
|
||||||
selectedTopicId.value = Number(route.query.topicId)
|
|
||||||
}
|
|
||||||
if (route.query.llmConfigId) {
|
|
||||||
selectedLlmConfigId.value = Number(route.query.llmConfigId)
|
|
||||||
}
|
|
||||||
if (route.query.reportId) {
|
|
||||||
selectedReportId.value = Number(route.query.reportId)
|
|
||||||
}
|
|
||||||
if (route.query.conversationId) {
|
|
||||||
const conv = await getConversation(Number(route.query.conversationId))
|
|
||||||
if (conv) {
|
|
||||||
loadConversation(conv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 默认选择第一个
|
|
||||||
if (!selectedTopicId.value && topics.value.length > 0) {
|
|
||||||
selectedTopicId.value = topics.value[0].id
|
|
||||||
}
|
|
||||||
if (!selectedLlmConfigId.value && llmConfigs.value.length > 0) {
|
|
||||||
selectedLlmConfigId.value = llmConfigs.value[0].id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 自动滚动到底部
|
|
||||||
watch([messages, isLoading], () => {
|
watch([messages, isLoading], () => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (messageListRef.value) {
|
if (scrollContainer.value) {
|
||||||
messageListRef.value.scrollTop = messageListRef.value.scrollHeight
|
scrollContainer.value.scrollTop = scrollContainer.value.scrollHeight
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 加载主题列表
|
onMounted(async () => {
|
||||||
|
await Promise.all([loadTopics(), loadLlmConfigs(), loadReports(), loadConversations()])
|
||||||
|
|
||||||
|
if (route.query.topicId) selectedTopicId.value = Number(route.query.topicId)
|
||||||
|
if (route.query.reportId) selectedReportId.value = Number(route.query.reportId)
|
||||||
|
|
||||||
|
if (!selectedTopicId.value && topics.value.length > 0) selectedTopicId.value = topics.value[0].id
|
||||||
|
if (!selectedLlmConfigId.value && llmConfigs.value.length > 0) selectedLlmConfigId.value = llmConfigs.value[0].id
|
||||||
|
})
|
||||||
|
|
||||||
async function loadTopics() {
|
async function loadTopics() {
|
||||||
try {
|
|
||||||
const res = await request.get('/topics')
|
const res = await request.get('/topics')
|
||||||
topics.value = res.data || res
|
topics.value = res.data || []
|
||||||
} catch (error) {
|
|
||||||
console.error('加载主题失败:', error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载 LLM 配置列表
|
|
||||||
async function loadLlmConfigs() {
|
async function loadLlmConfigs() {
|
||||||
try {
|
|
||||||
const res = await request.get('/llm-configs')
|
const res = await request.get('/llm-configs')
|
||||||
llmConfigs.value = res.data || res
|
llmConfigs.value = res.data || []
|
||||||
} catch (error) {
|
|
||||||
console.error('加载 LLM 配置失败:', error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载报告列表
|
|
||||||
async function loadReports() {
|
async function loadReports() {
|
||||||
try {
|
const res = await request.get('/reports', { params: { status: 'completed', limit: 10 } })
|
||||||
const res = await request.get('/reports', {
|
reports.value = res.data || []
|
||||||
params: { status: 'completed', limit: 20 },
|
|
||||||
})
|
|
||||||
reports.value = res.data || res
|
|
||||||
} catch (error) {
|
|
||||||
console.error('加载报告失败:', error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载对话列表
|
|
||||||
async function loadConversations() {
|
async function loadConversations() {
|
||||||
|
loadingHistory.value = true
|
||||||
try {
|
try {
|
||||||
conversations.value = await getConversations()
|
conversations.value = await getConversations()
|
||||||
} catch (error) {
|
} finally {
|
||||||
console.error('加载对话列表失败:', error)
|
loadingHistory.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载对话
|
|
||||||
function loadConversation(conv: Conversation) {
|
|
||||||
selectedTopicId.value = conv.topicId
|
|
||||||
selectedReportId.value = conv.reportId
|
|
||||||
loadMessages(conv.messages || [], conv.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送消息
|
|
||||||
async function handleSendMessage() {
|
async function handleSendMessage() {
|
||||||
if (!inputMessage.value.trim() || isLoading.value) {
|
if (!inputMessage.value.trim() || isLoading.value) return
|
||||||
|
if (!selectedTopicId.value || !selectedLlmConfigId.value) {
|
||||||
|
ElMessage.warning('请先选择主题和模型配置')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selectedTopicId.value) {
|
const msg = inputMessage.value
|
||||||
ElMessage.warning('请先选择主题')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selectedLlmConfigId.value) {
|
|
||||||
ElMessage.warning('请先选择 LLM 配置')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = inputMessage.value
|
|
||||||
inputMessage.value = ''
|
inputMessage.value = ''
|
||||||
|
|
||||||
await sendMessage({
|
await sendMessage({
|
||||||
topicId: selectedTopicId.value,
|
topicId: selectedTopicId.value,
|
||||||
llmConfigId: selectedLlmConfigId.value,
|
llmConfigId: selectedLlmConfigId.value,
|
||||||
reportId: selectedReportId.value,
|
reportId: selectedReportId.value,
|
||||||
message,
|
message: msg
|
||||||
})
|
})
|
||||||
|
loadConversations()
|
||||||
// 刷新对话列表
|
|
||||||
await loadConversations()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新建对话
|
|
||||||
function handleNewChat() {
|
function handleNewChat() {
|
||||||
clearMessages()
|
clearMessages()
|
||||||
selectedReportId.value = undefined
|
selectedReportId.value = undefined
|
||||||
inputMessage.value = ''
|
inputMessage.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除对话
|
function loadConversation(conv: Conversation) {
|
||||||
async function handleDeleteConversation(id: number) {
|
selectedTopicId.value = conv.topicId
|
||||||
try {
|
selectedReportId.value = conv.reportId
|
||||||
await ElMessageBox.confirm('确定要删除这个对话吗?', '提示', {
|
loadMessages(conv.messages || [], conv.id)
|
||||||
type: 'warning',
|
}
|
||||||
})
|
|
||||||
|
async function handleDeleteConversation(id: number) {
|
||||||
await deleteConversation(id)
|
try {
|
||||||
ElMessage.success('删除成功')
|
await ElMessageBox.confirm('彻底删除此对话历史?', '警告', { type: 'warning' })
|
||||||
|
await deleteConversation(id)
|
||||||
// 如果删除的是当前对话,清空消息
|
if (id === conversationId.value) handleNewChat()
|
||||||
if (id === conversationId.value) {
|
loadConversations()
|
||||||
handleNewChat()
|
} catch {}
|
||||||
}
|
|
||||||
|
|
||||||
await loadConversations()
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error !== 'cancel') {
|
|
||||||
ElMessage.error('删除失败')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化时间
|
|
||||||
function formatTime(time: string): string {
|
function formatTime(time: string): string {
|
||||||
const date = new Date(time)
|
const date = new Date(time)
|
||||||
const now = new Date()
|
const diff = Date.now() - date.getTime()
|
||||||
const diff = now.getTime() - date.getTime()
|
if (diff < 60000) return '刚刚'
|
||||||
|
if (diff < 3600000) return `${Math.floor(diff / 60000)}m前`
|
||||||
const minutes = Math.floor(diff / 60000)
|
if (diff < 86400000) return `${Math.floor(diff / 3600000)}h前`
|
||||||
const hours = Math.floor(diff / 3600000)
|
return date.toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' })
|
||||||
const days = Math.floor(diff / 86400000)
|
|
||||||
|
|
||||||
if (minutes < 1) return '刚刚'
|
|
||||||
if (minutes < 60) return `${minutes}分钟前`
|
|
||||||
if (hours < 24) return `${hours}小时前`
|
|
||||||
if (days < 7) return `${days}天前`
|
|
||||||
|
|
||||||
return date.toLocaleDateString('zh-CN')
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.agent-chat {
|
::-webkit-scrollbar {
|
||||||
display: flex;
|
width: 5px;
|
||||||
height: calc(100vh - 100px);
|
|
||||||
background-color: #fff;
|
|
||||||
border-radius: 8px;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
.chat-main {
|
@apply bg-muted rounded-full;
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 顶部配置栏 */
|
|
||||||
.config-bar {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 12px 16px;
|
|
||||||
border-bottom: 1px solid #e6e6e6;
|
|
||||||
background-color: #fafafa;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.config-left {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.config-right {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 消息列表 */
|
|
||||||
.message-list {
|
|
||||||
flex: 1;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-indicator {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
color: #909399;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 输入区域 */
|
|
||||||
.input-area {
|
|
||||||
border-top: 1px solid #e6e6e6;
|
|
||||||
padding: 16px;
|
|
||||||
background-color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-actions {
|
|
||||||
margin-top: 10px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-hint {
|
|
||||||
font-size: 12px;
|
|
||||||
color: #909399;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 历史对话面板 */
|
|
||||||
.history-panel {
|
|
||||||
width: 280px;
|
|
||||||
border-left: 1px solid #e6e6e6;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
background-color: #fafafa;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 12px 16px;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 14px;
|
|
||||||
border-bottom: 1px solid #e6e6e6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-list {
|
|
||||||
flex: 1;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-item {
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
background-color: #fff;
|
|
||||||
border: 1px solid #e6e6e6;
|
|
||||||
transition: all 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-item:hover {
|
|
||||||
border-color: #409eff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-item.active {
|
|
||||||
border-color: #409eff;
|
|
||||||
background-color: #ecf5ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-item-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-title {
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 13px;
|
|
||||||
color: #303133;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-preview {
|
|
||||||
font-size: 12px;
|
|
||||||
color: #909399;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.history-time {
|
|
||||||
font-size: 11px;
|
|
||||||
color: #c0c4cc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 过渡动画 */
|
|
||||||
.slide-enter-active,
|
|
||||||
.slide-leave-active {
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slide-enter-from,
|
|
||||||
.slide-leave-to {
|
|
||||||
width: 0;
|
|
||||||
opacity: 0;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,402 +1,255 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="sources">
|
<div class="space-y-6 animate-in fade-in duration-500">
|
||||||
<div class="page-header">
|
<div class="flex items-center justify-between">
|
||||||
<h2>数据源管理</h2>
|
<div class="space-y-1">
|
||||||
<el-button type="primary" @click="handleAdd">
|
<h2 class="text-2xl font-bold tracking-tight">数据源 (Sources)</h2>
|
||||||
<el-icon><Plus /></el-icon>
|
<p class="text-sm text-muted-foreground">管理系统采集资讯的来源,包括 RSS、API 及网页爬虫</p>
|
||||||
新增数据源
|
</div>
|
||||||
|
<el-button type="primary" @click="handleAdd" class="!rounded-lg !px-6 shadow-sm">
|
||||||
|
<el-icon class="mr-2"><Plus /></el-icon>
|
||||||
|
新增来源
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-card>
|
<!-- Modern Table -->
|
||||||
<el-table :data="tableData" v-loading="loading" stripe>
|
<div class="rounded-xl border bg-card shadow-sm overflow-hidden">
|
||||||
<el-table-column prop="id" label="ID" width="80" />
|
<el-table :data="tableData" v-loading="loading" class="modern-table">
|
||||||
<el-table-column prop="name" label="名称" min-width="150" />
|
<el-table-column prop="name" label="数据源名称" min-width="200">
|
||||||
<el-table-column prop="type" label="类型" width="100">
|
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="getTypeTagType(row.type)">{{ getTypeLabel(row.type) }}</el-tag>
|
<div class="flex items-center gap-3">
|
||||||
|
<div :class="['p-2 rounded-lg bg-muted', getTypeIconClass(row.type)]">
|
||||||
|
<component :is="getTypeIcon(row.type)" class="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<span class="font-medium text-sm">{{ row.name }}</span>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="cronExpression" label="采集频率" width="120" />
|
|
||||||
<el-table-column prop="lastCollectedAt" label="最后采集" width="180">
|
<el-table-column label="类型" width="120">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ row.lastCollectedAt ? formatTime(row.lastCollectedAt) : '从未采集' }}
|
<span class="text-xs font-bold uppercase tracking-wider text-muted-foreground">{{ getTypeLabel(row.type) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="enabled" label="状态" width="100">
|
|
||||||
|
<el-table-column prop="cronExpression" label="频率" width="140">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-switch v-model="row.enabled" @change="handleToggleEnabled(row)" />
|
<code class="px-1.5 py-0.5 rounded bg-muted text-[10px] font-mono">{{ row.cronExpression }}</code>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="200" fixed="right">
|
|
||||||
|
<el-table-column label="健康状态" width="120">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
<div class="flex items-center gap-2">
|
||||||
<el-button type="success" link @click="handleCollect(row)">采集</el-button>
|
<span :class="['h-2 w-2 rounded-full', row.enabled ? 'bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.5)]' : 'bg-muted']"></span>
|
||||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
<span class="text-xs">{{ row.enabled ? '运行中' : '已停止' }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column label="最后同步" width="180">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span class="text-xs text-muted-foreground italic">{{ row.lastCollectedAt ? formatTime(row.lastCollectedAt) : '从未同步' }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column label="操作" width="180" fixed="right" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="flex justify-end gap-1">
|
||||||
|
<el-button type="primary" link @click="handleEdit(row)" title="编辑">
|
||||||
|
<el-icon><EditPen /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
<el-button type="success" link @click="handleCollect(row)" title="立即采集">
|
||||||
|
<el-icon><Refresh /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
<el-button type="danger" link @click="handleDelete(row)" title="删除">
|
||||||
|
<el-icon><Delete /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
|
||||||
<div class="pagination-wrapper">
|
<div class="px-6 py-4 border-t flex justify-end">
|
||||||
<el-pagination
|
<el-pagination
|
||||||
v-model:current-page="pagination.page"
|
v-model:current-page="pagination.page"
|
||||||
v-model:page-size="pagination.limit"
|
v-model:page-size="pagination.limit"
|
||||||
:total="pagination.total"
|
:total="pagination.total"
|
||||||
:page-sizes="[10, 20, 50]"
|
size="small"
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
layout="prev, pager, next"
|
||||||
@size-change="loadData"
|
|
||||||
@current-change="loadData"
|
@current-change="loadData"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</div>
|
||||||
|
|
||||||
<!-- 新增/编辑对话框 -->
|
<!-- Side Drawer Form -->
|
||||||
<el-dialog
|
<el-drawer
|
||||||
v-model="dialogVisible"
|
v-model="drawerVisible"
|
||||||
:title="isEdit ? '编辑数据源' : '新增数据源'"
|
:title="isEdit ? '编辑数据源' : '新增数据源'"
|
||||||
width="600px"
|
size="480px"
|
||||||
|
direction="rtl"
|
||||||
@close="resetForm"
|
@close="resetForm"
|
||||||
>
|
>
|
||||||
<el-form
|
<el-form
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
:model="formData"
|
:model="formData"
|
||||||
:rules="formRules"
|
:rules="formRules"
|
||||||
label-width="100px"
|
label-position="top"
|
||||||
|
class="space-y-6"
|
||||||
>
|
>
|
||||||
<el-form-item label="名称" prop="name">
|
<div class="space-y-4 rounded-xl border bg-muted/30 p-4">
|
||||||
<el-input v-model="formData.name" placeholder="请输入数据源名称" />
|
<p class="text-sm font-bold">基础信息</p>
|
||||||
|
<el-form-item prop="name" label="名称">
|
||||||
|
<el-input v-model="formData.name" placeholder="Hacker News Top" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="类型" prop="type">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<el-select v-model="formData.type" placeholder="请选择类型" style="width: 100%">
|
<el-form-item prop="type" label="协议类型">
|
||||||
<el-option label="RSS 订阅" value="rss" />
|
<el-select v-model="formData.type" class="w-full">
|
||||||
<el-option label="API 接口" value="api" />
|
<el-option label="RSS Feed" value="rss" />
|
||||||
<el-option label="网页爬虫" value="playwright" />
|
<el-option label="JSON API" value="api" />
|
||||||
|
<el-option label="Browser Crawler" value="playwright" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="采集频率" prop="cronExpression">
|
<el-form-item prop="cronExpression" label="采集频率">
|
||||||
<el-input v-model="formData.cronExpression" placeholder="Cron 表达式,如:0 * * * *">
|
<el-input v-model="formData.cronExpression" placeholder="0 * * * *" />
|
||||||
<template #append>
|
</el-form-item>
|
||||||
<el-tooltip content="每小时: 0 * * * * 每天: 0 0 * * * 每周: 0 0 * * 0" raw-content>
|
</div>
|
||||||
<el-icon><QuestionFilled /></el-icon>
|
</div>
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
<div class="space-y-4 rounded-xl border bg-muted/30 p-4">
|
||||||
</el-input>
|
<p class="text-sm font-bold">连接配置</p>
|
||||||
|
<el-form-item prop="config.url" label="目标 URL">
|
||||||
|
<el-input v-model="formData.config.url" placeholder="https://..." />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<!-- RSS 配置 -->
|
|
||||||
<template v-if="formData.type === 'rss'">
|
|
||||||
<el-divider content-position="left">RSS 配置</el-divider>
|
|
||||||
<el-form-item label="RSS URL" prop="config.url">
|
|
||||||
<el-input v-model="formData.config.url" placeholder="RSS 订阅地址" />
|
|
||||||
</el-form-item>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- API 配置 -->
|
|
||||||
<template v-if="formData.type === 'api'">
|
<template v-if="formData.type === 'api'">
|
||||||
<el-divider content-position="left">API 配置</el-divider>
|
<el-form-item label="HTTP Method">
|
||||||
<el-form-item label="API URL" prop="config.url">
|
<el-select v-model="formData.config.method" class="w-full">
|
||||||
<el-input v-model="formData.config.url" placeholder="API 接口地址" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="请求方法">
|
|
||||||
<el-select v-model="formData.config.method" style="width: 100%">
|
|
||||||
<el-option label="GET" value="GET" />
|
<el-option label="GET" value="GET" />
|
||||||
<el-option label="POST" value="POST" />
|
<el-option label="POST" value="POST" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="请求头">
|
|
||||||
<el-input
|
|
||||||
v-model="formData.config.headers"
|
|
||||||
type="textarea"
|
|
||||||
:rows="3"
|
|
||||||
placeholder='JSON 格式,如:{"Authorization": "Bearer xxx"}'
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Playwright 配置 -->
|
|
||||||
<template v-if="formData.type === 'playwright'">
|
<template v-if="formData.type === 'playwright'">
|
||||||
<el-divider content-position="left">爬虫配置</el-divider>
|
<el-form-item label="List Selector (CSS)">
|
||||||
<el-form-item label="目标 URL" prop="config.url">
|
<el-input v-model="formData.config.listSelector" placeholder=".news-list > .item" />
|
||||||
<el-input v-model="formData.config.url" placeholder="要爬取的网页地址" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="列表选择器">
|
|
||||||
<el-input v-model="formData.config.listSelector" placeholder="文章列表的 CSS 选择器" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="标题选择器">
|
|
||||||
<el-input v-model="formData.config.titleSelector" placeholder="标题的 CSS 选择器" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="链接选择器">
|
|
||||||
<el-input v-model="formData.config.linkSelector" placeholder="链接的 CSS 选择器" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="内容选择器">
|
|
||||||
<el-input v-model="formData.config.contentSelector" placeholder="内容的 CSS 选择器" />
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
<el-form-item label="启用状态">
|
<el-form-item>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
<el-switch v-model="formData.enabled" />
|
<el-switch v-model="formData.enabled" />
|
||||||
|
<span class="text-sm font-medium">启用此采集任务</span>
|
||||||
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="dialogVisible = false">取消</el-button>
|
<div class="flex gap-3 px-4 py-4 border-t">
|
||||||
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
<el-button @click="drawerVisible = false" class="flex-1">取消</el-button>
|
||||||
确定
|
<el-button type="primary" @click="handleSubmit" :loading="submitting" class="flex-1">
|
||||||
|
{{ isEdit ? '保存更改' : '立即创建' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Plus, QuestionFilled } from '@element-plus/icons-vue'
|
import {
|
||||||
|
Plus, EditPen, Delete, Refresh
|
||||||
|
} from '@element-plus/icons-vue'
|
||||||
|
import { Rss, Globe, Code2 } from 'lucide-vue-next'
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
import request from '@/api/request'
|
import request from '@/api/request'
|
||||||
import type { Source } from '@/api/types'
|
import type { Source } from '@/api/types'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
const dialogVisible = ref(false)
|
const drawerVisible = ref(false)
|
||||||
const isEdit = ref(false)
|
const isEdit = ref(false)
|
||||||
const tableData = ref<Source[]>([])
|
const tableData = ref<Source[]>([])
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
|
|
||||||
const pagination = reactive({
|
const pagination = reactive({ page: 1, limit: 10, total: 0 })
|
||||||
page: 1,
|
|
||||||
limit: 10,
|
|
||||||
total: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: 0,
|
id: 0, name: '', type: 'rss', cronExpression: '0 * * * *',
|
||||||
name: '',
|
config: { url: '', method: 'GET', listSelector: '' },
|
||||||
type: 'rss' as 'rss' | 'api' | 'playwright',
|
enabled: true
|
||||||
cronExpression: '0 * * * *',
|
|
||||||
config: {
|
|
||||||
url: '',
|
|
||||||
method: 'GET',
|
|
||||||
headers: '',
|
|
||||||
listSelector: '',
|
|
||||||
titleSelector: '',
|
|
||||||
linkSelector: '',
|
|
||||||
contentSelector: '',
|
|
||||||
},
|
|
||||||
enabled: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const formRules: FormRules = {
|
const formRules: FormRules = {
|
||||||
name: [{ required: true, message: '请输入数据源名称', trigger: 'blur' }],
|
name: [{ required: true, message: '名称必填', trigger: 'blur' }],
|
||||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
|
'config.url': [{ required: true, message: 'URL必填', trigger: 'blur' }]
|
||||||
cronExpression: [{ required: true, message: '请输入采集频率', trigger: 'blur' }],
|
|
||||||
'config.url': [{ required: true, message: '请输入 URL', trigger: 'blur' }],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await request.get('/sources', {
|
const res = await request.get('/sources', { params: { page: pagination.page, limit: pagination.limit } })
|
||||||
params: {
|
|
||||||
page: pagination.page,
|
|
||||||
limit: pagination.limit,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
tableData.value = res.data || []
|
tableData.value = res.data || []
|
||||||
pagination.total = res.pagination?.total || 0
|
pagination.total = res.pagination?.total || 0
|
||||||
} catch (error) {
|
|
||||||
console.error('加载数据失败', error)
|
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => { isEdit.value = false; drawerVisible.value = true }
|
||||||
isEdit.value = false
|
|
||||||
dialogVisible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEdit = (row: Source) => {
|
const handleEdit = (row: Source) => {
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
const config = row.config || {}
|
Object.assign(formData, { id: row.id, name: row.name, type: row.type, cronExpression: row.cronExpression, config: { ...row.config }, enabled: row.enabled })
|
||||||
Object.assign(formData, {
|
drawerVisible.value = true
|
||||||
id: row.id,
|
|
||||||
name: row.name,
|
|
||||||
type: row.type,
|
|
||||||
cronExpression: row.cronExpression,
|
|
||||||
config: {
|
|
||||||
url: config.url || '',
|
|
||||||
method: config.method || 'GET',
|
|
||||||
headers: config.headers ? JSON.stringify(config.headers) : '',
|
|
||||||
listSelector: config.listSelector || '',
|
|
||||||
titleSelector: config.titleSelector || '',
|
|
||||||
linkSelector: config.linkSelector || '',
|
|
||||||
contentSelector: config.contentSelector || '',
|
|
||||||
},
|
|
||||||
enabled: row.enabled,
|
|
||||||
})
|
|
||||||
dialogVisible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleDelete = async (row: Source) => {
|
|
||||||
try {
|
|
||||||
await ElMessageBox.confirm(`确定要删除数据源 "${row.name}" 吗?`, '提示', {
|
|
||||||
type: 'warning',
|
|
||||||
})
|
|
||||||
await request.delete(`/sources/${row.id}`)
|
|
||||||
ElMessage.success('删除成功')
|
|
||||||
loadData()
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error !== 'cancel') {
|
|
||||||
console.error('删除失败', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleToggleEnabled = async (row: Source) => {
|
|
||||||
try {
|
|
||||||
await request.put(`/sources/${row.id}`, {
|
|
||||||
enabled: row.enabled,
|
|
||||||
})
|
|
||||||
ElMessage.success(row.enabled ? '已启用' : '已禁用')
|
|
||||||
} catch (error) {
|
|
||||||
row.enabled = !row.enabled
|
|
||||||
console.error('更新状态失败', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCollect = async (row: Source) => {
|
|
||||||
try {
|
|
||||||
await request.post(`/sources/${row.id}/collect`)
|
|
||||||
ElMessage.success('采集任务已触发')
|
|
||||||
} catch (error) {
|
|
||||||
console.error('触发采集失败', error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!formRef.value) return
|
if (!formRef.value) return
|
||||||
|
|
||||||
try {
|
|
||||||
await formRef.value.validate()
|
await formRef.value.validate()
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
|
|
||||||
// 构建配置对象
|
|
||||||
let config: Record<string, any> = { url: formData.config.url }
|
|
||||||
|
|
||||||
if (formData.type === 'api') {
|
|
||||||
config.method = formData.config.method
|
|
||||||
if (formData.config.headers) {
|
|
||||||
try {
|
try {
|
||||||
config.headers = JSON.parse(formData.config.headers)
|
const method = isEdit.value ? 'put' : 'post'
|
||||||
} catch {
|
const url = isEdit.value ? `/sources/${formData.id}` : '/sources'
|
||||||
ElMessage.error('请求头格式错误,请输入有效的 JSON')
|
await request[method](url, formData)
|
||||||
submitting.value = false
|
ElMessage.success('操作成功')
|
||||||
return
|
drawerVisible.value = false
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (formData.type === 'playwright') {
|
|
||||||
config = {
|
|
||||||
url: formData.config.url,
|
|
||||||
listSelector: formData.config.listSelector,
|
|
||||||
titleSelector: formData.config.titleSelector,
|
|
||||||
linkSelector: formData.config.linkSelector,
|
|
||||||
contentSelector: formData.config.contentSelector,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
name: formData.name,
|
|
||||||
type: formData.type,
|
|
||||||
cronExpression: formData.cronExpression,
|
|
||||||
config,
|
|
||||||
enabled: formData.enabled,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEdit.value) {
|
|
||||||
await request.put(`/sources/${formData.id}`, data)
|
|
||||||
ElMessage.success('更新成功')
|
|
||||||
} else {
|
|
||||||
await request.post('/sources', data)
|
|
||||||
ElMessage.success('创建成功')
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogVisible.value = false
|
|
||||||
loadData()
|
loadData()
|
||||||
} catch (error) {
|
|
||||||
console.error('提交失败', error)
|
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetForm = () => {
|
const handleCollect = async (row: Source) => {
|
||||||
Object.assign(formData, {
|
await request.post(`/sources/${row.id}/collect`)
|
||||||
id: 0,
|
ElMessage.success('采集任务已排队')
|
||||||
name: '',
|
|
||||||
type: 'rss',
|
|
||||||
cronExpression: '0 * * * *',
|
|
||||||
config: {
|
|
||||||
url: '',
|
|
||||||
method: 'GET',
|
|
||||||
headers: '',
|
|
||||||
listSelector: '',
|
|
||||||
titleSelector: '',
|
|
||||||
linkSelector: '',
|
|
||||||
contentSelector: '',
|
|
||||||
},
|
|
||||||
enabled: true,
|
|
||||||
})
|
|
||||||
formRef.value?.resetFields()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTypeLabel = (type: string) => {
|
const handleDelete = async (row: Source) => {
|
||||||
const map: Record<string, string> = {
|
await ElMessageBox.confirm('确定彻底删除该数据源?', '删除确认', { type: 'warning' })
|
||||||
rss: 'RSS',
|
await request.delete(`/sources/${row.id}`)
|
||||||
api: 'API',
|
|
||||||
playwright: '爬虫',
|
|
||||||
}
|
|
||||||
return map[type] || type
|
|
||||||
}
|
|
||||||
|
|
||||||
const getTypeTagType = (type: string) => {
|
|
||||||
const map: Record<string, 'success' | 'warning' | 'info'> = {
|
|
||||||
rss: 'success',
|
|
||||||
api: 'warning',
|
|
||||||
playwright: 'info',
|
|
||||||
}
|
|
||||||
return map[type] || 'info'
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatTime = (time: string) => {
|
|
||||||
return new Date(time).toLocaleString('zh-CN')
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadData()
|
loadData()
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
Object.assign(formData, { id: 0, name: '', type: 'rss', cronExpression: '0 * * * *', config: { url: '', method: 'GET' }, enabled: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTypeIcon = (type: string) => {
|
||||||
|
if (type === 'rss') return Rss
|
||||||
|
if (type === 'api') return Code2
|
||||||
|
return Globe
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTypeIconClass = (type: string) => {
|
||||||
|
if (type === 'rss') return 'text-orange-500'
|
||||||
|
if (type === 'api') return 'text-blue-500'
|
||||||
|
return 'text-purple-500'
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTypeLabel = (type: string) => ({ rss: 'RSS Feed', api: 'REST API', playwright: 'Crawler' }[type] || type)
|
||||||
|
const formatTime = (t: string) => new Date(t).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
|
||||||
|
|
||||||
|
onMounted(loadData)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.sources {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.page-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.page-header h2 {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 20px;
|
|
||||||
color: #303133;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pagination-wrapper {
|
|
||||||
margin-top: 20px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
export default {
|
||||||
|
darkMode: 'class',
|
||||||
|
content: [
|
||||||
|
'./index.html',
|
||||||
|
'./src/**/*.{vue,js,ts,jsx,tsx}',
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
container: {
|
||||||
|
center: true,
|
||||||
|
padding: '2rem',
|
||||||
|
screens: {
|
||||||
|
'2xl': '1400px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extend: {
|
||||||
|
colors: {
|
||||||
|
border: 'hsl(var(--border))',
|
||||||
|
input: 'hsl(var(--input))',
|
||||||
|
ring: 'hsl(var(--ring))',
|
||||||
|
background: 'hsl(var(--background))',
|
||||||
|
foreground: 'hsl(var(--foreground))',
|
||||||
|
primary: {
|
||||||
|
DEFAULT: 'hsl(var(--primary))',
|
||||||
|
foreground: 'hsl(var(--primary-foreground))',
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
DEFAULT: 'hsl(var(--secondary))',
|
||||||
|
foreground: 'hsl(var(--secondary-foreground))',
|
||||||
|
},
|
||||||
|
destructive: {
|
||||||
|
DEFAULT: 'hsl(var(--destructive))',
|
||||||
|
foreground: 'hsl(var(--destructive-foreground))',
|
||||||
|
},
|
||||||
|
muted: {
|
||||||
|
DEFAULT: 'hsl(var(--muted))',
|
||||||
|
foreground: 'hsl(var(--muted-foreground))',
|
||||||
|
},
|
||||||
|
accent: {
|
||||||
|
DEFAULT: 'hsl(var(--accent))',
|
||||||
|
foreground: 'hsl(var(--accent-foreground))',
|
||||||
|
},
|
||||||
|
popover: {
|
||||||
|
DEFAULT: 'hsl(var(--popover))',
|
||||||
|
foreground: 'hsl(var(--popover-foreground))',
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
DEFAULT: 'hsl(var(--card))',
|
||||||
|
foreground: 'hsl(var(--card-foreground))',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
borderRadius: {
|
||||||
|
lg: 'var(--radius)',
|
||||||
|
md: 'calc(var(--radius) - 2px)',
|
||||||
|
sm: 'calc(var(--radius) - 4px)',
|
||||||
|
},
|
||||||
|
keyframes: {
|
||||||
|
'accordion-down': {
|
||||||
|
from: { height: 0 },
|
||||||
|
to: { height: 'var(--radix-accordion-content-height)' },
|
||||||
|
},
|
||||||
|
'accordion-up': {
|
||||||
|
from: { height: 'var(--radix-accordion-content-height)' },
|
||||||
|
to: { height: 0 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
animation: {
|
||||||
|
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||||
|
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
require('@tailwindcss/typography'),
|
||||||
|
],
|
||||||
|
}
|
||||||
Reference in new issue
Block a user