Files
tool-node/README.md
2026-03-19 14:21:14 +08:00

192 lines
4.1 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.

# 公告抓取与分析工具
一个用于管理公告抓取任务、查看抓取结果、查询项目数据并维护系统配置的工具。
当前项目结构已经升级为:
- 前端Vue 3 + JavaScript + Vite + Vue Router + Axios + Element Plus
- 后端Node.js + Express
- 数据存储better-sqlite3
- 调度node-cron
- 邮件nodemailer
## 功能概览
- 任务管理:新增、编辑、启用、禁用、删除任务
- 手动执行:支持单任务运行和批量运行
- 结果查看:按城市、板块、类型筛选抓取结果
- 项目查询:按项目名称、金额、日期范围过滤项目
- 系统设置:维护 Agent、定时任务、邮件配置
- 定时调度:支持 cron 表达式配置
- 数据持久化:任务与结果保存在 SQLite
## 环境要求
- Node.js 20 及以上可运行当前项目
- 建议使用 Node.js 22
说明:
- 当前依赖 `@mendable/firecrawl-js` 会提示要求 Node `>=22`
- 目前在 Node `20.19.4` 下可以安装、构建和启动
- 如果后续采集运行时出现环境兼容问题,优先升级到 Node 22
## 安装依赖
```bash
npm install
```
## 配置文件
项目根目录下使用 `config.json` 作为运行配置文件。
如果你还没有该文件,可以参考:
```bash
cp config.example.json config.json
```
需要重点配置的内容包括:
- `agent.baseUrl`
- `scheduler.enabled`
- `scheduler.cronTime`
- `email.smtpHost`
- `email.smtpUser`
- `email.smtpPass`
- `email.recipients`
## 启动方式
### 开发模式
前后端同时启动:
```bash
npm run dev
```
启动后地址如下:
- 前端开发服务:`http://localhost:5173`
- 后端 API 服务:`http://localhost:5000`
说明:
- Vite 前端会通过代理把 `/api` 请求转发到 `5000`
- 开发时建议直接访问 `http://localhost:5173`
### 生产模式
先构建前端,再启动 Express
```bash
npm run build
npm start
```
启动后访问:
- `http://localhost:5000`
说明:
- `npm run build` 会把前端构建到 `dist/`
- `npm start` 会由 Express 托管 `dist/` 静态资源和 `/api`
## 常用脚本
```bash
npm run dev
npm run build
npm run preview
npm start
```
脚本说明:
- `npm run dev`:开发模式,前后端同时启动
- `npm run build`:构建前端生产包
- `npm run preview`:本地预览前端构建结果
- `npm start`:启动后端服务,并托管前端构建产物
## 页面说明
### 任务配置
- 管理抓取任务
- 支持单独运行和批量运行
- 支持查看运行状态
### 抓取结果
- 查看每次抓取生成的记录
- 支持按条件筛选
- 支持删除结果
### 项目管理
- 对抓取出的项目做去重查询
- 支持金额和日期范围过滤
### 系统设置
- 配置 Agent 服务地址
- 配置定时任务
- 配置邮件发送参数
## 技术栈
- 前端Vue 3、Vite、Vue Router、Axios、Element Plus
- 后端Express
- 数据库better-sqlite3
- 调度node-cron
- 邮件nodemailer
## 项目结构
```text
.
├─ client/ # Vue 3 前端源码
│ ├─ index.html
│ └─ src/
│ ├─ api/
│ ├─ components/
│ ├─ pages/
│ ├─ router/
│ ├─ App.vue
│ ├─ main.js
│ └─ styles.css
├─ dist/ # Vite 构建产物
├─ src/ # Express 服务端
│ ├─ server.js
│ ├─ scheduler.js
│ ├─ resultStore.js
│ ├─ agentService.js
│ └─ emailService.js
├─ data/ # SQLite 数据文件目录
├─ config.json # 运行配置
├─ config.example.json # 配置示例
├─ package.json
├─ vite.config.js
└─ README.md
```
## 数据说明
- 任务数据和抓取结果保存在 SQLite
- 默认数据库路径位于 `data/results.sqlite`
- 配置数据保存在根目录 `config.json`
## 部署建议
- 使用 PM2 或 systemd 保持进程常驻
- 通过反向代理暴露 `5000` 端口
- 不要把 `config.json``data/``.env` 提交到公开仓库
## 备注
- 旧版 `public/` 页面已不再作为当前主前端入口
- 当前主前端以 `client/` 目录为准