dieya-app-portal/README.md

86 lines
2.8 KiB
Markdown
Raw 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.

# 蝶雅产品AI中心
面向产品部的对外统一工作台,当前只展示两个正式产品工具:风险预警、成本识别。项目按 frontend/ + backend/ 分层,采用 Vite 前端、FastAPI 后端与 SQLite 持久化统计。
## 目录
- frontend/:工作台卡片、浅色/深色主题、使用统计页面、前端测试及构建配置。
- backend/:FastAPI API、SQLite 数据库、统计接口和后端测试。
- deploy/nginx.conf.example:Nginx 静态站点与 API 反向代理配置示例。
## 使用统计
点击“打开工作台”时,前端向 POST /api/apps/{app_id}/click 发送一次请求,后端在 SQLite 中为该入口增加一次点击。使用统计页面通过 GET /api/stats 读取总次数、分应用次数和最近更新时间。后端只接受 risk、cost 两个白名单入口。
数据默认保存在 backend/data/usage.sqlite3。数据库使用事务与 WAL,服务重启后记录会保留。运行数据、密钥和依赖环境不会提交 Git。
## 本地运行
后端需要 Python 3.10+:
```powershell
cd backend
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
uvicorn app.main:app --reload --host 127.0.0.1 --port 8800
```
另开终端启动前端:
```powershell
cd frontend
npm install
npm run dev
```
访问 http://127.0.0.1:5173。Vite 会把 /api 代理到 127.0.0.1:8800。
前端检查和构建:
```powershell
cd frontend
npm test
npm run build
```
后端测试:
```powershell
cd backend
python -m unittest discover -s tests -p "test_*.py" -v
```
## 宝塔部署
先在 /www/wwwroot/dieya-app-portal/backend 安装后端依赖:
```bash
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/gunicorn -w 2 -k uvicorn.workers.UvicornWorker app.main:app -b 127.0.0.1:8800
```
宝塔使用 Python 项目或 Supervisor 托管该命令。工作目录是 backend,运行用户建议为 www,并确保 backend/data 可写。
再构建前端:
```bash
cd /www/wwwroot/dieya-app-portal/frontend
npm install
npm run build
```
网站根目录设为 /www/wwwroot/dieya-app-portal/frontend/dist。Nginx 把 /api/ 转发到 127.0.0.1:8800,其余路径返回 index.html,配置示例见 deploy/nginx.conf.example。前后端使用同一门户域名时无需额外配置 CORS。
部署后可用 curl https://你的域名/api/health 检查后端,用 curl https://你的域名/api/stats 查看统计。打开工作台后刷新“使用统计”,对应次数应增加 1。
## 应用范围
| 应用 | 地址 | 环境 |
| --- | --- | --- |
| 风险预警 | http://risk-prod.dieya.net.cn/ | 正式 |
| 成本识别 | http://cost.dieya.net.cn/ | 正式 |
其他业务入口、测试版应用和制度小助手不在门户展示。目标业务系统仍负责登录、钉钉免登及权限校验。