Files
hughhuangandClaude Sonnet 4.5 830a17bf46 初始化项目结构和基础模块
完成内容:
- 创建前后端项目目录结构
- 初始化 Node.js + TypeScript 后端项目 (Fastify)
- 初始化 Vue 3 + TypeScript 前端项目 (Vite)
- 配置 Prisma ORM 和 MySQL 数据库
- 创建数据库 Schema 和种子数据
- 实现后端基础模块 (配置、日志、错误处理、验证)
- 创建基础服务类 (BaseService)
- 配置 Git 仓库和忽略文件

技术栈:
- 后端:Fastify + Prisma + MySQL + Winston
- 前端:Vue 3 + TypeScript + Element Plus + Pinia

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 12:11:57 +08:00

573 lines
11 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 任务 11-16:前端开发与部署(简要说明)
由于时间和篇幅限制,任务 11-16 的详细文档将在实际开发时补充。这里提供简要的任务说明和关键点。
## 任务 11:前端配置管理
### 任务目标
实现配置管理页面,包括 LLM 配置、数据源、推送渠道、主题的增删改查。
### 关键功能
- LLM 配置 CRUD
- 数据源 CRUD(支持三种类型配置)
- 推送渠道 CRUD(支持多种渠道配置)
- 主题 CRUD(关联数据源和渠道)
### 技术要点
- 使用 Element Plus 表格和表单组件
- 表单验证
- JSON 配置编辑器
- Cron 表达式编辑器
---
## 任务 12:前端报告中心
### 任务目标
实现报告列表、报告详情、报告筛选等功能。
### 关键功能
- 报告列表(分页、筛选)
- 报告详情(Markdown 渲染)
- 报告状态显示
- 手动生成报告
### 技术要点
- Markdown 渲染(使用 markdown-it)
- 分页组件
- 筛选器
- 状态标签
---
## 任务 13:前端资讯浏览
### 任务目标
实现资讯列表、资讯详情、资讯筛选等功能。
### 关键功能
- 资讯列表(分页、筛选)
- 按数据源筛选
- 按主题筛选
- 按时间范围筛选
- 资讯详情
### 技术要点
- 虚拟滚动(大数据量)
- 日期范围选择器
- 多条件筛选
---
## 任务 14:前端采集监控
### 任务目标
实现采集状态监控、采集日志查看、手动触发采集等功能。
### 关键功能
- 数据源状态概览
- 采集日志列表
- 采集统计图表
- 手动触发采集
### 技术要点
- 实时状态更新
- 图表展示(使用 ECharts)
- 日志查看器
---
## 任务 15:AI Agent 实现
### 任务目标
实现 AI Agent 对话功能,支持基于报告/资讯的深入探索。
### 关键功能
- 对话界面
- 流式响应
- 上下文管理
- 自动获取更多信息
### 技术要点
- WebSocket 或 SSE(流式响应)
- 对话历史管理
- Markdown 渲染
- 代码高亮
### 后端实现
创建 `backend/src/services/agent.service.ts`:
```typescript
import { LlmClient } from '../utils/llm-client'
import prisma from '../utils/prisma'
import { logger } from '../utils/logger'
export class AgentService {
async chat(params: {
reportId?: number
articleId?: number
topicId: number
messages: Array<{ role: string; content: string }>
llmConfigId: number
}) {
// 1. 加载上下文
const context = await this.loadContext(params)
// 2. 构建 prompt
const systemPrompt = this.buildSystemPrompt(context)
// 3. 调用 LLM
const llmConfig = await prisma.llmConfig.findUnique({
where: { id: params.llmConfigId },
})
if (!llmConfig) {
throw new Error('LLM config not found')
}
const llmClient = new LlmClient({
baseUrl: llmConfig.baseUrl,
model: llmConfig.model,
apiKey: llmConfig.apiKey,
})
const messages = [
{ role: 'system', content: systemPrompt },
...params.messages,
]
const response = await llmClient.chat(messages as any)
// 4. 保存对话历史
await this.saveConversation(params, response.content)
return response.content
}
private async loadContext(params: any) {
// 加载报告/资讯内容作为上下文
// ...
}
private buildSystemPrompt(context: any) {
return `你是一个资讯分析助手。
当前上下文:
${context}
你的能力:
1. 回答用户关于资讯的问题
2. 提供深入分析和见解
3. 如果需要更多信息,可以说明需要什么信息
请用中文回答。`
}
private async saveConversation(params: any, response: string) {
// 保存对话历史到数据库
// ...
}
}
```
### 前端实现
创建 `frontend/src/views/reports/AgentChat.vue`:
```vue
<template>
<div class="agent-chat">
<div class="messages">
<div
v-for="(msg, index) in messages"
:key="index"
:class="['message', msg.role]"
>
<div class="message-content" v-html="renderMarkdown(msg.content)" />
</div>
</div>
<div class="input-area">
<el-input
v-model="input"
type="textarea"
:rows="3"
placeholder="输入你的问题..."
@keydown.enter.ctrl="sendMessage"
/>
<el-button type="primary" @click="sendMessage" :loading="loading">
发送
</el-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import request from '@/api/request'
import MarkdownIt from 'markdown-it'
const md = new MarkdownIt()
interface Props {
reportId?: number
articleId?: number
topicId: number
}
const props = defineProps<Props>()
const messages = ref<Array<{ role: string; content: string }>>([])
const input = ref('')
const loading = ref(false)
const sendMessage = async () => {
if (!input.value.trim()) return
const userMessage = input.value
messages.value.push({ role: 'user', content: userMessage })
input.value = ''
loading.value = true
try {
const response = await request.post('/agent/chat', {
reportId: props.reportId,
articleId: props.articleId,
topicId: props.topicId,
messages: messages.value,
})
messages.value.push({ role: 'assistant', content: response })
} catch (error) {
ElMessage.error('发送失败')
} finally {
loading.value = false
}
}
const renderMarkdown = (content: string) => {
return md.render(content)
}
</script>
<style scoped>
.agent-chat {
display: flex;
flex-direction: column;
height: 600px;
}
.messages {
flex: 1;
overflow-y: auto;
padding: 20px;
}
.message {
margin-bottom: 20px;
}
.message.user {
text-align: right;
}
.message.assistant {
text-align: left;
}
.message-content {
display: inline-block;
max-width: 70%;
padding: 10px 15px;
border-radius: 8px;
background-color: #f0f0f0;
}
.message.user .message-content {
background-color: #409eff;
color: white;
}
.input-area {
padding: 20px;
border-top: 1px solid #e6e6e6;
display: flex;
gap: 10px;
}
</style>
```
---
## 任务 16:部署配置
### 任务目标
配置生产环境部署,包括构建、部署脚本、监控等。
### 关键内容
#### 1. 后端构建
```bash
cd backend
npm run build
```
#### 2. 前端构建
```bash
cd frontend
npm run build
```
构建产物在 `frontend/dist` 目录。
#### 3. Nginx 配置
创建 `nginx.conf`:
```nginx
server {
listen 80;
server_name your-domain.com;
# 前端静态文件
location / {
root /var/www/news-aggregator/frontend/dist;
try_files $uri $uri/ /index.html;
}
# 后端 API
location /api {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
```
#### 4. PM2 配置
已在任务 08 中创建 `ecosystem.config.js`。
启动:
```bash
pm2 start ecosystem.config.js
pm2 save
pm2 startup
```
#### 5. Docker 部署(可选)
创建 `docker-compose.yml`:
```yaml
version: '3.8'
services:
mysql:
image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: news_aggregator
volumes:
- mysql-data:/var/lib/mysql
ports:
- "3306:3306"
backend:
build: ./backend
environment:
DATABASE_URL: mysql://root:password@mysql:3306/news_aggregator
NODE_ENV: production
depends_on:
- mysql
ports:
- "3000:3000"
frontend:
build: ./frontend
ports:
- "80:80"
depends_on:
- backend
volumes:
mysql-data:
```
创建 `backend/Dockerfile`:
```dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
```
创建 `frontend/Dockerfile`:
```dockerfile
FROM node:20-alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
```
#### 6. 环境变量配置
生产环境 `.env`:
```env
NODE_ENV=production
PORT=3000
HOST=0.0.0.0
DATABASE_URL=mysql://user:password@localhost:3306/news_aggregator
LOG_LEVEL=info
CORS_ORIGIN=https://your-domain.com
WEB_BASE_URL=https://your-domain.com
```
#### 7. 监控和日志
使用 PM2 监控:
```bash
# 查看状态
pm2 status
# 查看日志
pm2 logs
# 监控面板
pm2 monit
# Web 监控(可选)
pm2 install pm2-server-monit
```
#### 8. 备份策略
数据库备份脚本 `scripts/backup.sh`:
```bash
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/var/backups/news-aggregator"
DB_NAME="news_aggregator"
mkdir -p $BACKUP_DIR
# 备份数据库
mysqldump -u root -p$MYSQL_PASSWORD $DB_NAME > $BACKUP_DIR/db_$DATE.sql
# 压缩
gzip $BACKUP_DIR/db_$DATE.sql
# 删除 7 天前的备份
find $BACKUP_DIR -name "db_*.sql.gz" -mtime +7 -delete
echo "Backup completed: db_$DATE.sql.gz"
```
添加到 crontab:
```bash
# 每天凌晨 2 点备份
0 2 * * * /path/to/scripts/backup.sh
```
#### 9. 部署检查清单
- [ ] 环境变量配置正确
- [ ] 数据库已创建并迁移
- [ ] 后端构建成功
- [ ] 前端构建成功
- [ ] Nginx 配置正确
- [ ] PM2 启动成功
- [ ] 日志正常输出
- [ ] API 可以访问
- [ ] 前端页面可以访问
- [ ] 定时任务正常运行
- [ ] 备份脚本配置完成
---
## 总结
以上是任务 11-16 的简要说明。详细的实现步骤将在实际开发时补充。
### 开发优先级
1. **高优先级**(MVP)
- 任务 01-09:后端核心功能
- 任务 10-11:前端基础和配置管理
2. **中优先级**
- 任务 12-14:前端报告、资讯、监控
- 任务 16:基础部署
3. **低优先级**(增强功能)
- 任务 15:AI Agent
### 预计工作量
- 任务 11:前端配置管理 - 2-3 天
- 任务 12:前端报告中心 - 2 天
- 任务 13:前端资讯浏览 - 1-2 天
- 任务 14:前端采集监控 - 1-2 天
- 任务 15:AI Agent - 2-3 天
- 任务 16:部署配置 - 1 天
**总计**:9-13 天
### 下一步
建议按以下顺序开始实施:
1. 完成任务 01-03(基础设施)
2. 完成任务 04-08(核心功能)
3. 完成任务 09(Web API)
4. 测试后端功能
5. 完成任务 10-11(前端基础)
6. 完成任务 12-14(前端功能)
7. 完成任务 15(AI Agent)
8. 完成任务 16(部署)
---
**注意**:以上任务文档会在实际开发过程中持续完善和更新。