实现前端配置管理页面(Task 10-11)
- 完成前端基础设施:路由、API 封装、状态管理、布局组件 - 实现 LLM 配置管理:增删改查、启用禁用 - 实现数据源管理:支持 RSS/API/爬虫三种类型 - 实现推送渠道管理:支持邮件/钉钉/企业微信/Slack - 实现主题管理:关联数据源、渠道、LLM 配置 - 实现报告中心、资讯浏览、采集监控页面 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
697430feed
commit
8edf7cbc9e
17 files changed
+3220
-30
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_BASE_URL=http://localhost:3000/api/v1
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_BASE_URL=/api/v1
|
||||||
+13
-24
@@ -1,30 +1,19 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import HelloWorld from './components/HelloWorld.vue'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<MainLayout />
|
||||||
<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" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<script setup lang="ts">
|
||||||
.logo {
|
import MainLayout from '@/layouts/MainLayout.vue'
|
||||||
height: 6em;
|
</script>
|
||||||
padding: 1.5em;
|
|
||||||
will-change: filter;
|
<style>
|
||||||
transition: filter 300ms;
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.logo:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #646cffaa);
|
#app {
|
||||||
}
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||||
.logo.vue:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #42b883aa);
|
|
||||||
}
|
}
|
||||||
</style>
|
</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 { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
import type { RouteRecordRaw } from 'vue-router'
|
||||||
|
|
||||||
|
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({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes: [
|
routes,
|
||||||
{
|
})
|
||||||
path: '/',
|
|
||||||
redirect: '/dashboard',
|
// 路由守卫
|
||||||
},
|
router.beforeEach((to, _from, next) => {
|
||||||
],
|
// 设置页面标题
|
||||||
|
if (to.meta.title) {
|
||||||
|
document.title = `${to.meta.title} - 资讯聚合系统`
|
||||||
|
}
|
||||||
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
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,306 @@
|
|||||||
|
<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="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, onMounted } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { Refresh } from '@element-plus/icons-vue'
|
||||||
|
import request from '@/api/request'
|
||||||
|
import type { CollectionStats, CollectionLog, Source } from '@/api/types'
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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,163 @@
|
|||||||
|
<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>
|
||||||
|
<div></div>
|
||||||
|
</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">
|
||||||
|
<h3>报告内容</h3>
|
||||||
|
<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="报告正在生成中,请稍后刷新查看" />
|
||||||
|
</div>
|
||||||
|
<div v-else class="content-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 { ArrowLeft } from '@element-plus/icons-vue'
|
||||||
|
import request from '@/api/request'
|
||||||
|
import type { Report } from '@/api/types'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const loading = ref(false)
|
||||||
|
const report = ref<Report | null>(null)
|
||||||
|
|
||||||
|
const renderedContent = computed(() => {
|
||||||
|
if (!report.value?.content) return ''
|
||||||
|
// 简单的 Markdown 渲染(实际项目中可以使用 markdown-it)
|
||||||
|
return report.value.content
|
||||||
|
.replace(/^### (.*$)/gim, '<h3>$1</h3>')
|
||||||
|
.replace(/^## (.*$)/gim, '<h2>$1</h2>')
|
||||||
|
.replace(/^# (.*$)/gim, '<h1>$1</h1>')
|
||||||
|
.replace(/\*\*(.*)\*\*/gim, '<strong>$1</strong>')
|
||||||
|
.replace(/\*(.*)\*/gim, '<em>$1</em>')
|
||||||
|
.replace(/\n/gim, '<br>')
|
||||||
|
})
|
||||||
|
|
||||||
|
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 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 h3 {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-body {
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #fafafa;
|
||||||
|
border-radius: 4px;
|
||||||
|
line-height: 1.8;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-body :deep(h1),
|
||||||
|
.content-body :deep(h2),
|
||||||
|
.content-body :deep(h3) {
|
||||||
|
margin: 20px 0 10px;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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