Compare commits
4
Commits
697430feed
...
cb54568b22
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb54568b22 | ||
|
|
07edbca4af | ||
|
|
457d69799d | ||
|
|
8edf7cbc9e |
No files matched your search
+13
-7
@@ -22,25 +22,25 @@
|
||||
## 前端任务
|
||||
|
||||
### 基础设施
|
||||
- [x] [任务 10:前端初始化](./10-frontend-setup.md) - 基础结构已创建
|
||||
- [x] [任务 10:前端初始化](./10-frontend-setup.md) - 已完成
|
||||
|
||||
### 配置管理
|
||||
- [ ] [任务 11:前端配置管理](./11-frontend-config.md)
|
||||
- [x] [任务 11:前端配置管理](./11-16-summary.md) - 已完成
|
||||
|
||||
### 报告中心
|
||||
- [ ] [任务 12:前端报告中心](./12-frontend-reports.md)
|
||||
- [x] [任务 12:前端报告中心](./11-16-summary.md) - 已完成
|
||||
|
||||
### 资讯浏览
|
||||
- [ ] [任务 13:前端资讯浏览](./13-frontend-articles.md)
|
||||
- [x] [任务 13:前端资讯浏览](./11-16-summary.md) - 已完成
|
||||
|
||||
### 采集监控
|
||||
- [ ] [任务 14:前端采集监控](./14-frontend-monitoring.md)
|
||||
- [x] [任务 14:前端采集监控](./11-16-summary.md) - 已完成
|
||||
|
||||
## AI Agent
|
||||
- [ ] [任务 15:AI Agent 实现](./15-ai-agent.md)
|
||||
- [ ] [任务 15:AI Agent 实现](./11-16-summary.md)
|
||||
|
||||
## 部署
|
||||
- [ ] [任务 16:部署配置](./16-deployment.md)
|
||||
- [ ] [任务 16:部署配置](./11-16-summary.md)
|
||||
|
||||
## 任务说明
|
||||
|
||||
@@ -202,3 +202,9 @@ npm run dev
|
||||
|
||||
- 2024-01-01: 创建任务清单
|
||||
- 2024-01-02: 完成任务 01-09 文档
|
||||
- 2025-02-05: 完成任务 10-14(前端开发)
|
||||
- 任务 10:前端基础设施(路由、API封装、状态管理、布局)
|
||||
- 任务 11:前端配置管理(LLM配置、数据源、推送渠道、主题)
|
||||
- 任务 12:前端报告中心(Markdown渲染、复制下载功能)
|
||||
- 任务 13:前端资讯浏览(列表、筛选、详情)
|
||||
- 任务 14:前端采集监控(ECharts图表、状态概览、日志)
|
||||
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=http://localhost:3000/api/v1
|
||||
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=/api/v1
|
||||
Generated
+127
@@ -9,10 +9,14 @@
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"axios": "^1.13.4",
|
||||
"echarts": "^6.0.0",
|
||||
"element-plus": "^2.13.2",
|
||||
"markdown-it": "^14.1.0",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.24",
|
||||
"vue-echarts": "^8.0.1",
|
||||
"vue-router": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -936,6 +940,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/linkify-it": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
|
||||
"integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.23",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.23.tgz",
|
||||
@@ -952,6 +962,22 @@
|
||||
"@types/lodash": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/markdown-it": {
|
||||
"version": "14.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
|
||||
"integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/linkify-it": "^5",
|
||||
"@types/mdurl": "^2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mdurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
|
||||
"integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.10.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.9.tgz",
|
||||
@@ -1278,6 +1304,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||
"license": "Python-2.0"
|
||||
},
|
||||
"node_modules/async-validator": {
|
||||
"version": "4.2.5",
|
||||
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz",
|
||||
@@ -1385,6 +1417,17 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/echarts": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/echarts/-/echarts-6.0.0.tgz",
|
||||
"integrity": "sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==",
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0",
|
||||
"zrender": "6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/element-plus": {
|
||||
"version": "2.13.2",
|
||||
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.13.2.tgz",
|
||||
@@ -1699,6 +1742,15 @@
|
||||
"url": "https://github.com/sponsors/mesqueeb"
|
||||
}
|
||||
},
|
||||
"node_modules/linkify-it": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",
|
||||
"integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"uc.micro": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.23",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.23.tgz",
|
||||
@@ -1733,6 +1785,35 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/markdown-it": {
|
||||
"version": "14.1.0",
|
||||
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz",
|
||||
"integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1",
|
||||
"entities": "^4.4.0",
|
||||
"linkify-it": "^5.0.0",
|
||||
"mdurl": "^2.0.0",
|
||||
"punycode.js": "^2.3.1",
|
||||
"uc.micro": "^2.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"markdown-it": "bin/markdown-it.mjs"
|
||||
}
|
||||
},
|
||||
"node_modules/markdown-it/node_modules/entities": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
|
||||
"integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=0.12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
@@ -1742,6 +1823,12 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/mdurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
|
||||
"integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/memoize-one": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-6.0.0.tgz",
|
||||
@@ -1894,6 +1981,15 @@
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/punycode.js": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
|
||||
"integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/rfdc": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz",
|
||||
@@ -1992,6 +2088,12 @@
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
|
||||
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
@@ -2007,6 +2109,12 @@
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/uc.micro": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
|
||||
"integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.16.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||
@@ -2119,6 +2227,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vue-echarts": {
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/vue-echarts/-/vue-echarts-8.0.1.tgz",
|
||||
"integrity": "sha512-23rJTFLu1OUEGRWjJGmdGt8fP+8+ja1gVgzMYPIPaHWpXegcO1viIAaeu2H4QHESlVeHzUAHIxKXGrwjsyXAaA==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"echarts": "^6.0.0",
|
||||
"vue": "^3.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vue-router": {
|
||||
"version": "4.6.4",
|
||||
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.6.4.tgz",
|
||||
@@ -2156,6 +2274,15 @@
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/zrender": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/zrender/-/zrender-6.0.0.tgz",
|
||||
"integrity": "sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,14 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"axios": "^1.13.4",
|
||||
"echarts": "^6.0.0",
|
||||
"element-plus": "^2.13.2",
|
||||
"markdown-it": "^14.1.0",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.24",
|
||||
"vue-echarts": "^8.0.1",
|
||||
"vue-router": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+13
-24
@@ -1,30 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a href="https://vite.dev" target="_blank">
|
||||
<img src="/vite.svg" class="logo" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://vuejs.org/" target="_blank">
|
||||
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
|
||||
</a>
|
||||
</div>
|
||||
<HelloWorld msg="Vite + Vue" />
|
||||
<MainLayout />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
<script setup lang="ts">
|
||||
import MainLayout from '@/layouts/MainLayout.vue'
|
||||
</script>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.vue:hover {
|
||||
filter: drop-shadow(0 0 2em #42b883aa);
|
||||
|
||||
#app {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,103 @@
|
||||
import axios from 'axios'
|
||||
import type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
// API 响应类型
|
||||
export interface ApiResponse<T = any> {
|
||||
success: boolean
|
||||
data: T
|
||||
pagination?: {
|
||||
total: number
|
||||
page: number
|
||||
limit: number
|
||||
totalPages: number
|
||||
}
|
||||
message?: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
// 创建 axios 实例
|
||||
const service: AxiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || '/api/v1',
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
console.error('Request error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response: AxiosResponse): any => {
|
||||
const res = response.data
|
||||
|
||||
// 如果响应格式不是标准格式,直接返回
|
||||
if (res.success === undefined) {
|
||||
return res
|
||||
}
|
||||
|
||||
// 处理业务错误
|
||||
if (!res.success) {
|
||||
ElMessage.error(res.error || '请求失败')
|
||||
return Promise.reject(new Error(res.error || '请求失败'))
|
||||
}
|
||||
|
||||
// 返回包含 data 和 pagination 的完整响应
|
||||
return res
|
||||
},
|
||||
(error) => {
|
||||
console.error('Response error:', error)
|
||||
|
||||
// 处理 HTTP 错误
|
||||
if (error.response) {
|
||||
const status = error.response.status
|
||||
switch (status) {
|
||||
case 401:
|
||||
ElMessage.error('未授权,请登录')
|
||||
break
|
||||
case 403:
|
||||
ElMessage.error('拒绝访问')
|
||||
break
|
||||
case 404:
|
||||
ElMessage.error('请求的资源不存在')
|
||||
break
|
||||
case 500:
|
||||
ElMessage.error('服务器错误')
|
||||
break
|
||||
default:
|
||||
ElMessage.error(error.response.data?.error || '请求失败')
|
||||
}
|
||||
} else if (error.request) {
|
||||
ElMessage.error('网络错误,请检查网络连接')
|
||||
} else {
|
||||
ElMessage.error('请求配置错误')
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 封装请求方法
|
||||
const request = {
|
||||
get<T = any>(url: string, config?: any): Promise<ApiResponse<T>> {
|
||||
return service.get(url, config)
|
||||
},
|
||||
post<T = any>(url: string, data?: any, config?: any): Promise<ApiResponse<T>> {
|
||||
return service.post(url, data, config)
|
||||
},
|
||||
put<T = any>(url: string, data?: any, config?: any): Promise<ApiResponse<T>> {
|
||||
return service.put(url, data, config)
|
||||
},
|
||||
delete<T = any>(url: string, config?: any): Promise<ApiResponse<T>> {
|
||||
return service.delete(url, config)
|
||||
},
|
||||
}
|
||||
|
||||
export default request
|
||||
@@ -0,0 +1,127 @@
|
||||
// 分页参数
|
||||
export interface PaginationParams {
|
||||
page?: number
|
||||
limit?: number
|
||||
}
|
||||
|
||||
// 分页信息
|
||||
export interface Pagination {
|
||||
total: number
|
||||
page: number
|
||||
limit: number
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
// 分页响应
|
||||
export interface PaginatedResponse<T> {
|
||||
success: boolean
|
||||
data: T[]
|
||||
pagination: Pagination
|
||||
}
|
||||
|
||||
// LLM 配置
|
||||
export interface LlmConfig {
|
||||
id: number
|
||||
name: string
|
||||
baseUrl: string
|
||||
model: string
|
||||
apiKey: string
|
||||
enabled: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
// 数据源
|
||||
export interface Source {
|
||||
id: number
|
||||
name: string
|
||||
type: 'api' | 'playwright' | 'rss'
|
||||
config: Record<string, any>
|
||||
cronExpression: string
|
||||
enabled: boolean
|
||||
lastCollectedAt: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
// 推送渠道
|
||||
export interface Channel {
|
||||
id: number
|
||||
name: string
|
||||
type: 'email' | 'dingtalk' | 'wechat' | 'slack'
|
||||
config: Record<string, any>
|
||||
enabled: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
// 主题
|
||||
export interface Topic {
|
||||
id: number
|
||||
name: string
|
||||
description: string | null
|
||||
processMode: 'aggregate' | 'summary' | 'deep_analysis'
|
||||
llmConfigId: number | null
|
||||
scheduleConfig: Record<string, any>
|
||||
enabled: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
llmConfig?: LlmConfig
|
||||
topicSources?: Array<{ source: Source }>
|
||||
topicChannels?: Array<{ channel: Channel }>
|
||||
}
|
||||
|
||||
// 报告
|
||||
export interface Report {
|
||||
id: number
|
||||
topicId: number
|
||||
title: string
|
||||
content: string
|
||||
periodStart: string
|
||||
periodEnd: string
|
||||
status: 'pending' | 'generating' | 'completed' | 'failed'
|
||||
errorMessage: string | null
|
||||
articleCount: number
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
topic?: Topic
|
||||
}
|
||||
|
||||
// 资讯
|
||||
export interface Article {
|
||||
id: number
|
||||
sourceId: number
|
||||
title: string
|
||||
content: string | null
|
||||
summary: string | null
|
||||
url: string | null
|
||||
publishedAt: string | null
|
||||
collectedAt: string
|
||||
createdAt: string
|
||||
source?: Source
|
||||
}
|
||||
|
||||
// 采集日志
|
||||
export interface CollectionLog {
|
||||
id: number
|
||||
sourceId: number
|
||||
status: 'success' | 'failed' | 'running'
|
||||
errorMessage: string | null
|
||||
articlesCount: number
|
||||
startedAt: string
|
||||
finishedAt: string | null
|
||||
createdAt: string
|
||||
source?: Source
|
||||
}
|
||||
|
||||
// 采集统计
|
||||
export interface CollectionStats {
|
||||
id: number
|
||||
name: string
|
||||
type: string
|
||||
enabled: boolean
|
||||
totalArticles: number
|
||||
totalCollections: number
|
||||
lastCollectedAt: string | null
|
||||
lastLog: CollectionLog | null
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<el-container class="main-layout">
|
||||
<!-- 侧边栏 -->
|
||||
<el-aside :width="sidebarWidth">
|
||||
<div class="logo">
|
||||
<h2 v-if="!appStore.sidebarCollapsed">资讯聚合</h2>
|
||||
<h2 v-else>NA</h2>
|
||||
</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">
|
||||
<el-icon><HomeFilled /></el-icon>
|
||||
<template #title>仪表盘</template>
|
||||
</el-menu-item>
|
||||
|
||||
<el-sub-menu index="/config">
|
||||
<template #title>
|
||||
<el-icon><Setting /></el-icon>
|
||||
<span>配置管理</span>
|
||||
</template>
|
||||
<el-menu-item index="/config/llm">LLM 配置</el-menu-item>
|
||||
<el-menu-item index="/config/sources">数据源</el-menu-item>
|
||||
<el-menu-item index="/config/channels">推送渠道</el-menu-item>
|
||||
<el-menu-item index="/config/topics">主题</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<el-menu-item index="/reports">
|
||||
<el-icon><Document /></el-icon>
|
||||
<template #title>报告中心</template>
|
||||
</el-menu-item>
|
||||
|
||||
<el-menu-item index="/articles">
|
||||
<el-icon><Reading /></el-icon>
|
||||
<template #title>资讯浏览</template>
|
||||
</el-menu-item>
|
||||
|
||||
<el-menu-item index="/monitoring">
|
||||
<el-icon><Monitor /></el-icon>
|
||||
<template #title>采集监控</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="/">
|
||||
<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>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<el-main>
|
||||
<router-view />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import {
|
||||
HomeFilled,
|
||||
Setting,
|
||||
Document,
|
||||
Reading,
|
||||
Monitor,
|
||||
Expand,
|
||||
Fold,
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
const route = useRoute()
|
||||
const appStore = useAppStore()
|
||||
|
||||
const sidebarWidth = computed(() => {
|
||||
return appStore.sidebarCollapsed ? '64px' : '200px'
|
||||
})
|
||||
|
||||
const activeMenu = computed(() => {
|
||||
return route.path
|
||||
})
|
||||
|
||||
const breadcrumbs = computed(() => {
|
||||
const matched = route.matched.filter((item) => item.meta?.title)
|
||||
return matched.map((item) => ({
|
||||
path: item.path,
|
||||
title: item.meta.title as string,
|
||||
}))
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.main-layout {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.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>
|
||||
@@ -1,13 +1,85 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/dashboard',
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/MainLayout.vue'),
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('@/views/Dashboard.vue'),
|
||||
meta: { title: '仪表盘' },
|
||||
},
|
||||
{
|
||||
path: 'config/llm',
|
||||
name: 'LlmConfig',
|
||||
component: () => import('@/views/config/LlmConfig.vue'),
|
||||
meta: { title: 'LLM 配置' },
|
||||
},
|
||||
{
|
||||
path: 'config/sources',
|
||||
name: 'Sources',
|
||||
component: () => import('@/views/config/Sources.vue'),
|
||||
meta: { title: '数据源管理' },
|
||||
},
|
||||
{
|
||||
path: 'config/channels',
|
||||
name: 'Channels',
|
||||
component: () => import('@/views/config/Channels.vue'),
|
||||
meta: { title: '推送渠道' },
|
||||
},
|
||||
{
|
||||
path: 'config/topics',
|
||||
name: 'Topics',
|
||||
component: () => import('@/views/config/Topics.vue'),
|
||||
meta: { title: '主题管理' },
|
||||
},
|
||||
{
|
||||
path: 'reports',
|
||||
name: 'Reports',
|
||||
component: () => import('@/views/reports/ReportList.vue'),
|
||||
meta: { title: '报告中心' },
|
||||
},
|
||||
{
|
||||
path: 'reports/:id',
|
||||
name: 'ReportDetail',
|
||||
component: () => import('@/views/reports/ReportDetail.vue'),
|
||||
meta: { title: '报告详情' },
|
||||
},
|
||||
{
|
||||
path: 'articles',
|
||||
name: 'Articles',
|
||||
component: () => import('@/views/articles/ArticleList.vue'),
|
||||
meta: { title: '资讯浏览' },
|
||||
},
|
||||
{
|
||||
path: 'monitoring',
|
||||
name: 'Monitoring',
|
||||
component: () => import('@/views/monitoring/Monitoring.vue'),
|
||||
meta: { title: '采集监控' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
// 路由守卫
|
||||
router.beforeEach((to, _from, next) => {
|
||||
// 设置页面标题
|
||||
if (to.meta.title) {
|
||||
document.title = `${to.meta.title} - 资讯聚合系统`
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,17 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
// 侧边栏折叠状态
|
||||
const sidebarCollapsed = ref(false)
|
||||
|
||||
// 切换侧边栏
|
||||
const toggleSidebar = () => {
|
||||
sidebarCollapsed.value = !sidebarCollapsed.value
|
||||
}
|
||||
|
||||
return {
|
||||
sidebarCollapsed,
|
||||
toggleSidebar,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,276 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#409eff"><Connection /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.sources }}</div>
|
||||
<div class="stat-label">数据源</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#67c23a"><Collection /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.topics }}</div>
|
||||
<div class="stat-label">主题</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<el-icon class="stat-icon" :size="40" color="#e6a23c"><Document /></el-icon>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.reports }}</div>
|
||||
<div class="stat-label">报告</div>
|
||||
</div>
|
||||
</div>
|
||||
</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
|
||||
v-for="report in recentReports"
|
||||
:key="report.id"
|
||||
class="report-item"
|
||||
@click="$router.push(`/reports/${report.id}`)"
|
||||
>
|
||||
<div class="report-title">{{ report.title }}</div>
|
||||
<div class="report-meta">
|
||||
<el-tag :type="getStatusType(report.status)" size="small">
|
||||
{{ getStatusText(report.status) }}
|
||||
</el-tag>
|
||||
<span class="report-time">
|
||||
{{ formatTime(report.createdAt) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>采集状态</span>
|
||||
<el-button type="primary" link @click="$router.push('/monitoring')">
|
||||
查看详情
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-empty v-if="collectionStats.length === 0" description="暂无数据" />
|
||||
<div v-else class="collection-list">
|
||||
<div
|
||||
v-for="stat in collectionStats"
|
||||
:key="stat.id"
|
||||
class="collection-item"
|
||||
>
|
||||
<div class="collection-name">{{ stat.name }}</div>
|
||||
<div class="collection-meta">
|
||||
<el-tag
|
||||
:type="stat.lastLog?.status === 'success' ? 'success' : (stat.lastLog ? 'danger' : 'info')"
|
||||
size="small"
|
||||
>
|
||||
{{ stat.lastLog?.status === 'success' ? '成功' : (stat.lastLog ? '失败' : '未采集') }}
|
||||
</el-tag>
|
||||
<span class="collection-time">
|
||||
{{ stat.lastCollectedAt ? formatTime(stat.lastCollectedAt) : '从未采集' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { Connection, Collection, Document, Reading } from '@element-plus/icons-vue'
|
||||
import request from '@/api/request'
|
||||
import type { Report, CollectionStats } from '@/api/types'
|
||||
|
||||
const stats = ref({
|
||||
sources: 0,
|
||||
topics: 0,
|
||||
reports: 0,
|
||||
articles: 0,
|
||||
})
|
||||
|
||||
const recentReports = ref<Report[]>([])
|
||||
const collectionStats = ref<CollectionStats[]>([])
|
||||
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
const [sourcesRes, topicsRes, reportsRes, articlesRes] = await Promise.all([
|
||||
request.get('/sources', { params: { limit: 1 } }),
|
||||
request.get('/topics', { params: { limit: 1 } }),
|
||||
request.get('/reports', { params: { limit: 1 } }),
|
||||
request.get('/articles', { params: { limit: 1 } }),
|
||||
])
|
||||
|
||||
stats.value = {
|
||||
sources: sourcesRes.pagination?.total || 0,
|
||||
topics: topicsRes.pagination?.total || 0,
|
||||
reports: reportsRes.pagination?.total || 0,
|
||||
articles: articlesRes.pagination?.total || 0,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadRecentReports = async () => {
|
||||
try {
|
||||
const res = await request.get('/reports', { params: { limit: 5 } })
|
||||
recentReports.value = res.data || []
|
||||
} catch (error) {
|
||||
console.error('加载最近报告失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadCollectionStats = async () => {
|
||||
try {
|
||||
const res = await request.get('/collection-logs/stats')
|
||||
collectionStats.value = (res.data || []).slice(0, 5)
|
||||
} catch (error) {
|
||||
console.error('加载采集状态失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusType = (status: string) => {
|
||||
const map: Record<string, 'info' | 'warning' | 'success' | 'danger'> = {
|
||||
pending: 'info',
|
||||
generating: 'warning',
|
||||
completed: 'success',
|
||||
failed: 'danger',
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
pending: '待处理',
|
||||
generating: '生成中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
const formatTime = (time: string | null) => {
|
||||
if (!time) return '未知'
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStats()
|
||||
loadRecentReports()
|
||||
loadCollectionStats()
|
||||
})
|
||||
</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>
|
||||
@@ -0,0 +1,277 @@
|
||||
<template>
|
||||
<div class="article-list">
|
||||
<div class="page-header">
|
||||
<h2>资讯浏览</h2>
|
||||
</div>
|
||||
|
||||
<el-card class="filter-card">
|
||||
<el-form :inline="true" :model="filters">
|
||||
<el-form-item label="数据源">
|
||||
<el-select v-model="filters.sourceId" placeholder="全部数据源" clearable style="width: 180px">
|
||||
<el-option
|
||||
v-for="item in sources"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="主题">
|
||||
<el-select v-model="filters.topicId" placeholder="全部主题" clearable style="width: 180px">
|
||||
<el-option
|
||||
v-for="item in topics"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="日期范围">
|
||||
<el-date-picker
|
||||
v-model="filters.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 260px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadData">查询</el-button>
|
||||
<el-button @click="resetFilters">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card style="margin-top: 20px">
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="title" label="标题" min-width="250" show-overflow-tooltip />
|
||||
<el-table-column label="数据源" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small">{{ row.source?.name || '-' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="url" label="链接" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-link v-if="row.url" :href="row.url" target="_blank" type="primary">查看</el-link>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="publishedAt" label="发布时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ row.publishedAt ? formatTime(row.publishedAt) : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="collectedAt" label="采集时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.collectedAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleView(row)">详情</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 详情对话框 -->
|
||||
<el-dialog v-model="detailVisible" title="资讯详情" width="700px">
|
||||
<template v-if="currentArticle">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="标题" :span="2">{{ currentArticle.title }}</el-descriptions-item>
|
||||
<el-descriptions-item label="数据源">{{ currentArticle.source?.name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="链接">
|
||||
<el-link v-if="currentArticle.url" :href="currentArticle.url" target="_blank" type="primary">
|
||||
{{ currentArticle.url }}
|
||||
</el-link>
|
||||
<span v-else>-</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="发布时间">
|
||||
{{ currentArticle.publishedAt ? formatTime(currentArticle.publishedAt) : '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="采集时间">{{ formatTime(currentArticle.collectedAt) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<el-divider />
|
||||
|
||||
<div v-if="currentArticle.summary" class="article-section">
|
||||
<h4>摘要</h4>
|
||||
<p>{{ currentArticle.summary }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="currentArticle.content" class="article-section">
|
||||
<h4>内容</h4>
|
||||
<div class="article-content">{{ currentArticle.content }}</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { Article, Source, Topic } from '@/api/types'
|
||||
|
||||
const loading = ref(false)
|
||||
const tableData = ref<Article[]>([])
|
||||
const sources = ref<Source[]>([])
|
||||
const topics = ref<Topic[]>([])
|
||||
const detailVisible = ref(false)
|
||||
const currentArticle = ref<Article | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 20,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const filters = reactive({
|
||||
sourceId: null as number | null,
|
||||
topicId: null as number | null,
|
||||
dateRange: null as [string, string] | null,
|
||||
})
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: Record<string, any> = {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
}
|
||||
if (filters.sourceId) params.sourceId = filters.sourceId
|
||||
if (filters.topicId) params.topicId = filters.topicId
|
||||
if (filters.dateRange) {
|
||||
params.startDate = filters.dateRange[0]
|
||||
params.endDate = filters.dateRange[1]
|
||||
}
|
||||
|
||||
const res = await request.get('/articles', { params })
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadOptions = async () => {
|
||||
try {
|
||||
const [sourceRes, topicRes] = await Promise.all([
|
||||
request.get('/sources', { params: { limit: 100 } }),
|
||||
request.get('/topics', { params: { limit: 100 } }),
|
||||
])
|
||||
sources.value = sourceRes.data || []
|
||||
topics.value = topicRes.data || []
|
||||
} catch (error) {
|
||||
console.error('加载选项失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.sourceId = null
|
||||
filters.topicId = null
|
||||
filters.dateRange = null
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handleView = async (row: Article) => {
|
||||
try {
|
||||
const res = await request.get(`/articles/${row.id}`)
|
||||
currentArticle.value = res.data
|
||||
detailVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取详情失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (row: Article) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除资讯 "${row.title}" 吗?`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
await request.delete(`/articles/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.article-list {
|
||||
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;
|
||||
}
|
||||
|
||||
.filter-card :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.pagination-wrapper {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.article-section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.article-section h4 {
|
||||
margin-bottom: 10px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
padding: 15px;
|
||||
background-color: #fafafa;
|
||||
border-radius: 4px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,396 @@
|
||||
<template>
|
||||
<div class="channels">
|
||||
<div class="page-header">
|
||||
<h2>推送渠道管理</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增渠道
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="name" label="名称" min-width="150" />
|
||||
<el-table-column prop="type" label="类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getTypeTagType(row.type)">{{ getTypeLabel(row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="enabled" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-model="row.enabled" @change="handleToggleEnabled(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createdAt" label="创建时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑推送渠道' : '新增推送渠道'"
|
||||
width="550px"
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入渠道名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="formData.type" placeholder="请选择类型" style="width: 100%">
|
||||
<el-option label="邮件" value="email" />
|
||||
<el-option label="钉钉" value="dingtalk" />
|
||||
<el-option label="企业微信" value="wechat" />
|
||||
<el-option label="Slack" value="slack" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 邮件配置 -->
|
||||
<template v-if="formData.type === 'email'">
|
||||
<el-divider content-position="left">邮件配置</el-divider>
|
||||
<el-form-item label="SMTP 服务器" prop="config.host">
|
||||
<el-input v-model="formData.config.host" placeholder="如:smtp.gmail.com" />
|
||||
</el-form-item>
|
||||
<el-form-item label="端口" prop="config.port">
|
||||
<el-input-number v-model="formData.config.port" :min="1" :max="65535" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名">
|
||||
<el-input v-model="formData.config.user" placeholder="SMTP 用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码">
|
||||
<el-input v-model="formData.config.pass" type="password" show-password placeholder="SMTP 密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="发件人">
|
||||
<el-input v-model="formData.config.from" placeholder="发件人邮箱地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="收件人" prop="config.to">
|
||||
<el-input v-model="formData.config.to" placeholder="收件人邮箱,多个用逗号分隔" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<!-- 钉钉配置 -->
|
||||
<template v-if="formData.type === 'dingtalk'">
|
||||
<el-divider content-position="left">钉钉配置</el-divider>
|
||||
<el-form-item label="Webhook" prop="config.webhook">
|
||||
<el-input v-model="formData.config.webhook" placeholder="钉钉机器人 Webhook 地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="签名密钥">
|
||||
<el-input v-model="formData.config.secret" placeholder="加签密钥(可选)" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<!-- 企业微信配置 -->
|
||||
<template v-if="formData.type === 'wechat'">
|
||||
<el-divider content-position="left">企业微信配置</el-divider>
|
||||
<el-form-item label="Webhook" prop="config.webhook">
|
||||
<el-input v-model="formData.config.webhook" placeholder="企业微信机器人 Webhook 地址" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<!-- Slack 配置 -->
|
||||
<template v-if="formData.type === 'slack'">
|
||||
<el-divider content-position="left">Slack 配置</el-divider>
|
||||
<el-form-item label="Webhook" prop="config.webhook">
|
||||
<el-input v-model="formData.config.webhook" placeholder="Slack Webhook URL" />
|
||||
</el-form-item>
|
||||
<el-form-item label="频道">
|
||||
<el-input v-model="formData.config.channel" placeholder="频道名称(可选)" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-form-item label="启用状态">
|
||||
<el-switch v-model="formData.enabled" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { Channel } from '@/api/types'
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const tableData = ref<Channel[]>([])
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
type: 'email' as 'email' | 'dingtalk' | 'wechat' | 'slack',
|
||||
config: {
|
||||
// 邮件
|
||||
host: '',
|
||||
port: 587,
|
||||
user: '',
|
||||
pass: '',
|
||||
from: '',
|
||||
to: '',
|
||||
// 钉钉/企业微信/Slack
|
||||
webhook: '',
|
||||
secret: '',
|
||||
channel: '',
|
||||
},
|
||||
enabled: true,
|
||||
})
|
||||
|
||||
const formRules: FormRules = {
|
||||
name: [{ required: true, message: '请输入渠道名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
|
||||
'config.to': [{ required: true, message: '请输入收件人', trigger: 'blur' }],
|
||||
'config.webhook': [{ required: true, message: '请输入 Webhook 地址', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get('/channels', {
|
||||
params: {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
},
|
||||
})
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleEdit = (row: Channel) => {
|
||||
isEdit.value = true
|
||||
const config = row.config || {}
|
||||
Object.assign(formData, {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
type: row.type,
|
||||
config: {
|
||||
host: config.host || '',
|
||||
port: config.port || 587,
|
||||
user: config.user || '',
|
||||
pass: config.pass || '',
|
||||
from: config.from || '',
|
||||
to: config.to || '',
|
||||
webhook: config.webhook || '',
|
||||
secret: config.secret || '',
|
||||
channel: config.channel || '',
|
||||
},
|
||||
enabled: row.enabled,
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleDelete = async (row: Channel) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除渠道 "${row.name}" 吗?`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
await request.delete(`/channels/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleEnabled = async (row: Channel) => {
|
||||
try {
|
||||
await request.put(`/channels/${row.id}`, {
|
||||
enabled: row.enabled,
|
||||
})
|
||||
ElMessage.success(row.enabled ? '已启用' : '已禁用')
|
||||
} catch (error) {
|
||||
row.enabled = !row.enabled
|
||||
console.error('更新状态失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
|
||||
// 根据类型构建配置对象
|
||||
let config: Record<string, any> = {}
|
||||
|
||||
if (formData.type === 'email') {
|
||||
config = {
|
||||
host: formData.config.host,
|
||||
port: formData.config.port,
|
||||
user: formData.config.user,
|
||||
pass: formData.config.pass,
|
||||
from: formData.config.from,
|
||||
to: formData.config.to,
|
||||
}
|
||||
} else if (formData.type === 'dingtalk') {
|
||||
config = {
|
||||
webhook: formData.config.webhook,
|
||||
secret: formData.config.secret || undefined,
|
||||
}
|
||||
} else if (formData.type === 'wechat') {
|
||||
config = {
|
||||
webhook: formData.config.webhook,
|
||||
}
|
||||
} else if (formData.type === 'slack') {
|
||||
config = {
|
||||
webhook: formData.config.webhook,
|
||||
channel: formData.config.channel || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const data = {
|
||||
name: formData.name,
|
||||
type: formData.type,
|
||||
config,
|
||||
enabled: formData.enabled,
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
await request.put(`/channels/${formData.id}`, data)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await request.post('/channels', data)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
|
||||
dialogVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
console.error('提交失败', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formData, {
|
||||
id: 0,
|
||||
name: '',
|
||||
type: 'email',
|
||||
config: {
|
||||
host: '',
|
||||
port: 587,
|
||||
user: '',
|
||||
pass: '',
|
||||
from: '',
|
||||
to: '',
|
||||
webhook: '',
|
||||
secret: '',
|
||||
channel: '',
|
||||
},
|
||||
enabled: true,
|
||||
})
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const getTypeLabel = (type: string) => {
|
||||
const map: Record<string, string> = {
|
||||
email: '邮件',
|
||||
dingtalk: '钉钉',
|
||||
wechat: '企业微信',
|
||||
slack: 'Slack',
|
||||
}
|
||||
return map[type] || type
|
||||
}
|
||||
|
||||
const getTypeTagType = (type: string) => {
|
||||
const map: Record<string, 'success' | 'warning' | 'info' | 'danger'> = {
|
||||
email: 'info',
|
||||
dingtalk: 'success',
|
||||
wechat: 'warning',
|
||||
slack: 'danger',
|
||||
}
|
||||
return map[type] || 'info'
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.channels {
|
||||
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,281 @@
|
||||
<template>
|
||||
<div class="llm-config">
|
||||
<div class="page-header">
|
||||
<h2>LLM 配置管理</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增配置
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="name" label="名称" min-width="120" />
|
||||
<el-table-column prop="baseUrl" label="API 地址" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="model" label="模型" min-width="120" />
|
||||
<el-table-column prop="apiKey" label="API Key" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<span>{{ maskApiKey(row.apiKey) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="enabled" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch
|
||||
v-model="row.enabled"
|
||||
@change="handleToggleEnabled(row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createdAt" label="创建时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑 LLM 配置' : '新增 LLM 配置'"
|
||||
width="500px"
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入配置名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="API 地址" prop="baseUrl">
|
||||
<el-input v-model="formData.baseUrl" placeholder="如:https://api.openai.com/v1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="模型" prop="model">
|
||||
<el-input v-model="formData.model" placeholder="如:gpt-4、gpt-3.5-turbo" />
|
||||
</el-form-item>
|
||||
<el-form-item label="API Key" prop="apiKey">
|
||||
<el-input
|
||||
v-model="formData.apiKey"
|
||||
type="password"
|
||||
show-password
|
||||
placeholder="请输入 API Key"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="启用状态">
|
||||
<el-switch v-model="formData.enabled" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { LlmConfig } from '@/api/types'
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const tableData = ref<LlmConfig[]>([])
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
baseUrl: '',
|
||||
model: '',
|
||||
apiKey: '',
|
||||
enabled: true,
|
||||
})
|
||||
|
||||
const formRules: FormRules = {
|
||||
name: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
|
||||
baseUrl: [{ required: true, message: '请输入 API 地址', trigger: 'blur' }],
|
||||
model: [{ required: true, message: '请输入模型名称', trigger: 'blur' }],
|
||||
apiKey: [{ required: true, message: '请输入 API Key', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get('/llm-configs', {
|
||||
params: {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
},
|
||||
})
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleEdit = (row: LlmConfig) => {
|
||||
isEdit.value = true
|
||||
Object.assign(formData, {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
baseUrl: row.baseUrl,
|
||||
model: row.model,
|
||||
apiKey: row.apiKey,
|
||||
enabled: row.enabled,
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleDelete = async (row: LlmConfig) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除配置 "${row.name}" 吗?`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
await request.delete(`/llm-configs/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleEnabled = async (row: LlmConfig) => {
|
||||
try {
|
||||
await request.put(`/llm-configs/${row.id}`, {
|
||||
enabled: row.enabled,
|
||||
})
|
||||
ElMessage.success(row.enabled ? '已启用' : '已禁用')
|
||||
} catch (error) {
|
||||
row.enabled = !row.enabled
|
||||
console.error('更新状态失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
|
||||
const data = {
|
||||
name: formData.name,
|
||||
baseUrl: formData.baseUrl,
|
||||
model: formData.model,
|
||||
apiKey: formData.apiKey,
|
||||
enabled: formData.enabled,
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
await request.put(`/llm-configs/${formData.id}`, data)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await request.post('/llm-configs', data)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
|
||||
dialogVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
console.error('提交失败', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formData, {
|
||||
id: 0,
|
||||
name: '',
|
||||
baseUrl: '',
|
||||
model: '',
|
||||
apiKey: '',
|
||||
enabled: true,
|
||||
})
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const maskApiKey = (key: string) => {
|
||||
if (!key || key.length < 8) return '****'
|
||||
return key.slice(0, 4) + '****' + key.slice(-4)
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.llm-config {
|
||||
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,402 @@
|
||||
<template>
|
||||
<div class="sources">
|
||||
<div class="page-header">
|
||||
<h2>数据源管理</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增数据源
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="name" label="名称" min-width="150" />
|
||||
<el-table-column prop="type" label="类型" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getTypeTagType(row.type)">{{ getTypeLabel(row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="cronExpression" label="采集频率" width="120" />
|
||||
<el-table-column prop="lastCollectedAt" label="最后采集" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ row.lastCollectedAt ? formatTime(row.lastCollectedAt) : '从未采集' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="enabled" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-model="row.enabled" @change="handleToggleEnabled(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="success" link @click="handleCollect(row)">采集</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑数据源' : '新增数据源'"
|
||||
width="600px"
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入数据源名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="formData.type" placeholder="请选择类型" style="width: 100%">
|
||||
<el-option label="RSS 订阅" value="rss" />
|
||||
<el-option label="API 接口" value="api" />
|
||||
<el-option label="网页爬虫" value="playwright" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="采集频率" prop="cronExpression">
|
||||
<el-input v-model="formData.cronExpression" placeholder="Cron 表达式,如:0 * * * *">
|
||||
<template #append>
|
||||
<el-tooltip content="每小时: 0 * * * * 每天: 0 0 * * * 每周: 0 0 * * 0" raw-content>
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-input>
|
||||
</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'">
|
||||
<el-divider content-position="left">API 配置</el-divider>
|
||||
<el-form-item label="API URL" prop="config.url">
|
||||
<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="POST" value="POST" />
|
||||
</el-select>
|
||||
</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>
|
||||
|
||||
<!-- Playwright 配置 -->
|
||||
<template v-if="formData.type === 'playwright'">
|
||||
<el-divider content-position="left">爬虫配置</el-divider>
|
||||
<el-form-item label="目标 URL" prop="config.url">
|
||||
<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>
|
||||
</template>
|
||||
|
||||
<el-form-item label="启用状态">
|
||||
<el-switch v-model="formData.enabled" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, QuestionFilled } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { Source } from '@/api/types'
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const tableData = ref<Source[]>([])
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
type: 'rss' as 'rss' | 'api' | 'playwright',
|
||||
cronExpression: '0 * * * *',
|
||||
config: {
|
||||
url: '',
|
||||
method: 'GET',
|
||||
headers: '',
|
||||
listSelector: '',
|
||||
titleSelector: '',
|
||||
linkSelector: '',
|
||||
contentSelector: '',
|
||||
},
|
||||
enabled: true,
|
||||
})
|
||||
|
||||
const formRules: FormRules = {
|
||||
name: [{ required: true, message: '请输入数据源名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
|
||||
cronExpression: [{ required: true, message: '请输入采集频率', trigger: 'blur' }],
|
||||
'config.url': [{ required: true, message: '请输入 URL', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get('/sources', {
|
||||
params: {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
},
|
||||
})
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleEdit = (row: Source) => {
|
||||
isEdit.value = true
|
||||
const config = row.config || {}
|
||||
Object.assign(formData, {
|
||||
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 () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
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 {
|
||||
config.headers = JSON.parse(formData.config.headers)
|
||||
} catch {
|
||||
ElMessage.error('请求头格式错误,请输入有效的 JSON')
|
||||
submitting.value = false
|
||||
return
|
||||
}
|
||||
}
|
||||
} 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()
|
||||
} catch (error) {
|
||||
console.error('提交失败', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formData, {
|
||||
id: 0,
|
||||
name: '',
|
||||
type: 'rss',
|
||||
cronExpression: '0 * * * *',
|
||||
config: {
|
||||
url: '',
|
||||
method: 'GET',
|
||||
headers: '',
|
||||
listSelector: '',
|
||||
titleSelector: '',
|
||||
linkSelector: '',
|
||||
contentSelector: '',
|
||||
},
|
||||
enabled: true,
|
||||
})
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const getTypeLabel = (type: string) => {
|
||||
const map: Record<string, string> = {
|
||||
rss: 'RSS',
|
||||
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()
|
||||
})
|
||||
</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,396 @@
|
||||
<template>
|
||||
<div class="topics">
|
||||
<div class="page-header">
|
||||
<h2>主题管理</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增主题
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="name" label="名称" min-width="150" />
|
||||
<el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="processMode" label="处理模式" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag>{{ getProcessModeLabel(row.processMode) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="LLM 配置" width="150">
|
||||
<template #default="{ row }">
|
||||
{{ row.llmConfig?.name || '未配置' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="enabled" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-model="row.enabled" @change="handleToggleEnabled(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="success" link @click="handleGenerateReport(row)">生成报告</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑主题' : '新增主题'"
|
||||
width="650px"
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入主题名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input
|
||||
v-model="formData.description"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="请输入主题描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="处理模式" prop="processMode">
|
||||
<el-select v-model="formData.processMode" placeholder="请选择处理模式" style="width: 100%">
|
||||
<el-option label="聚合" value="aggregate" />
|
||||
<el-option label="摘要" value="summary" />
|
||||
<el-option label="深度分析" value="deep_analysis" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="LLM 配置">
|
||||
<el-select
|
||||
v-model="formData.llmConfigId"
|
||||
placeholder="请选择 LLM 配置"
|
||||
style="width: 100%"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="item in llmConfigs"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="调度配置" prop="scheduleConfig">
|
||||
<el-input
|
||||
v-model="formData.scheduleCron"
|
||||
placeholder="Cron 表达式,如:0 0 * * 0(每周日)"
|
||||
>
|
||||
<template #append>
|
||||
<el-tooltip content="每天: 0 0 * * * 每周: 0 0 * * 0 每月: 0 0 1 * *" raw-content>
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">关联数据源</el-divider>
|
||||
<el-form-item label="数据源">
|
||||
<el-select
|
||||
v-model="formData.sourceIds"
|
||||
multiple
|
||||
placeholder="请选择关联的数据源"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in sources"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">关联推送渠道</el-divider>
|
||||
<el-form-item label="推送渠道">
|
||||
<el-select
|
||||
v-model="formData.channelIds"
|
||||
multiple
|
||||
placeholder="请选择关联的推送渠道"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in channels"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="启用状态">
|
||||
<el-switch v-model="formData.enabled" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, QuestionFilled } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { Topic, LlmConfig, Source, Channel } from '@/api/types'
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const tableData = ref<Topic[]>([])
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 下拉选项数据
|
||||
const llmConfigs = ref<LlmConfig[]>([])
|
||||
const sources = ref<Source[]>([])
|
||||
const channels = ref<Channel[]>([])
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
description: '',
|
||||
processMode: 'summary' as 'aggregate' | 'summary' | 'deep_analysis',
|
||||
llmConfigId: null as number | null,
|
||||
scheduleCron: '0 0 * * 0',
|
||||
sourceIds: [] as number[],
|
||||
channelIds: [] as number[],
|
||||
enabled: true,
|
||||
})
|
||||
|
||||
const formRules: FormRules = {
|
||||
name: [{ required: true, message: '请输入主题名称', trigger: 'blur' }],
|
||||
processMode: [{ required: true, message: '请选择处理模式', trigger: 'change' }],
|
||||
scheduleConfig: [{ required: true, message: '请输入调度配置', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get('/topics', {
|
||||
params: {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
},
|
||||
})
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadOptions = async () => {
|
||||
try {
|
||||
const [llmRes, sourceRes, channelRes] = await Promise.all([
|
||||
request.get('/llm-configs', { params: { limit: 100 } }),
|
||||
request.get('/sources', { params: { limit: 100 } }),
|
||||
request.get('/channels', { params: { limit: 100 } }),
|
||||
])
|
||||
llmConfigs.value = llmRes.data || []
|
||||
sources.value = sourceRes.data || []
|
||||
channels.value = channelRes.data || []
|
||||
} catch (error) {
|
||||
console.error('加载选项数据失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleEdit = async (row: Topic) => {
|
||||
isEdit.value = true
|
||||
|
||||
// 获取详情以获取关联数据
|
||||
try {
|
||||
const res = await request.get(`/topics/${row.id}`)
|
||||
const topic = res.data
|
||||
|
||||
Object.assign(formData, {
|
||||
id: topic.id,
|
||||
name: topic.name,
|
||||
description: topic.description || '',
|
||||
processMode: topic.processMode,
|
||||
llmConfigId: topic.llmConfigId,
|
||||
scheduleCron: topic.scheduleConfig?.cron || '0 0 * * 0',
|
||||
sourceIds: topic.topicSources?.map((ts: any) => ts.source.id) || [],
|
||||
channelIds: topic.topicChannels?.map((tc: any) => tc.channel.id) || [],
|
||||
enabled: topic.enabled,
|
||||
})
|
||||
dialogVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取主题详情失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (row: Topic) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除主题 "${row.name}" 吗?`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
await request.delete(`/topics/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleEnabled = async (row: Topic) => {
|
||||
try {
|
||||
await request.put(`/topics/${row.id}`, {
|
||||
enabled: row.enabled,
|
||||
})
|
||||
ElMessage.success(row.enabled ? '已启用' : '已禁用')
|
||||
} catch (error) {
|
||||
row.enabled = !row.enabled
|
||||
console.error('更新状态失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleGenerateReport = async (row: Topic) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要为主题 "${row.name}" 生成报告吗?`, '提示', {
|
||||
type: 'info',
|
||||
})
|
||||
await request.post(`/topics/${row.id}/generate-report`)
|
||||
ElMessage.success('报告生成任务已触发')
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('触发报告生成失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
|
||||
const data = {
|
||||
name: formData.name,
|
||||
description: formData.description || undefined,
|
||||
processMode: formData.processMode,
|
||||
llmConfigId: formData.llmConfigId || undefined,
|
||||
scheduleConfig: { cron: formData.scheduleCron },
|
||||
sourceIds: formData.sourceIds,
|
||||
channelIds: formData.channelIds,
|
||||
enabled: formData.enabled,
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
await request.put(`/topics/${formData.id}`, data)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await request.post('/topics', data)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
|
||||
dialogVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
console.error('提交失败', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formData, {
|
||||
id: 0,
|
||||
name: '',
|
||||
description: '',
|
||||
processMode: 'summary',
|
||||
llmConfigId: null,
|
||||
scheduleCron: '0 0 * * 0',
|
||||
sourceIds: [],
|
||||
channelIds: [],
|
||||
enabled: true,
|
||||
})
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const getProcessModeLabel = (mode: string) => {
|
||||
const map: Record<string, string> = {
|
||||
aggregate: '聚合',
|
||||
summary: '摘要',
|
||||
deep_analysis: '深度分析',
|
||||
}
|
||||
return map[mode] || mode
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.topics {
|
||||
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,469 @@
|
||||
<template>
|
||||
<div class="monitoring">
|
||||
<div class="page-header">
|
||||
<h2>采集监控</h2>
|
||||
<el-button type="primary" @click="loadData">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 统计图表 -->
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>采集趋势(近7天)</span>
|
||||
</template>
|
||||
<v-chart class="chart" :option="trendChartOption" autoresize />
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>数据源采集分布</span>
|
||||
</template>
|
||||
<v-chart class="chart" :option="pieChartOption" autoresize />
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 数据源状态概览 -->
|
||||
<el-row :gutter="20" style="margin-top: 20px">
|
||||
<el-col :span="24">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>数据源状态概览</span>
|
||||
</template>
|
||||
<el-table :data="statsData" v-loading="statsLoading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="name" label="数据源" min-width="150" />
|
||||
<el-table-column prop="type" label="类型" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getTypeTagType(row.type)" size="small">{{ getTypeLabel(row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="enabled" label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.enabled ? 'success' : 'info'" size="small">
|
||||
{{ row.enabled ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="totalArticles" label="文章数" width="100" />
|
||||
<el-table-column prop="totalCollections" label="采集次数" width="100" />
|
||||
<el-table-column label="最后采集" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ row.lastCollectedAt ? formatTime(row.lastCollectedAt) : '从未采集' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="最后状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag
|
||||
v-if="row.lastLog"
|
||||
:type="row.lastLog.status === 'success' ? 'success' : (row.lastLog.status === 'running' ? 'warning' : 'danger')"
|
||||
size="small"
|
||||
>
|
||||
{{ getLogStatusText(row.lastLog.status) }}
|
||||
</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleCollect(row)" :disabled="!row.enabled">
|
||||
采集
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 采集日志 -->
|
||||
<el-row :gutter="20" style="margin-top: 20px">
|
||||
<el-col :span="24">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>采集日志</span>
|
||||
<div class="filter-inline">
|
||||
<el-select v-model="logFilters.sourceId" placeholder="全部数据源" clearable size="small" style="width: 150px">
|
||||
<el-option
|
||||
v-for="item in sources"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select v-model="logFilters.status" placeholder="全部状态" clearable size="small" style="width: 120px; margin-left: 10px">
|
||||
<el-option label="成功" value="success" />
|
||||
<el-option label="失败" value="failed" />
|
||||
<el-option label="运行中" value="running" />
|
||||
</el-select>
|
||||
<el-button type="primary" size="small" style="margin-left: 10px" @click="loadLogs">查询</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-table :data="logsData" v-loading="logsLoading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="数据源" width="150">
|
||||
<template #default="{ row }">
|
||||
{{ row.source?.name || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getLogStatusType(row.status)" size="small">
|
||||
{{ getLogStatusText(row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="articlesCount" label="采集数量" width="100" />
|
||||
<el-table-column prop="startedAt" label="开始时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.startedAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="finishedAt" label="结束时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ row.finishedAt ? formatTime(row.finishedAt) : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="errorMessage" label="错误信息" min-width="200" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.errorMessage" class="error-text">{{ row.errorMessage }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="logPagination.page"
|
||||
v-model:page-size="logPagination.limit"
|
||||
:total="logPagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadLogs"
|
||||
@current-change="loadLogs"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Refresh } from '@element-plus/icons-vue'
|
||||
import { use } from 'echarts/core'
|
||||
import { CanvasRenderer } from 'echarts/renderers'
|
||||
import { LineChart, PieChart } from 'echarts/charts'
|
||||
import {
|
||||
TitleComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
GridComponent,
|
||||
} from 'echarts/components'
|
||||
import VChart from 'vue-echarts'
|
||||
import request from '@/api/request'
|
||||
import type { CollectionStats, CollectionLog, Source } from '@/api/types'
|
||||
|
||||
// 注册 ECharts 组件
|
||||
use([
|
||||
CanvasRenderer,
|
||||
LineChart,
|
||||
PieChart,
|
||||
TitleComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
GridComponent,
|
||||
])
|
||||
|
||||
const statsLoading = ref(false)
|
||||
const logsLoading = ref(false)
|
||||
const statsData = ref<CollectionStats[]>([])
|
||||
const logsData = ref<CollectionLog[]>([])
|
||||
const sources = ref<Source[]>([])
|
||||
|
||||
const logFilters = reactive({
|
||||
sourceId: null as number | null,
|
||||
status: '',
|
||||
})
|
||||
|
||||
const logPagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
// 采集趋势图表配置
|
||||
const trendChartOption = computed(() => {
|
||||
// 生成近7天的日期
|
||||
const dates: string[] = []
|
||||
const successData: number[] = []
|
||||
const failedData: number[] = []
|
||||
|
||||
for (let i = 6; i >= 0; i--) {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() - i)
|
||||
dates.push(`${date.getMonth() + 1}/${date.getDate()}`)
|
||||
|
||||
// 统计当天的成功和失败次数
|
||||
const dayStart = new Date(date)
|
||||
dayStart.setHours(0, 0, 0, 0)
|
||||
const dayEnd = new Date(date)
|
||||
dayEnd.setHours(23, 59, 59, 999)
|
||||
|
||||
const dayLogs = logsData.value.filter(log => {
|
||||
const logDate = new Date(log.startedAt)
|
||||
return logDate >= dayStart && logDate <= dayEnd
|
||||
})
|
||||
|
||||
successData.push(dayLogs.filter(l => l.status === 'success').length)
|
||||
failedData.push(dayLogs.filter(l => l.status === 'failed').length)
|
||||
}
|
||||
|
||||
return {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
},
|
||||
legend: {
|
||||
data: ['成功', '失败'],
|
||||
bottom: 0,
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '15%',
|
||||
top: '10%',
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: dates,
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
minInterval: 1,
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '成功',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
data: successData,
|
||||
itemStyle: { color: '#67c23a' },
|
||||
areaStyle: { color: 'rgba(103, 194, 58, 0.1)' },
|
||||
},
|
||||
{
|
||||
name: '失败',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
data: failedData,
|
||||
itemStyle: { color: '#f56c6c' },
|
||||
areaStyle: { color: 'rgba(245, 108, 108, 0.1)' },
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
// 数据源采集分布饼图配置
|
||||
const pieChartOption = computed(() => {
|
||||
const data = statsData.value
|
||||
.filter(s => s.totalArticles > 0)
|
||||
.map(s => ({
|
||||
name: s.name,
|
||||
value: s.totalArticles,
|
||||
}))
|
||||
|
||||
return {
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: '{b}: {c} ({d}%)',
|
||||
},
|
||||
legend: {
|
||||
orient: 'vertical',
|
||||
right: '5%',
|
||||
top: 'center',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
type: 'pie',
|
||||
radius: ['40%', '70%'],
|
||||
center: ['40%', '50%'],
|
||||
avoidLabelOverlap: false,
|
||||
itemStyle: {
|
||||
borderRadius: 4,
|
||||
borderColor: '#fff',
|
||||
borderWidth: 2,
|
||||
},
|
||||
label: {
|
||||
show: false,
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
show: true,
|
||||
fontSize: 14,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
},
|
||||
data: data.length > 0 ? data : [{ name: '暂无数据', value: 1 }],
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
const loadData = () => {
|
||||
loadStats()
|
||||
loadLogs()
|
||||
}
|
||||
|
||||
const loadStats = async () => {
|
||||
statsLoading.value = true
|
||||
try {
|
||||
const res = await request.get('/collection-logs/stats')
|
||||
statsData.value = res.data || []
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败', error)
|
||||
} finally {
|
||||
statsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadLogs = async () => {
|
||||
logsLoading.value = true
|
||||
try {
|
||||
const params: Record<string, any> = {
|
||||
page: logPagination.page,
|
||||
limit: logPagination.limit,
|
||||
}
|
||||
if (logFilters.sourceId) params.sourceId = logFilters.sourceId
|
||||
if (logFilters.status) params.status = logFilters.status
|
||||
|
||||
const res = await request.get('/collection-logs', { params })
|
||||
logsData.value = res.data || []
|
||||
logPagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载日志失败', error)
|
||||
} finally {
|
||||
logsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadSources = async () => {
|
||||
try {
|
||||
const res = await request.get('/sources', { params: { limit: 100 } })
|
||||
sources.value = res.data || []
|
||||
} catch (error) {
|
||||
console.error('加载数据源失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCollect = async (row: CollectionStats) => {
|
||||
try {
|
||||
await request.post(`/sources/${row.id}/collect`)
|
||||
ElMessage.success('采集任务已触发')
|
||||
// 延迟刷新数据
|
||||
setTimeout(() => {
|
||||
loadData()
|
||||
}, 1000)
|
||||
} catch (error) {
|
||||
console.error('触发采集失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getTypeLabel = (type: string) => {
|
||||
const map: Record<string, string> = {
|
||||
rss: 'RSS',
|
||||
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 getLogStatusType = (status: string) => {
|
||||
const map: Record<string, 'success' | 'warning' | 'danger'> = {
|
||||
success: 'success',
|
||||
running: 'warning',
|
||||
failed: 'danger',
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getLogStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
success: '成功',
|
||||
running: '运行中',
|
||||
failed: '失败',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadSources()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.monitoring {
|
||||
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;
|
||||
}
|
||||
|
||||
.chart {
|
||||
height: 280px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pagination-wrapper {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: #f56c6c;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,336 @@
|
||||
<template>
|
||||
<div class="report-detail" v-loading="loading">
|
||||
<div class="page-header">
|
||||
<el-button @click="$router.back()">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
返回
|
||||
</el-button>
|
||||
<h2>{{ report?.title || '报告详情' }}</h2>
|
||||
<el-button type="primary" @click="handleRefresh" :loading="loading">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card v-if="report">
|
||||
<div class="report-meta">
|
||||
<el-descriptions :column="3" border>
|
||||
<el-descriptions-item label="主题">{{ report.topic?.name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="getStatusType(report.status)">{{ getStatusText(report.status) }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="LLM 配置">{{ report.topic?.llmConfig?.name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="周期开始">{{ formatDate(report.periodStart) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="周期结束">{{ formatDate(report.periodEnd) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ formatTime(report.createdAt) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
|
||||
<el-divider />
|
||||
|
||||
<div class="report-content">
|
||||
<div class="content-header">
|
||||
<h3>报告内容</h3>
|
||||
<el-button-group v-if="report.status === 'completed'">
|
||||
<el-button size="small" @click="copyContent">
|
||||
<el-icon><CopyDocument /></el-icon>
|
||||
复制
|
||||
</el-button>
|
||||
<el-button size="small" @click="downloadContent">
|
||||
<el-icon><Download /></el-icon>
|
||||
下载
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
<div v-if="report.status === 'failed'" class="error-message">
|
||||
<el-alert :title="report.errorMessage || '生成失败'" type="error" show-icon :closable="false" />
|
||||
</div>
|
||||
<div v-else-if="report.status === 'pending' || report.status === 'generating'" class="pending-message">
|
||||
<el-empty description="报告正在生成中,请稍后刷新查看">
|
||||
<el-button type="primary" @click="handleRefresh">刷新状态</el-button>
|
||||
</el-empty>
|
||||
</div>
|
||||
<div v-else class="content-body markdown-body" v-html="renderedContent"></div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-empty v-else-if="!loading" description="报告不存在" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ArrowLeft, Refresh, CopyDocument, Download } from '@element-plus/icons-vue'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import request from '@/api/request'
|
||||
import type { Report } from '@/api/types'
|
||||
|
||||
// 初始化 markdown-it
|
||||
const md = new MarkdownIt({
|
||||
html: true,
|
||||
linkify: true,
|
||||
typographer: true,
|
||||
breaks: true,
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const report = ref<Report | null>(null)
|
||||
|
||||
const renderedContent = computed(() => {
|
||||
if (!report.value?.content) return ''
|
||||
return md.render(report.value.content)
|
||||
})
|
||||
|
||||
const loadReport = async () => {
|
||||
const id = route.params.id
|
||||
if (!id) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get(`/reports/${id}`)
|
||||
report.value = res.data
|
||||
} catch (error) {
|
||||
console.error('加载报告失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleRefresh = () => {
|
||||
loadReport()
|
||||
}
|
||||
|
||||
const copyContent = async () => {
|
||||
if (!report.value?.content) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(report.value.content)
|
||||
ElMessage.success('已复制到剪贴板')
|
||||
} catch (error) {
|
||||
ElMessage.error('复制失败')
|
||||
}
|
||||
}
|
||||
|
||||
const downloadContent = () => {
|
||||
if (!report.value?.content) return
|
||||
const blob = new Blob([report.value.content], { type: 'text/markdown' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `${report.value.title || '报告'}.md`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
ElMessage.success('下载成功')
|
||||
}
|
||||
|
||||
const getStatusType = (status: string) => {
|
||||
const map: Record<string, 'info' | 'warning' | 'success' | 'danger'> = {
|
||||
pending: 'info',
|
||||
generating: 'warning',
|
||||
completed: 'success',
|
||||
failed: 'danger',
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
pending: '待处理',
|
||||
generating: '生成中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
const formatDate = (date: string) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
if (!time) return '-'
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadReport()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.report-detail {
|
||||
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;
|
||||
}
|
||||
|
||||
.report-meta {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.report-content .content-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.report-content .content-header h3 {
|
||||
margin: 0;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.content-body {
|
||||
padding: 24px;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
line-height: 1.8;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
/* Markdown 样式 */
|
||||
.markdown-body :deep(h1) {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 24px 0 16px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.markdown-body :deep(h2) {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 12px;
|
||||
padding-bottom: 6px;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.markdown-body :deep(h3) {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin: 16px 0 10px;
|
||||
}
|
||||
|
||||
.markdown-body :deep(h4) {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin: 14px 0 8px;
|
||||
}
|
||||
|
||||
.markdown-body :deep(p) {
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.markdown-body :deep(ul),
|
||||
.markdown-body :deep(ol) {
|
||||
padding-left: 24px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.markdown-body :deep(li) {
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.markdown-body :deep(blockquote) {
|
||||
margin: 16px 0;
|
||||
padding: 12px 20px;
|
||||
background-color: #f5f7fa;
|
||||
border-left: 4px solid #409eff;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.markdown-body :deep(code) {
|
||||
padding: 2px 6px;
|
||||
background-color: #f5f7fa;
|
||||
border-radius: 3px;
|
||||
font-family: 'Consolas', 'Monaco', monospace;
|
||||
font-size: 14px;
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.markdown-body :deep(pre) {
|
||||
margin: 16px 0;
|
||||
padding: 16px;
|
||||
background-color: #282c34;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.markdown-body :deep(pre code) {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
color: #abb2bf;
|
||||
}
|
||||
|
||||
.markdown-body :deep(table) {
|
||||
width: 100%;
|
||||
margin: 16px 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.markdown-body :deep(th),
|
||||
.markdown-body :deep(td) {
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #ebeef5;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.markdown-body :deep(th) {
|
||||
background-color: #f5f7fa;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-body :deep(tr:nth-child(even)) {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.markdown-body :deep(a) {
|
||||
color: #409eff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.markdown-body :deep(a:hover) {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.markdown-body :deep(hr) {
|
||||
margin: 24px 0;
|
||||
border: none;
|
||||
border-top: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.markdown-body :deep(img) {
|
||||
max-width: 100%;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.markdown-body :deep(strong) {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-body :deep(em) {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.error-message,
|
||||
.pending-message {
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,220 @@
|
||||
<template>
|
||||
<div class="report-list">
|
||||
<div class="page-header">
|
||||
<h2>报告中心</h2>
|
||||
</div>
|
||||
|
||||
<el-card class="filter-card">
|
||||
<el-form :inline="true" :model="filters">
|
||||
<el-form-item label="主题">
|
||||
<el-select v-model="filters.topicId" placeholder="全部主题" clearable style="width: 200px">
|
||||
<el-option
|
||||
v-for="item in topics"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="filters.status" placeholder="全部状态" clearable style="width: 150px">
|
||||
<el-option label="待处理" value="pending" />
|
||||
<el-option label="生成中" value="generating" />
|
||||
<el-option label="已完成" value="completed" />
|
||||
<el-option label="失败" value="failed" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadData">查询</el-button>
|
||||
<el-button @click="resetFilters">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card style="margin-top: 20px">
|
||||
<el-table :data="tableData" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column prop="title" label="标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="主题" width="150">
|
||||
<template #default="{ row }">
|
||||
{{ row.topic?.name || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="周期" width="200">
|
||||
<template #default="{ row }">
|
||||
{{ formatDate(row.periodStart) }} ~ {{ formatDate(row.periodEnd) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createdAt" label="创建时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleView(row)">查看</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadData"
|
||||
@current-change="loadData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
import type { Report, Topic } from '@/api/types'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const tableData = ref<Report[]>([])
|
||||
const topics = ref<Topic[]>([])
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total: 0,
|
||||
})
|
||||
|
||||
const filters = reactive({
|
||||
topicId: null as number | null,
|
||||
status: '',
|
||||
})
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: Record<string, any> = {
|
||||
page: pagination.page,
|
||||
limit: pagination.limit,
|
||||
}
|
||||
if (filters.topicId) params.topicId = filters.topicId
|
||||
if (filters.status) params.status = filters.status
|
||||
|
||||
const res = await request.get('/reports', { params })
|
||||
tableData.value = res.data || []
|
||||
pagination.total = res.pagination?.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载数据失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadTopics = async () => {
|
||||
try {
|
||||
const res = await request.get('/topics', { params: { limit: 100 } })
|
||||
topics.value = res.data || []
|
||||
} catch (error) {
|
||||
console.error('加载主题失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.topicId = null
|
||||
filters.status = ''
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handleView = (row: Report) => {
|
||||
router.push(`/reports/${row.id}`)
|
||||
}
|
||||
|
||||
const handleDelete = async (row: Report) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除报告 "${row.title}" 吗?`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
await request.delete(`/reports/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusType = (status: string) => {
|
||||
const map: Record<string, 'info' | 'warning' | 'success' | 'danger'> = {
|
||||
pending: 'info',
|
||||
generating: 'warning',
|
||||
completed: 'success',
|
||||
failed: 'danger',
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
pending: '待处理',
|
||||
generating: '生成中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
const formatDate = (date: string) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
const formatTime = (time: string) => {
|
||||
return new Date(time).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadTopics()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.report-list {
|
||||
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;
|
||||
}
|
||||
|
||||
.filter-card :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.pagination-wrapper {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user