Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12f8ec2bd2 | ||
|
|
b76e703dba | ||
|
|
c0fd432fc8 | ||
|
|
2bc1986e93 | ||
|
|
97899b5d06 | ||
|
|
5df05b4ebc | ||
|
|
9f9cd3e730 | ||
|
|
fb70082d54 | ||
|
|
32de74f103 | ||
|
|
cad685fe40 | ||
|
|
a7dbc5a77e | ||
|
|
f0a94bf523 | ||
|
|
872d3dc5c8 | ||
|
|
816af4b960 | ||
|
|
27f9054671 | ||
|
|
0964245246 | ||
|
|
e7c874537e | ||
|
|
489748dfc1 | ||
|
|
eeb951f9f6 | ||
|
|
68f29d0a14 | ||
|
|
6525275a54 | ||
|
|
8c61a05d8a | ||
|
|
57028b8626 | ||
|
|
5abdd91f35 | ||
|
|
008f6f5998 | ||
|
|
41bcb44e34 | ||
|
|
26d4125798 | ||
|
|
08d26a416e | ||
|
|
ffeebf80e6 | ||
|
|
e115bb7113 | ||
|
|
2a08338ed1 | ||
|
|
ee46776648 | ||
|
|
f8f108af5d | ||
|
|
87f995ca47 | ||
|
|
3214305dea | ||
|
|
7e0838de64 | ||
|
|
be1a2899ba | ||
|
|
dd546fc07b | ||
|
|
a4c172bc98 | ||
|
|
c7add9574e | ||
|
|
b034b51685 | ||
|
|
600379933d | ||
|
|
530cfe38dc | ||
|
|
11fc3cee6a | ||
|
|
78aa8c361c | ||
|
|
f30ab9cc29 | ||
|
|
6d2dd93628 | ||
|
|
813bee743b | ||
|
|
0ab43d0ed8 | ||
|
|
a1a06504a5 | ||
|
|
b86bc1bf97 | ||
|
|
67bb73fa30 | ||
|
|
6f248b0741 | ||
|
|
9f6deaae76 | ||
|
|
d605a7f9cc | ||
|
|
42c7cf24f2 | ||
|
|
c00c4423f0 | ||
|
|
3f901d3882 | ||
|
|
65540fb121 | ||
|
|
9d067c0646 | ||
|
|
be07de0e92 | ||
|
|
0354a1ca58 | ||
|
|
1a16b1b5b7 | ||
|
|
f8889cdf51 | ||
|
|
8593f0fec4 | ||
|
|
e5884bd943 | ||
|
|
657f444041 | ||
|
|
16d59e4e69 | ||
|
|
ea92c62bb9 | ||
|
|
121df38da1 | ||
|
|
75d0903c0a | ||
|
|
8375df692a | ||
|
|
3b5ce2d219 | ||
|
|
9cfa096ec8 | ||
|
|
30218cc339 | ||
|
|
1178ea37b3 | ||
|
|
5c90747d0f | ||
|
|
be6817bafd | ||
|
|
7af2132b99 | ||
|
|
acca8c5e8a | ||
|
|
aee37b200f | ||
|
|
05842f36d5 | ||
|
|
76d7459515 | ||
|
|
fc2cf49c35 | ||
|
|
93795ffec0 | ||
|
|
4b168c3982 | ||
|
|
e3dc6369ee | ||
|
|
bdcc0326bf | ||
|
|
20d93187f9 | ||
|
|
b2db418d39 | ||
|
|
d19b783302 | ||
|
|
13eb46f4e1 | ||
|
|
7a4f3590ef | ||
|
|
9e61206be2 | ||
|
|
e5c598e67a | ||
|
|
39bf3e14a0 | ||
|
|
ce0422979a | ||
|
|
bfef048695 | ||
|
|
2f67a15083 | ||
|
|
d773f783eb | ||
|
|
dc8d038e34 | ||
|
|
195edb8b32 | ||
|
|
59b2ee9acb | ||
|
|
d7f3cbfcfd | ||
|
|
d2b24051af | ||
|
|
0973533bab | ||
|
|
61e9e123c4 | ||
|
|
60a177605a | ||
|
|
60112ad367 | ||
|
|
c95720514b | ||
|
|
2fafd9af18 | ||
|
|
4d9928abf3 | ||
|
|
28b74fce4e | ||
|
|
d468d15032 | ||
|
|
c1c54e61fc | ||
|
|
966d529551 | ||
|
|
186636a8e4 | ||
|
|
c749d951a0 | ||
|
|
9a14f5aca6 | ||
|
|
9927066abb | ||
|
|
7e46b5cc06 | ||
|
|
eef5df9ce2 | ||
|
|
83d8204847 | ||
|
|
0489fbe62c | ||
|
|
5d339b3d0e | ||
|
|
724a4f7b77 |
@@ -1,51 +1,93 @@
|
|||||||
# ---------- Python ----------
|
# ---------- Python ----------
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
*.so
|
*.so
|
||||||
.Python
|
.Python
|
||||||
*.egg
|
*.egg
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
dist/
|
dist/
|
||||||
build/
|
build/
|
||||||
eggs/
|
eggs/
|
||||||
sdist/
|
sdist/
|
||||||
wheels/
|
wheels/
|
||||||
*.manifest
|
*.manifest
|
||||||
*.spec
|
*.spec
|
||||||
pip-log.txt
|
# 前端依赖与构建产物(desktop 桌面端)
|
||||||
pip-delete-this-directory.txt
|
desktop/*/frontend/node_modules
|
||||||
|
plugins/**/ui-src/node_modules
|
||||||
# ---------- 虚拟环境 ----------
|
desktop/*/frontend/dist/
|
||||||
.venv/
|
desktop/**/frontend/*.zip # controlplane-web-dist.zip 等部署用压缩包
|
||||||
venv/
|
# Node 依赖全局兜底(含 electron-shell 根目录)
|
||||||
env/
|
node_modules/
|
||||||
ENV/
|
# Electron 壳子运行环境 / 打包产物(可再生,不入库;详细规则见 desktop/electron-shell/.gitignore)
|
||||||
|
dist-app/
|
||||||
# ---------- 环境变量 / 密钥 ----------
|
dist-env/
|
||||||
.env
|
python-env/
|
||||||
.env.*
|
|
||||||
!.env.example
|
# 桌面版打包产物(PyInstaller 中间/输出、安装包、插件构建包,不入库)
|
||||||
# 各平台会话 cookies 持久化目录(OA / 其他平台共用,按平台名分文件)
|
# 仅执行机(壳子)/文件服务器仍走 PyInstaller 打包;中心机已改源码部署,不再产出 exe
|
||||||
app/service/.sessions/
|
desktop/*/build-exe/
|
||||||
|
desktop/*/dist-exe/
|
||||||
# ---------- IDE ----------
|
desktop/releases/
|
||||||
.idea/
|
desktop/build/
|
||||||
.vscode/
|
dist-plugin/
|
||||||
*.swp
|
desktop/**/setup-*.exe
|
||||||
*.swo
|
desktop/**/installer/
|
||||||
|
pip-log.txt
|
||||||
# ---------- 操作系统 ----------
|
pip-delete-this-directory.txt
|
||||||
.DS_Store
|
|
||||||
Thumbs.db
|
# ---------- 虚拟环境 ----------
|
||||||
desktop.ini
|
.venv/
|
||||||
|
venv/
|
||||||
# ---------- 日志 ----------
|
env/
|
||||||
*.log
|
ENV/
|
||||||
logs/
|
|
||||||
|
# ---------- 环境变量 / 密钥 ----------
|
||||||
# ---------- 测试 / 覆盖率 ----------
|
.env
|
||||||
.pytest_cache/
|
.env.*
|
||||||
.coverage
|
!.env.example
|
||||||
htmlcov/
|
# 控制面签名密钥 / 运行期产物(禁止入库)
|
||||||
.tox/
|
.admin_secret
|
||||||
|
.webhost.pid
|
||||||
|
*.pid
|
||||||
|
desktop/**/keys/
|
||||||
|
desktop/**/packages/
|
||||||
|
desktop/**/controlplane.db
|
||||||
|
desktop/**/_cp_sessions.json
|
||||||
|
# 各平台会话 cookies / 缓存目录(统一移入 %LOCALAPPDATA%\37duAutomation,禁止入库)
|
||||||
|
**/.sessions/
|
||||||
|
|
||||||
|
# ---------- IDE ----------
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
# Trae IDE 本地配置/技能(不入库)
|
||||||
|
.trae/
|
||||||
|
# 工具 ACL 恢复备份产物
|
||||||
|
.dsh-acl-recovery/
|
||||||
|
|
||||||
|
# ---------- 操作系统 ----------
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
desktop.ini
|
||||||
|
|
||||||
|
# ---------- 日志 ----------
|
||||||
|
*.log
|
||||||
|
logs/
|
||||||
|
|
||||||
|
# ---------- 测试 / 覆盖率 ----------
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
aa.md
|
||||||
|
|
||||||
|
# vc运行库
|
||||||
|
vc_redist/
|
||||||
|
vc_redist_x64/
|
||||||
|
vc_redist_x86/
|
||||||
|
|
||||||
|
静态资源/
|
||||||
|
.assets/
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
---
|
||||||
|
name: BT-Go-Project-Deploy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上部署 Go 项目(编译好的二进制,含 Go SDK 版本安装、项目注册、进程启停、域名/外网映射),
|
||||||
|
并在项目启动失败时排错。当用户要求把本机编译好的 Go 二进制部署成面板可管理的项目(含 Go SDK 安装、
|
||||||
|
端口/运行用户配置、域名绑定),或 Go 项目启动失败/访问异常需要排查根因时使用。
|
||||||
|
触发关键词:部署 Go、Go 项目、go build 产物部署、Go 二进制、Gin/Beego/Echo 服务、Go SDK 安装、
|
||||||
|
go1.xx、GOPROXY、Go 项目启动失败、error while loading shared libraries、Address already in use。
|
||||||
|
日常的启停/状态/日志/改配置/删项目等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Go 项目部署与启动排错 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 只覆盖两个主场景:**① 部署 Go 项目(含 Go SDK 安装);② 项目启动排错**。其他简单操作(状态查看、启停、日志、域名、改配置、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 部署前先 `GoProjectInfo` 查是否已存在同名项目、`GoVersion(action=list)` 看 SDK;排错先读日志,不盲目重启。
|
||||||
|
2. **Go 是编译产物,无源码分析** —— `GoProjectCreate` 不需要分析步骤:给二进制绝对路径 + 端口 + 启动命令(缺省=二进制)直接注册。**不提供 analyze_only。**
|
||||||
|
3. **Go SDK 安装走 Bash 后台** —— btpygvm 装的是完整预编译包(快),但网络慢仍可能超时:`GoVersion(action=install, version=...)` 返回 `install_command` 后,必须用 `Bash(command=install_command, run_in_background=true)` 后台执行 + `BashStatus(task_id, wait=true)` 轮询;**一次只装一个版本**。
|
||||||
|
4. **创建即同步启动** —— `GoProjectCreate` 注册后面板同步启动(nohup 脚本 + pid,**无守护、崩了不自愈**);创建成功 ≠ 进程一定活着,必须 `GoProjectInfo` 核验 `run=true` + 端口在 `listen`。
|
||||||
|
5. **Go 项目是编译二进制** —— 缺动态库/权限/端口占用是启动失败主因,排错按日志对号入座(场景二)。
|
||||||
|
6. **改配置即重启** —— `GoProjectModify(action='config')` 面板改完自动 stop+start;改端口后若绑了域名,nginx 反代按新端口重写。
|
||||||
|
7. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
8. **禁止操作**:删除项目目录/二进制源码、`rm -rf` 项目目录、修改宝塔/插件自身文件、读取插件 `data/` 凭据。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:部署 Go 项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"部署 Go 项目"(非排错/运维)。
|
||||||
|
2. 确认有编译好的**可执行二进制**(`go build` 产物,Linux 目标平台),拿到绝对路径。
|
||||||
|
3. 确认**端口**(应用监听,10-65535)与**运行用户**(默认 www)。
|
||||||
|
4. 需要外网域名访问时,确认 Nginx 已安装;否则只能本机/内网访问。
|
||||||
|
|
||||||
|
## Step 1 —— Go SDK 确认 / 安装
|
||||||
|
1. `GoVersion(action='list')`:看 `data.installed` 是否已有可用 Go、`data.used` 当前版本。
|
||||||
|
2. 没有可用版本 → `GoVersion(action='list')` 的 `data.available` 挑一个稳定版(每项含 `install_command`),再调 `GoVersion(action='install', version=<go1.xx>)` 拿该版本的 install_command。
|
||||||
|
3. **用 Bash 后台执行**:`Bash(command=<install_command>, run_in_background=true)` → 得到 task_id → `BashStatus(task_id, wait=true)` 轮询到完成(预编译包下载+解压,通常几十秒到几分钟)。
|
||||||
|
4. 完成后 `GoVersion(action='list')` 确认该版本在 `installed`;需要时 `GoVersion(action='use', version=...)` 切换当前版本;拉依赖慢可 `GoVersion(action='goproxy', goproxy=<源>)` 设置 GOPROXY。
|
||||||
|
|
||||||
|
## Step 2 —— 创建项目(注册 + 启动)
|
||||||
|
调用 `GoProjectCreate(project_name=..., project_exe=<二进制绝对路径>, port=<端口>, ...)`:
|
||||||
|
- **必填**:`project_name`(字母/数字/下划线)、`project_exe`、`port`。
|
||||||
|
- **可选**:`project_cmd`(缺省=二进制本身)、`run_user`(默认 www)、`domains`(给则自动开启外网映射,'域名' 或 '域名:端口')、`env_list`(`[{"k","v"}]`,如 `[{"k":"PORT","v":"9000"}]`,**字符串 "K=V" 会被 schema 拒**)、`env_file`、`is_power_on`(默认 true)、`ps`、`release_firewall`(需外网访问时 true)。
|
||||||
|
|
||||||
|
> 返回"创建成功"= 已注册并尝试启动;`data.project` 含 run/listen 运行态。
|
||||||
|
|
||||||
|
## Step 3 —— 启动验证(强制)
|
||||||
|
1. `GoProjectInfo(project_name=...)`:`run=true`、端口在 `listen`。
|
||||||
|
2. 用返回的 `log_files` 里应用日志路径(`/www/wwwlogs/go/<name>.log`)调 filesystem `Read` 看尾部无致命异常(`error while loading shared libraries`/`Address already in use`/`bind: address already in use`)。
|
||||||
|
3. 有域名映射的项目核验外网映射(`bind_extranet`)与反代(nginx `go_<name>.conf` 的 `proxy_pass 127.0.0.1:{port}`)。
|
||||||
|
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 任一失败 → **转场景二排错**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:启动排错
|
||||||
|
|
||||||
|
> 适用:创建后 run=false、或用户报"Go 项目启动失败/访问异常"。
|
||||||
|
|
||||||
|
## Step 0 —— 快速定位现状(只读)
|
||||||
|
并行收集,不跳过:
|
||||||
|
1. `GoProjectInfo(project_name=...)`:`run`、`listen`、`project_config`(exe/命令/端口/用户/环境变量)。
|
||||||
|
2. 读应用日志尾部(`log_files` 里"应用日志")找根因。
|
||||||
|
3. 已知配置:二进制路径、启动命令、端口、运行用户、是否绑域名。
|
||||||
|
|
||||||
|
收集后按症状进分支。
|
||||||
|
|
||||||
|
## 分支 A —— 启动失败(进程起不来 / run=false)
|
||||||
|
按日志根因对号入座:
|
||||||
|
| 日志特征 | 根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| `error while loading shared libraries: libxxx.so` | 缺动态库 | 汇报需装系统库(如 glibc/其他 .so),装后 `GoProjectControl(action='start')` |
|
||||||
|
| `bind: address already in use` / `EADDRINUSE` | 端口被占 | `GoProjectModify(action='config', port=新端口)`(自动重启) |
|
||||||
|
| `permission denied` / 无法写入日志 | 运行用户无权限 | `GoProjectModify(action='config', run_user=<有权限用户>)` |
|
||||||
|
| 启动即退出 / pid 无 | 启动命令错 / 环境变量缺 | 核对 `project_cmd` 与 `env_list`;`GoProjectControl(action='start')` 重试 |
|
||||||
|
| 二进制非当前平台编译 | 目标平台不符 | 重新 `go build` 目标平台二进制 |
|
||||||
|
|
||||||
|
- 修正后回场景一 Step 3 重新验证。**Go 进程无守护,崩了不会自动拉起**——排错后必须手动 start。
|
||||||
|
|
||||||
|
## 分支 B —— 访问异常(502/无法访问,但进程活着)
|
||||||
|
1. `GoProjectInfo`:进程在跑、端口在听吗?→ 不在则回分支 A。
|
||||||
|
2. **端口/反代核对**:`listen`(实际监听)vs `project_config.port`(反代目标)是否一致;grep `proxy_pass` `nginx/go_<name>.conf` 确认指向 `127.0.0.1:{实际端口}`。
|
||||||
|
- 端口改了没同步 → `GoProjectModify(action='config', port=实际端口)`。
|
||||||
|
- 反代指向错误端口 → 同上。
|
||||||
|
3. 域名绑定:`bind_extranet` 是否开、域名是否在 nginx `server_name`(未绑 → `GoProjectModify(action='add_domain', domains=[...])` + `bind_extranet`)。
|
||||||
|
4. 读 nginx error log(`log_files` 里 `/www/wwwlogs/<name>.error.log`)进一步定位。
|
||||||
|
5. 修正后验证。
|
||||||
|
|
||||||
|
## 分支 C —— 进程在但无响应 / 卡死
|
||||||
|
1. 应用日志尾部看异常/死锁(filesystem `Read`)。
|
||||||
|
2. `SystemInfo()` 看系统资源(CPU/内存/负载)。
|
||||||
|
3. 汇报,建议用户确认后 `GoProjectControl(action='restart')` 重启。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 日常运维速查(简单操作,直接按工具描述调用)
|
||||||
|
|
||||||
|
| 需求 | 工具 |
|
||||||
|
|---|---|
|
||||||
|
| 查看项目列表/状态 | `GoProjectInfo()`(project_name 留空) |
|
||||||
|
| 查看单项目详情(run/listen/log_files/配置) | `GoProjectInfo(project_name=...)` |
|
||||||
|
| 启动 / 停止 / 重启 | `GoProjectControl(project_name, action='start'/'stop'/'restart')` |
|
||||||
|
| 看应用日志 / nginx 日志 | `GoProjectInfo` 返回 `log_files` → filesystem `Read` |
|
||||||
|
| 改二进制/命令/端口/用户/开机自启/环境变量/备注(自动重启) | `GoProjectModify(action='config', ...)` |
|
||||||
|
| 加域名 / 删域名(至少留一个) / 开 / 关外网映射 | `GoProjectModify(action='add_domain'/'remove_domain'/'bind_extranet'/'unbind_extranet', domains=[...])` |
|
||||||
|
| Go SDK 列表 / 安装(Bash 后台) / 切换 / 卸载 / 设 GOPROXY | `GoVersion(action='list'/'install'/'use'/'uninstall'/'goproxy', ...)` |
|
||||||
|
| **安装 Go SDK(下载+解压,后台)** | `GoVersion` install 取 `install_command` → `Bash(run_in_background=true)` + `BashStatus` 轮询 |
|
||||||
|
| 删除项目(**高风险,先确认**;保留二进制与目录) | `GoProjectDelete(project_name=...)` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板(部署成功)
|
||||||
|
|
||||||
|
返回:项目名 / 二进制路径(project_exe)/ 端口 / 运行用户 / Go SDK 版本;若绑域名:访问地址 + nginx 配置路径;启动验证结果(进程/端口/日志);遗留隐患提示(GOPROXY 未设、防火墙未放行、依赖库缺失、绑外网未开等)。
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
---
|
||||||
|
name: BT-Html-Project-Deploy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上管理 Html(静态)项目:创建静态站点(域名 + 网站根目录)、把前端构建产物部署到站点目录、
|
||||||
|
编辑伪静态 rewrite 配置(SPA try_files / 自定义 location / 缓存)、改域名/网站根目录/运行目录/启停,
|
||||||
|
并在静态站点访问异常(404 / SPA 刷新 404 / 伪静态不生效 / 目录权限)时排错。
|
||||||
|
当用户要求把前端静态页面(HTML/SPA/单页应用)挂到域名上,或静态站点访问异常需要排查时使用。
|
||||||
|
触发关键词:静态网站、HTML项目、部署前端、SPA、单页应用、伪静态、rewrite、运行目录、静态站 404、
|
||||||
|
SPA 404、BT-Html-Project-Deploy。
|
||||||
|
日常的查看/启停/改备注等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Html(静态)项目运维 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 覆盖三个主场景:**① 创建静态项目;② 配置编辑(伪静态 rewrite / 主 conf);③ 静态站点访问异常排错**。其他简单操作(状态查看、启停、改备注、绑删域名、改目录、运行目录、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 操作前先 `HtmlProjectInfo`(site_name 留空)列项目找到站点名(可能带 `_<端口>` 后缀),再 `HtmlProjectInfo(site_name=...)` 看当前域名/路径/运行目录/SSL;排错先读日志,不盲目重写配置。
|
||||||
|
2. **静态站点本质 = 网站根目录 + nginx/apache conf + rewrite 文件** —— nginx 主 conf 在 `/www/server/panel/vhost/nginx/html_<name>.conf`(模板渲染产物),**伪静态 rewrite 文件在 `/www/server/panel/vhost/rewrite/html_<name>.conf`(面板官方自定义配置入口,被主 conf include)**。
|
||||||
|
3. **改配置优先写 rewrite 文件** —— SPA `try_files`、自定义 `location`、静态资源缓存等写 rewrite 文件(面板创建的注释即引导"请将伪静态规则或自定义NGINX配置填写到此处");**只有确实要改 listen/root/自定义 server 段才动主 conf,且改前必须 filesystem `Read` 留基线**(面板 SSL/域名/改目录操作会重写覆盖主 conf)。
|
||||||
|
4. **域名/路径/启停/运行目录走 `HtmlProjectModify`** —— 面板方法同步 domain 表与 nginx/apache server_name;**不要用 filesystem 直接改主 conf 来加域名**,会与面板不同步。
|
||||||
|
5. **创建即生效** —— `HtmlProjectCreate` 成功即写 nginx/apache 配置 + 建目录(目录不存在自动创建)+ 非 80 端口放行防火墙 + 重载服务;返回的 `site_name_hint` 仅供参考,**实际站点名以 `HtmlProjectInfo` 列表返回的 name 为准**(主域名重名会带 `_<端口>`)。
|
||||||
|
6. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
7. **禁止操作**:`rm -rf` 站点根目录外的路径、修改宝塔/插件自身文件、读取插件 `data/` 凭据、直接写 nginx 主 conf 来改域名(走 Modify)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:创建静态项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"创建 Html(静态)项目"。
|
||||||
|
2. 拿到**要对外暴露的域名**(可带 `:端口`,非 80 端口会成为监听端口)与**网站根目录**(绝对路径,目录不存在会自动创建;也可指向已有前端目录)。
|
||||||
|
3. 确认 Nginx/Apache 已安装(静态站依赖 web 服务)。
|
||||||
|
|
||||||
|
## Step 1 —— 调用创建
|
||||||
|
`HtmlProjectCreate(domains=[...], path=...)`:
|
||||||
|
- **必填**:`domains`(list,首项为主域名,如 `'example.com'` 或 `'example.com:8080'`)、`path`(网站根目录绝对路径,如 `/www/wwwroot/demo.example.com`)。
|
||||||
|
- **可选**:`ps`(备注)、`type_id`(项目分类,默认 0)。
|
||||||
|
|
||||||
|
> 返回"创建成功"= 已写 nginx/apache 配置 + 建目录 + 放行端口 + 重载。`site_name_hint` 仅供参考。
|
||||||
|
|
||||||
|
## Step 2 —— 部署静态文件
|
||||||
|
1. 把前端构建产物(如 `dist/` 下文件)上传到站点根目录 `path`:
|
||||||
|
- 文件已在本机:用文件上传(PrepareUpload 分块上传)到站点目录,或用 filesystem 移动。
|
||||||
|
- 远端构建:先下载到本机再上传,或直接把站点 `path` 指到已有构建目录。
|
||||||
|
2. 确认 `index.html` 已在根目录(或运行目录,见场景二 set_run_path)。
|
||||||
|
|
||||||
|
## Step 3 —— 验证(强制)
|
||||||
|
1. `HtmlProjectInfo`(site_name 留空)确认站点出现,记下真实 `name`。
|
||||||
|
2. `HtmlProjectInfo(site_name=...)` 看域名/路径/SSL。
|
||||||
|
3. 访问域名验证首页正常返回。
|
||||||
|
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 访问异常 → 转场景三排错。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:配置编辑(伪静态 rewrite / 主 conf)
|
||||||
|
|
||||||
|
## Step 0 —— 拿基线与现状
|
||||||
|
1. `HtmlProjectInfo(site_name=...)`:拿到 `rewrite_file`(伪静态/自定义入口)、`config_file`(nginx 主 conf)、`apache_config_file` 路径,以及当前域名/路径/运行目录。
|
||||||
|
2. filesystem `Read` `rewrite_file` 与 `config_file` 看当前配置。
|
||||||
|
|
||||||
|
## Step 1 —— 改配置(优先 rewrite 文件)
|
||||||
|
按「常用静态站点 nginx 配置速查」(见文末)在 **rewrite 文件**里加/改规则。常见操作:
|
||||||
|
- **SPA 路由重写**(刷新子路由 404):`location / { try_files $uri $uri/ /index.html; }`。
|
||||||
|
- **自定义 location**:如 `location /api { proxy_pass http://127.0.0.1:9000; ... }`(把某路径转发到后端)。
|
||||||
|
- **静态资源缓存**:`location ~* \.(js|css|png|jpg|svg|woff2)$ { expires 30d; add_header Cache-Control "public, max-age=2592000"; }`。
|
||||||
|
- **开启 gzip**:`gzip on; gzip_types text/css application/javascript image/svg+xml;`。
|
||||||
|
|
||||||
|
> 只有确实要改 `listen` / `root` / `server_name` 之外的 server 层配置才动**主 conf**:filesystem `Read` `config_file` 留基线 → 改 → filesystem `Write` 回写。**改主 conf 前必须 Read**,写坏可恢复。
|
||||||
|
|
||||||
|
## Step 2 —— 回传并验证
|
||||||
|
1. filesystem `Write` 回写修改后的文件(rewrite 或主 conf)。
|
||||||
|
2. `Bash` 执行 `nginx -t` 确认配置语法通过;失败按报错行修文件重写。
|
||||||
|
3. `Bash` `nginx -s reload`(如有需要)让新配置生效。
|
||||||
|
4. 访问验证(如有域名):确认新规则生效、旧规则仍在。
|
||||||
|
|
||||||
|
- 配置写坏导致站点异常 → 用 Read 留的基线恢复重写;主 conf 被面板覆盖 → 用 `HtmlProjectModify(action='change_path'/'set_run_path')` 走面板。
|
||||||
|
|
||||||
|
## Step 3 —— 面板操作走 Modify(域名/路径/启停/运行目录)
|
||||||
|
| 需求 | 调用 |
|
||||||
|
|---|---|
|
||||||
|
| 加域名 | `HtmlProjectModify(site_name, action='add_domain', domains=['www.example.com'])` |
|
||||||
|
| 删域名 | `HtmlProjectModify(site_name, action='remove_domain', domain='www.example.com')` |
|
||||||
|
| 启/停/重启 | `HtmlProjectModify(site_name, action='start'/'stop'/'restart')` |
|
||||||
|
| 改网站根目录 | `HtmlProjectModify(site_name, action='change_path', path='/www/wwwroot/new')`(**目标目录必须已存在**) |
|
||||||
|
| 设运行目录(子目录) | `HtmlProjectModify(site_name, action='set_run_path', run_path='/dist')` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景三:静态站点访问异常排错
|
||||||
|
|
||||||
|
## Step 0 —— 只读侦察(不盲改)
|
||||||
|
1. `HtmlProjectInfo` 确认项目存在、域名/路径/运行目录现状。
|
||||||
|
2. `Bash` 读 nginx 错误日志 `/www/wwwlogs/<name>.error.log` 与访问日志 `/www/wwwlogs/<name>.log` 尾部。
|
||||||
|
|
||||||
|
## Step 1 —— 按症状对号入座
|
||||||
|
|
||||||
|
| 症状 | 常见根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| **首页 404 / 空白** | 前端文件没传到根目录、`index.html` 缺失、运行目录不对 | 确认文件在站点根目录(或运行目录);`HtmlProjectModify(action='set_run_path', run_path=...)` 指到实际构建目录 |
|
||||||
|
| **子路由刷新 404(SPA)** | 没配 `try_files` 回退 index.html | 场景二在 rewrite 文件加 `location / { try_files $uri $uri/ /index.html; }` |
|
||||||
|
| **伪静态不生效** | rewrite 文件没写对/没 include、nginx 没重载 | `nginx -t` + `nginx -s reload`;确认 rewrite 文件语法 |
|
||||||
|
| **静态资源 404 / 403** | 目录权限不对、资源在子目录但 root 指错 | `Bash` `ls -la` 站点目录、`chown -R www:www` 站点目录 |
|
||||||
|
| **只对本机/内网生效** | 域名未绑定、非 80 端口防火墙未放行 | `HtmlProjectModify(action='add_domain')` 补域名;`Bash` 查防火墙端口放行状态 |
|
||||||
|
| **HTTPS 不生效** | 证书未部署(MCP 不封装 SSL) | 证书部署走面板,MCP 只读 ssl 状态 |
|
||||||
|
|
||||||
|
## Step 2 —— 修复与验证
|
||||||
|
1. 按上表定位根因,**改配置文件必须 filesystem Read 基线 → 改 → Write → `nginx -t`**,改域名/路径走 `HtmlProjectModify`。
|
||||||
|
2. 修复后重访验证;仍异常则回到 Step 0 换角度(读实时日志尾部 `tail -f`)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 运维速查
|
||||||
|
|
||||||
|
| 需求 | 调用 |
|
||||||
|
|---|---|
|
||||||
|
| 列表/找站点名 | `HtmlProjectInfo(search=..., page=...)`(site_name 留空) |
|
||||||
|
| 查看详情/域名/路径/conf 路径 | `HtmlProjectInfo(site_name=...)` |
|
||||||
|
| 创建静态项目 | `HtmlProjectCreate(domains=[...], path=...)` |
|
||||||
|
| 读/改伪静态(优先) | filesystem `Read`/`Write` `rewrite_file`(`/www/server/panel/vhost/rewrite/html_<name>.conf`) |
|
||||||
|
| 读/改 nginx 主 conf | filesystem `Read` 留基线 → 改 → `Write` `config_file`(`/www/server/panel/vhost/nginx/html_<name>.conf`) |
|
||||||
|
| 验证语法 | `Bash` `nginx -t` |
|
||||||
|
| 加删域名 / 启停 / 改目录 / 运行目录 | `HtmlProjectModify(site_name=..., action=..., ...)` |
|
||||||
|
| 删除项目 | `HtmlProjectDelete(site_name=...)`(高风险,确认后;不删站点目录,需删目录用文件系统工具) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 常用静态站点 nginx 配置格式与位置速查
|
||||||
|
|
||||||
|
**位置**:
|
||||||
|
- **rewrite 文件**(`/www/server/panel/vhost/rewrite/html_<name>.conf`):被 nginx 主 conf include 在 server 块内,**伪静态/自定义 location/缓存优先写这里**。
|
||||||
|
- **nginx 主 conf**(`/www/server/panel/vhost/nginx/html_<name>.conf`):完整 server 块(listen/server_name/root/ssl/日志/include),模板渲染产物。
|
||||||
|
|
||||||
|
**典型片段**(写进 rewrite 文件即可):
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# SPA 单页应用:子路由刷新回退到 index.html(最常用)
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 静态资源缓存
|
||||||
|
location ~* \.(js|css|png|jpg|jpeg|gif|svg|woff2|ico)$ {
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, max-age=2592000";
|
||||||
|
}
|
||||||
|
|
||||||
|
# 自定义 location:把某路径转发到后端
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 开启 gzip 压缩(server 层,放 rewrite 文件顶部即可)
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
|
||||||
|
```
|
||||||
|
|
||||||
|
**规则**:
|
||||||
|
- `location / { try_files $uri $uri/ /index.html; }` 是 SPA(Vue/React 等 history 路由)部署后**必配**的伪静态规则,否则刷新子路由 404。
|
||||||
|
- 伪静态/缓存/自定义 location 一律写 rewrite 文件,**不改主 conf**;只有要动 listen/root/自定义 server 段才碰主 conf,且先 `Read` 留基线。
|
||||||
|
- 改完**必须** `nginx -t` 验证,再确认访问生效。
|
||||||
|
- 涉及域名/路径/运行目录的变更走 `HtmlProjectModify`,不要手改主 conf。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板
|
||||||
|
|
||||||
|
汇报固定四段(每段 1-3 行,用一次工具查证一个结论,不堆 log):
|
||||||
|
|
||||||
|
- **现状**:静态项目 `<name>`,域名 `<域名:端口>`,网站根目录 `<path>`,状态(运行中/已停止)。
|
||||||
|
- **变更**:`<创建了静态项目 / 部署了前端文件到 <path> / 添加了 SPA try_files 伪静态 / 修改了网站根目录 / 启停了项目 / 绑定了域名>`。
|
||||||
|
- **验证**:`nginx -t` 通过 / `HtmlProjectInfo` 复查域名与路径 / 访问 `<域名>` 返回预期。
|
||||||
|
- **遗留**:`<若有:SSL 证书未部署需面板处理 / 后端服务未监听需确认>;否则无`。
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
---
|
||||||
|
name: BT-Java-Project-Deploy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上部署 Java jar 项目(Spring Boot),并在项目启动失败时排错。
|
||||||
|
当用户要求把本机已有的 jar 包部署成面板可管理的 Java 项目(含 JDK、Nginx 代理/域名),
|
||||||
|
或 Java 项目启动失败/访问异常需要排查根因时使用。
|
||||||
|
触发关键词:部署 Java、jar 包部署、Spring Boot 部署、Java 项目创建、
|
||||||
|
Java 项目启动失败、jar 起不来、jar 启动报错、502、访问异常、JDK 版本不匹配。
|
||||||
|
日常的启停/状态/日志/改配置等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Java 项目部署与启动排错 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 只覆盖两个主场景:**① 部署 Java 项目;② 项目启动排错**。其他简单操作(状态查看、启停、日志、域名、改配置、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 部署前必须完成 jar 分析;排错先读日志,不盲目重启。
|
||||||
|
2. **创建后必须验证启动** —— "创建成功"不算完,必须确认进程存活 + 监听端口 + 日志无致命错误;验证失败即转入场景二。
|
||||||
|
3. **删除项目属高风险**,必须先获得用户明确确认;启停/重启/改配置属中风险,操作前说明影响。
|
||||||
|
4. **JDK 匹配** —— Spring Boot 3.x 需 JDK 17+,Boot 2.x 需 JDK 8/11;安装或切换前先检测本机 JDK。
|
||||||
|
5. **端口唯一性** —— 创建/改端口前检查占用。
|
||||||
|
6. **域名可访问 = 三件事** —— ① `add_domain` 写入 `server_name`;② `bind_extranet` 开启外网框架(生成 conf 骨架,**不含反代**);③ `add_proxy(proxy_port=应用端口)` 真正注入 `proxy_pass http://127.0.0.1:port`。**漏掉 ③ 会访问 403**。创建时带 `domains` 会完成 ①② 并尝试自动建 ③,但**必须验证**(`proxy_list` 或 grep `proxy_pass`),缺失即补 `add_proxy`。
|
||||||
|
7. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
8. **禁止操作**:删除 jar 源文件、`rm -rf` 项目目录、修改宝塔/插件自身文件、读取插件 `data/` 凭据。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:部署 Java 项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"部署新 Java 项目"(非排错/运维)。
|
||||||
|
2. 需要外网域名访问时,确认 Nginx 已安装;否则只能本机/内网访问。
|
||||||
|
3. (可用 todo 工具时)建任务列表:定位 jar → 分析 → JDK → 创建 → 验证。
|
||||||
|
|
||||||
|
## Step 1 —— 定位 jar 包
|
||||||
|
- 用户直接给出 jar 绝对路径,或:
|
||||||
|
- 用文件工具 `Glob(pattern='**/*.jar')` / `LS(path=...)` 在服务器上定位 jar(排除运行目录与 `lib/` 依赖库)。
|
||||||
|
- **校验**:路径存在、是普通文件、非敏感目录(`/etc`、`/boot`、插件 `data/` 等)。
|
||||||
|
- 记录 jar 绝对路径与所在目录(jar_path)。
|
||||||
|
|
||||||
|
## Step 2 —— 分析 jar(部署前必须)
|
||||||
|
调用 `JavaProjectCreate(jar_path=..., analyze_only=true)`(只读,不创建)。返回:
|
||||||
|
1. 是否 Spring Boot 可执行 jar(jar_info)。
|
||||||
|
2. **应用端口**(`application.yml/properties` 的 `server.port`,或命令行/环境变量覆盖)。
|
||||||
|
3. 实际生效的配置文件路径与优先级(config_files)。
|
||||||
|
4. **启动前隐患清单**(tips:数据库/中间件连通性、账号密码疑似错误、profile 缺失等)。
|
||||||
|
|
||||||
|
**决策**:
|
||||||
|
- 解析不出端口 → 询问用户指定,并在创建时显式传 `port`。
|
||||||
|
- 隐患清单含阻断级(error)→ 向用户说明,确认是否继续。
|
||||||
|
|
||||||
|
## Step 3 —— JDK 确认 / 安装
|
||||||
|
1. `JavaJdk(action='list')` 检测本机 JDK(name/path/operation:0 未装 1 已装 2 系统 3 安装中)。
|
||||||
|
2. 按 Spring Boot 版本定所需 JDK(Boot3→17+,Boot2→8/11)。
|
||||||
|
3. 已有 → 记录 path;无 → 询问用户后 `JavaJdk(action='install', version=...)`(异步,用 list 轮询 operation=3→1)。
|
||||||
|
|
||||||
|
## Step 4 —— 创建项目(注册)
|
||||||
|
调用 `JavaProjectCreate(project_name=..., jar_path=..., port=..., [domains=...])`。
|
||||||
|
创建前确认参数:`project_name`(1-20 字符、不重复)、jar 路径、JDK 路径(缺省自动选已装)、`run_user`(默认 www)、端口(**检查未被占用**)、启动命令(缺省自动拼 `{jdk}/bin/java -jar ... --server.port=<port>`)。
|
||||||
|
**外网映射决策**:
|
||||||
|
- 要域名访问 → `domains=['域名']`(或 `['域名:端口']`),创建时绑定域名并开启外网框架(`server_name`)。创建工具会**尝试**自动建反代(`proxy_path` 默认 `'/'` 全站,可改如 `'/api'`;`proxy_path=''` 关闭)。
|
||||||
|
**创建后必须验证反代已注入**:`JavaProjectModify(action='proxy_list')` 应有 `proxy_port`,或 grep `proxy_pass` `java_<name>.conf`。缺失 → `JavaProjectModify(action='add_proxy', proxy_port=应用端口, proxy_dir='/')` 补齐,否则访问 403。
|
||||||
|
- 仅本机 → 不传 domains(`bind_extranet=0`)。
|
||||||
|
|
||||||
|
## Step 5 —— 启动验证(强制)
|
||||||
|
创建后调用 `JavaProjectInfo(project_name=...)` 依次确认:
|
||||||
|
1. 进程存活(有 pid)。
|
||||||
|
2. 应用端口在 `listen` 列表。
|
||||||
|
3. 用返回的 `log_files` 里的应用日志路径,调 filesystem `Read` 看尾部无致命异常(`Exception`/`Caused by`)。
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 任一失败 → **转场景二排错**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:项目启动排错
|
||||||
|
|
||||||
|
> 适用:部署后验证失败、或用户报"Java 项目启动失败/访问异常"。
|
||||||
|
|
||||||
|
## Step 0 —— 快速定位现状(只读)
|
||||||
|
并行收集 3 项,不跳过:
|
||||||
|
1. `JavaProjectInfo(project_name=...)`:pid 是否生成、`listen` 端口、运行态(区分"进程没起来"与"进程起来了但访问不了")。
|
||||||
|
2. 读应用日志尾部:用返回的 `log_files` 应用日志路径调 filesystem `Read`,找异常堆栈根因。
|
||||||
|
3. 已知配置:jar 路径、JDK、端口、启动命令。
|
||||||
|
|
||||||
|
收集后按症状进分支。
|
||||||
|
|
||||||
|
## 分支 A —— 启动失败(进程起不来 / pid 无 / 端口未监听)
|
||||||
|
按日志根因对号入座:
|
||||||
|
| 日志特征 | 根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| `Address already in use` / 端口占用 | 端口被占 | 换端口:`JavaProjectModify(action='config', project_cmd=改 --server.port=)` 或重建 |
|
||||||
|
| `UnsupportedClassVersionError` | JDK 版本过低/过高 | `JavaProjectModify(action='config', project_jdk=匹配JDK)` 或 `JavaJdk(action='install', version=...)` |
|
||||||
|
| `ClassNotFoundException` / 缺依赖 | 依赖库缺失 | 检查启动命令 `-Dloader.path` 与 lib 目录,改 `project_cmd` |
|
||||||
|
| 数据库/中间件连接失败 | 服务未起或账号密码错 | 结合 Step 2 的 tips,确认中间件与账号 |
|
||||||
|
| 配置缺失 / 环境变量 | 缺配置 | 改 `project_cmd`/`env_file` 补配置后重启 |
|
||||||
|
|
||||||
|
- 无明确报错 → 查 `JavaProjectInfo`:pid 是否生成、端口是否监听、启动命令是否完整。
|
||||||
|
- 修复后回到场景一 Step 5 重新验证。
|
||||||
|
|
||||||
|
## 分支 B —— 访问异常(502 / 无法访问,但进程活着)
|
||||||
|
1. `JavaProjectInfo`:进程在跑、端口在听吗?→ 不在则回分支 A。
|
||||||
|
2. **nginx 反代目标匹配**:用 `log_files` 或 `JavaProjectInfo` 定位 `java_<name>.conf`,调 filesystem `Read` 看 `proxy_pass` 是否指向 `127.0.0.1:实际端口`。
|
||||||
|
- 配置里**没有** `proxy_pass` location(`project_config.proxy_info` 为空)→ 反代缺失,用 `JavaProjectModify(action='add_proxy', proxy_port=实际端口, proxy_dir='/')` 补齐,`action='proxy_list'` 核对。
|
||||||
|
- 端口改了但反代没同步 → `JavaProjectModify(action='add_proxy', proxy_port=新端口)` 或改配置重建。
|
||||||
|
3. **反代是否真注入**:`JavaProjectModify(action='proxy_list')` 看有无 `proxy_port`;`grep proxy_pass /www/server/panel/vhost/nginx/java_<name>.conf`。`bind_extranet` 为开但 `proxy_pass` 为空 → 漏了 `add_proxy`,用 `action='add_proxy', proxy_port=实际端口` 补。
|
||||||
|
4. **外网绑定状态**:`bind_extranet` 是否为开;域名是否在 nginx `server_name`(未开 → `JavaProjectModify(action='bind_extranet')`)。
|
||||||
|
5. 读 nginx error log(`log_files` 里的路径)进一步定位。
|
||||||
|
6. 修正后验证。
|
||||||
|
|
||||||
|
## 分支 C —— 进程在但无响应 / 卡死
|
||||||
|
1. 应用日志尾部看异常/死锁(filesystem `Read`)。
|
||||||
|
2. `SystemInfo()` 看系统资源(CPU/内存/负载)是否异常。
|
||||||
|
3. 汇报,建议用户确认后 `JavaProjectControl(action='restart')` 重启。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 日常运维速查(简单操作,直接按工具描述调用)
|
||||||
|
|
||||||
|
| 需求 | 工具 |
|
||||||
|
|---|---|
|
||||||
|
| 查看项目列表/状态 | `JavaProjectInfo()`(project_name 留空) |
|
||||||
|
| 查看单项目详情(含日志路径) | `JavaProjectInfo(project_name=...)` |
|
||||||
|
| 启动 / 停止 / 重启 | `JavaProjectControl(project_name, action='start'/'stop'/'restart')` |
|
||||||
|
| 看应用日志 / nginx 日志 | `JavaProjectInfo` 返回 `log_files` → filesystem `Read` |
|
||||||
|
| 加域名 / 删域名(至少留一个) | `JavaProjectModify(action='add_domain'/'remove_domain', domains=[...])` |
|
||||||
|
| 开/关外网框架(只生成 server_name 骨架,**不注入反代**) | `JavaProjectModify(action='bind_extranet'/'unbind_extranet')` |
|
||||||
|
| 增反代(真正注入 proxy_pass) | `JavaProjectModify(action='add_proxy', proxy_port=应用端口, proxy_dir='/')` |
|
||||||
|
| 删反代 | `JavaProjectModify(action='remove_proxy', proxy_id=...)`(id 用 proxy_list 取) |
|
||||||
|
| 查反代 | `JavaProjectModify(action='proxy_list')` |
|
||||||
|
| 改 jar / JDK / 启动命令 / 运行用户 / 守护 | `JavaProjectModify(action='config', ...)`(重启生效) |
|
||||||
|
| 删除项目(**高风险,先确认**) | `JavaProjectDelete(project_name=...)`(保留 jar) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板(部署成功)
|
||||||
|
|
||||||
|
返回:项目名 / jar 路径 / 运行用户 / JDK 路径 / 监听端口;若绑域名:访问地址 + nginx 配置路径;应用日志路径;启动验证结果(进程/端口/日志);遗留隐患提示(若有)。
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
---
|
||||||
|
name: BT-Node-Project-Deploy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上部署 Node.js 项目(nodejs/general/pm2 三种类型,含 Nginx 域名/反代),
|
||||||
|
并在项目启动失败或访问异常时排错。
|
||||||
|
当用户要求把本机已有的 Node 项目目录部署成面板可管理的项目(含 node 版本、依赖安装、
|
||||||
|
Nginx 代理/域名、pm2 守护),或 Node 项目启动失败/访问异常需要排查根因时使用。
|
||||||
|
触发关键词:部署 Node、Node 项目部署、nodejs 部署、npm 项目部署、PM2 部署、
|
||||||
|
Node 项目启动失败、npm 起不来、Node 报错、502、访问异常、pm2 errored、Cannot find module。
|
||||||
|
日常的启停/状态/日志/改配置等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Node.js 项目部署与启动排错 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 只覆盖两个主场景:**① 部署 Node 项目;② 启动排错**。其他简单操作(状态查看、启停、日志、域名、改配置、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 部署前必须完成项目分析;排错先读日志,不盲目重启。
|
||||||
|
2. **创建后必须验证启动** —— "创建成功"不算完,必须确认进程存活 + 监听端口 + 日志无致命错误;验证失败即转入场景二。
|
||||||
|
3. **删除项目属高风险**,必须先获得用户明确确认;启停/重启/改配置属中风险,操作前说明影响。
|
||||||
|
4. **Node 版本匹配** —— 创建前用 `NodeVersion(action='list')` 检测已装版本;`package.json` 的 `engines.node` 不符时优先换已装版本或安装。
|
||||||
|
5. **端口唯一性** —— 创建/改端口前检查占用;**绑外网必须有端口**(`bind_extranet` 依赖 `port`)。
|
||||||
|
6. **绑域名 = 自动反代** —— Node 的反代由 nginx 模板按 `project_config.port` 自动生成(`proxy_pass http://127.0.0.1:{port}`),**无独立反代步骤**。访问异常时核对:`NodeProjectInfo` 的 `listen`(实际监听端口)vs 配置端口(反代目标)是否一致,不一致 = 502。
|
||||||
|
7. **依赖先行** —— nodejs 类型缺 `node_modules` 启动必失败。创建时 `install_deps=true` 或创建后装依赖再启动。
|
||||||
|
8. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
9. **禁止操作**:删除项目目录/源码、`rm -rf` 项目目录、修改宝塔/插件自身文件、读取插件 `data/` 凭据。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:部署 Node 项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"部署新 Node 项目"(非排错/运维)。
|
||||||
|
2. 确定**项目类型**:`nodejs`(package.json scripts)/ `general`(直接指定启动文件)/ `pm2`(守护+cluster+自愈)。
|
||||||
|
3. 需要外网域名访问时,确认 Nginx 已安装;否则只能本机/内网访问。
|
||||||
|
|
||||||
|
## Step 1 —— 定位项目目录
|
||||||
|
- 用户给出 `project_cwd`(项目根,含 package.json),或:
|
||||||
|
- 用文件工具 `Glob(pattern='**/package.json')` / `LS(path=...)` 定位(排除 `node_modules`、`dist`、`build` 等构建目录)。
|
||||||
|
- **校验**:目录存在、含 `package.json`(nodejs/pm2 必需;general 可没有)、非敏感目录(`/etc`、`/boot`、插件 `data/` 等)。
|
||||||
|
|
||||||
|
## Step 2 —— 分析项目(部署前必须)
|
||||||
|
调用 `NodeProjectCreate(project_cwd=..., analyze_only=true)`(只读,不创建)。返回:
|
||||||
|
1. `package.json` 的 `name/version`、`engines.node`、`dependencies` 数量。
|
||||||
|
2. `scripts` 启动项列表(nodejs 类型的 `project_script` 从这里选)。
|
||||||
|
3. `node_modules` 是否存在(缺 → 需先装依赖)。
|
||||||
|
4. `port`/`port_hints`:从入口文件启发式探测的端口(仅供参考)。
|
||||||
|
|
||||||
|
**决策**:
|
||||||
|
- nodejs 类型:确认启动脚本名(`start`/`dev`/自定义),即 `project_script`。
|
||||||
|
- pm2 类型:确认入口文件(js 或 ecosystem 配置)与 `cluster` 实例数。
|
||||||
|
- 无端口或启发式不准 → 询问用户,创建时显式传 `port`(绑外网必需)。
|
||||||
|
|
||||||
|
## Step 3 —— Node 版本确认 / 安装
|
||||||
|
1. `NodeVersion(action='list')` 检测已装版本与可用包管理器(npm/yarn/pnpm)。
|
||||||
|
2. 若返回 `plugin_installed=false`:nodejs 版本管理器插件未装,**先调 `SoftwareInstall(name='nodejs')` 安装插件**(可再用 `SoftwareList(name='nodejs')` 查进度),装完继续。
|
||||||
|
3. 需要新装版本时,用 `NodeVersion(action='online', lts_only=true, page=...)` 浏览可安装版本(按版本从新到旧排序、本地分页,`lts_only=false` 看全部;每项 `installed` 标记是否已装),从中挑选稳定版。
|
||||||
|
4. 对照 `engines.node`(无则默认 LTS)。
|
||||||
|
5. 已装 → 记录版本号(如 `v20.15.0`);无 → 询问用户后 `NodeVersion(action='install', version=..., install_pm2=<pm2 类型时 true>)`(插件安装,较慢,装完用 list 确认)。
|
||||||
|
|
||||||
|
## Step 4 —— 创建项目(注册)
|
||||||
|
调用 `NodeProjectCreate(project_type=..., project_name=..., project_cwd=..., nodejs_version=..., ...)`。
|
||||||
|
按类型传参:
|
||||||
|
- **nodejs**:`project_script`(scripts key,如 `'start'`)、`pkg_manager`(npm/yarn/pnpm)。
|
||||||
|
- **general**:`project_file`(启动文件绝对路径)、`project_args`(可选)。**同时必须传 `nodejs_version`**(三类型均必填、须已安装——general 漏传会直接报错,不是可选项)。
|
||||||
|
- **pm2**:`project_file`(js 入口或 ecosystem 配置,内容检测自动路由)、`cluster`、`watch`、`max_memory_limit`。**pm2 类型项目启动依赖该 node 版本已全局安装 pm2**——创建工具会自动检测,该版本缺 pm2 时自动调插件安装(结果 `data.pm2_auto_installed` 标记);也可手动 `NodeVersion(action='module', version=<nodejs_version>, modules=['pm2'])`。
|
||||||
|
- **通用**:`port`(绑外网必需)、`run_user`(默认 www)、`env`(**注意:面板对 nodejs 类型的 env 注入有缺陷——存了但不写进启动脚本,需要环境变量的项目建议用 general 类型**)、`install_deps`(package.json 有依赖且未装 node_modules 时给 true)、`release_firewall`(需放行端口时)、`domains=['域名']`(绑域名+自动反代)。
|
||||||
|
|
||||||
|
**外网映射**:要域名访问 → 传 `domains`(自动写 `server_name` + `proxy_pass 127.0.0.1:{port}`,**无需额外反代步骤**)。`install_deps=true` 较慢(npm install),可接受等待。
|
||||||
|
|
||||||
|
## Step 5 —— 启动验证(强制)
|
||||||
|
创建后调用 `NodeProjectInfo(project_name=...)` 依次确认:
|
||||||
|
1. 进程存活(`run=true`)。
|
||||||
|
2. 应用端口在 `listen` 列表(`listen_ok=true`)。
|
||||||
|
3. 用返回的 `log_files` 里应用日志路径,调 filesystem `Read` 看尾部无致命异常(`Cannot find module`/`EADDRINUSE`/`throw er`)。
|
||||||
|
|
||||||
|
⚠️ **pm2 类型不要信创建返回的「已自动启动」**:daemon 可能未持久化(`run:false`、`listen` 空但 `listen_ok=true`)。创建后必须:
|
||||||
|
① 立即 `NodeProjectInfo` 核验 `run=true`;
|
||||||
|
② 间隔几秒**再次** `NodeProjectInfo` 复检持久化(本地等待即可,不调长工具);
|
||||||
|
③ 不持久 → `NodeProjectControl(action='start')` 重拉再复检。
|
||||||
|
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 任一失败 → **转场景二排错**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:启动排错
|
||||||
|
|
||||||
|
> 适用:部署后验证失败、或用户报"Node 项目启动失败/访问异常"。
|
||||||
|
|
||||||
|
## Step 0 —— 快速定位现状(只读)
|
||||||
|
并行收集,不跳过:
|
||||||
|
1. `NodeProjectInfo(project_name=...)`:`run`、`listen`、`listen_ok`(区分"进程没起来"与"起来了但访问不了");pm2 项目看状态。
|
||||||
|
2. 读应用日志尾部:用返回的 `log_files` 应用日志路径调 filesystem `Read`,找异常堆栈根因。
|
||||||
|
3. 已知配置:项目类型、入口/脚本、node 版本、端口、是否已装依赖。
|
||||||
|
|
||||||
|
收集后按症状进分支。
|
||||||
|
|
||||||
|
## 分支 A —— 启动失败(进程起不来 / run=false)
|
||||||
|
按日志根因对号入座:
|
||||||
|
| 日志特征 | 根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| `Error: Cannot find module 'x'` | 依赖未安装 | `NodeProjectCreate(project_cwd=<项目目录>, nodejs_version=..., project_script=..., install_deps=true)` 或装依赖后重启 |
|
||||||
|
| `EADDRINUSE` / `Port 3000 is already in use` | 端口被占 | `NodeProjectModify(action='config', port=新端口)` 后 `NodeProjectControl(action='restart')` |
|
||||||
|
| `npm ERR! Missing script: "start"` | scripts key 名错 | `NodeProjectModify(action='config', project_script=正确key)` |
|
||||||
|
| `throw er; Unhandled 'error' event` | 启动即崩(端口/环境) | 看堆栈中具体原因;换端口或补 env |
|
||||||
|
| `ERR_REQUIRE_ESM` / 语法错误 | 模块系统/代码问题 | 检查入口与 `package.json` 的 `type` 字段 |
|
||||||
|
| node 版本引擎不符 | `engines.node` 不匹配 | `NodeProjectModify(action='config', nodejs_version=匹配版本)` 或 `NodeVersion(action='install')` |
|
||||||
|
| 进程起来但 pid 无/端口没监听 | 启动后立即退出 | 读日志尾找 `exit`/`Error` 根因 |
|
||||||
|
|
||||||
|
- 无明确报错 → 查 `NodeProjectInfo`:run、listen、启动命令是否完整;`log_files` 有无 pm2 err.log。
|
||||||
|
- 修复后回到场景一 Step 5 重新验证。
|
||||||
|
|
||||||
|
## 分支 B —— 访问异常(502/无法访问,但进程活着)
|
||||||
|
1. `NodeProjectInfo`:进程在跑、端口在听吗?→ 不在则回分支 A。
|
||||||
|
2. **反代端口匹配**:看 `listen`(实际监听)vs `project_config.port`(反代目标)是否一致;grep `proxy_pass` `node_<name>.conf`(`/www/server/panel/vhost/nginx/node_<name>.conf`)确认反代指向 `127.0.0.1:{实际端口}`。
|
||||||
|
- 端口改了没同步 → `NodeProjectModify(action='config', port=实际端口)`(有 domains 时自动重写反代)。
|
||||||
|
- 反代指向错误端口 → 同上。
|
||||||
|
3. **域名绑定**:`bind_extranet` 是否开、域名是否在 nginx `server_name`(未绑 → `NodeProjectModify(action='add_domain', domains=[...])`)。
|
||||||
|
4. 读 nginx error log(`log_files` 里 `/www/wwwlogs/<name>.error.log`)进一步定位。
|
||||||
|
5. 修正后验证。
|
||||||
|
|
||||||
|
## 分支 C —— PM2 项目异常
|
||||||
|
1. `NodeProjectInfo` 看 pm2 状态(online/stopped/errored)。
|
||||||
|
2. `errored`(崩溃超限)→ 读 `log_files` 里 pm2 `err.log` 找根因;修复后用 `NodeProjectControl(action='restart')` 重启。
|
||||||
|
3. 读 `/www/wwwlogs/pm2/<name>/out.log|err.log`。
|
||||||
|
4. 依赖问题 → 同分支 A。
|
||||||
|
|
||||||
|
## 分支 D —— 进程在但无响应 / 卡死
|
||||||
|
1. 应用日志尾部看异常/死锁(filesystem `Read`)。
|
||||||
|
2. `SystemInfo()` 看系统资源(CPU/内存/负载)。
|
||||||
|
3. 汇报,建议用户确认后 `NodeProjectControl(action='restart')` 重启。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 日常运维速查(简单操作,直接按工具描述调用)
|
||||||
|
|
||||||
|
| 需求 | 工具 |
|
||||||
|
|---|---|
|
||||||
|
| 查看项目列表/状态 | `NodeProjectInfo()`(project_name 留空) |
|
||||||
|
| 查看单项目详情(含日志路径) | `NodeProjectInfo(project_name=...)` |
|
||||||
|
| 启动 / 停止 / 重启 | `NodeProjectControl(project_name, action='start'/'stop'/'restart')` |
|
||||||
|
| 看应用日志 / pm2 / nginx 日志 | `NodeProjectInfo` 返回 `log_files` → filesystem `Read` |
|
||||||
|
| 改脚本/参数/node 版本/端口/用户/环境/内存 | `NodeProjectModify(action='config', ...)`(重启生效) |
|
||||||
|
| 加域名 / 删域名(至少留一个) | `NodeProjectModify(action='add_domain'/'remove_domain', domains=[...])` |
|
||||||
|
| node 版本检测 / 在线浏览 / 安装 | `NodeVersion(action='list'/'online'/'install', ...)` |
|
||||||
|
| 给 node 版本装全局模块(pm2/pnpm/yarn 等) | `NodeVersion(action='module', version=<nodejs_version>, modules=['pm2'])` |
|
||||||
|
| 删除项目(**高风险,先确认**) | `NodeProjectDelete(project_name=...)`(保留目录源码) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板(部署成功)
|
||||||
|
|
||||||
|
返回:项目名 / 项目类型 / 目录 / node 版本 / 运行用户 / 监听端口;若绑域名:访问地址 + nginx 配置路径;应用日志路径;启动验证结果(进程/端口/日志);遗留隐患提示(依赖未装、env 未注入等)。
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
---
|
||||||
|
name: BT-Python-Project-Deploy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上部署 Python 项目(uwsgi/gunicorn/command 三种运行方式,含虚拟环境配置、
|
||||||
|
Python 版本安装、requirements 依赖、Nginx 域名/反代),并在环境准备或启动失败时排错。
|
||||||
|
当用户要求把本机已有的 Python 项目目录部署成面板可管理的项目(含 Python 版本安装、
|
||||||
|
虚拟环境创建、pip 依赖、uwsgi/gunicorn 托管或自定义命令启动),或 Python 项目
|
||||||
|
启动失败/访问异常/环境准备失败需要排查根因时使用。
|
||||||
|
触发关键词:部署 Python、Python 项目部署、django/flask/fastapi/sanic 部署、
|
||||||
|
uvicorn/gunicorn/uwsgi、虚拟环境 venv、pip install、Python 项目启动失败、
|
||||||
|
ImportError、ModuleNotFoundError、502、访问异常、celery、关联进程、requirements。
|
||||||
|
日常的启停/状态/日志/改配置/装包等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Python 项目部署与启动排错 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 只覆盖两个主场景:**① 部署 Python 项目;② 环境准备/启动排错**。其他简单操作(状态查看、启停、日志、域名、改配置、装包、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 部署前必须完成项目分析;排错先读日志,不盲目重启。
|
||||||
|
2. **创建成功 ≠ 启动成功** —— Python 创建项目后环境准备(装依赖+生成启动脚本+尝试启动)是**后台异步**的。必须用 `PythonProjectInfo` 轮询 `prep_status` 到 `complete`,再核验进程存活 + 监听端口 + 日志无致命错误;`prep_status=failure` 立即转场景二。**这是本场景最容易栽的坑。**
|
||||||
|
3. **建项目前必须有虚拟环境** —— 面板要求 `python_bin` 是已托管的 venv/conda(`can_use_directly`)。部署顺序:版本 → 环境 → 项目。
|
||||||
|
4. **Python 版本安装走 Bash 后台** —— 源码编译极慢(10-30 分钟),不得用同步工具卡住;必须 `Bash(run_in_background=true)` + `BashStatus` 轮询。
|
||||||
|
5. **删除项目保留虚拟环境** —— venv 与项目非强绑定(可复用/共享),删除不删 venv(面板语义);如需移除单独用 `PythonEnv(action='remove')`。删除本身仍高风险(停进程/清配置/删记录),先确认。
|
||||||
|
6. **绑域名 = 外网映射 + 反代** —— `add_domain` 只写域名,需 `bind_extranet` 生成 nginx 配置(proxy 到 127.0.0.1:port);path→port 反代(`add_proxy`)**必须先开启外网映射**。
|
||||||
|
7. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
8. **禁止操作**:删除项目目录/源码、`rm -rf` 项目目录、修改宝塔/插件自身文件、读取插件 `data/` 凭据。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:部署 Python 项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"部署新 Python 项目"(非排错/运维)。
|
||||||
|
2. 确定**运行方式 `stype`**:`uwsgi` / `gunicorn` / `command`(直跑,python 文件方式已并入 command)。
|
||||||
|
3. 确认**协议**:`wsgi`(Flask/Django 传统)/ `asgi`(FastAPI/Sanic/uvicorn)。
|
||||||
|
4. 需要外网域名访问时,确认 Nginx 已安装;否则只能本机/内网访问。
|
||||||
|
|
||||||
|
## Step 1 —— 定位项目目录
|
||||||
|
- 用户给出 `project_path`(项目根,含 `*.py`),或:
|
||||||
|
- 用文件工具 `Glob(pattern='**/*.py')` / `LS(path=...)` 定位(排除 `node_modules`、`dist`、`.venv`、`venv` 等)。
|
||||||
|
- **校验**:目录存在、含入口 `*.py`(或 `requirements.txt`)、非敏感目录(`/etc`、`/boot`、插件 `data/` 等)。
|
||||||
|
|
||||||
|
## Step 2 —— 分析项目(部署前必须)
|
||||||
|
调用 `PythonProjectCreate(project_path=..., analyze_only=true)`(只读,不创建)。返回:
|
||||||
|
1. `framework`:django/flask/sanic/fastapi 等(按 requirement/入口代码识别)。
|
||||||
|
2. `runfile`:入口文件、`xsgi`(wsgi/asgi)、`call_app`(可调用对象名)。
|
||||||
|
3. `requirement_path`:requirements 文件(缺 → 需先补)。
|
||||||
|
4. `has_venv` / `port` / `port_hints`:目录是否自带 venv、启发式端口(仅供参考)。
|
||||||
|
|
||||||
|
**决策**:
|
||||||
|
- 选 `stype`:Django/Flask 传统 → `gunicorn`(或 `uwsgi`);FastAPI/Sanic → `gunicorn` + `xsgi='asgi'`;无框架/自写 socket → `command`(`project_cmd='{python_bin} -u {runfile} {parm}'`)。
|
||||||
|
- 确认 `rfile`(启动文件绝对路径)与 `call_app`(app/application,或自动探测)。
|
||||||
|
- 无端口或启发式不准 → 询问用户,创建时显式传 `port`(uwsgi/gunicorn 必填;command 可空)。
|
||||||
|
|
||||||
|
## Step 3 —— Python 版本确认 / 虚拟环境准备
|
||||||
|
1. `PythonVersion(action='list')` 查看已装 Python 版本与当前默认;返回含 `install_hint`。
|
||||||
|
2. 需要新版本时 `PythonVersion(action='online', ...)` 浏览可安装版本(每项含 `install_command`),**用 Bash 后台安装**:
|
||||||
|
- `Bash(command=<install_command>, run_in_background=true)` → 得到 `task_id`;
|
||||||
|
- `BashStatus(task_id, wait=true)` 轮询到完成(后台最长 30 分钟,超时强杀;若超时汇报并让用户决定重跑/换源)。
|
||||||
|
3. `PythonEnv(action='list')` 查看虚拟环境:找 `can_use_directly=true` 的 venv;若需新建,看每项 `source` 与顶层 `source_priority` 判断源优先级。
|
||||||
|
4. 没有可用 venv → `PythonEnv(action='create', venv_name=<项目名或自定义>, python_bin=<源环境bin>, ps=<备注>)` 创建,得到 `python_bin`(venv_path + python_bin)。创建较慢(venv + ensurepip),**创建成功返回后必须再跑一次 `PythonEnv(action='list')` 确认该 venv 出现在列表里且目录真实存在**——工具已规避面板 `create_venv_sync` 的"只写记录不建目录"假成功缺陷并做磁盘校验,但仍建议复核。
|
||||||
|
**源 python_bin 选择优先级(重要)**:① 面板安装的 Python 版本(`source=panel_installed`,如 `/www/server/pyporject_evn/versions/<ver>/bin/python`,**推荐**)→ ② 系统 Python(`source=system`,如 `/usr/bin/python3`,需有 venv/pip,缺则自动安装可能失败)→ ③ 面板自带 pyenv(`source=panel_pyenv`,`/www/server/panel/pyenv`——打包时移除过大量非必要文件,**不适合普通用户**,工具会直接拒绝)。优先用 `PythonVersion` 装好版本再作源。
|
||||||
|
|
||||||
|
## Step 4 —— 创建项目(注册)
|
||||||
|
调用 `PythonProjectCreate(project_name=..., project_path=..., python_bin=<第3步的venv>, stype=..., ...)`。
|
||||||
|
按类型传参:
|
||||||
|
- **uwsgi**:`rfile` + `call_app` + `port`(+ `processes`/`threads`)。
|
||||||
|
- **gunicorn**:`rfile` + `call_app` + `port`;FastAPI/Sanic 加 `xsgi='asgi'`。
|
||||||
|
- **command**:`project_cmd`(如 `'{python_bin} -u {runfile}'`,**占位符由工具替换为实际路径**),`port` 可留 0。
|
||||||
|
- **通用**:`user`(默认 root)、`env_list=[{"k","v"}]`(**必须 dict 格式**,如 `[{"k":"PORT","v":"9000"}]`,字符串 "K=V" 会被 schema 拒绝)、`env_file`、`requirement_path`(有则自动装依赖)、`auto_run`、`release_firewall`(需外网访问时 true)、`initialize`(可选初始化命令)。
|
||||||
|
创建返回 `prep_status=running`(或 complete/failure)+ `prep_log` 路径。
|
||||||
|
|
||||||
|
## Step 5 —— 环境准备等待 + 启动验证(强制)
|
||||||
|
1. `PythonProjectInfo(project_name=...)` 轮询 `prep_status`:**`running` → 等待后重查**(本地 sleep 即可,不调长工具);到 `complete` 继续,到 `failure` **立即转场景二分支 A**。
|
||||||
|
2. 核验启动:`run=true`、应用端口在 `listen` 列表。
|
||||||
|
3. 用返回的 `log_files` 里应用日志路径,调 filesystem `Read` 看尾部无致命异常(`ImportError`/`ModuleNotFoundError`/`Address already in use`/`Error: [Errno 98]`)。
|
||||||
|
4. 有域名映射的项目核验 `services`(关联进程)与反代。
|
||||||
|
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 任一失败 → **转场景二排错**。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:环境准备 / 启动排错
|
||||||
|
|
||||||
|
> 适用:部署后验证失败(prep_status=failure / run=false)、或用户报"Python 项目启动失败/访问异常"。
|
||||||
|
|
||||||
|
## Step 0 —— 快速定位现状(只读)
|
||||||
|
并行收集,不跳过:
|
||||||
|
1. `PythonProjectInfo(project_name=...)`:`prep_status`、`run`、`listen`、`log_files`(区分"环境没准备好 / 进程没起来 / 起来了但访问不了")。
|
||||||
|
2. 按症状读日志:`prep_status=failure` 读**环境准备日志**(`log_files` 里 "环境准备日志");`run=false` 读**应用日志**(`log_files` 里 stype 对应项:error.log / uwsgi.log / gunicorn_error.log)。
|
||||||
|
3. 已知配置:stype、入口文件、虚拟环境、端口、是否已装依赖。
|
||||||
|
|
||||||
|
收集后按症状进分支。
|
||||||
|
|
||||||
|
## 分支 A —— 环境准备失败(prep_status=failure)
|
||||||
|
- 读 `log_files` 里的"环境准备日志"(`/www/server/python_project/vhost/logs/<name>.log`)找根因:
|
||||||
|
| 日志特征 | 根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| `pip ... Could not find a version that satisfies` | 依赖源/包名错 | 换 pip 源或 `PythonEnv` 手动装对应包;`PythonProjectControl(action='restart')` 重拉 |
|
||||||
|
| `ImportError` / `ModuleNotFoundError: No module named 'x'` | 缺依赖 | `PythonEnv(action='package', python_bin=<env>, package_action='install', package_name='x')` 后重启 |
|
||||||
|
| `configure: error` / `make: *** Error`(装托管依赖失败) | 编译缺系统库 | 汇报,需安装系统依赖库后再 `re_prep_env` 或重建 |
|
||||||
|
| `uwsgi/gunicorn` 命令 not found | 托管依赖没装上 | 同上 |
|
||||||
|
- 修复后 `PythonProjectControl(action='restart')`(或 `action='start'`)重新拉取,回场景一 Step 5 复检。
|
||||||
|
|
||||||
|
## 分支 B —— 启动失败(进程起不来 / run=false,但 prep_status=complete)
|
||||||
|
按应用日志根因对号入座:
|
||||||
|
| 日志特征 | 根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| `ModuleNotFoundError` / `ImportError: No module named 'x'` | 依赖未装 | `PythonEnv(action='package', python_bin=..., package_action='install', package_name='x')` 后重启 |
|
||||||
|
| `Error: [Errno 98] Address already in use` | 端口被占 | `PythonProjectModify(action='config', port=新端口)` 后 `PythonProjectControl(action='restart')` |
|
||||||
|
| `[Errno 13] Permission denied` | 目录/日志权限 | `PythonProjectModify(action='config', user=<有权限用户>)` 或修目录属主 |
|
||||||
|
| `No module named 'app'` / `gunicorn.errors.HaltServer` | rfile/call_app 错 | `PythonProjectModify(action='config', rfile=/call_app=正确值)` |
|
||||||
|
| `Command '('...')' returned non-zero exit status` | command 命令本身失败 | 检查 `project_cmd` 与环境变量 |
|
||||||
|
| `django.core.exceptions.ImproperlyConfigured` | Django settings 问题 | 检查 env_list 里的 DJANGO_SETTINGS_MODULE 等 |
|
||||||
|
| 进程起来但 pid 无/端口没监听 | 启动后立即退出 | 读日志尾找 `Traceback` 根因 |
|
||||||
|
|
||||||
|
- 无明确报错 → 查 `PythonProjectInfo`:run、listen、启动脚本(`project_config`)是否完整。
|
||||||
|
- 修复后回场景一 Step 5 重新验证。
|
||||||
|
|
||||||
|
## 分支 C —— 访问异常(502/无法访问,但进程活着)
|
||||||
|
1. `PythonProjectInfo`:进程在跑、端口在听吗?→ 不在则回分支 B。
|
||||||
|
2. **映射/反代核对**:
|
||||||
|
- 域名是否绑定、`bind_extranet` 是否开启(未开启 → `PythonProjectModify(action='add_domain', domains=[...])` + `action='bind_extranet'`)。
|
||||||
|
- `listen`(实际监听端口)vs `project_config.port`(反代目标)是否一致;grep `proxy_pass` `python_<name>.conf`(`/www/server/panel/vhost/nginx/python_<name>.conf`)确认反代指向 `127.0.0.1:{实际端口}`。
|
||||||
|
- path→port 反代缺失/指错 → `PythonProjectModify(action='add_proxy', proxy_path='/', proxy_port=实际端口)`(**需已开启外网映射**)。
|
||||||
|
3. 读 nginx error log(`/www/wwwlogs/<name>.error.log`)进一步定位。
|
||||||
|
4. 修正后验证。
|
||||||
|
|
||||||
|
## 分支 D —— 关联进程异常(celery worker 等)
|
||||||
|
1. `PythonProjectService(project_name=..., action='list')` 看各服务 pid/ports(主服务 sid='main' 之外为关联进程)。
|
||||||
|
2. 某服务异常 → `action='log'`(`sid=...`)读服务日志;`action='start'/'stop'/'restart'`(`sid=...`)重拉。
|
||||||
|
3. 缺 celery → `PythonEnv(action='package', python_bin=..., package_action='install', package_name='celery')`。
|
||||||
|
4. 修正后 `action='list'` 复检 pid 存在。
|
||||||
|
|
||||||
|
## 分支 E —— 依赖问题(环境内包管理)
|
||||||
|
- `PythonEnv(action='package', python_bin=<虚拟环境>, package_action='list')` 看已装包。
|
||||||
|
- `package_action='install'`(`package_name` + 可选 `package_version` + 可选 `pip_source`)/ `package_action='uninstall'`(`package_name`)。安装慢,返回 `log_tail`。
|
||||||
|
- 修完回场景一 Step 5 验证。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 日常运维速查(简单操作,直接按工具描述调用)
|
||||||
|
|
||||||
|
| 需求 | 工具 |
|
||||||
|
|---|---|
|
||||||
|
| 查看项目列表/状态 | `PythonProjectInfo()`(project_name 留空) |
|
||||||
|
| 查看单项目详情(prep_status/run/listen/日志路径/服务) | `PythonProjectInfo(project_name=...)` |
|
||||||
|
| 启动 / 停止 / 重启(含关联进程) | `PythonProjectControl(project_name, action='start'/'stop'/'restart')` |
|
||||||
|
| 只启动 / 只停止主服务 | `PythonProjectControl(project_name, action='start_main'/'stop_main')` |
|
||||||
|
| 看应用 / 环境准备 / 服务日志 | `PythonProjectInfo` 返回 `log_files` → filesystem `Read` |
|
||||||
|
| 改端口/启动方式/入口/用户/环境变量/日志路径 | `PythonProjectModify(action='config', ...)`(重启生效) |
|
||||||
|
| 加 / 删域名、开 / 关外网映射、path→port 反代 | `PythonProjectModify(action='add_domain'/'remove_domain'/'bind_extranet'/'unbind_extranet'/'add_proxy', ...)` |
|
||||||
|
| Python 版本检测 / 在线浏览 / 移除 | `PythonVersion(action='list'/'online'/'remove', ...)` |
|
||||||
|
| **安装 Python 版本(编译慢,后台)** | `PythonVersion` online 取 `install_command` → `Bash(run_in_background=true)` + `BashStatus` 轮询 |
|
||||||
|
| 虚拟环境列表 / 创建 / 移除 / 设默认 | `PythonEnv(action='list'/'create'/'remove'/'set_default', ...)` |
|
||||||
|
| 环境内 pip 装 / 卸 / 列表 | `PythonEnv(action='package', python_bin=<env>, package_action='install'/'uninstall'/'list', ...)` |
|
||||||
|
| 关联进程列表 / 启停 / 日志 / **删除(先停再删)** | `PythonProjectService(project_name, action='list'/'start'/'stop'/'restart'/'log'/'remove', sid=...)` |
|
||||||
|
| 删除项目(**高风险,先确认**;保留虚拟环境,需删除用 `PythonEnv(action='remove')`) | `PythonProjectDelete(project_name=...)`(保留目录源码) |
|
||||||
|
|
||||||
|
> ⚠️ **remove_domain 注意**:面板移除域名会连带停止项目服务(主服务+协同服务,与是否剩最后一个域名无关,已实证、根因待定位)。工具**不自动恢复**(避免掩盖根因):移除后必须用 `PythonProjectInfo` 复核运行态,被停则手动 `PythonProjectControl(action='start')` 拉起。
|
||||||
|
> **add_domain 注意**:对已存在的域名面板返回"已存在"=实际已绑定/可访问,工具按逐域结果如实上报(非失败);只有格式错误等才报错。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板(部署成功)
|
||||||
|
|
||||||
|
返回:项目名 / 运行方式(stype)/ 目录 / 虚拟环境 python_bin / 运行用户 / 监听端口;若绑域名:访问地址 + nginx 配置路径;环境准备状态(prep_status=complete)与启动验证结果(进程/端口/日志);关联进程清单;遗留隐患提示(依赖未装、requirements 缺失、env 未注入、端口启发不准等)。
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
---
|
||||||
|
name: BT-Reverse-Proxy
|
||||||
|
description: >
|
||||||
|
在宝塔面板上管理反向代理项目:创建反代站点(域名 + 目标上游)、查看/增删改 URL 级转发规则、
|
||||||
|
自由编辑 nginx 反代配置、改备注/启停/绑删域名/强制 HTTPS,并在反代访问异常(502/404/转发不生效)时排错。
|
||||||
|
当用户要求把某个域名/路径转发到后端服务(HTTP/HTTPS 或 unix socket),或反代站点访问异常需要排查时使用。
|
||||||
|
触发关键词:反向代理、反代、代理转发、proxy_pass、location 转发、域名转发到端口、nginx 反代配置、
|
||||||
|
反代 502、反代 404、转发不生效、BT-Reverse-Proxy。
|
||||||
|
日常的查看/启停/改备注等简单操作不依赖本 SOP,直接按工具描述调用即可。
|
||||||
|
---
|
||||||
|
|
||||||
|
# 反向代理项目运维 SOP
|
||||||
|
|
||||||
|
> **停止。执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> 本 Skill 的工具均指 bt_agent_mcp 插件暴露的 MCP 工具;同一能力在宝塔 AI 内置端可能有不同命名,按当前环境可用工具调用。
|
||||||
|
> 本 SOP 覆盖三个主场景:**① 创建反代项目;② 编辑/增删 URL 转发规则(自由配置);③ 反代访问异常排错**。其他简单操作(状态查看、启停、改备注、绑删域名、强制 HTTPS、删除)不做 SOP,直接使用工具。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **先只读侦察,再执行变更** —— 操作前先 `ProxyProjectInfo`(site_name 留空)列项目找到站点名(可能带 `_<端口>` 后缀),再 `ProxyProjectInfo(site_name=...)` 看当前规则/域名/端口/SSL;排错先读日志,不盲目重写配置。
|
||||||
|
2. **反代项目 = sites 行 + 反代 JSON** —— 真正的配置在 `/www/server/proxy_project/sites/<name>/<name>.json`(`proxy_info[]` 多条 URL 规则);nginx conf 由它渲染。**改配置必须走 MCP 工具**(ProxyWriteConfig),保持 JSON 与 nginx 同步。
|
||||||
|
3. **URL 规则增删改走自由配置** —— 不要期待 add/set/del_url_proxy 之类的工具(未提供)。改规则 = 读 conf → 改 location 块 → `ProxyWriteConfig` 回传完整 conf → `Bash` `nginx -t` 验证。**面板保存后会自动把 proxy_info/域名/端口同步回反代 JSON。**
|
||||||
|
4. **改配置三步走**:`ProxyProjectInfo` 拿 `config_file` 路径 → filesystem `Read` 读当前 conf 作基线 → 修改后 `ProxyWriteConfig(conf_data=<完整 conf>)` → `Bash` 执行 `nginx -t` 验证。**改前必须 Read 留基线**,写坏可恢复。
|
||||||
|
5. **域名增删走 `ProxyProjectModify`** —— 用 comMod 的方法(会同步反代 JSON);**不要用通用网站域名工具**(不更新反代 JSON,面板会不同步)。至少保留一个域名。
|
||||||
|
6. **创建即生效** —— `ProxyProjectCreate` 成功即写 nginx + 放行防火墙 + 重载服务;返回的 `site_name_hint` 是主域名小写形式,**实际站点名以 `ProxyProjectInfo` 列表返回的 name 为准**(非 80 端口会带 `_<端口>`)。
|
||||||
|
7. **每个任务最多调用 15 次工具**,超出后汇总当前发现并停止。
|
||||||
|
8. **禁止操作**:`rm -rf` 反代站点根目录外的路径、修改宝塔/插件自身文件、读取插件 `data/` 凭据、直接用 filesystem Write 覆盖反代 nginx conf(必须走 ProxyWriteConfig 保持 JSON 同步)。
|
||||||
|
9. **反代目标勿指向 bt_agent_mcp 自身端口**(`127.0.0.1:<MCP端口>`,默认 8765)——会把 MCP 服务暴露给该反代域名,且反代 conf 未设 `X-Real-IP` 时来源 IP 白名单会被绕过(仅剩 API Key 鉴权兜底)。**若工具返回 `data.warning` 说明代理目标指向 MCP 自身,须与用户确认意图**;确需经反代暴露 MCP,则在该 location 补 `proxy_set_header X-Real-IP $remote_addr;` 并把真实客户端 IP 加入白名单(`security.ip_allowlist`)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景一:创建反代项目
|
||||||
|
|
||||||
|
## Step 0 —— 预检
|
||||||
|
1. 确认任务确为"创建反向代理项目"。
|
||||||
|
2. 拿到**要对外暴露的域名**(可带 `:端口`,非 80 端口会成为监听端口)与**目标上游**(http/https URL 或 unix socket 路径)。
|
||||||
|
3. 确认 Nginx 已安装(反代只支持 nginx)。
|
||||||
|
|
||||||
|
## Step 1 —— 调用创建
|
||||||
|
`ProxyProjectCreate(domains=[...], proxy_pass=...)`:
|
||||||
|
- **必填**:`domains`(list,`'example.com'` 或 `'example.com:8080'`)、`proxy_pass`(`http://127.0.0.1:8080`、`https://api.example.com`,或 unix 时 `/tmp/app.sock`)。
|
||||||
|
- **可选**:`proxy_path`(默认 `/`,前缀)、`proxy_host`(默认 `$http_host`,转发 Host)、`proxy_type`(http/unix,默认 http)、`remark`。
|
||||||
|
|
||||||
|
> 返回"添加成功"= 已写 nginx conf + 放行端口 + 重载。`site_name_hint` 仅供参考。
|
||||||
|
|
||||||
|
## Step 2 —— 验证(强制)
|
||||||
|
1. `ProxyProjectInfo`(site_name 留空)确认站点出现,记下真实 `name`。
|
||||||
|
2. `ProxyProjectInfo(site_name=...)` 看 `config`(域名/端口/首条 proxy_info 的 proxy_pass 是否对上)。
|
||||||
|
3. 需要的话 filesystem `Read` conf 确认 `location { proxy_pass ... }` 已渲染。
|
||||||
|
|
||||||
|
- 全通过 → 按"完成汇报"收尾。
|
||||||
|
- 配置与预期不符 → 转场景二修正配置,或转场景三排错。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景二:编辑 / 增删 URL 转发规则(自由配置)
|
||||||
|
|
||||||
|
## Step 0 —— 拿基线与现状
|
||||||
|
1. `ProxyProjectInfo(site_name=...)`:拿到 `config_file` 路径(`/www/server/panel/vhost/nginx/<name>.conf`)、当前 `proxy_info`(每条 proxy_path/proxy_pass/proxy_host/websocket/超时)、域名与端口。
|
||||||
|
2. filesystem `Read` `config_file` 读当前完整 conf。
|
||||||
|
|
||||||
|
## Step 1 —— 修改 conf
|
||||||
|
按「常用 nginx 反代配置速查」(见文末)在 conf 里**增/删/改 location 块**(或 server/http 层配置)。常见操作:
|
||||||
|
- **加一条转发规则**:新增 `location /api { proxy_pass http://127.0.0.1:9000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }`。
|
||||||
|
- **改目标**:改对应 `location` 里的 `proxy_pass`(换后端端口/地址)。
|
||||||
|
- **删规则**:删掉对应 `location` 块。
|
||||||
|
- **改超时**:在 location 内加 `proxy_connect_timeout 60s; proxy_read_timeout 600s; proxy_send_timeout 600s;`。
|
||||||
|
- **开 WebSocket**:加 `proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";`(反代 JSON 的 websocket 默认支持)。
|
||||||
|
- **强制 HTTPS**:优先用 `ProxyProjectModify(action='force_https', force_https=true)`,不要手改 ssl 块。
|
||||||
|
|
||||||
|
> 注意:**location 的 proxy_pass 末尾不带 `;` 前不可跟变量**(`proxy_pass http://127.0.0.1:9000;` 可直接跟 URI 或不带 URI;用变量时必须 `resolver`)。简单场景直接写死目标即可。
|
||||||
|
|
||||||
|
## Step 2 —— 回传并验证
|
||||||
|
1. `ProxyWriteConfig(site_name=..., conf_data=<修改后的完整 conf>)` → 面板写 conf 并自动同步反代 JSON。
|
||||||
|
2. `Bash` 执行 `nginx -t` 确认配置语法通过;失败按报错行修 conf 重存。
|
||||||
|
3. `ProxyProjectInfo` 复查 `proxy_info` 已同步新规则。
|
||||||
|
4. 访问验证(如有域名):确认新规则生效、旧规则仍在。
|
||||||
|
|
||||||
|
- 配置写坏导致站点异常 → 用 Read 留的基线恢复后 `ProxyWriteConfig` 重存,或面板历史版本回滚。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 场景三:反代访问异常排错
|
||||||
|
|
||||||
|
## Step 0 —— 只读侦察(不盲改)
|
||||||
|
1. `ProxyProjectInfo` 确认项目存在、域名/端口/规则现状。
|
||||||
|
2. filesystem `Read` nginx 错误日志 `/www/wwwlogs/<name>.error.log` 与访问日志 `/www/wwwlogs/<name>.log`;必要时 `ProxyWriteConfig` 不变,仅 Read conf 检查 proxy_pass/upstream。
|
||||||
|
|
||||||
|
## Step 1 —— 按症状对号入座
|
||||||
|
|
||||||
|
| 症状 | 常见根因 | 处置 |
|
||||||
|
|---|---|---|
|
||||||
|
| **502 Bad Gateway** | 后端未启动/端口错、proxy_pass 写错、unix socket 不存在、超时太短 | 确认后端进程在监听(`Bash` `ss -tlnp \| grep <port>`);核对 `ProxyProjectInfo` 的 proxy_pass 与真实后端;unix 路径检查文件存在;长请求调大 `proxy_read_timeout` |
|
||||||
|
| **404** | proxy_path 前缀与后端路由不匹配、location 前缀未命中、误写 `try_files` | 核对 location 的 `proxy_pass` 是否带 URI 前缀;检查 conf 是否有多余 location 拦截 |
|
||||||
|
| **转发不生效 / 仍是静态页** | conf 没保存成功、location 与现有规则冲突、缓存 | `nginx -t` + `ProxyProjectInfo` 看 JSON 是否同步;必要时 `Bash` `nginx -s reload` 后重试;缓存类规则先关 `proxy_cache` |
|
||||||
|
| **只对本机/内网生效** | 域名未绑定外网、防火墙未放行端口 | `ProxyProjectModify(action='add_domain')` 补域名;`Bash` 查防火墙端口放行状态 |
|
||||||
|
| **HTTPS 不强制 / 证书异常** | SSL 未部署、force_https 未开 | `ProxyProjectModify(action='force_https', force_https=true)`;证书部署走面板 |
|
||||||
|
|
||||||
|
## Step 2 —— 修复与验证
|
||||||
|
1. 按上表定位根因,**改 conf 必须走 ProxyWriteConfig + `nginx -t`**,改域名走 `ProxyProjectModify`。
|
||||||
|
2. 修复后重访验证;仍异常则回到 Step 0 换角度(读实时日志尾部 `tail`)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 运维速查
|
||||||
|
|
||||||
|
| 需求 | 调用 |
|
||||||
|
|---|---|
|
||||||
|
| 列表/找站点名 | `ProxyProjectInfo(search=..., page=...)`(site_name 留空) |
|
||||||
|
| 查看详情/规则/conf 路径 | `ProxyProjectInfo(site_name=...)` |
|
||||||
|
| 创建反代 | `ProxyProjectCreate(domains=[...], proxy_pass=...)` |
|
||||||
|
| 读/改 nginx conf | filesystem `Read` + `ProxyWriteConfig(site_name=..., conf_data=...)` |
|
||||||
|
| 验证语法 | `Bash` `nginx -t` |
|
||||||
|
| 改备注 / 启停 / 绑删域名 / 强制 HTTPS | `ProxyProjectModify(site_name=..., action=..., ...)` |
|
||||||
|
| 删除项目 | `ProxyProjectDelete(site_name=..., remove_path=false)`(高风险,确认后) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 常用 nginx 反代配置格式与位置速查
|
||||||
|
|
||||||
|
**位置**:反代项目的 nginx conf(`/www/server/panel/vhost/nginx/<name>.conf`)是完整 server 块。三块区域:
|
||||||
|
- **http 层**(`server {` 之前):upstream 定义、`proxy_cache_path`。
|
||||||
|
- **server 层**(`server { ... }` 内、location 外):`listen`、`server_name`、ssl 证书、`proxy_set_header`、`client_max_body_size`。
|
||||||
|
- **location 层**:每一条 `location <path> { ... }` 是一条 URL 转发规则,对应反代 JSON 的 `proxy_info[]`。
|
||||||
|
|
||||||
|
**典型片段**:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# location 转发(最常用):/ 全站转发
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8080;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 按路径前缀转发:/api 到另一后端
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 带自定义超时 + WebSocket
|
||||||
|
location /ws {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_read_timeout 600s;
|
||||||
|
proxy_send_timeout 600s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# server 层常用:限制上传大小、传递真实协议
|
||||||
|
client_max_body_size 50m;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
```
|
||||||
|
|
||||||
|
**规则**:
|
||||||
|
- `proxy_pass` 后**直接写死目标**(`http://IP:端口` 或 `https://域名`)最简单;若需在 URL 中带变量,必须配 `resolver`(一般不需要)。
|
||||||
|
- **勿把 `proxy_pass` 指向本机 bt_agent_mcp 自身端口**(默认 8765);若工具返回 `data.warning` 提示目标指向 MCP 自身,先与用户确认,确需暴露则在 location 补 `proxy_set_header X-Real-IP $remote_addr;` 并把真实客户端 IP 加入白名单。
|
||||||
|
- 改完**必须** `nginx -t` 验证,再确认访问生效。
|
||||||
|
- 涉及 SSL/强制 HTTPS 用 `ProxyProjectModify(action='force_https')`,别手改 ssl 块。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 完成汇报模板
|
||||||
|
|
||||||
|
汇报固定四段(每段 1-3 行,用一次工具查证一个结论,不堆 log):
|
||||||
|
|
||||||
|
- **现状**:反代项目 `<name>`,域名 `<域名:端口>`,转发目标 `<proxy_pass>`,状态(运行中/已停止)。
|
||||||
|
- **变更**:`<创建了反代项目 / 新增了 /api 转发规则 / 修改了 proxy_pass / 启停了项目 / 设置了强制 HTTPS>`。
|
||||||
|
- **验证**:`nginx -t` 通过 / `ProxyProjectInfo` 复查 proxy_info 已同步 / 访问 `<域名>` 返回预期。
|
||||||
|
- **遗留**:`<若有:SSL 证书未部署需面板处理 / 后端服务未监听需确认>;否则无`。
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
---
|
||||||
|
name: BT-Website-Troubleshoot
|
||||||
|
description: >
|
||||||
|
诊断并修复 bt panel 网站访问异常和服务启动失败问题。
|
||||||
|
当用户报告以下问题时使用此技能:网站无法打开、403/404/500/502/503 错误、
|
||||||
|
空白页/白屏、数据库连接错误、nginx 或 php-fpm 启动失败、
|
||||||
|
服务启动失败但没有明确原因,或任何网站宕机/访问被拒绝问题。
|
||||||
|
触发关键词:网站宕机、网站打不开、网站无法访问、502、
|
||||||
|
500、403、404、空白页、白屏、nginx 错误、php-fpm 错误、启动失败、
|
||||||
|
数据库连接失败、连接被拒绝、连接数过多、访问被拒绝、
|
||||||
|
网站不可达、服务不可用、错误网关、网站异常。
|
||||||
|
---
|
||||||
|
|
||||||
|
# bt panel 网站故障排查
|
||||||
|
|
||||||
|
> **停止。在执行任何操作前,必须完整阅读本文档。**
|
||||||
|
> **第一个动作:若当前环境有 todo 工具(`TodoWrite`),先用它创建诊断任务列表**;没有则直接进入诊断。
|
||||||
|
> 不要跳过任何章节。按顺序执行决策树。
|
||||||
|
> 永远不要向用户展示原始命令、btpython 路径或代码块 —— 仅使用自然语言报告。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
1. **始终先执行预检查** —— 永远不要跳过 `curl --resolve` 本地回环验证。
|
||||||
|
2. **修复前先读取** —— 在执行任何修复操作前,先诊断根因。
|
||||||
|
3. **每个任务最多调用 15 次工具** —— 超出后,汇总当前发现并停止。
|
||||||
|
4. **绝不让用户手动输入命令** —— 始终通过 `RunCommand/Bash` 执行。
|
||||||
|
5. **修复过程中发生错误时** —— 向用户报告,不要自动重试。
|
||||||
|
6. **服务报告“启动失败”时,始终检查原始服务日志** —— 面板提示通常过于模糊,无法直接采取行动。
|
||||||
|
7. **禁止操作**:删除网站、删除数据库、删除文件、`rm -rf`、`DROP TABLE/DATABASE`。
|
||||||
|
8. **任务跟踪(可选)** —— 若当前环境提供 todo 工具(`TodoWrite`/`TodoRead`),用它跟踪诊断:开始 Step 0 前建任务列表,保持单任务 `in_progress`,完成后标 `completed`,被中断用 `TodoRead` 恢复。没有 todo 工具则跳过,直接按决策树推进。
|
||||||
|
9. **工具名双写(两个部署环境)** —— 同一个能力在内置宝塔 AI 端和插件对外接口里名字不同:执行命令是 `RunCommand` / `Bash`,精确编辑是 `SearchReplace` / `Edit`。本文档统一写成 `RunCommand/Bash`、`SearchReplace/Edit`,你按当前手头可用的那个调用即可。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 0 —— 预检查(强制)
|
||||||
|
|
||||||
|
在任何诊断前,确认网站确实属于当前服务器,并且请求能够到达该服务器。
|
||||||
|
|
||||||
|
1. **创建任务列表(若可用)**:若当前有 `TodoWrite` 工具,先列出本次案例的步骤(预检查 → 探测 → 状态码分支 → 修复);没有则跳过本步,直接进入第 2 步。
|
||||||
|
2. **执行**:`RunCommand/Bash: curl --resolve <domain>:80:127.0.0.1 -sS -o /dev/null -w '%{http_code}\\n' http://<domain>/`
|
||||||
|
- 返回实际到达面板 nginx 的 HTTP 状态码。
|
||||||
|
3. **列出网站**:`SiteList()` → 找到匹配的 `name`(域名,作为 `site_name` 传给 `SiteGetConfig`)、`path`、`project_type`。
|
||||||
|
4. **如果网站不在当前面板上**(`curl` 返回连接错误或返回了其他网站):告知用户该域名可能并未托管在此处,不要继续。
|
||||||
|
|
||||||
|
> 仅当用户明确确认网站位于当前服务器,或直接提供了 `site_name`(域名)时,才可跳过预检查。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 1 —— 双探针
|
||||||
|
|
||||||
|
这些探针是只读验证,不产生持久副作用。创建、测试,并在完成后**删除**。
|
||||||
|
|
||||||
|
### 探针 A —— 静态文件(验证域名绑定 + nginx + 根目录)
|
||||||
|
|
||||||
|
1. `RunCommand/Bash: echo 'bt Panel probe $(date)' > <site_path>/.probe_static.html`
|
||||||
|
2. `RunCommand/Bash: chown www:www <site_path>/.probe_static.html && chmod 644 <site_path>/.probe_static.html`
|
||||||
|
3. `RunCommand/Bash: curl --resolve <domain>:80:127.0.0.1 -sS http://<domain>/.probe_static.html`
|
||||||
|
4. **预期结果**:返回探针文本,HTTP 状态码为 200。
|
||||||
|
5. 清理:`RunCommand/Bash: rm -f <site_path>/.probe_static.html`
|
||||||
|
|
||||||
|
### 探针 B —— PHP 文件(验证 PHP 运行时 + php-fpm socket)
|
||||||
|
|
||||||
|
1. `RunCommand/Bash: echo '<?php echo "bt Panel PHP probe ".PHP_VERSION; ?>' > <site_path>/.probe_php.php`
|
||||||
|
2. `RunCommand/Bash: chown www:www <site_path>/.probe_php.php && chmod 644 <site_path>/.probe_php.php`
|
||||||
|
3. `RunCommand/Bash: curl --resolve <domain>:80:127.0.0.1 -sS http://<domain>/.probe_php.php`
|
||||||
|
4. **预期结果**:返回包含 PHP 版本字符串的探针文本。
|
||||||
|
5. 清理:`RunCommand/Bash: rm -f <site_path>/.probe_php.php`
|
||||||
|
|
||||||
|
> 从 `SiteList` 返回的匹配项 `path` 字段获取 `site_path`。`SiteGetConfig(site_name)` 返回的是**原始虚拟主机配置文本**(不是结构化字段)—— 阅读文本中的 `root`、`access_log` 和 `include enable-php-<ver>.conf;` 指令,以验证根目录。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 2 —— 状态码决策树
|
||||||
|
|
||||||
|
### 403 Forbidden —— 权限 / 所有权
|
||||||
|
|
||||||
|
**目标**:确认 `www` 拥有网站目录树,目录权限为 755、文件权限为 644,并且父目录可读。
|
||||||
|
|
||||||
|
1. `SiteGetConfig(site_name)` → 获取 `root` 目录。
|
||||||
|
2. `RunCommand/Bash: ls -la <root>/` 和 `RunCommand/Bash: ls -la <parent_of_root>/`(父目录同样重要)。
|
||||||
|
3. 检查:
|
||||||
|
- root 及所有父目录的所有者/用户组 = `www:www`
|
||||||
|
- 目录权限 = `755`
|
||||||
|
- 文件权限 = `644`
|
||||||
|
4. 如果任一项不正确(自动修复,低风险):
|
||||||
|
- `RunCommand/Bash: chown -R www:www <root>`
|
||||||
|
- `RunCommand/Bash: find <root> -type d -exec chmod 755 {} \;`
|
||||||
|
- `RunCommand/Bash: find <root> -type f -exec chmod 644 {} \;`
|
||||||
|
5. 使用预检查 curl 重新测试。如果仍然返回 403,检查 nginx 错误日志:
|
||||||
|
- `Read: /www/wwwlogs/<domain>.error.log`(最后 50 行,查找 `directory index of "..." is forbidden` 或 `access denied`)。
|
||||||
|
|
||||||
|
### 404 Not Found —— 路径 / Rewrite
|
||||||
|
|
||||||
|
**先分类**:缺失的 URL 应该由动态路由(PHP 路由/框架路由)提供,还是由静态文件提供?
|
||||||
|
|
||||||
|
- **静态 404**(例如 `/favicon.ico`、`/uploads/foo.jpg`):
|
||||||
|
1. `SiteGetConfig(site_name)` → 检查 `root` 和 `access_log` 的位置。
|
||||||
|
2. `RunCommand/Bash: ls -la <root>/<expected_path>` → 文件是否缺失?root 是否错误?
|
||||||
|
3. 确认虚拟主机配置中的 `root` 指令与 `SiteList` 返回的实际 `site_path` 一致。
|
||||||
|
|
||||||
|
- **动态 404**(例如 `/category/news/`、`/article/123`、`/admin/login`):
|
||||||
|
1. `SiteGetConfig(site_name)` → 查找 `include .../rewrite/<domain>.conf;` 行。
|
||||||
|
2. `Read: /www/server/panel/vhost/rewrite/<domain>.conf`(如果存在)。
|
||||||
|
3. **常见原因**:框架(WordPress / ThinkPHP / Laravel / Typecho 等)的 rewrite 规则缺失或错误。
|
||||||
|
4. 修复(高风险 —— 需要面板确认):根据框架标准规则使用 `SearchReplace/Edit` 编辑 rewrite 文件,然后执行 `RunCommand/Bash: nginx -t && nginx -s reload`。
|
||||||
|
|
||||||
|
### 500 Internal Server Error —— 三个分支
|
||||||
|
|
||||||
|
运行预检查 curl,确认返回 500。然后依次检查各分支:
|
||||||
|
|
||||||
|
#### 分支 A —— 数据库
|
||||||
|
|
||||||
|
1. 读取 `SiteGetConfig` 找到项目根目录,然后查找框架数据库配置:
|
||||||
|
- WordPress:`Read: <root>/wp-config.php` → 提取 `DB_NAME`、`DB_USER`、`DB_PASSWORD`、`DB_HOST`。
|
||||||
|
- 其他框架:查找 `.env`、`config/database.php`、`application/database.php` 等。
|
||||||
|
2. `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> <DB_NAME> -e "SELECT VERSION()"` → 连接成功时返回 MySQL 版本号(即连接测试通过);失败则按下一步读错误码。
|
||||||
|
3. 如果连接失败,从 `mysql` 客户端的原始错误输出(形如 `ERROR 1045 (28000): ...`)中读取错误码,按下表判断:
|
||||||
|
- `2002` / `2003` → MySQL 未运行。进入**服务启动失败 → MySQL**。
|
||||||
|
- `1045` → 密码错误。比较配置中的 `DB_PASSWORD` 与 `databases` 表;如果不一致,向用户报告(不要自动重置数据库密码)。
|
||||||
|
- `1146` → 数据表缺失。用 `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> <DB_NAME> -e "SHOW TABLES"` / `DESC <表名>` 确认(凭据取自上一步 wp-config;RunCommand/Bash 为 high,会触发确认),然后报告。
|
||||||
|
- `1040` → 连接数过多。执行 `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW FULL PROCESSLIST"`,查看连接数与连接来源;建议提高 `max_connections`(高风险)。
|
||||||
|
|
||||||
|
#### 分支 B —— 代码(未捕获异常)
|
||||||
|
|
||||||
|
1. 启用 PHP 错误显示(高风险 —— 需要确认,且仅适用于非生产环境):
|
||||||
|
- `Read: /www/server/php/<ver>/etc/php.ini` → 检查 `display_errors` 和 `error_reporting`。
|
||||||
|
2. `Read: /www/wwwlogs/<domain>.error.log`(最后 100 行)→ 查找 PHP `Fatal error` / `Parse error` / `Uncaught`。
|
||||||
|
3. 向用户报告文件、行号和错误信息。不要自动修改网站代码。
|
||||||
|
|
||||||
|
#### 分支 C —— 配置(HTTP 200 但页面空白)
|
||||||
|
|
||||||
|
1. 这是典型的 **fastcgi.conf 损坏**模式:状态码为 200、响应体为空,并且网站此前正常。
|
||||||
|
2. `Read: /www/server/nginx/conf/fastcgi.conf` → 检查文件是否被清空或被过度注释。
|
||||||
|
3. 如果异常,向用户报告。修复需要恢复面板默认的 `fastcgi.conf`(高风险 —— 需要确认,并需要原始文件)。
|
||||||
|
|
||||||
|
### 502 / 503 Bad Gateway / Service Unavailable —— PHP-FPM 环境
|
||||||
|
|
||||||
|
1. `RunCommand/Bash: ps -ef \| grep php-fpm \| grep -v grep` → php-fpm 是否正在运行?
|
||||||
|
2. `ServiceStatus("php-fpm-<ver>")` → 确认安装和运行状态。从 `SiteGetConfig` 中的 `include enable-php-<ver>.conf;` 行确定版本。
|
||||||
|
3. `SiteGetConfig(site_name)` → 检查虚拟主机实际包含的 `enable-php-<ver>.conf` 是否与运行中的版本**一致**。
|
||||||
|
4. `RunCommand/Bash: curl -sS http://127.0.0.1/phpfpm_<ver>_status` → 检查 active processes、listen queue、max children。
|
||||||
|
- 如果 `listen queue` 非零 → 进程池已耗尽。参见**服务启动失败 → php-fpm**中的 OOM。
|
||||||
|
5. `RunCommand/Bash: free -m` → 查看可用内存;如果少于 200MB,OOM killer 可能已终止 php-fpm。
|
||||||
|
6. 对于**反向代理 502**:从面板主机执行 `RunCommand/Bash: curl -v <upstream_host>` → 检查上游是否可达(防火墙 / DNS / 上游宕机)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 3 —— 服务启动失败
|
||||||
|
|
||||||
|
> **核心原则**:当面板显示“启动失败”但没有有效细节时,**始终先读取原始服务日志**。面板提示通常过于模糊,无法直接采取行动。
|
||||||
|
|
||||||
|
### 3.1 nginx
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 语法检查 —— 可给出任何错误的准确文件和行号
|
||||||
|
/www/server/nginx/sbin/nginx -t
|
||||||
|
```
|
||||||
|
|
||||||
|
三种常见失败模式:
|
||||||
|
|
||||||
|
| 现象 | 原因 | 修复 |
|
||||||
|
|---|---|---|
|
||||||
|
| `unknown directive "xxx" in /www/server/panel/vhost/nginx/<site>.conf:N` | 网站虚拟主机配置中存在拼写错误或不受支持的指令 | 使用 `Read` 读取对应行,使用 `SearchReplace/Edit` 修复(高风险),然后重新执行 `nginx -t` |
|
||||||
|
| `bind() to 0.0.0.0:80 failed` / `bind() to [::]:443 failed` | 端口被占用 | `RunCommand/Bash: netstat -tlnp \| grep -E ':80\|:443'` → 找出冲突进程,并向用户报告 |
|
||||||
|
| `host not found in upstream "<name>"` | 启动时无法解析上游 DNS | 使用 `RunCommand/Bash: dig +short <name>` 验证;如果无法解析,向用户报告。修复:在虚拟主机中添加 `resolver` 指令,或替换为 IP(高风险) |
|
||||||
|
|
||||||
|
修复后,**始终**再次执行 `nginx -t`,然后执行 `RunCommand/Bash: /etc/init.d/nginx restart`(或 `ServiceRestart("nginx")`,高风险 —— 需要确认)。
|
||||||
|
|
||||||
|
### 3.2 php-fpm
|
||||||
|
|
||||||
|
从故障网站引用的 `enable-php-<ver>.conf` 中获取版本,然后执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 查看原始 php-fpm 错误日志末尾 —— 信息最完整
|
||||||
|
tail -n 50 /www/server/php/<ver>/var/log/php-fpm.log
|
||||||
|
```
|
||||||
|
|
||||||
|
| 现象 | 原因 | 修复 |
|
||||||
|
|---|---|---|
|
||||||
|
| `Unable to load dynamic library '<ext>.so'` / `segfault (core dumped)` | 新安装的 PHP 扩展损坏 | 二分排查:在面板中进入应用商店 → PHP → 设置 → 扩展,逐个卸载最近新增的扩展,每次卸载后重启(`RunCommand/Bash: /etc/init.d/php-fpm-<ver> restart`) |
|
||||||
|
| 启动后立即显示 `active (exited)` | 被 OOM killer 终止 | `RunCommand/Bash: dmesg \| grep -E "php\|oom" \| tail -20` + `RunCommand/Bash: free -m` → 降低 `/www/server/php/<ver>/etc/php-fpm.conf` 中的 `pm.max_children`(高风险) |
|
||||||
|
| `bind() to /tmp/php-cgi-<ver>.sock failed: Address already in use` | 旧 php-fpm 进程仍在运行 | `RunCommand/Bash: pkill php-fpm && sleep 2 && /etc/init.d/php-fpm-<ver> start`(高风险) |
|
||||||
|
| `ERROR: [/www/server/php/<ver>/etc/php-fpm.conf:N] unknown parameter` | 手动编辑导致指令损坏 | 使用 `Read` 读取对应行,修复或通过面板应用商店 → PHP → 设置 → 配置 → 重置(高风险) |
|
||||||
|
| `Unable to access php-fpm.sock: Permission denied` | Socket 文件所有者错误 | `RunCommand/Bash: ls -la /tmp/php-cgi-<ver>.sock` → 如果不是 `www:www`,执行 `RunCommand/Bash: chown www:www /tmp/php-cgi-<ver>.sock && chown -R www:www /www/server/php/<ver>/var/log/`(低风险) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 4 —— 工具风险等级
|
||||||
|
|
||||||
|
工具由其注册的 `risk_level` 控制,而不是由命令本身的行为控制。
|
||||||
|
|
||||||
|
| risk_level | 工具 | 典型用途 | 处理方式 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **low** | `Read`、`SiteGetConfig`、`SiteLogs`、`ServiceStatus`、`TodoRead`、`TodoWrite` | 读取配置/日志、检查服务状态、跟踪任务 | 直接执行 |
|
||||||
|
| **high** | `RunCommand/Bash`、`ServiceRestart`、`SearchReplace/Edit`、`Write` | 任何 shell 命令(包括只读的 `curl`/`ls`/`netstat`/`ps`/`mysql -e`,以及 `chown`/`chmod`)、重启服务、编辑 nginx/php 配置、写入文件、执行 SQL(读/写) | 每次调用都必须经过面板确认门禁 |
|
||||||
|
| **forbidden** | — | 删除网站、删除数据库、删除文件、`rm -rf`、`DROP TABLE/DATABASE` | 永不执行 |
|
||||||
|
|
||||||
|
- `RunCommand/Bash` 作为工具的 `risk_level="high"`,因此即使是**只读探测**(`curl`、`ls`、`netstat`)也会触发确认门禁。应优先使用低风险读取工具(使用 `Read` 读取日志/配置,使用 `ServiceStatus` 检查状态),在无需确认的情况下收集事实。
|
||||||
|
- 任何配置编辑(`SearchReplace/Edit`/`Write`)完成后,**必须**执行 `nginx -t` 验证,再进行 reload。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Step 5 —— 输出格式
|
||||||
|
|
||||||
|
向用户报告发现时,始终使用以下形式的**自然语言**:
|
||||||
|
|
||||||
|
```
|
||||||
|
根因:<用一句话说明根因>
|
||||||
|
|
||||||
|
已执行步骤:
|
||||||
|
- <步骤 1>
|
||||||
|
- <步骤 2>
|
||||||
|
...
|
||||||
|
|
||||||
|
建议:
|
||||||
|
- <预防措施或后续操作>
|
||||||
|
```
|
||||||
|
|
||||||
|
规则:
|
||||||
|
|
||||||
|
- **绝不**在面向用户的消息中粘贴原始 shell 命令、btpython 路径或配置差异。
|
||||||
|
- **绝不**要求用户手动输入命令 —— 如果需要修复,描述修复内容并等待用户确认。
|
||||||
|
- 如果诊断尚不完整(例如无法复现、日志不明确),必须明确说明。不要编造根因。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 快速参考 —— 常见错误码
|
||||||
|
|
||||||
|
这些错误由 `mysql_engine.MYSQL_ERROR_MAP` 自动映射;此处映射仅供 Agent 自身推理使用,**不要向用户原样输出错误码**。
|
||||||
|
|
||||||
|
| SQLSTATE / 错误码 | 友好含义 | 下一步 |
|
||||||
|
|---|---|---|
|
||||||
|
| `2002` / `2003` | 无法连接 MySQL socket / 端口 | 检查 `ServiceStatus("mysql")` |
|
||||||
|
| `1045` | 数据库用户密码错误 | 比较 `wp-config.php` 与面板 `databases` 表 |
|
||||||
|
| `1146` | 数据表不存在 | `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> <DB_NAME> -e "SHOW TABLES"` / `DESC` 确认 |
|
||||||
|
| `1040` | 连接数过多 | `RunCommand/Bash: mysql -h<DB_HOST> -u<DB_USER> -p<DB_PASSWORD> -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW FULL PROCESSLIST"` |
|
||||||
|
| `1452` | 外键约束失败 | 检查被引用的数据行,并向用户报告 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 快速参考 —— 文件 / 日志路径
|
||||||
|
|
||||||
|
| 内容 | 路径 |
|
||||||
|
|---|---|
|
||||||
|
| Nginx 虚拟主机配置 | `/www/server/panel/vhost/nginx/<domain>.conf` |
|
||||||
|
| Apache 虚拟主机配置 | `/www/server/panel/vhost/apache/<domain>.conf` |
|
||||||
|
| Rewrite 规则 | `/www/server/panel/vhost/rewrite/<domain>.conf` |
|
||||||
|
| Nginx 主配置 | `/www/server/nginx/conf/nginx.conf` |
|
||||||
|
| Nginx fastcgi 配置(空白页常见原因) | `/www/server/nginx/conf/fastcgi.conf` |
|
||||||
|
| 网站访问日志 | `/www/wwwlogs/<domain>.log` |
|
||||||
|
| 网站错误日志 | `/www/wwwlogs/<domain>.error.log` |
|
||||||
|
| PHP-FPM 错误日志 | `/www/server/php/<ver>/var/log/php-fpm.log` |
|
||||||
|
| PHP-FPM socket | `/tmp/php-cgi-<ver>.sock` |
|
||||||
|
| PHP-FPM 进程池配置 | `/www/server/php/<ver>/etc/php-fpm.conf` |
|
||||||
|
| WordPress 数据库配置 | `<site_root>/wp-config.php` |
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
AI 智能体开发约束 & 项目执行规范
|
||||||
|
本文件为项目根目录全局 Agent 行为规则,AI 编码、重构、调试、优化、答疑均需默认遵循以下配置,无需用户重复说明。
|
||||||
|
|
||||||
|
---
|
||||||
|
1. 运行环境规范
|
||||||
|
- 默认强制使用本地 .venv 虚拟环境,禁止使用任何沙箱环境、在线临时环境、容器模拟环境。
|
||||||
|
- 所有代码运行、依赖安装、调试、语法检查、模块测试,均基于项目根目录 .venv 环境执行。
|
||||||
|
- 如需安装依赖,仅操作本地虚拟环境,不污染全局 Python 环境。
|
||||||
|
- 所有需要【写入文件内容】的操作(导出落盘、覆盖目标文件、复制/移动文件、下载保存等)一律不使用沙箱:执行时触发沙箱外运行(requires_approval 申请用户批准),避免被沙箱拦截(如 D:\资料 等受保护目录只读可读、写入被拒)。
|
||||||
|
2. 影刀开发规范
|
||||||
|
- 影刀项目默认采用单文件自包含架构。
|
||||||
|
- 输出影刀脚本、逻辑代码、流程封装时,优先单文件独立实现,功能自包含、可直接导入运行,不拆分冗余子文件。
|
||||||
|
- 单文件需具备完整性:依赖声明、核心逻辑、异常处理、入口执行全部内聚在当前文件。
|
||||||
|
3. 项目通用架构规范
|
||||||
|
- 代码组织:不同业务、不同流程独立模块化运行,互不侵入、互不影响。
|
||||||
|
- 各方向零依赖:项目并存多个独立演进方向,彼此【绝不跨目录 import】,登录/数据导出等数据层各自内置(允许少量重复换取完全解耦),任一方向可单独拷贝、单独演进、独享依赖与启动:
|
||||||
|
- 桌面端 desktop/:中心机 desktop/controlplane/ + 执行机桌面壳 desktop/electron-shell/(当前宿主,Electron + Node,内置便携 python 环境 python-env/<版本>/ 跑插件)+ 老版执行机底座 desktop/webhost/(标记老版本、后续废弃、不再维护)。各自互不 import、独立演进、可单独拷贝(模块搜索根 = desktop/,运行均以 desktop/ 为 cwd)。
|
||||||
|
- 插件 plugins/:根级独立目录(按号段分桶 plugins/XQ0001-0100/),被执行机(electron-shell 壳)按账号权限自下载加载,不随底座发布。
|
||||||
|
- 影刀版 workflows/:单文件自包含,需求脚本按号段分桶(workflows/XQ0001-0100/)。
|
||||||
|
- app/ 蓝图版:已弃用,保留归档、不再维护。
|
||||||
|
- 代码形态分三类,按各方向性质采用不同组织方式(【单文件自包含】仅适用于影刀版,其它一律按正常项目开发):
|
||||||
|
- workflows/(影刀版):沿用单文件自包含架构(见第 2 节,仅影刀适用)。
|
||||||
|
- 桌面端各后端(desktop/controlplane/ 中心机、desktop/electron-shell/ 执行机壳、desktop/webhost/ 老版执行机底座[后续废弃]):按正常 Python 模块化项目开发,允许按包/模块/多文件拆分(如 main.py/app.py 分割逻辑与路由),不做单文件约束。
|
||||||
|
- 插件(执行机加载的执行单元,源码位于根级 plugins/XQ0001-0100/<中文目录>/,如 plugins/XQ0001-0100/XQ0011 考勤月报封存检查/,id 用固定规则 xq{单号},与目录名解耦):内部按正常项目组织,可拆 config/data/logic/report 等多文件;但强调【插件自包含】——插件内模块只能互相引用、依赖 Python 标准库/第三方依赖/底座注入的插件接口(webhost.backend.plugins.base),严禁 import 插件包之外的任何代码(根目录、desktop 底座业务、app 一律禁止),保证插件完整交付物=插件包本身,可单独拷贝发布、独立演进。插件目录结构、前端(ui/ 与 ui-src/)存放、打包产物位置(dist-plugin/<id>_v<版本>.zip)、发布流程等细则见 docs/插件/插件开发规范.md 与 docs/插件/发版规范.md。
|
||||||
|
- 环境变量按模块隔离,各自使用自己目录下的 .env,互不覆盖、互不依赖:
|
||||||
|
- 根目录 .env:仅供 workflows/(影刀) 脚本使用,承载各 XQ 业务路径/账号等配置;禁止向根 .env 写入桌面端/app 的变量。
|
||||||
|
- desktop/controlplane/ → desktop/controlplane/.env(中心机配置,含 CONTROLPLANE_PORT、CONTROLPLANE_TOKEN)
|
||||||
|
- desktop/webhost/ → desktop/webhost/.env(老版执行机底座配置,后续废弃);当前宿主 desktop/electron-shell/ 无独立 .env,配置在 electron/config.js,数据根 %LOCALAPPDATA%\37duAutomation
|
||||||
|
- app/ → app/.env(app 版业务配置,已弃用)
|
||||||
|
- workflows/ 影刀不再单独建 .env,所需配置统一放在根 .env。
|
||||||
|
- 各模块加载器只允许读取本模块目录下的 .env,禁止读取/改写其它模块或根 .env。
|
||||||
|
- 插件本地配置(当前宿主 electron-shell):明文 JSON,路径 %LOCALAPPDATA%\37duAutomation\plugin_configs\<插件id>.json,electron-shell/electron/runner.js 直接 JSON.parse 读取、无加密解密(登录类插件需自行清洗首尾空白防误存空格导致"密码不正确"累计触发平台锁定);旧 SQLite 场景配置(plugin_configs 表,enc:v1: AES-256-GCM 加密)是另一套,不参与插件执行参数注入。
|
||||||
|
- 错误处理:全局项目级重试机制,最大重试 3 次,三次失败后再记录错误日志。
|
||||||
|
- 日志规范:正常 INFO 级别屏蔽大体积 JSON 调试日志,保证日志整洁;仅 DEBUG 模式开启完整 JSON 调试信息输出。
|
||||||
|
4. AI 工作默认规则
|
||||||
|
- 所有代码生成、修改、重构必须贴合 Python 模块化编程思想。
|
||||||
|
- 不主动创建冗余文件、不随意变更项目结构、不混用沙箱环境。
|
||||||
|
- 输出代码优先保证:可运行、结构清晰、符合项目统一规范、按代码形态适配(单文件自包含仅影刀版需要;后端与插件按正常模块化项目开发)。
|
||||||
|
- 变量配置规范:禁止使用命令行传入变量的方式实现参数配置,所有参数、变量、配置项均在代码/配置文件内部定义、固化或读取本地配置,保证运行无外部参数依赖。
|
||||||
|
5. 发版与自动更新操作规范
|
||||||
|
- 自动更新:插件由执行机按账号权限自下载(plugin_sync.py);壳子由执行机自动下载安装包 + 用户点击升级重启(shell_updater.py)。版本源都在中心机控制面。
|
||||||
|
- 发版统一走 agent CLI(desktop/ 下执行:.venv\Scripts\python.exe -m controlplane.tools.agent_cli)。插件用 publish / grant / revoke;壳子用 file push --category shell;中心机控制面为源码部署(宝塔 gunicorn 8800),改代码后按 SOP 部署。
|
||||||
|
- 鉴权:密码登录 `--admin puddy --password 123456`,**一律显式加 `--base http://172.30.30.243:8800`(内网生产控制面,执行机实际连接源)**,或中心机本机密钥自签。⚠️ 控制面有两套且数据不同步:公网 `http://117.72.191.188:8800` 是迁移前旧库(仍在线但执行机不连),发版/授权/登记发到公网库 = 执行机永远检测不到新版本;端口分工(内网 172.30.30.243):8800 控制面 / 8802 文件服务器下载 / 8899 文件服务器管理台。
|
||||||
|
- 完整流程、命令示例见 docs/插件/发版规范.md;中心机前后端部署步骤见 docs/部署/控制面前后端部署SOP.md。
|
||||||
@@ -1,235 +1,235 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 3, 19 November 2007
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||||
|
|
||||||
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and modification follow.
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
1. Source Code.
|
1. Source Code.
|
||||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||||
subprograms and other parts of the work.
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that same work.
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
|
|
||||||
2. Basic Permissions.
|
2. Basic Permissions.
|
||||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
4. Conveying Verbatim Copies.
|
||||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
5. Conveying Modified Source Versions.
|
||||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
6. Conveying Non-Source Forms.
|
||||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||||
|
|
||||||
7. Additional Terms.
|
7. Additional Terms.
|
||||||
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||||
|
|
||||||
8. Termination.
|
8. Termination.
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
11. Patents.
|
11. Patents.
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||||
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||||
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||||
|
|
||||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
16. Limitation of Liability.
|
16. Limitation of Liability.
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
Process-Automation
|
Process-Automation
|
||||||
Copyright (C) 2026 spudding
|
Copyright (C) 2026 spudding
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
||||||
|
|||||||
@@ -1,2 +1,178 @@
|
|||||||
# Process-Automation
|
# Process-Automation
|
||||||
|
|
||||||
|
HR 业务流程自动化(37duAutomation):覆盖 HRBP OA 审批、EHR 数据核对/导出、社保、考勤、排班、雇主险等场景,提供桌面端插件体系(中心机 + 执行机)、影刀 RPA 单文件版本及配套的「需求单 → 评分」文档体系。
|
||||||
|
|
||||||
|
## 项目简介
|
||||||
|
|
||||||
|
基于 Python / Node 的 HR 流程自动化工具,实现形态上分两条落地路线:
|
||||||
|
|
||||||
|
* **桌面端插件体系**:中心机控制面(插件发布 / 账号权限 / 壳子分发)+ 执行机桌面壳(Electron + Node,内置便携 Python,插件以 Python 子进程运行),插件按账号权限自动同步加载,另配独立内网文件服务器承载大文件分发;
|
||||||
|
|
||||||
|
* **影刀 RPA 单文件版**:`workflows/` 下按业务隔离的单文件自包含脚本,可直接导入影刀平台运行。
|
||||||
|
|
||||||
|
业务上覆盖两大类场景:
|
||||||
|
|
||||||
|
* **OA 审批自动化**:通过 DrissionPage 浏览器自动化 + OA 接口,自动处理请假、加班、离职电子签等审批流程,内置规则校验、OCR(rapidocr 3.x)附件识别、钉钉/工作沟通推送、审批报告生成;
|
||||||
|
|
||||||
|
* **EHR 数据处理自动化**:对接 HR 平台接口与本地 Excel,完成考勤异常核对、排班异常识别、工资卡核对、社保增减名单/告知书、雇主险名额等。
|
||||||
|
|
||||||
|
## 项目结构
|
||||||
|
|
||||||
|
```
|
||||||
|
Process-Automation/
|
||||||
|
├── desktop/ # 桌面端:中心机 + 执行机 + 文件服务,各方向独立演进(模块搜索根 = desktop/,运行 cwd 均为 desktop/)
|
||||||
|
│ ├── controlplane/ # 中心机:插件发布 / 账号权限 / 壳子分发控制面
|
||||||
|
│ │ ├── app.py # FastAPI 服务入口(desktop/ 下 python -m controlplane.app)
|
||||||
|
│ │ ├── core/ / apis/ / frontend/ # 配置存储鉴权 / REST 接口 / 管理前端
|
||||||
|
│ │ ├── packages/ / shell/ # 插件包与壳子安装包仓库
|
||||||
|
│ │ └── tools/ # agent_cli 发布 CLI、运维脚本
|
||||||
|
│ ├── electron-shell/ # 执行机桌面壳(当前宿主,Electron + Node)
|
||||||
|
│ │ ├── electron/ # 主进程:本地服务、插件同步/调度/执行、壳子自动升级、Chrome 管理
|
||||||
|
│ │ ├── frontend/ / renderer/ # 工作台前端
|
||||||
|
│ │ ├── python-env/ # 内置便携 Python(插件以 Python 子进程执行)
|
||||||
|
│ │ └── dist-app/ # 打包产物(electron-builder NSIS)
|
||||||
|
│ ├── fileserver/ # 内网文件服务器(独立 FastAPI,端口 8802,存放壳子更新包/Chrome 安装包等大文件)
|
||||||
|
│ └── webhost/ # 老版执行机底座(Python + PyWebView,已废弃,不再维护)
|
||||||
|
├── plugins/ # 插件:号段桶目录为源码,扁平 id 目录为开发态运行目录
|
||||||
|
│ ├── XQ0001-0100/ # 插件源码(按号段分桶,含 ui-src/ 前端源码与 _pack.py 打包脚本)
|
||||||
|
│ │ ├── XQ0002 雇主险增减操作/
|
||||||
|
│ │ ├── XQ0010 EHR系统月考勤异常处理/
|
||||||
|
│ │ ├── XQ0011 考勤月报封存检查/
|
||||||
|
│ │ └── ... # 插件内部按 config/data/logic/report/ui 多文件组织,自包含可独立发布
|
||||||
|
│ └── xq0002/ xq0010/ xq0011/ ... # 开发态运行目录(打包产物解压得到,执行机注册表只扫一层)
|
||||||
|
├── dist-plugin/ # 插件打包产物 <id>_v<版本>.zip(经 agent_cli publish 发布到中心机)
|
||||||
|
├── workflows/ # 影刀 RPA 单文件版(需求脚本按号段分桶,对应 docs/需求单/XQ00xx)
|
||||||
|
│ ├── share/ # 共享指令:钉钉群机器人/推送、OA/HR 登录、花名册导出、工作沟通
|
||||||
|
│ ├── XQ0001-0100/ # 需求脚本(每 100 号一桶)
|
||||||
|
│ │ ├── XQ0001 排班异常识别/ # 调动/预入职台账导出 + 排班异常判定(钉钉单聊推送)
|
||||||
|
│ │ ├── XQ0002 雇主险增减操作/ # 名额调度、变更清单导出、增减员导入
|
||||||
|
│ │ ├── XQ0003 EHR系统请假流程审核/
|
||||||
|
│ │ ├── XQ0004 EHR系统加班流程审核/
|
||||||
|
│ │ ├── XQ0005 银行卡检查/
|
||||||
|
│ │ ├── XQ0006 EHR系统周考勤异常处理/
|
||||||
|
│ │ ├── XQ0007 OA系统社保增减名单梳理/
|
||||||
|
│ │ ├── XQ0008 重庆社保增减员导入名单制作/ # 增员/减员导入名单生成
|
||||||
|
│ │ ├── XQ0009 门店上月请休假异常人员名单梳理/
|
||||||
|
│ │ ├── XQ0010 EHR系统月考勤异常处理/
|
||||||
|
│ │ ├── XQ0011 考勤月报封存检查/ # 月报封存、加班补偿、休班核对等多维检查
|
||||||
|
│ │ ├── XQ0012 EHR预支及支付报酬自动发起ERP付款申请/ # *仅说明文档,未实现*
|
||||||
|
│ │ ├── XQ0013 社保费用申报导出并汇总/ # *仅说明文档,未实现*
|
||||||
|
│ │ ├── XQ0014 社保系统增减员办理/ # 社保系统登录、增员/减员导入、回盘审核结果检查回写
|
||||||
|
│ │ ├── XQ0015 参保成功及异常告知书制作与下发/ # 覆盖 XQ0016 社保转移告知书
|
||||||
|
│ │ ├── XQ0016 社保转移告知书制作与下发/ # *已由 XQ0015 覆盖*
|
||||||
|
│ │ ├── XQ0017 入职人事手续办理/ # *仅说明文档,未实现*
|
||||||
|
│ │ ├── XQ0018 调动人事手续跟进/ # *仅说明文档,未实现*
|
||||||
|
│ │ ├── XQ0019 离职人事手续跟进与检查/ # *仅说明文档,未实现*
|
||||||
|
│ │ ├── XQ0020 EHR系统离职电子签流程审核/
|
||||||
|
│ │ ├── XQ0031 物料收发汇总表导出/
|
||||||
|
│ │ └── XQ0032 ERP采购订单列表导出/
|
||||||
|
│ └── README.md # 影刀版开发指南
|
||||||
|
├── app/ # *已弃用归档,不再维护*(早期模块化蓝图,仅留作参考)
|
||||||
|
├── tests/ # 测试与试验脚本(xq0002_雇主险/ 冒烟与原型;_app_蓝图版归档/ 弃用蓝图时代的测试;汇总社保申报.py 独立工具)
|
||||||
|
├── docs/
|
||||||
|
│ ├── README.md # 文档总索引
|
||||||
|
│ ├── 需求单/ # 各 XQ 四件套(按号段分桶 XQ0001-0100/)+ 需求单索引 + 评分规则 + 实现形态登记表
|
||||||
|
│ ├── 插件/ # 插件开发规范 / 插件UI开发规范 / 发版规范
|
||||||
|
│ ├── 架构/ # 架构蓝图 / 插件管理系统设计 / 迭代规划 / 重构方案
|
||||||
|
│ ├── 部署/ # 控制面前后端部署 SOP
|
||||||
|
│ └── 桌面端/ # Node 版客户端开发交接 / 桌面端发版 SOP / 平台账号本地加密存储等
|
||||||
|
├── AGENTS.md # AI 智能体开发约束 & 项目执行规范
|
||||||
|
└── requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## 核心功能
|
||||||
|
|
||||||
|
| 模块 | 说明 |
|
||||||
|
| ------- | ------------------------------------------- |
|
||||||
|
| 自动登录/会话 | OA(SSO)、HR 平台、社保系统登录,cookie 缓存,过期自动重登 |
|
||||||
|
| 审批流程引擎 | 待办获取、表单解析、规则校验、结果提交、报告生成 |
|
||||||
|
| 请假/加班审批 | 多类型(事假/病假/产假/年度福利假/加班类型等)分支校验,含附件 OCR |
|
||||||
|
| 离职电子签审核 | 离职电子签流程自动审批 |
|
||||||
|
| 考勤异常处理 | 周/月考勤异常核对,三查复核,钉钉推送 |
|
||||||
|
| 考勤月报封存检查 | 月报封存状态、加班补偿、休班核对等多维检查与封存数据导出 |
|
||||||
|
| 排班异常识别 | 调动/预入职台账导出 + 部门排班集合比对判定,序列/离职过滤,按店长分组钉钉单聊推送 |
|
||||||
|
| 工资卡核对 | 身份证/姓名/银行卡号格式与一致性校验 |
|
||||||
|
| 社保类 | 增减名单梳理、导入名单生成、社保系统增减员办理与回盘核对、参保异常处理 |
|
||||||
|
| 社保告知书 | 按模板生成 Word/PDF 告知书并合并下发 |
|
||||||
|
| 雇主险 | 名额调度、增减操作、变更名单导出 |
|
||||||
|
| 数据导出类插件 | 物料收发汇总、ERP 采购订单列表、通联交易数据导出(按商户分组拆分) |
|
||||||
|
| 重试/日志 | 项目级最大 3 次重试;INFO 屏蔽大体积 JSON 调试日志,DEBUG 全量输出 |
|
||||||
|
|
||||||
|
## 技术依赖
|
||||||
|
|
||||||
|
* `DrissionPage`:浏览器自动化
|
||||||
|
|
||||||
|
* `pandas` / `openpyxl`:Excel 读写
|
||||||
|
|
||||||
|
* `rapidocr`(3.x)/ `opencv-python`(numpy 2.x):OCR 附件识别
|
||||||
|
|
||||||
|
* `python-docx` / WPS COM:Word/PDF 生成
|
||||||
|
|
||||||
|
* `python-dotenv`、`chinese_calendar` 等
|
||||||
|
|
||||||
|
* `Electron` + `Node.js`:执行机桌面壳(当前宿主),插件以 Python 子进程运行
|
||||||
|
|
||||||
|
> 运行一律使用项目本地虚拟环境 `d:\work\code\37duAutomation\.venv`(`.venv\Scripts\python.exe`)。
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入虚拟环境
|
||||||
|
.venv\Scripts\Activate.ps1
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
# 中心机控制面 / 内网文件服务器(cwd = desktop/,用项目根 .venv)
|
||||||
|
python -m controlplane.app
|
||||||
|
python -m fileserver.main
|
||||||
|
|
||||||
|
# 执行机桌面壳开发态(desktop/electron-shell/ 下)
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# 影刀版脚本(单文件自包含,直接运行,按号段分桶存放):
|
||||||
|
# 排班异常识别(第二步导出 + 第三步识别)
|
||||||
|
python "workflows/XQ0001-0100/XQ0001 排班异常识别/transfer_roster_export.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0001 排班异常识别/pre_entry_roster_export.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0001 排班异常识别/shift_abnormal_check.py"
|
||||||
|
|
||||||
|
# 雇主险增减操作(名额调度、增减员导入)
|
||||||
|
python "workflows/XQ0001-0100/XQ0002 雇主险增减操作/roster_filter.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0002 雇主险增减操作/employer_insurance_schedule.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0002 雇主险增减操作/add_sub_import.py"
|
||||||
|
|
||||||
|
# OA 审批流程审核(请假 / 加班 / 离职电子签)
|
||||||
|
python "workflows/XQ0001-0100/XQ0003 EHR系统请假流程审核/leave_approval.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0004 EHR系统加班流程审核/overtime_approval.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0020 EHR系统离职电子签流程审核/resign_e_sign_approval.py"
|
||||||
|
|
||||||
|
# 考勤异常处理(周 / 月)
|
||||||
|
python "workflows/XQ0001-0100/XQ0006 EHR系统周考勤异常处理/attendance_abnormal.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0010 EHR系统月考勤异常处理/attendance_abnormal_monthly.py"
|
||||||
|
|
||||||
|
# 社保增减名单梳理 / 增减员导入名单 / 社保系统增减员办理 / 告知书制作与下发
|
||||||
|
python "workflows/XQ0001-0100/XQ0007 OA系统社保增减名单梳理/social_change.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0008 重庆社保增减员导入名单制作/generate_add.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0014 社保系统增减员办理/import_add.py"
|
||||||
|
python "workflows/XQ0001-0100/XQ0015 参保成功及异常告知书制作与下发/notice_mail_merge.py"
|
||||||
|
|
||||||
|
# 先运行登录指令写入共享登录态,再执行业务脚本
|
||||||
|
python workflows/share/oa_login.py
|
||||||
|
python workflows/share/hr_login.py
|
||||||
|
python workflows/share/roster_export.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## 文档体系
|
||||||
|
|
||||||
|
* 每个需求单在 `docs/需求单/XQ0001-0100/XQ00xx 名称/` 下维护 需求文档 / 流程文档 / 开发文档 / 评分文档 四件套(需求单目录按号段分桶,每 100 号一桶);
|
||||||
|
|
||||||
|
* RPA 场景分级依据 `docs/需求单/评分规则.md`(系统对接数 / 业务分支数 / 智能识别场景数 / 异常类型数,四档定级);
|
||||||
|
|
||||||
|
* 已落地场景的评分文档为初稿,需经业务方签字 + 网络信息部审批 + 人资备案。
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. 确保已安装 Chrome/Edge;
|
||||||
|
2. 首次运行需手动登录一次并缓存会话/cookie(或先运行 `workflows/share/` 下的 `oa_login.py` / `hr_login.py` 写入共享登录态);
|
||||||
|
3. OA/HR 需在登录态有效期内运行,脚本会自动重登或提示重新登录;
|
||||||
|
4. 影刀版本为单文件自包含,直接导入影刀平台运行;业务脚本不 import 共享指令模块,仅读 cookies 文件、写全局变量,消息生成与发送解耦(详见 `workflows/README.md`)。
|
||||||
|
|
||||||
|
> **桌面端与影刀版**:桌面端 = 中心机 `desktop/controlplane/` + 执行机壳 `desktop/electron-shell/`(当前宿主)+ 内网文件服务 `desktop/fileserver/`,各方向互不 import、独立演进、可单独拷贝;`desktop/webhost/` 为老版执行机底座,已废弃不再维护。插件源码统一放根级 `plugins/`(按号段分桶),打包产物在 `dist-plugin/`,经 agent CLI 发布到中心机后由执行机按账号权限自下载。开发流程为「桌面端测试通过 → 影刀版(`workflows/`,单文件自包含)落地部署」;`app/` 为早期模块化蓝图,已**弃用归档、不再维护**,仅留作参考。
|
||||||
|
|||||||
@@ -0,0 +1,367 @@
|
|||||||
|
{
|
||||||
|
"code": "10000",
|
||||||
|
"msg": null,
|
||||||
|
"subCode": "200",
|
||||||
|
"subMsg": "",
|
||||||
|
"data": {
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": "20445751",
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": "Z1002",
|
||||||
|
"aac002": "510222197804160909",
|
||||||
|
"aac003": "孙智慧",
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": "在职人员主动解除劳动合同",
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": "3 劳动者自愿辞职",
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": [
|
||||||
|
{
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": null,
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": null,
|
||||||
|
"aac002": null,
|
||||||
|
"aac003": null,
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": null,
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": null,
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": null,
|
||||||
|
"xh": "1",
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": "养老保险",
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": null,
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": null,
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": null,
|
||||||
|
"aac002": null,
|
||||||
|
"aac003": null,
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": null,
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": null,
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": null,
|
||||||
|
"xh": "2",
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": "失业保险",
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": null,
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": null,
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": null,
|
||||||
|
"aac002": null,
|
||||||
|
"aac003": null,
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": null,
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": null,
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": null,
|
||||||
|
"xh": "3",
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": "医疗保险",
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": null,
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": null,
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": null,
|
||||||
|
"aac002": null,
|
||||||
|
"aac003": null,
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": null,
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": null,
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": null,
|
||||||
|
"xh": "4",
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": "工伤保险",
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": null,
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bws071": null,
|
||||||
|
"bws072": null,
|
||||||
|
"aab003": null,
|
||||||
|
"aab001": null,
|
||||||
|
"aab004": null,
|
||||||
|
"aaa121": null,
|
||||||
|
"aac002": null,
|
||||||
|
"aac003": null,
|
||||||
|
"aac005": null,
|
||||||
|
"aac007": null,
|
||||||
|
"aab120": null,
|
||||||
|
"aab121": null,
|
||||||
|
"aab122": null,
|
||||||
|
"aac020": null,
|
||||||
|
"aca111": null,
|
||||||
|
"aac060": null,
|
||||||
|
"aac009": null,
|
||||||
|
"aae005": null,
|
||||||
|
"aac011": null,
|
||||||
|
"aai030": null,
|
||||||
|
"aaj030": null,
|
||||||
|
"aak030": null,
|
||||||
|
"aal030": null,
|
||||||
|
"aam034": null,
|
||||||
|
"aai031": null,
|
||||||
|
"aae013": null,
|
||||||
|
"aab020": null,
|
||||||
|
"aac014": null,
|
||||||
|
"aac001": "2061656779",
|
||||||
|
"aad030": "2026/6/29",
|
||||||
|
"aad013": null,
|
||||||
|
"abi030": null,
|
||||||
|
"abj030": null,
|
||||||
|
"abk030": null,
|
||||||
|
"abl030": null,
|
||||||
|
"abm030": null,
|
||||||
|
"abi031": null,
|
||||||
|
"abj040": null,
|
||||||
|
"aae201": null,
|
||||||
|
"aab084": null,
|
||||||
|
"aab085": null,
|
||||||
|
"aab086": null,
|
||||||
|
"aae202": null,
|
||||||
|
"aae500": null,
|
||||||
|
"aae501": null,
|
||||||
|
"aae036": null,
|
||||||
|
"aae100": null,
|
||||||
|
"itmes": null,
|
||||||
|
"xh": "5",
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": "生育保险",
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": null,
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"xh": null,
|
||||||
|
"sxjg": null,
|
||||||
|
"aae140": null,
|
||||||
|
"aae035": null,
|
||||||
|
"asl001": "10047223466559",
|
||||||
|
"aac004": null,
|
||||||
|
"aac091": null,
|
||||||
|
"aae038": null,
|
||||||
|
"aae040": null,
|
||||||
|
"aae041": null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +1,147 @@
|
|||||||
一、延时加班
|
# 门店服务岗转正(离职+入职)自动化流程说明
|
||||||
(一)驳回门槛(任一不满足直接驳回)
|
|
||||||
1. 日期匹配规则:加班开始时间所属日期 = 加班申请日期。当日开始、次日结束的跨天加班,按开始时间判定日期,视为符合要求。
|
AI表格:【门店服务岗转正跟进-周更新】(下称"AI表格")
|
||||||
2. 时长达标规则:以「申请结束时间 - 申请开始时间」计算申请加班总时长,统一执行以下计时标准:
|
字段对照:人资是否处理、离职推送时间、到期能否考核通过、人员处理意见、合同签署单位、新合同推送日期、签署跟进
|
||||||
◦ 不足1小时的,直接驳回;
|
|
||||||
◦ 满1小时及以上的,超出1小时的部分按0.5小时为单位向下取整累加,不足0.5小时的部分不计入有效时长。
|
---
|
||||||
◦ 跨天延时加班的总时长统一套用上述取整规则,不按日期分段计算。
|
|
||||||
3. 区间合规校验:申请开始时间 ≥ 当日规定下班时间,且申请结束时间 ≤ 当日实际下班打卡时间;超出该区间的申请直接驳回。
|
## 分支1:到期能否考核通过 = 能
|
||||||
(二)弹性到岗兑换规则(仅影响结算时长,不影响审批通过与否)
|
|
||||||
员工可使用当日加班时长等额兑换次日晚到时长,兑换额度、校验规则如下:
|
「人资是否处理」直接回填「否」(无需离职+入职处理)。
|
||||||
1. 弹性额度D计算规则
|
|
||||||
◦ 计算基准:以当日实际下班打卡时间为准,与申请结束时间无关。
|
## 分支2:人员处理意见 = 离职后再入职
|
||||||
◦ 触发条件:实际下班打卡时间 < 23:00 时,弹性额度 D=0,不可兑换次日晚到。
|
|
||||||
◦ 额度计算公式:实际下班打卡时间 ≥ 23:00 时,基础兑换额度1小时;超出23:00的部分,按0.5小时为单位向下取整,每满0.5小时累加0.5小时额度。
|
- 「到期能否考核通过」= 不能 → 进入子分支处理;
|
||||||
公式:D = 1 + FLOOR( (实际下班打卡时间 - 23:00) / 0.5小时 ) × 0.5小时
|
- 「到期能否考核通过」未填写 → 先回填「不能」,再进入子分支处理。
|
||||||
2. 次日场景分支校验
|
|
||||||
对申请日的次日进行判断,符合以下任一情形的,不触发弹性兑换校验,仅校验当日申请与打卡、请假数据匹配(次日为休息且存在加班申请的,同步核实上班打卡记录):
|
### 超龄判定(进入子分支后、跑流程前先判定)
|
||||||
① 次日排班为“休息”或无排班;
|
|
||||||
② 次日排班数据获取失败;
|
按工号调用员工花名册接口,取三个字段:
|
||||||
③ 次日有请假时段覆盖09:00(任意假期类型)。
|
|
||||||
不属于以上情形的正常工作日,按次日实际打卡时间P进行校验:
|
| 字段 | 用途 |
|
||||||
① 无次日打卡记录:不触发弹性兑换校验,仅校验当日数据;
|
|---|---|
|
||||||
② P ≤ 09:00:无晚到,无需兑换,直接通过;
|
| 性别 | 退休年龄:男 60 / 女 50,退休日 = 出生日期 + 对应年数(生日当天即满龄) |
|
||||||
③ 09:00 < P ≤ 09:00+D:实际晚到时长 = P - 09:00,不足1小时按1小时计算;
|
| 出生日期 | 算退休日 |
|
||||||
校验规则:申请加班时长 + 实际晚到时长 ≤ 申请加班时间至实际打卡的总自然时长,不符合则驳回;
|
| 序列 | 新合同期限:XX服务序列、XX技师序列 = 1 年,其他序列 = 3 年 |
|
||||||
④ P > 09:00+D:可兑换的晚到时长最高按D计算,超出D的晚到部分按考勤迟到规则处理,不影响本次加班审批;
|
|
||||||
校验规则:申请加班时长 + D ≤ 申请加班时间至实际打卡的总自然时长,不符合则驳回。
|
两级判定:
|
||||||
---
|
|
||||||
二、休息日加班
|
1. **已达龄**:操作当天 ≥ 退休日;
|
||||||
(一)适用范围
|
2. **新签合同超龄**:未达龄,但新合同估算终止日 ≥ 退休日
|
||||||
1. 周末休息日加班;
|
(估算起点 = 实际离职日期(=试用期到期日期)+1 天,终止日 = 起始 + 期限 - 1 天)。
|
||||||
2. 除春节外的其余法定节假日加班,统一按本规则执行。
|
|
||||||
(二)审批条件(全部满足则通过,任一不满足即驳回)
|
仅「新签合同超龄」(需分段)算异常走子分支1;已达龄与都未超龄走子分支2
|
||||||
1. 申请有效:申请加班时长 > 0;
|
(已达龄不再报异常,照常办理,后续新签自动签超龄用工协议)。
|
||||||
2. 打卡完整:申请对应时段内有完整的上班打卡、下班打卡记录;跨次日0点的连续加班,下班打卡可在次日,只要时段连续、覆盖申请时段,即视为打卡完整;
|
|
||||||
3. 排班匹配:申请当日排班显示为休息;
|
### 子分支1:超龄需分段记录(照常办离职与延期转正,仅不自动新签合同)
|
||||||
4. 时长达标:上下班打卡的自然时间间隔(含午休、用餐等自然时长)满足申报档位要求:
|
|
||||||
◦ 申报0.5天:打卡间隔 ≥ 4小时
|
1. 发起「调动解除(电子签)」流程;
|
||||||
◦ 申报1天:打卡间隔 ≥ 9小时
|
2. 完善信息:**「是否需要新签合同」= 否**(一律填否,新签全由独立分支延后办理)、
|
||||||
◦ 申报1.5天:打卡间隔 ≥ 13小时
|
实际离职日期 = 试用期到期日期;
|
||||||
◦ 申报2天:打卡间隔 ≥ 18小时
|
3. 先检测该员工离职电子签流程是否已发起(断点续跑保护,见下):
|
||||||
以此类推,每增加0.5天,对应时长要求增加4小时。
|
未发起 → 发起电子签流程(员工真实 CA 签署);
|
||||||
---
|
已发起 → 跳过发起,记下实际发起日期;
|
||||||
三、法定假日加班(仅春节法定节假日适用)
|
发起失败 → 记录异常,**变更试用期仍继续**(实测变更试用期不依赖电子签完成);
|
||||||
1. 基础审批规则与休息日加班完全一致;
|
4. 变更试用期:新试用期(月) = 1、新试用结束日期 = 原试用期结束日期 + 1 个月;
|
||||||
2. 额外校验:申请日期必须为春节法定节假日;春节假期内的调休休息日,不适用本规则,按休息日加班规则执行。
|
5. 进入【变更/转正待确认】页面,找到该员工记录后进行确认;
|
||||||
---
|
6. 上述环节完成后,AI表格回填「人资是否处理 = 是、离职推送时间 = 电子签实际发起当天」;
|
||||||
|
7. **新签合同不进入自动化流程**,只记录异常转人工:
|
||||||
|
人工分段新签(先签至退休日前,退休后另签超龄用工协议)。
|
||||||
|
(已达龄不算异常,走子分支2,后续由新签合同分支自动签超龄用工协议。)
|
||||||
|
|
||||||
|
### 子分支2:未超龄 + 已达龄记录
|
||||||
|
|
||||||
|
第 1~6 步与子分支1完全相同,完善信息同样「是否需要新签合同 = 否」;
|
||||||
|
已达龄与新签无异常的后续都由新签合同分支自动签(已达龄合同类型为超龄用工协议)。
|
||||||
|
差异:电子签不是马上完成的(员工 CA 签署需要时间),所以**新签合同是分阶段的独立分支**,不在本次运行立即签,等后续运行检测(见下)。
|
||||||
|
|
||||||
|
**断点续跑说明**:回填「人资是否处理=是」之前的任何环节失败,记录下次运行会被重新捞出。
|
||||||
|
重处理时先检测该员工离职电子签流程是否已发起:已发起 → 不再重复发起,
|
||||||
|
跳过发起环节,继续补齐变更试用期 / 确认 / 回填
|
||||||
|
(离职推送时间取电子签实际发起日期,而非本次操作日期)。
|
||||||
|
|
||||||
|
## 新签合同分支(独立阶段,每次运行执行)
|
||||||
|
|
||||||
|
选择条件(AI表格):**人资是否处理 = 是 且 离职推送时间不为空 且 新合同推送日期为空**,
|
||||||
|
且工号不在异常记录表(超龄需分段)名单中。
|
||||||
|
|
||||||
|
1. 查该员工离职电子签流程状态:已全部办结?未办结 → 跳过,等下一次运行再检测;
|
||||||
|
2. 查合同台账【生效中合同】:无生效中合同?仍有 → 跳过,等下一次运行再检测;
|
||||||
|
3. 在【劳动关系→合同台账→未签合同】按工号查询该员工:
|
||||||
|
已办结但查无此人 = 旧合同解除尚未生效/数据未同步 → 跳过,等下一次运行(不按"无需处理"漏掉);
|
||||||
|
4. 存在则点击「新签」:
|
||||||
|
- 合同类型:未达龄 = 劳动合同,已达龄 = 超龄用工协议;期限按序列(服务/技师序列 1 年,其他 3 年);
|
||||||
|
- 起始日期 = 上一份合同终止/解除日期 + 1 天,终止日期 = 起始 + 期限 - 1 天;
|
||||||
|
(签署前复核:未达龄且终止日 ≥ 退休日 → 记录异常「超龄需分段」,不签,转人工)
|
||||||
|
- 合同签署单位 = AI表格「合同签署单位」;
|
||||||
|
- 电子签期望推送时间 = 操作当天;
|
||||||
|
5. 成功后 AI表格写入「新合同推送日期 = 操作当天」;
|
||||||
|
6. 推送后合同是否已签署生效,由下方「签署生效复核分支」独立检测回填。
|
||||||
|
|
||||||
|
## 签署生效复核分支(独立阶段,每次运行执行)
|
||||||
|
|
||||||
|
新签合同推送后,需复核合同是否已签署生效(同时覆盖自动新签与超龄人工新签两种情形)。
|
||||||
|
|
||||||
|
选择条件(AI表格):**人资是否处理 = 是 且 签署跟进 ≠ 是**。
|
||||||
|
|
||||||
|
1. 到合同台账【生效中合同】按工号查询;
|
||||||
|
2. 用「合同起始日期 > 试用期到期日期」判断是否为新合同:
|
||||||
|
旧合同起始日必然早于试用期到期日(先签合同后进试用期),
|
||||||
|
新合同起始日必然晚于试用期到期日(离职后才签);
|
||||||
|
3. 查到起始日期晚于试用期到期日期的生效中合同 → 新合同已签署生效,
|
||||||
|
AI表格回填「签署跟进 = 是」;
|
||||||
|
4. 只查到旧合同(起始日期 ≤ 试用期到期日期,离职解除尚未生效)或查无 →
|
||||||
|
尚未生效,跳过,等下一次运行再检测。
|
||||||
|
|
||||||
|
## 拆分方案
|
||||||
|
|
||||||
|
三个分支各自独立排程,互不依赖、单文件自包含
|
||||||
|
(登录 / AI表格读写等公共逻辑各自内置,允许少量重复换取完全解耦):
|
||||||
|
|
||||||
|
| 脚本 | 职责 | 建议排程 |
|
||||||
|
|---|---|---|
|
||||||
|
| 主流程 | 分支1回填否;分支2超龄判定 → 离职电子签(断点续跑)→ 变更试用期 → 确认 → 回填「人资是否处理」 | 每日 1 次(如 09:00) |
|
||||||
|
| 新签合同 | 新签分支:电子签办结 + 无生效中合同 + 不在异常表(超龄需分段)→ 新签 → 回填「新合同推送日期」 | 主流程后(如 09:30) |
|
||||||
|
| 生效复核 | 生效复核分支:生效中合同起始日 > 试用期到期日 → 回填「签署跟进 = 是」 | 新签脚本后(如 10:00) |
|
||||||
|
|
||||||
|
## 异常与消息
|
||||||
|
|
||||||
|
- 异常记录表:`D:\资料\人资\试用期变更\异常记录.xlsx`
|
||||||
|
(员工工号/姓名/异常类型/异常详情/记录时间;类型:超龄需分段、提交报错;同工号重复出现保留最新一条);
|
||||||
|
- 钉钉群消息四类:成功 / 跳过(已被他人处理)/ 超龄需分段异常转人工 / 失败;
|
||||||
|
- 全局失败重试 3 次,仍失败才记录。
|
||||||
|
|
||||||
|
## 与当前脚本实现的差异(待改造项)
|
||||||
|
|
||||||
|
1. 回填时机:离职电子签(含发起前断点续跑检测)+ 变更试用期 + 确认完成后即回填
|
||||||
|
「人资是否处理=是 + 离职推送时间」,新签合同不再阻塞回填
|
||||||
|
(当前实现 = 包含新签在内的全部环节完成后才回填);
|
||||||
|
2. 新签合同:改为独立分支延后签(当前实现 = 发起电子签后同次运行立即签);
|
||||||
|
3. 超龄处理:超龄不再终止全流程,继续走解除/电子签/变更试用期/确认(完善信息与其他记录一致);
|
||||||
|
已达龄不报异常,由新签分支自动签超龄用工协议;仅「新签合同超龄」(分段)记录异常转人工
|
||||||
|
(当前实现 = 已达龄直接终止);
|
||||||
|
4. 完善信息表单覆写「是否需要新签合同 = 否」(当前只覆写实际离职日期、其余透传;字段名已确认);
|
||||||
|
5. 分支2前置:到期能否考核通过未填写 → 先回填「不能」(当前未实现);
|
||||||
|
6. 签署生效复核分支:查生效中合同 + 起始日期判新旧 + 回填「签署跟进=是」(当前未实现);
|
||||||
|
7. 脚本拆分:按分支拆为主流程 / 新签合同 / 生效复核 3 个独立影刀脚本(当前 = 单文件全流程)。
|
||||||
|
|
||||||
|
## 已确认事项(2026-10-09)
|
||||||
|
|
||||||
|
- 回填时机:「人资是否处理=是」在离职电子签 + 变更试用期 + 确认完成后回填;
|
||||||
|
回填前检测电子签流程是否已发起(断点续跑,应对仅试用期变更失败的情况);
|
||||||
|
- 新签分支排除超龄需分段记录:按异常记录表过滤(不改 AI表格结构);
|
||||||
|
- AI表格已有「签署跟进」列,无需加列;
|
||||||
|
- 超龄人工新签的记录,生效后同样自动回填「签署跟进=是」;
|
||||||
|
- 脚本形态:拆为 3 个独立影刀脚本(主流程 / 新签合同 / 生效复核);
|
||||||
|
- 完善信息表单字段名为「是否需要新签合同」,超龄/未超龄一律填"否"
|
||||||
|
(新签全部由新签合同分支延后办理,解除流程不自动带出新签)。
|
||||||
|
|
||||||
|
### 口径更新(2026-10-12)
|
||||||
|
|
||||||
|
- 已达龄不再报异常:照常办离职与延期转正,新签合同分支按超龄用工协议自动新签,不转人工;
|
||||||
|
- 仅「新签合同超龄」(未达龄但新合同终止日越过退休日)保留异常「超龄需分段」转人工,
|
||||||
|
由人工分段新签。
|
||||||
|
|
||||||
|
## 待需求方确认
|
||||||
|
|
||||||
|
(暂无,口径已全部确认。)
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: app
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: 应用主包
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: HRBP 审批服务包:oa(OA 系统公共模块)+ flows(业务流程:请假/加班等)
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: OA 系统模块:包含 common(公共组件)、leave(请假流程)、work_overtime(加班流程)
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: OA 系统公共模块:登录、会话管理、接口调用、解析
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.approval_flow
|
|
||||||
@FileName: approval_flow.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 23:52
|
|
||||||
@Description: 公共审批引擎:登录(复用登录态)→ 查待办 → 解析 SSO → 获取表单 → 校验 → 生成报告
|
|
||||||
加班/请假共用,业务差异通过 subject + validate_doc + generate_report 注入
|
|
||||||
@Version: 1.2.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from typing import Any, Callable, Dict, List
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger, setup_logging
|
|
||||||
from utils.intelligent_retry import retry
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .login import oa_login
|
|
||||||
from .session_manager import (
|
|
||||||
init_session_from_page,
|
|
||||||
refresh_session_cookies,
|
|
||||||
load_saved_session,
|
|
||||||
save_browser_cookies,
|
|
||||||
create_browser_with_saved_cookies,
|
|
||||||
is_session_valid,
|
|
||||||
)
|
|
||||||
from .oa_api import (
|
|
||||||
get_documents,
|
|
||||||
get_wf_activity_by_task_id,
|
|
||||||
extract_form_id,
|
|
||||||
get_business_data,
|
|
||||||
)
|
|
||||||
from .sso import resolve_sso_params
|
|
||||||
except ImportError:
|
|
||||||
from login import oa_login
|
|
||||||
from session_manager import (
|
|
||||||
init_session_from_page,
|
|
||||||
refresh_session_cookies,
|
|
||||||
load_saved_session,
|
|
||||||
save_browser_cookies,
|
|
||||||
create_browser_with_saved_cookies,
|
|
||||||
is_session_valid,
|
|
||||||
)
|
|
||||||
from oa_api import (
|
|
||||||
get_documents,
|
|
||||||
get_wf_activity_by_task_id,
|
|
||||||
extract_form_id,
|
|
||||||
get_business_data,
|
|
||||||
)
|
|
||||||
from sso import resolve_sso_params
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@retry(max_attempts=3)
|
|
||||||
def _login():
|
|
||||||
"""完整登录 OA(失败自动重试,最多 3 次)"""
|
|
||||||
return oa_login()
|
|
||||||
|
|
||||||
|
|
||||||
def _get_browser_and_session(subject: str):
|
|
||||||
"""
|
|
||||||
获取浏览器和会话:优先复用已保存的登录 cookies,无效或不存在时才完整登录。
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
(browser, session, is_fresh_login)
|
|
||||||
"""
|
|
||||||
saved_session = load_saved_session()
|
|
||||||
if saved_session is not None and is_session_valid(saved_session, subject):
|
|
||||||
logger.info("复用已保存的登录会话,跳过登录")
|
|
||||||
browser = create_browser_with_saved_cookies()
|
|
||||||
return browser, saved_session, False
|
|
||||||
|
|
||||||
browser = _login()
|
|
||||||
session = init_session_from_page(browser)
|
|
||||||
save_browser_cookies(browser)
|
|
||||||
return browser, session, True
|
|
||||||
|
|
||||||
|
|
||||||
@retry(max_attempts=3)
|
|
||||||
def _fetch_documents(session, subject: str) -> List[Dict[str, Any]]:
|
|
||||||
"""按主题拉取待办单据(失败自动重试,最多 3 次)"""
|
|
||||||
return get_documents(session, subject=subject)
|
|
||||||
|
|
||||||
|
|
||||||
@retry(max_attempts=3)
|
|
||||||
def _fetch_doc_detail(browser, session, doc: Dict[str, Any]) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
解析单据详情:SSO 取 taskId/businessKey → WfActivity 取 formId → WorkformEngine 取表单数据。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
browser: 已登录的 ChromiumPage 对象(用于执行 SSO 的 JS 跳转)
|
|
||||||
session: 已登录的 SessionPage 对象(用于后台 API 请求)
|
|
||||||
doc: 单据信息(包含 detail_url)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
单据信息 + taskId/businessKey/formId/formData
|
|
||||||
"""
|
|
||||||
detail_url = doc.get("detail_url", "")
|
|
||||||
if not detail_url:
|
|
||||||
raise RuntimeError(f"单据无详情链接: {doc.get('title')}")
|
|
||||||
|
|
||||||
# Step 1: 浏览器打开 SSO 链接,从重定向后的 URL 提取 taskId 和 businessKey
|
|
||||||
sso_params = resolve_sso_params(browser, detail_url)
|
|
||||||
task_id = sso_params["taskId"]
|
|
||||||
business_key = sso_params["businessKey"]
|
|
||||||
logger.info("SSO 解析完成: taskId=%s, businessKey=%s", task_id, business_key)
|
|
||||||
|
|
||||||
# SSO 的 linkLogin 在 hr 域产生了新的会话 cookie,先同步回 SessionPage
|
|
||||||
refresh_session_cookies(session, browser)
|
|
||||||
|
|
||||||
# Step 2: 通过 taskId 获取 formId
|
|
||||||
wf_activity_data = get_wf_activity_by_task_id(session, task_id)
|
|
||||||
form_id = extract_form_id(wf_activity_data)
|
|
||||||
|
|
||||||
# Step 3: 通过 businessKey + formId 获取表单数据
|
|
||||||
form_data = get_business_data(session, business_key, form_id)
|
|
||||||
|
|
||||||
return {
|
|
||||||
**doc,
|
|
||||||
"taskId": task_id,
|
|
||||||
"businessKey": business_key,
|
|
||||||
"formId": form_id,
|
|
||||||
"formData": form_data,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def run_flow(
|
|
||||||
subject: str,
|
|
||||||
validate_doc: Callable[[Dict[str, Any], Any], Dict[str, Any]],
|
|
||||||
generate_report: Callable[[List[Dict[str, Any]]], str],
|
|
||||||
) -> str:
|
|
||||||
"""
|
|
||||||
公共审批流程:登录(优先复用已保存会话)→ 查待办 → 逐单解析详情并校验 → 生成报告。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
subject: 待办标题关键字,如 "加班" / "请假"
|
|
||||||
validate_doc: 单张单据的校验函数,签名为 (doc, session) -> result
|
|
||||||
generate_report: 校验结果报告生成函数
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
报告文本
|
|
||||||
"""
|
|
||||||
setup_logging()
|
|
||||||
logger.info("%s审批流程开始", subject)
|
|
||||||
|
|
||||||
browser, session, _ = _get_browser_and_session(subject)
|
|
||||||
|
|
||||||
docs = _fetch_documents(session, subject)
|
|
||||||
logger.info("共获取%s待办 %d 条", subject, len(docs))
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for doc in docs:
|
|
||||||
try:
|
|
||||||
doc_detail = _fetch_doc_detail(browser, session, doc)
|
|
||||||
result = validate_doc(doc_detail, session)
|
|
||||||
results.append(result)
|
|
||||||
logger.info(
|
|
||||||
"已校验: %s - %s -> %s",
|
|
||||||
result["creator"], result["title"], result["decision"],
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("处理单据失败: %s, 错误: %s", doc.get("title"), str(e))
|
|
||||||
results.append({
|
|
||||||
"creator": doc.get("creator", "未知"),
|
|
||||||
"title": doc.get("title", "未知"),
|
|
||||||
"decision": "失败",
|
|
||||||
"error": str(e),
|
|
||||||
})
|
|
||||||
|
|
||||||
report = generate_report(results)
|
|
||||||
print("\n" + report)
|
|
||||||
|
|
||||||
# 保存最新 cookies(SSO 已刷新 hr 域会话,供下次运行免登录复用)
|
|
||||||
save_browser_cookies(browser)
|
|
||||||
|
|
||||||
logger.info("%s审批流程结束,共处理 %d 条", subject, len(results))
|
|
||||||
return report
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.config
|
|
||||||
@FileName: config.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:09
|
|
||||||
@Description: OA 系统配置,集中管理接口地址、待办类型、分页大小等常量
|
|
||||||
@Version: 1.2.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
# ---------- OA 系统 ----------
|
|
||||||
# 待办列表等后台接口在 oa 域名;流程引擎/表单/考勤等 RedseaPlatform 接口在 hr 域名
|
|
||||||
BASE_URL = "https://oa.37du.co"
|
|
||||||
HR_BASE_URL = "https://hr.37du.co"
|
|
||||||
# 待办列表接口(oa 域名):按标题关键字查询当前账号的待办单据,用于抓取请假/加班等待审批流程
|
|
||||||
TODO_LIST_URL = f"{BASE_URL}/sys/notify/sys_notify_todo/sysNotifyMainIndex.do"
|
|
||||||
# 待办类型编码:"13" 对应需人工处理的审批类待办
|
|
||||||
FD_TYPE = "13"
|
|
||||||
|
|
||||||
# OA 流程接口(hr 域名)
|
|
||||||
# 通过 taskId 获取流程表单 ID(formId),用于后续拉取表单详情
|
|
||||||
WF_ACTIVITY_URL = f"{HR_BASE_URL}/RedseaPlatform/WfActivity.mc"
|
|
||||||
# 表单引擎接口:通过 businessKey + formId 获取审批单的表单数据(如加班日期、申请人等)
|
|
||||||
WORKFORM_ENGINE_URL = f"{HR_BASE_URL}/RedseaPlatform/WorkformEngine.mc"
|
|
||||||
|
|
||||||
# 排班接口(hr 域名,按员工 + 年月查询当月排班)
|
|
||||||
PAIBAN_URL = f"{HR_BASE_URL}/RedseaPlatform/KqCount.mc"
|
|
||||||
|
|
||||||
# 考勤打卡明细接口(hr 域名,按员工 + 日期范围查询原始打卡记录)
|
|
||||||
KQ_DATA_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_data_queryByStaffId_all/getExecuteResult.mc"
|
|
||||||
|
|
||||||
# 请假记录接口(hr 域名,按员工 + 日期范围查询请假明细)
|
|
||||||
LEAVE_RECORD_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_leave_record_SelectByStaffID/redApiExec.mc"
|
|
||||||
|
|
||||||
# ---------- 加班审批规则常量(对应 aa.md 审批规则) ----------
|
|
||||||
# 次日正常上班时间 T(固定 09:00)
|
|
||||||
WORK_START_TIME = "09:00"
|
|
||||||
# 当日规定下班时间(固定 18:00,用于区间合规校验)
|
|
||||||
WORK_END_TIME = "18:00"
|
|
||||||
# 弹性额度触发阈值:实际下班打卡时间 >= 该时刻才计算弹性额度 D
|
|
||||||
FLEX_TRIGGER_TIME = "23:00"
|
|
||||||
# 延时加班有效时长门槛:不足该小时数直接驳回
|
|
||||||
OT_MIN_HOURS = 1
|
|
||||||
|
|
||||||
# ---------- 分页 ----------
|
|
||||||
DEFAULT_PAGE_SIZE = 15
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.login
|
|
||||||
@FileName: login.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-04 17:34
|
|
||||||
@Description: 自动登录 OA 系统
|
|
||||||
@Version: 1.1.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
try:
|
|
||||||
from DrissionPage import ChromiumPage
|
|
||||||
except ImportError:
|
|
||||||
ChromiumPage = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
except ImportError:
|
|
||||||
load_dotenv = lambda *args, **kwargs: None
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def oa_login(
|
|
||||||
username: str = None,
|
|
||||||
password: str = None,
|
|
||||||
timeout: float = 10,
|
|
||||||
wait_after_load: float = 2,
|
|
||||||
) -> ChromiumPage:
|
|
||||||
"""
|
|
||||||
自动登录 OA 系统,返回已登录的 ChromiumPage 对象。
|
|
||||||
|
|
||||||
参数:
|
|
||||||
username: 登录用户名,若不提供则从环境变量 oa_login_username 读取
|
|
||||||
password: 登录密码,若不提供则从环境变量 oa_login_password 读取
|
|
||||||
|
|
||||||
timeout: URL 跳转等待超时(秒,默认 10)
|
|
||||||
wait_after_load: 页面加载后的额外等待时间(秒,默认 2)
|
|
||||||
|
|
||||||
返回:
|
|
||||||
登录成功后的 ChromiumPage 对象
|
|
||||||
|
|
||||||
异常:
|
|
||||||
若登录失败或关键元素未找到,抛出 RuntimeError
|
|
||||||
"""
|
|
||||||
# 加载 .env 环境变量(默认读取当前工作目录下的 .env)
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
# 获取配置,参数优先于环境变量
|
|
||||||
login_url = os.getenv('oa_login_url')
|
|
||||||
if not login_url:
|
|
||||||
raise RuntimeError("环境变量 oa_login_url 未设置")
|
|
||||||
target_url_keyword = os.getenv('oa_target_url_keyword')
|
|
||||||
if not target_url_keyword:
|
|
||||||
raise RuntimeError("环境变量 oa_target_url_keyword 未设置")
|
|
||||||
|
|
||||||
final_username = username or os.getenv('oa_login_username')
|
|
||||||
final_password = password or os.getenv('oa_login_password')
|
|
||||||
if not final_username or not final_password:
|
|
||||||
raise RuntimeError("用户名或密码未提供,请设置环境变量或传入参数")
|
|
||||||
|
|
||||||
# 创建浏览器页面对象
|
|
||||||
page = ChromiumPage()
|
|
||||||
# page.set.window.max()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# 访问登录页面
|
|
||||||
page.get(login_url)
|
|
||||||
time.sleep(wait_after_load) # 等待页面初步加载
|
|
||||||
|
|
||||||
# 定位并填写用户名
|
|
||||||
username_input = page.ele('tag:input@name=j_username')
|
|
||||||
if not username_input:
|
|
||||||
raise RuntimeError("未找到用户名输入框")
|
|
||||||
username_input.input(final_username)
|
|
||||||
|
|
||||||
page.wait(0.5)
|
|
||||||
|
|
||||||
# 定位并填写密码
|
|
||||||
password_input = page.ele('tag:input@name=j_password')
|
|
||||||
if not password_input:
|
|
||||||
raise RuntimeError("未找到密码输入框")
|
|
||||||
password_input.input(final_password)
|
|
||||||
|
|
||||||
page.wait(0.5)
|
|
||||||
|
|
||||||
# 定位并点击登录按钮
|
|
||||||
login_button = page.ele('.lui_login_button_div_c')
|
|
||||||
if not login_button:
|
|
||||||
raise RuntimeError("未找到登录按钮")
|
|
||||||
login_button.click()
|
|
||||||
|
|
||||||
page.wait(0.5)
|
|
||||||
|
|
||||||
# ---------- 轮询检测 URL ----------
|
|
||||||
start = time.time()
|
|
||||||
while time.time() - start < timeout: # timeout 默认 10 秒
|
|
||||||
if target_url_keyword in page.url:
|
|
||||||
logger.info("登录成功!当前 URL: %s", page.url)
|
|
||||||
return page
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
# 超时处理
|
|
||||||
error_elem = page.ele('.error-msg') or page.ele('.alert-danger')
|
|
||||||
if error_elem:
|
|
||||||
logger.warning("登录失败,提示: %s", error_elem.text)
|
|
||||||
raise RuntimeError(f"登录超时,当前 URL: {page.url}")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
# 若发生异常,可选择关闭浏览器并重新抛出
|
|
||||||
page.quit()
|
|
||||||
raise RuntimeError(f"登录过程出错: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 使用示例 ----------
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from utils.logger import setup_logging
|
|
||||||
setup_logging()
|
|
||||||
try:
|
|
||||||
page = oa_login()
|
|
||||||
except RuntimeError as e:
|
|
||||||
logger.error(e)
|
|
||||||
@@ -1,532 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.oa_api
|
|
||||||
@FileName: oa_api.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:10
|
|
||||||
@Description: OA/HR 系统 API 模块,负责调用系统接口(待办列表、流程引擎、表单、排班等)
|
|
||||||
@Version: 1.3.1
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import re
|
|
||||||
from typing import List, Dict, Any
|
|
||||||
from urllib.parse import urlencode
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
try:
|
|
||||||
from DrissionPage import SessionPage
|
|
||||||
except ImportError:
|
|
||||||
SessionPage = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL, KQ_DATA_URL, LEAVE_RECORD_URL, PAIBAN_URL
|
|
||||||
except ImportError:
|
|
||||||
from config import BASE_URL, HR_BASE_URL, TODO_LIST_URL, DEFAULT_PAGE_SIZE, FD_TYPE, WF_ACTIVITY_URL, WORKFORM_ENGINE_URL, KQ_DATA_URL, LEAVE_RECORD_URL, PAIBAN_URL
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 获取待处理单据列表 ----------
|
|
||||||
def fetch_todo_page(
|
|
||||||
session: SessionPage,
|
|
||||||
subject: str,
|
|
||||||
page_no: int = 1,
|
|
||||||
page_size: int = DEFAULT_PAGE_SIZE
|
|
||||||
) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
请求单页待办列表数据。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
subject: 待办标题关键字,如 "请假" / "加班"
|
|
||||||
page_no: 页码(从1开始)
|
|
||||||
page_size: 每页条数
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
接口返回的 JSON 字典
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或状态码异常
|
|
||||||
"""
|
|
||||||
params = {
|
|
||||||
"method": "list",
|
|
||||||
"dataType": "todo",
|
|
||||||
"fdType": FD_TYPE, # 待办类型(请假/加班)
|
|
||||||
"fdCateId": "",
|
|
||||||
"q.fdSubject": subject, # 按标题关键字过滤(请假/加班)
|
|
||||||
"orderby": "fdCreateTime",
|
|
||||||
"ordertype": "down",
|
|
||||||
"page.pageNo": page_no,
|
|
||||||
"page.pageSize": page_size,
|
|
||||||
"__seq": int(time.time() * 1000), # 防缓存
|
|
||||||
}
|
|
||||||
url = f"{TODO_LIST_URL}?{urlencode(params)}"
|
|
||||||
logger.debug("请求第 %d 页: %s", page_no, url)
|
|
||||||
|
|
||||||
session.get(url)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"接口请求失败,状态码: {resp.status_code}")
|
|
||||||
try:
|
|
||||||
return resp.json()
|
|
||||||
except Exception:
|
|
||||||
raise RuntimeError("接口返回非 JSON 数据,请检查参数或登录状态")
|
|
||||||
|
|
||||||
|
|
||||||
def parse_todo_list(data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
解析接口返回的 JSON,提取每张单据的关键信息。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
data: 接口返回的 JSON
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
单据列表,每项包含:
|
|
||||||
- title: 标题(去除 HTML 标签)
|
|
||||||
- creator: 发起人
|
|
||||||
- time: 接收时间(字符串)
|
|
||||||
- detail_url: SSO 跳转链接(完整 URL)
|
|
||||||
"""
|
|
||||||
datas = data.get("datas", [])
|
|
||||||
if not datas:
|
|
||||||
return []
|
|
||||||
|
|
||||||
docs = []
|
|
||||||
for row in datas:
|
|
||||||
# 1. 标题
|
|
||||||
title_cell = next((c for c in row if c["col"] == "todo.subject4View"), {})
|
|
||||||
title_raw = title_cell.get("value", "")
|
|
||||||
# 移除 <span class="subjecthead"> 标签,仅保留内容
|
|
||||||
match = re.search(r'<span class="subjecthead"[^>]*>(.*?)</span>', title_raw, re.DOTALL)
|
|
||||||
title = match.group(1).strip() if match else re.sub(r'<[^>]+>', '', title_raw).strip()
|
|
||||||
|
|
||||||
# 2. 发起人
|
|
||||||
creator_cell = next((c for c in row if c["col"] == "docCreatorName"), {})
|
|
||||||
creator = creator_cell.get("value", "")
|
|
||||||
|
|
||||||
# 3. 接收时间
|
|
||||||
time_cell = next((c for c in row if c["col"] == "fdCreateTime"), {})
|
|
||||||
time_str = time_cell.get("value", "")
|
|
||||||
|
|
||||||
# 4. SSO 跳转链接(补全为完整 URL)
|
|
||||||
href_cell = next((c for c in row if c["col"] == "tr_href"), {})
|
|
||||||
detail_url = href_cell.get("value", "")
|
|
||||||
if detail_url and not detail_url.startswith(("http://", "https://")):
|
|
||||||
detail_url = BASE_URL + detail_url
|
|
||||||
|
|
||||||
docs.append({
|
|
||||||
"title": title,
|
|
||||||
"creator": creator,
|
|
||||||
"time": time_str,
|
|
||||||
"detail_url": detail_url,
|
|
||||||
})
|
|
||||||
return docs
|
|
||||||
|
|
||||||
|
|
||||||
def get_documents(
|
|
||||||
session: SessionPage,
|
|
||||||
subject: str,
|
|
||||||
page_size: int = DEFAULT_PAGE_SIZE
|
|
||||||
) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
主入口:获取所有待处理单据(自动分页)。
|
|
||||||
|
|
||||||
请假与加班流程逻辑一致,仅通过 subject 关键字区分。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象(已设置 cookies)
|
|
||||||
subject: 待办标题关键字,如 "请假" / "加班"
|
|
||||||
page_size: 每页条数(默认15)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
所有单据的列表
|
|
||||||
"""
|
|
||||||
all_docs = []
|
|
||||||
|
|
||||||
# 请求第一页,获取总条数
|
|
||||||
data = fetch_todo_page(session, subject, page_no=1, page_size=page_size)
|
|
||||||
total = int(data.get("page", {}).get("totalSize", 0))
|
|
||||||
logger.info("总待办[%s]条数: %d", subject, total)
|
|
||||||
|
|
||||||
# 解析第一页
|
|
||||||
docs = parse_todo_list(data)
|
|
||||||
all_docs.extend(docs)
|
|
||||||
logger.info("第 1 页获取 %d 条", len(docs))
|
|
||||||
|
|
||||||
# 若总条数超过单页,继续翻页
|
|
||||||
if total > page_size:
|
|
||||||
total_pages = (total + page_size - 1) // page_size
|
|
||||||
for p in range(2, total_pages + 1):
|
|
||||||
data = fetch_todo_page(session, subject, page_no=p, page_size=page_size)
|
|
||||||
docs = parse_todo_list(data)
|
|
||||||
all_docs.extend(docs)
|
|
||||||
logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(docs), len(all_docs))
|
|
||||||
|
|
||||||
return all_docs
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- WfActivity 接口:通过 taskId 获取 formId ----------
|
|
||||||
def get_wf_activity_by_task_id(
|
|
||||||
session: SessionPage,
|
|
||||||
task_id: str
|
|
||||||
) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
通过 taskId 调用 WfActivity 接口获取 formId。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
task_id: SSO 解析得到的 taskId
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
接口返回的 JSON 字典,包含 formId 等信息
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
url = f"{WF_ACTIVITY_URL}?method=getWfActivityByTaskId"
|
|
||||||
data = {"taskId": task_id}
|
|
||||||
logger.info("获取 formId: taskId=%s", task_id)
|
|
||||||
|
|
||||||
session.post(url, data=data)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("WfActivity 请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"WfActivity 接口状态码异常: {resp.status_code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_data = resp.json()
|
|
||||||
except Exception:
|
|
||||||
body = (resp.text or "")[:200]
|
|
||||||
raise RuntimeError(
|
|
||||||
f"WfActivity 接口返回非 JSON 数据(状态码 {resp.status_code}): {body}"
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("WfActivity 返回: %s", json_data)
|
|
||||||
return json_data
|
|
||||||
|
|
||||||
|
|
||||||
def extract_form_id(wf_activity_data: Dict[str, Any]) -> str:
|
|
||||||
"""
|
|
||||||
从 WfActivity 接口返回数据中提取 formId。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
wf_activity_data: get_wf_activity_by_task_id 返回的 JSON
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
formId 字符串
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: 未找到 formId
|
|
||||||
"""
|
|
||||||
# 常见 formId 字段路径:顶层,以及 data / result 子对象
|
|
||||||
form_id = (
|
|
||||||
wf_activity_data.get("formId")
|
|
||||||
or wf_activity_data.get("FormId")
|
|
||||||
or wf_activity_data.get("form_id")
|
|
||||||
)
|
|
||||||
if not form_id:
|
|
||||||
for key in ("data", "result"):
|
|
||||||
data_obj = wf_activity_data.get(key, {})
|
|
||||||
if isinstance(data_obj, dict):
|
|
||||||
form_id = (
|
|
||||||
data_obj.get("formId")
|
|
||||||
or data_obj.get("FormId")
|
|
||||||
or data_obj.get("form_id")
|
|
||||||
)
|
|
||||||
if form_id:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not form_id:
|
|
||||||
raise ValueError(f"无法从 WfActivity 返回数据中提取 formId: {wf_activity_data}")
|
|
||||||
|
|
||||||
logger.info("提取到 formId: %s", form_id)
|
|
||||||
return form_id
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- WorkformEngine 接口:获取加班申请表单数据 ----------
|
|
||||||
def get_business_data(
|
|
||||||
session: SessionPage,
|
|
||||||
business_key: str,
|
|
||||||
form_id: str
|
|
||||||
) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
通过 businessKey 和 formId 调用 WorkformEngine 接口获取加班申请表单数据。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
business_key: SSO 解析得到的 businessKey
|
|
||||||
form_id: 从 WfActivity 接口获取的 formId
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
表单详细数据字典(接口响应的 result 字段,如 ot_date/staff_name 等)
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
url = f"{WORKFORM_ENGINE_URL}?method=getBusinessDate"
|
|
||||||
data = {
|
|
||||||
"businessKey": business_key,
|
|
||||||
"formId": form_id,
|
|
||||||
}
|
|
||||||
logger.info("获取加班表单: businessKey=%s, formId=%s", business_key, form_id)
|
|
||||||
|
|
||||||
session.post(url, data=data)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("WorkformEngine 请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"WorkformEngine 接口状态码异常: {resp.status_code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_data = resp.json()
|
|
||||||
except Exception:
|
|
||||||
body = (resp.text or "")[:200]
|
|
||||||
raise RuntimeError(
|
|
||||||
f"WorkformEngine 接口返回非 JSON 数据(状态码 {resp.status_code}): {body}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 表单详情在 result 字段中(如 ot_date / staff_name 等)
|
|
||||||
result = json_data.get("result")
|
|
||||||
if json_data.get("state") != "1" or not isinstance(result, dict):
|
|
||||||
raise RuntimeError(f"WorkformEngine 接口返回失败: {json_data}")
|
|
||||||
|
|
||||||
logger.info("WorkformEngine 返回成功")
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 排班接口 ----------
|
|
||||||
def get_attendance_html(
|
|
||||||
session: SessionPage,
|
|
||||||
staff_id: str,
|
|
||||||
year: int,
|
|
||||||
month: int
|
|
||||||
) -> str:
|
|
||||||
"""
|
|
||||||
获取指定员工某月的排班 HTML。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
staff_id: 员工 UUID
|
|
||||||
year: 年份(如 2026)
|
|
||||||
month: 月份(1-12)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
排班表格的 HTML 字符串(从返回 JSON 的 caleHtml 字段提取)
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
url = f"{PAIBAN_URL}?method=geRenPaibanByMonth"
|
|
||||||
data = {
|
|
||||||
"type": "2",
|
|
||||||
"staffId": staff_id,
|
|
||||||
"year": str(year),
|
|
||||||
"month": str(month)
|
|
||||||
}
|
|
||||||
logger.info("获取排班: %s %d-%02d", staff_id, year, month)
|
|
||||||
|
|
||||||
session.post(url, data=data)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("排班请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"排班接口状态码异常: {resp.status_code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_data = resp.json()
|
|
||||||
except Exception:
|
|
||||||
raise RuntimeError("排班接口返回非 JSON 数据")
|
|
||||||
|
|
||||||
if json_data.get("success") != "true":
|
|
||||||
raise RuntimeError(f"排班接口返回失败: {json_data}")
|
|
||||||
|
|
||||||
html = json_data.get("caleHtml")
|
|
||||||
if not html:
|
|
||||||
raise RuntimeError("排班接口未返回 caleHtml 字段")
|
|
||||||
return html
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 考勤打卡明细接口 ----------
|
|
||||||
def get_attendance_records(
|
|
||||||
session: SessionPage,
|
|
||||||
staff_id: str,
|
|
||||||
start_date: str,
|
|
||||||
end_date: str
|
|
||||||
) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
查询员工某时间段的原始打卡明细。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
staff_id: 员工 UUID
|
|
||||||
start_date: 查询起始日期 "YYYY-MM-DD"
|
|
||||||
end_date: 查询结束日期 "YYYY-MM-DD"
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
打卡记录列表(接口返回的 jsonList,每条含 kq_time / status / time_order 等)
|
|
||||||
- status: "1"=上班打卡, "5"=下班打卡, "6"=重复打卡
|
|
||||||
- time_order: "1"=上班时段, "2"=下班时段
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
params = {
|
|
||||||
"staff_id": staff_id,
|
|
||||||
"rootId": "",
|
|
||||||
"countId": "",
|
|
||||||
"bc_date": start_date,
|
|
||||||
"bc_date_end": end_date,
|
|
||||||
"begin": start_date,
|
|
||||||
"end": end_date,
|
|
||||||
}
|
|
||||||
logger.info("获取打卡明细: staff_id=%s, %s 至 %s", staff_id, start_date, end_date)
|
|
||||||
|
|
||||||
session.get(KQ_DATA_URL, params=params)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("考勤打卡请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"考勤打卡接口状态码异常: {resp.status_code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_data = resp.json()
|
|
||||||
except Exception:
|
|
||||||
body = (resp.text or "")[:200]
|
|
||||||
raise RuntimeError(f"考勤打卡接口返回非 JSON 数据: {body}")
|
|
||||||
|
|
||||||
records = json_data.get("jsonList", [])
|
|
||||||
logger.info("打卡明细返回 %d 条", len(records))
|
|
||||||
return records
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 请假记录接口 ----------
|
|
||||||
def fetch_leave_record_page(
|
|
||||||
session: SessionPage,
|
|
||||||
staff_id: str,
|
|
||||||
begin_date: str,
|
|
||||||
end_date: str,
|
|
||||||
page_no: int = 1,
|
|
||||||
page_size: int = DEFAULT_PAGE_SIZE,
|
|
||||||
sub_type: str = "-1"
|
|
||||||
) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
请求单页员工请假记录。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
staff_id: 员工 UUID
|
|
||||||
begin_date: 查询起始日期 "YYYY-MM-DD"
|
|
||||||
end_date: 查询结束日期 "YYYY-MM-DD"
|
|
||||||
page_no: 页码(从1开始)
|
|
||||||
page_size: 每页条数
|
|
||||||
sub_type: 假期类型编码,默认 "-1" 表示全部
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
接口返回的 data 字段字典,包含 total / pageCount / list
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
data = {
|
|
||||||
"sub_type": sub_type,
|
|
||||||
"staff_id": staff_id,
|
|
||||||
"begin_date": begin_date,
|
|
||||||
"end_date": end_date,
|
|
||||||
"start": str((page_no - 1) * page_size),
|
|
||||||
"pageSize": str(page_size),
|
|
||||||
"sortType": "",
|
|
||||||
"sortName": "",
|
|
||||||
"pageNo": str(page_no),
|
|
||||||
}
|
|
||||||
logger.info("获取请假记录: staff_id=%s, %s 至 %s, 第%d页", staff_id, begin_date, end_date, page_no)
|
|
||||||
|
|
||||||
session.post(LEAVE_RECORD_URL, data=data)
|
|
||||||
resp = session.response
|
|
||||||
if not resp:
|
|
||||||
raise RuntimeError("请假记录请求失败,未获取到响应")
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise RuntimeError(f"请假记录接口状态码异常: {resp.status_code}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_data = resp.json()
|
|
||||||
except Exception:
|
|
||||||
body = (resp.text or "")[:200]
|
|
||||||
raise RuntimeError(f"请假记录接口返回非 JSON 数据: {body}")
|
|
||||||
|
|
||||||
if json_data.get("success") is not True or json_data.get("code") != 200:
|
|
||||||
raise RuntimeError(f"请假记录接口返回失败: {json_data}")
|
|
||||||
|
|
||||||
page_info = json_data.get("data")
|
|
||||||
if not isinstance(page_info, dict):
|
|
||||||
raise RuntimeError(f"请假记录接口未返回 data 字段: {json_data}")
|
|
||||||
return page_info
|
|
||||||
|
|
||||||
|
|
||||||
def get_leave_records(
|
|
||||||
session: SessionPage,
|
|
||||||
staff_id: str,
|
|
||||||
begin_date: str,
|
|
||||||
end_date: str,
|
|
||||||
page_size: int = DEFAULT_PAGE_SIZE,
|
|
||||||
sub_type: str = "-1"
|
|
||||||
) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
查询员工某时间段内的全部请假记录(自动分页)。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 已登录的 SessionPage 对象
|
|
||||||
staff_id: 员工 UUID
|
|
||||||
begin_date: 查询起始日期 "YYYY-MM-DD"
|
|
||||||
end_date: 查询结束日期 "YYYY-MM-DD"
|
|
||||||
page_size: 每页条数
|
|
||||||
sub_type: 假期类型编码,默认 "-1" 表示全部
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
请假记录列表,每条包含:
|
|
||||||
- staff_id: 员工ID
|
|
||||||
- staff_name: 员工姓名
|
|
||||||
- leave_businessKey: 审批单号
|
|
||||||
- sub_type: 假期类型编码
|
|
||||||
- vacation_type_name: 假期名称
|
|
||||||
- leave_reason: 请假原因
|
|
||||||
- leave_days: 请假天数
|
|
||||||
- leave_hours: 请假小时
|
|
||||||
- start_time: 开始时间
|
|
||||||
- end_time: 结束时间
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 请求失败或响应异常
|
|
||||||
"""
|
|
||||||
all_records: List[Dict[str, Any]] = []
|
|
||||||
|
|
||||||
# 请求第一页,获取总条数与总页数
|
|
||||||
page_info = fetch_leave_record_page(
|
|
||||||
session, staff_id, begin_date, end_date,
|
|
||||||
page_no=1, page_size=page_size, sub_type=sub_type
|
|
||||||
)
|
|
||||||
total = int(page_info.get("total", 0))
|
|
||||||
page_total = int(page_info.get("pageCount", 1))
|
|
||||||
records = page_info.get("list", []) or []
|
|
||||||
all_records.extend(records)
|
|
||||||
logger.info("请假记录总数: %d, 第1页获取 %d 条", total, len(records))
|
|
||||||
|
|
||||||
# 若存在多页,继续翻页
|
|
||||||
if page_total > 1:
|
|
||||||
for p in range(2, page_total + 1):
|
|
||||||
page_info = fetch_leave_record_page(
|
|
||||||
session, staff_id, begin_date, end_date,
|
|
||||||
page_no=p, page_size=page_size, sub_type=sub_type
|
|
||||||
)
|
|
||||||
records = page_info.get("list", []) or []
|
|
||||||
all_records.extend(records)
|
|
||||||
logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(records), len(all_records))
|
|
||||||
|
|
||||||
return all_records
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.parser
|
|
||||||
@FileName: parser.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:10
|
|
||||||
@Description: 解析模块(HTML 排班表格解析,供请假校验使用)
|
|
||||||
@Version: 1.3.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
from collections import defaultdict
|
|
||||||
from datetime import datetime
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 排班 HTML 解析 ----------
|
|
||||||
def parse_attendance_html(html: str) -> Dict[str, str]:
|
|
||||||
"""
|
|
||||||
解析排班 HTML 表格,提取每个日期的班次名称。
|
|
||||||
|
|
||||||
示例 HTML 片段:
|
|
||||||
<a class='cale_a' ... data-temp='2026-08-01' ...>正常</a>
|
|
||||||
或 <a ...>休息</a>
|
|
||||||
|
|
||||||
Args:
|
|
||||||
html: 排班接口返回的 HTML 字符串
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
字典:{日期字符串: 班次名称}
|
|
||||||
例如:{"2026-08-01": "正常", "2026-08-02": "休息"}
|
|
||||||
"""
|
|
||||||
# 正则匹配 <a> 标签中的 data-temp 和文本内容
|
|
||||||
pattern = r'<a[^>]*data-temp="([^"]+)"[^>]*>([^<]+)</a>'
|
|
||||||
matches = re.findall(pattern, html)
|
|
||||||
|
|
||||||
result = {}
|
|
||||||
for date, shift in matches:
|
|
||||||
# 去除可能的空格
|
|
||||||
date_clean = date.strip()
|
|
||||||
shift_clean = shift.strip()
|
|
||||||
result[date_clean] = shift_clean
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def get_work_days_in_range(
|
|
||||||
attendance_dict: Dict[str, str],
|
|
||||||
start_date: str,
|
|
||||||
end_date: str
|
|
||||||
) -> List[str]:
|
|
||||||
"""
|
|
||||||
根据排班字典和请假起止日期,返回请假区间内所有非“休息”的日期列表。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
attendance_dict: 由 parse_attendance_html 返回的字典
|
|
||||||
start_date: 请假开始日期,格式 "YYYY-MM-DD"
|
|
||||||
end_date: 请假结束日期,格式 "YYYY-MM-DD"
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
非休息日的日期字符串列表(格式 "YYYY-MM-DD")
|
|
||||||
"""
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
start = datetime.strptime(start_date, "%Y-%m-%d")
|
|
||||||
end = datetime.strptime(end_date, "%Y-%m-%d")
|
|
||||||
|
|
||||||
work_days = []
|
|
||||||
current = start
|
|
||||||
while current <= end:
|
|
||||||
date_str = current.strftime("%Y-%m-%d")
|
|
||||||
shift = attendance_dict.get(date_str, "")
|
|
||||||
# 如果该日期没有排班信息,或明确为“休息”,视为休息日
|
|
||||||
if shift != "休息" and shift != "":
|
|
||||||
work_days.append(date_str)
|
|
||||||
current += timedelta(days=1)
|
|
||||||
return work_days
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 打卡明细汇总 ----------
|
|
||||||
def summarize_attendance_records(records: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
按日汇总员工打卡明细:每天取最早打卡和最晚打卡。
|
|
||||||
|
|
||||||
实际接口返回的打卡记录 status 多为 "6"、time_order 为 null,
|
|
||||||
无法据其区分上下班,因此直接按 bc_date 分组后取时间最早和最晚的打卡。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
records: get_attendance_records 返回的原始打卡列表
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
每日汇总列表,每项含:
|
|
||||||
- staff_id / staff_name / dept_name / post_name / attend_date
|
|
||||||
- first_check_in: 当日最早打卡时间(字符串,无则 None)
|
|
||||||
- last_check_out: 当日最晚打卡时间(字符串,仅1条时为 None,含跨天凌晨)
|
|
||||||
"""
|
|
||||||
time_format = "%Y-%m-%d %H:%M:%S"
|
|
||||||
|
|
||||||
# 按 (staff_id, bc_date) 分组,取每天最早和最晚的打卡
|
|
||||||
group_map: Dict[tuple, List[Dict[str, Any]]] = defaultdict(list)
|
|
||||||
|
|
||||||
for item in records:
|
|
||||||
staff_id = item.get("staff_id", "")
|
|
||||||
bc_day = item.get("bc_date", "")
|
|
||||||
if not staff_id or not bc_day:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
kq_dt = datetime.strptime(item["kq_time"], time_format)
|
|
||||||
except (KeyError, ValueError):
|
|
||||||
continue
|
|
||||||
|
|
||||||
group_map[(staff_id, bc_day)].append({**item, "_dt": kq_dt})
|
|
||||||
|
|
||||||
summary: List[Dict[str, Any]] = []
|
|
||||||
for (sid, day), items in group_map.items():
|
|
||||||
items.sort(key=lambda x: x["_dt"])
|
|
||||||
base = items[0]
|
|
||||||
row = {
|
|
||||||
"staff_id": sid,
|
|
||||||
"staff_name": base.get("staff_name", ""),
|
|
||||||
"dept_name": base.get("DEPT_ORG_NAME", ""),
|
|
||||||
"post_name": base.get("POST_ALIAS_NAME", ""),
|
|
||||||
"attend_date": day,
|
|
||||||
"first_check_in": items[0]["kq_time"],
|
|
||||||
"last_check_out": items[-1]["kq_time"] if len(items) > 1 else None,
|
|
||||||
}
|
|
||||||
summary.append(row)
|
|
||||||
|
|
||||||
return summary
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 使用示例(测试用) ----------
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from utils.logger import setup_logging
|
|
||||||
setup_logging()
|
|
||||||
|
|
||||||
# 测试 HTML 解析
|
|
||||||
sample_html = """
|
|
||||||
<a class='cale_a' data-temp="2026-08-01">休息</a>
|
|
||||||
<a class='cale_a' data-temp="2026-08-02">正常</a>
|
|
||||||
<a class='cale_a' data-temp="2026-08-03">休息</a>
|
|
||||||
"""
|
|
||||||
result = parse_attendance_html(sample_html)
|
|
||||||
logger.info("解析结果: %s", result)
|
|
||||||
|
|
||||||
work = get_work_days_in_range(result, "2026-08-01", "2026-08-03")
|
|
||||||
logger.info("工作日: %s", work)
|
|
||||||
|
|
||||||
# 测试打卡汇总
|
|
||||||
sample_records = [
|
|
||||||
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
|
|
||||||
"kq_time": "2026-08-02 08:50:00", "status": "1", "time_order": "1",
|
|
||||||
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"},
|
|
||||||
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
|
|
||||||
"kq_time": "2026-08-03 00:30:00", "status": "5", "time_order": "2",
|
|
||||||
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"},
|
|
||||||
]
|
|
||||||
summary = summarize_attendance_records(sample_records)
|
|
||||||
logger.info("打卡汇总: %s", summary)
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.session_manager
|
|
||||||
@FileName: session_manager.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 10:30
|
|
||||||
@Description: 从 ChromiumPage 提取 Cookies,生成 SessionPage 供后台请求;支持 cookies 持久化复用
|
|
||||||
@Version: 1.3.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from DrissionPage import ChromiumPage, SessionPage
|
|
||||||
except ImportError:
|
|
||||||
ChromiumPage = None
|
|
||||||
SessionPage = None
|
|
||||||
|
|
||||||
# 登录 cookies 持久化目录:服务层统一管理各平台会话文件,文件名按平台区分
|
|
||||||
# 如 oa_cookies.json / xxx_cookies.json,便于后续扩展其他平台
|
|
||||||
_SESSIONS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '.sessions')
|
|
||||||
COOKIE_FILE = os.path.join(_SESSIONS_DIR, 'oa_cookies.json')
|
|
||||||
|
|
||||||
|
|
||||||
def init_session_from_page(
|
|
||||||
browser_page: ChromiumPage,
|
|
||||||
copy_headers: bool = True
|
|
||||||
) -> SessionPage:
|
|
||||||
"""
|
|
||||||
从已登录的 ChromiumPage 中提取 cookies 和 headers,
|
|
||||||
创建并返回一个可直接发送后台请求的 SessionPage 对象。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
browser_page: 已登录的 ChromiumPage 实例
|
|
||||||
copy_headers: 是否复制浏览器的 User-Agent 等头部信息(默认 True)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
已设置好 cookies 和 headers 的 SessionPage 对象
|
|
||||||
"""
|
|
||||||
session = SessionPage()
|
|
||||||
|
|
||||||
# 1. 获取浏览器 cookies(全域名:oa 域登录态 + hr 域可能已有的会话)
|
|
||||||
cookies_dict = browser_page.cookies(all_domains=True)
|
|
||||||
if cookies_dict:
|
|
||||||
session.set.cookies(cookies_dict)
|
|
||||||
logger.info("已复制 %d 个 Cookies 到 SessionPage", len(cookies_dict))
|
|
||||||
else:
|
|
||||||
logger.warning("未获取到 Cookies,请确认浏览器已登录")
|
|
||||||
|
|
||||||
# 2. 可选复制 headers(主要是 User-Agent,防止被反爬)
|
|
||||||
if copy_headers:
|
|
||||||
headers = {
|
|
||||||
"User-Agent": browser_page.run_js("return navigator.userAgent;")
|
|
||||||
}
|
|
||||||
session.set.headers(headers)
|
|
||||||
logger.info("已复制 User-Agent: %s...", headers['User-Agent'][:50])
|
|
||||||
|
|
||||||
# 3. 可额外设置默认超时、重试等
|
|
||||||
session.set.timeout(10) # 全局超时 10 秒
|
|
||||||
|
|
||||||
return session
|
|
||||||
|
|
||||||
|
|
||||||
# 便捷函数:SSO 跳转后同步浏览器 cookies 到 SessionPage
|
|
||||||
def refresh_session_cookies(session: SessionPage, browser_page: ChromiumPage) -> None:
|
|
||||||
"""
|
|
||||||
从浏览器重新同步全域名 cookies 到 SessionPage。
|
|
||||||
SSO 的 linkLogin 会在 hr 域产生新的会话 cookie,需在浏览器完成 SSO 跳转后调用。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
session: 目标 SessionPage 对象
|
|
||||||
browser_page: 已登录且已完成 SSO 跳转的 ChromiumPage 实例
|
|
||||||
"""
|
|
||||||
cookies = browser_page.cookies(all_domains=True)
|
|
||||||
if cookies:
|
|
||||||
session.set.cookies(cookies)
|
|
||||||
logger.info("已同步 %d 个 Cookies 到 SessionPage(含 SSO 会话)", len(cookies))
|
|
||||||
else:
|
|
||||||
logger.warning("未获取到 Cookies,请确认浏览器登录态")
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- Cookies 持久化(复用登录态,免重复登录) ----------
|
|
||||||
def save_browser_cookies(browser_page: ChromiumPage, path: str = COOKIE_FILE) -> None:
|
|
||||||
"""把浏览器全域名 cookies 保存到本地文件,下次运行可免登录复用。"""
|
|
||||||
cookies = browser_page.cookies(all_domains=True)
|
|
||||||
if not cookies:
|
|
||||||
logger.warning("未获取到 Cookies,跳过保存")
|
|
||||||
return
|
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
||||||
with open(path, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(cookies, f, ensure_ascii=False, indent=2)
|
|
||||||
logger.info("已保存 %d 个 Cookies 到 %s", len(cookies), path)
|
|
||||||
|
|
||||||
|
|
||||||
def load_cookies(path: str = COOKIE_FILE):
|
|
||||||
"""从本地文件加载 cookies 列表;文件不存在或为空时返回 None。"""
|
|
||||||
if not os.path.exists(path):
|
|
||||||
return None
|
|
||||||
with open(path, encoding='utf-8') as f:
|
|
||||||
cookies = json.load(f)
|
|
||||||
return cookies or None
|
|
||||||
|
|
||||||
|
|
||||||
def load_saved_session(path: str = COOKIE_FILE) -> SessionPage:
|
|
||||||
"""用已保存的 cookies 构建 SessionPage;无可用 cookies 时返回 None。"""
|
|
||||||
cookies = load_cookies(path)
|
|
||||||
if not cookies:
|
|
||||||
return None
|
|
||||||
session = SessionPage()
|
|
||||||
session.set.cookies(cookies)
|
|
||||||
session.set.timeout(10)
|
|
||||||
return session
|
|
||||||
|
|
||||||
|
|
||||||
def create_browser_with_saved_cookies(path: str = COOKIE_FILE) -> ChromiumPage:
|
|
||||||
"""用已保存的 cookies 创建 ChromiumPage(免输账号密码,SSO 跳转仍需真浏览器)。"""
|
|
||||||
browser = ChromiumPage()
|
|
||||||
cookies = load_cookies(path)
|
|
||||||
if cookies:
|
|
||||||
browser.set.cookies(cookies)
|
|
||||||
return browser
|
|
||||||
|
|
||||||
|
|
||||||
def is_session_valid(session: SessionPage, subject: str = "加班") -> bool:
|
|
||||||
"""通过拉取待办第一页判断会话是否有效(无效则需重新登录)。"""
|
|
||||||
try:
|
|
||||||
from .oa_api import fetch_todo_page
|
|
||||||
except ImportError:
|
|
||||||
from oa_api import fetch_todo_page
|
|
||||||
try:
|
|
||||||
fetch_todo_page(session, subject=subject, page_no=1, page_size=1)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
logger.info("会话已失效,需重新登录: %s", e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# 便捷函数:直接从已登录的浏览器提取会话,一步到位
|
|
||||||
def create_session_from_login() -> SessionPage:
|
|
||||||
"""
|
|
||||||
如果希望快速测试,可直接调用 oa_login() 获取浏览器,
|
|
||||||
再提取 SessionPage。
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
from .login import oa_login
|
|
||||||
except ImportError:
|
|
||||||
from login import oa_login
|
|
||||||
browser = oa_login()
|
|
||||||
return init_session_from_page(browser)
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.sso
|
|
||||||
@FileName: sso.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 23:50
|
|
||||||
@Description: SSO 链接解析模块:浏览器访问 SSO 链接,从重定向后的详情页 URL 提取 taskId/fkId 和 businessKey
|
|
||||||
@Version: 1.0.1
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from urllib.parse import urlparse, parse_qs
|
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from DrissionPage import ChromiumPage
|
|
||||||
except ImportError:
|
|
||||||
ChromiumPage = None
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_sso_params(
|
|
||||||
browser: ChromiumPage,
|
|
||||||
sso_url: str,
|
|
||||||
wait_timeout: float = 20,
|
|
||||||
) -> Dict[str, str]:
|
|
||||||
"""
|
|
||||||
用浏览器打开 SSO 链接,等待 JS 重定向到详情页,
|
|
||||||
从最终 URL 的 query 参数中提取 taskId(部分页面命名为 fkId)和 businessKey。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
browser: 已登录的 ChromiumPage 对象(SSO 的 JS 跳转必须用真浏览器)
|
|
||||||
sso_url: SSO 跳转链接(完整 URL)
|
|
||||||
wait_timeout: 等待 JS 跳转完成的超时时间(秒,默认 20)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
包含 taskId 和 businessKey 的字典
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
RuntimeError: 跳转失败或 URL 中缺少 taskId/businessKey
|
|
||||||
"""
|
|
||||||
logger.info("解析 SSO 重定向: %s", sso_url)
|
|
||||||
|
|
||||||
# 浏览器打开 SSO 链接,页面 JS 自动重定向到详情页。
|
|
||||||
# 跳转链: sso.mob → unifyWorkFlow.jsp(中间页,一闪而过) → goToWorkFlow 详情页。
|
|
||||||
# 因此不能等中间页(会匹配不到而超时卡 wait_timeout 秒),改为等待地址栏离开 SSO 链接。
|
|
||||||
browser.get(sso_url)
|
|
||||||
browser.wait.url_change(sso_url, exclude=True, timeout=wait_timeout, raise_err=False)
|
|
||||||
logger.info("重定向最终 URL: %s", browser.url)
|
|
||||||
|
|
||||||
# 从详情页 URL 提取 taskId(fkId 是同一字段的别名)和 businessKey
|
|
||||||
params = parse_qs(urlparse(browser.url).query)
|
|
||||||
task_id = params.get("taskId", [None])[0] or params.get("fkId", [None])[0]
|
|
||||||
business_key = params.get("businessKey", [None])[0]
|
|
||||||
|
|
||||||
if not task_id or not business_key:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"无法从重定向 URL 提取 taskId 或 businessKey: {browser.url}"
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("SSO 解析成功: taskId=%s, businessKey=%s", task_id, business_key)
|
|
||||||
return {"taskId": task_id, "businessKey": business_key}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.leave
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: 请假审批流程包
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.leave.leave_approval
|
|
||||||
@FileName: leave_approval.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 21:21
|
|
||||||
@Description: 请假审批流程入口(审批引擎见 common/approval_flow.py,校验规则见 validator.py,报告见 reporter.py)
|
|
||||||
@Version: 1.2.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
||||||
|
|
||||||
try:
|
|
||||||
from ..common.approval_flow import run_flow
|
|
||||||
from .validator import validate_doc
|
|
||||||
from .reporter import generate_report
|
|
||||||
except ImportError:
|
|
||||||
from common.approval_flow import run_flow
|
|
||||||
from validator import validate_doc
|
|
||||||
from reporter import generate_report
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""请假审批:登录 → 查待办 → 解析SSO → 获取表单 → 校验 → 报告"""
|
|
||||||
run_flow(subject="请假", validate_doc=validate_doc, generate_report=generate_report)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.leave.reporter
|
|
||||||
@FileName: reporter.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:11
|
|
||||||
@Description: 请假流程报告模块,生成审批报告
|
|
||||||
@Version: 1.1.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
def generate_report(results: List[Dict[str, Any]]) -> str:
|
|
||||||
"""
|
|
||||||
根据校验结果生成请假审批报告。
|
|
||||||
|
|
||||||
TODO: 按实际报告格式完善(导出 Excel/文件等)。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
results: validate_doc 返回的校验结果列表
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
报告文本
|
|
||||||
"""
|
|
||||||
lines = ["请假审批报告", "=" * 30]
|
|
||||||
for r in results:
|
|
||||||
lines.append(f"{r.get('creator', '')} | {r.get('title', '')} | {r.get('decision', '')}")
|
|
||||||
return "\n".join(lines)
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.leave.validator
|
|
||||||
@FileName: validator.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:11
|
|
||||||
@Description: 请假流程校验模块(审批规则:驳回/人工复核/通过)
|
|
||||||
@Version: 1.1.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Any, Dict
|
|
||||||
|
|
||||||
|
|
||||||
def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
校验单张请假单据,返回审批决策。
|
|
||||||
|
|
||||||
TODO: 请假审批规则在此实现(依据排班、假期类型、请假时长等判定通过/驳回/人工复核)。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
doc: 单据信息,含基本信息(title/creator/time/detail_url)
|
|
||||||
和审批引擎已获取的 taskId/businessKey/formId/formData(表单详情)
|
|
||||||
session: 已登录的 SessionPage 对象(用于调用排班接口)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
校验结果,包含审批决策
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
"title": doc.get("title", ""),
|
|
||||||
"creator": doc.get("creator", ""),
|
|
||||||
"time": doc.get("time", ""),
|
|
||||||
"decision": "pending", # pending: 规则未实现,默认待处理
|
|
||||||
"note": "请假校验规则待补充",
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.work_overtime
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: 加班审批流程包
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.work_overtime.overtime_approval
|
|
||||||
@FileName: overtime_approval.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 21:22
|
|
||||||
@Description: 加班审批流程入口(审批引擎见 common/approval_flow.py,校验规则见 validator.py,报告见 reporter.py)
|
|
||||||
@Version: 1.4.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
||||||
|
|
||||||
try:
|
|
||||||
from ..common.approval_flow import run_flow
|
|
||||||
from .validator import validate_doc
|
|
||||||
from .reporter import generate_report
|
|
||||||
except ImportError:
|
|
||||||
from common.approval_flow import run_flow
|
|
||||||
from validator import validate_doc
|
|
||||||
from reporter import generate_report
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""加班审批:登录 → 查待办 → 解析SSO → 获取表单 → 校验 → 报告"""
|
|
||||||
run_flow(subject="加班", validate_doc=validate_doc, generate_report=generate_report)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.work_overtime.parser
|
|
||||||
@FileName: parser.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-06 09:30
|
|
||||||
@Description: 加班表单解析模块(解析 WorkformEngine 返回的 result,提取关键字段并转换为中文描述)
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from typing import Any, Dict
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# 加班类型映射
|
|
||||||
OT_TYPE_MAP = {
|
|
||||||
"1": "延时加班",
|
|
||||||
"2": "法定假日加班",
|
|
||||||
"3": "休息日加班",
|
|
||||||
}
|
|
||||||
|
|
||||||
# 补贴类型映射
|
|
||||||
SUBSIDY_TYPE_MAP = {
|
|
||||||
"1": "转调休",
|
|
||||||
"2": "转补贴",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def parse_overtime_form(result: Dict[str, Any]) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
解析加班表单数据,提取关键字段并将代码转换为中文描述。
|
|
||||||
|
|
||||||
注意:入参为 oa_api.get_business_data 返回的 result 字段(state 校验已在
|
|
||||||
get_business_data 内完成),即审批引擎 doc['formData']。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
result: WorkformEngine 返回的 result 字典(含 ot_type / staff_name 等)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
包含加班关键字段的字典(中文键名);找不到映射时保留原始代码值
|
|
||||||
"""
|
|
||||||
# 获取原始类型代码
|
|
||||||
ot_type_code = result.get("ot_type")
|
|
||||||
subsidy_type_code = result.get("subsidy_type")
|
|
||||||
|
|
||||||
overtime_info = {
|
|
||||||
"加班人员ID": result.get("staff_id"),
|
|
||||||
"加班人员": result.get("staff_name"),
|
|
||||||
"所属部门": result.get("dept_org_name"),
|
|
||||||
"加班类型": OT_TYPE_MAP.get(ot_type_code, ot_type_code),
|
|
||||||
"补贴类型": SUBSIDY_TYPE_MAP.get(subsidy_type_code, subsidy_type_code),
|
|
||||||
"加班日期": result.get("ot_date"),
|
|
||||||
"加班开始时间": result.get("start_time"),
|
|
||||||
"加班结束时间": result.get("end_time"),
|
|
||||||
"加班时长(小时)": result.get("ot_hour"),
|
|
||||||
"加班天数(天)": result.get("ot_day"),
|
|
||||||
"系统判断加班时长(小时)": result.get("judge_ot_hour"),
|
|
||||||
"系统判断加班天数(天)": result.get("judge_ot_day"),
|
|
||||||
"附件": result.get("file"),
|
|
||||||
}
|
|
||||||
|
|
||||||
# 拼接系统判定的加班时间段
|
|
||||||
judge_start = result.get("judge_start_time")
|
|
||||||
judge_end = result.get("judge_end_time")
|
|
||||||
if judge_start and judge_end:
|
|
||||||
overtime_info["系统判定加班时间"] = f"{judge_start} 至 {judge_end}"
|
|
||||||
else:
|
|
||||||
overtime_info["系统判定加班时间"] = None
|
|
||||||
|
|
||||||
return overtime_info
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 使用示例(测试用) ----------
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from utils.logger import setup_logging
|
|
||||||
setup_logging()
|
|
||||||
|
|
||||||
# 示例 result(WorkformEngine 返回的 result 字段)
|
|
||||||
sample_result = {
|
|
||||||
"dept_org_name": "网络项目小组",
|
|
||||||
"end_time": "2026-08-03 00:00",
|
|
||||||
"judge_end_time": "2026-08-03 00:00:00",
|
|
||||||
"judge_ot_hour": 6.0,
|
|
||||||
"judge_start_time": "2026-08-02 18:00:00",
|
|
||||||
"ot_date": "2026-08-02",
|
|
||||||
"ot_hour": 6.0,
|
|
||||||
"ot_type": "1",
|
|
||||||
"staff_id": "572e6cce-7a9f-11ec-b449-000c296f9469",
|
|
||||||
"staff_name": "黄俊林",
|
|
||||||
"start_time": "2026-08-02 18:00",
|
|
||||||
"subsidy_type": "2",
|
|
||||||
"file": "ccc1d3ef-175a-4105-a8a8-0e63ed88d7bd",
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed = parse_overtime_form(sample_result)
|
|
||||||
logger.info("===== 加班信息解析结果 =====")
|
|
||||||
for key, value in parsed.items():
|
|
||||||
logger.info("%s: %s", key, value)
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.work_overtime.reporter
|
|
||||||
@FileName: reporter.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 21:35
|
|
||||||
@Description: 加班流程报告模块,生成审批报告(详细数据版,供自测阶段人工复核)
|
|
||||||
@Version: 1.3.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
def _format_detail(idx: int, r: Dict[str, Any]) -> str:
|
|
||||||
"""
|
|
||||||
格式化单条记录的详细信息:展示全部解析数据,最后是判断结果。
|
|
||||||
所有键值对左对齐,方便人工逐项核对。
|
|
||||||
"""
|
|
||||||
info = r.get("overtime_info", {}) or {}
|
|
||||||
|
|
||||||
# 收集全部要展示的键值对:先数据,后判断结果
|
|
||||||
items: List[tuple] = list(info.items())
|
|
||||||
items.append(("审批结果", r.get("decision", "")))
|
|
||||||
if r.get("note"):
|
|
||||||
items.append(("说明", r.get("note", "")))
|
|
||||||
if r.get("error"):
|
|
||||||
items.append(("错误", r.get("error", "")))
|
|
||||||
|
|
||||||
max_key = max((len(k) for k, _ in items), default=0)
|
|
||||||
|
|
||||||
lines = [
|
|
||||||
f"#{idx} 申请人: {r.get('creator', '')} | {r.get('title', '')}",
|
|
||||||
"-" * 60,
|
|
||||||
]
|
|
||||||
for key, value in items:
|
|
||||||
lines.append(f" {key:<{max_key}} : {value}")
|
|
||||||
lines.append("-" * 60)
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_report(results: List[Dict[str, Any]]) -> str:
|
|
||||||
"""
|
|
||||||
根据校验结果生成加班审批报告(详细数据版)。
|
|
||||||
|
|
||||||
每条记录展示全部解析数据(人员、日期、起止时间、时长、排班、打卡、
|
|
||||||
申报天数、计算结果等),最后是审批结果和说明,供自测阶段人工复核。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
results: validate_doc 返回的校验结果列表
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
报告文本
|
|
||||||
"""
|
|
||||||
passed = [r for r in results if r.get("decision") == "通过"]
|
|
||||||
rejected = [r for r in results if r.get("decision") == "不通过"]
|
|
||||||
failed = [r for r in results if r.get("decision") == "失败"]
|
|
||||||
|
|
||||||
lines = [
|
|
||||||
"加班审批报告",
|
|
||||||
"=" * 60,
|
|
||||||
f"共 {len(results)} 单:通过 {len(passed)},不通过 {len(rejected)},处理失败 {len(failed)}",
|
|
||||||
"",
|
|
||||||
]
|
|
||||||
|
|
||||||
if rejected:
|
|
||||||
lines.append("【审批未通过名单】")
|
|
||||||
for i, r in enumerate(rejected, 1):
|
|
||||||
lines.append(_format_detail(i, r))
|
|
||||||
lines.append("")
|
|
||||||
|
|
||||||
if passed:
|
|
||||||
lines.append("【审批通过名单】")
|
|
||||||
for i, r in enumerate(passed, 1):
|
|
||||||
lines.append(_format_detail(i, r))
|
|
||||||
lines.append("")
|
|
||||||
|
|
||||||
if failed:
|
|
||||||
lines.append("【处理失败】")
|
|
||||||
for i, r in enumerate(failed, 1):
|
|
||||||
lines.append(_format_detail(i, r))
|
|
||||||
|
|
||||||
return "\n".join(lines)
|
|
||||||
@@ -1,447 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.oa.work_overtime.validator
|
|
||||||
@FileName: validator.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 21:35
|
|
||||||
@Description: 加班流程校验模块(按 aa.md 审批规则:延时加班/休息日加班/法定假日加班,判定通过/不通过)
|
|
||||||
@Version: 3.0.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import math
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from typing import Any, Dict, Optional
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
|
|
||||||
|
|
||||||
from utils.logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .parser import parse_overtime_form
|
|
||||||
from ..common.oa_api import (
|
|
||||||
get_attendance_html,
|
|
||||||
get_attendance_records,
|
|
||||||
get_leave_records,
|
|
||||||
)
|
|
||||||
from ..common.parser import parse_attendance_html, summarize_attendance_records
|
|
||||||
from ..common.config import (
|
|
||||||
WORK_START_TIME,
|
|
||||||
WORK_END_TIME,
|
|
||||||
FLEX_TRIGGER_TIME,
|
|
||||||
OT_MIN_HOURS,
|
|
||||||
)
|
|
||||||
except ImportError:
|
|
||||||
from parser import parse_overtime_form
|
|
||||||
from common.oa_api import (
|
|
||||||
get_attendance_html,
|
|
||||||
get_attendance_records,
|
|
||||||
get_leave_records,
|
|
||||||
)
|
|
||||||
from common.parser import parse_attendance_html, summarize_attendance_records
|
|
||||||
from common.config import (
|
|
||||||
WORK_START_TIME,
|
|
||||||
WORK_END_TIME,
|
|
||||||
FLEX_TRIGGER_TIME,
|
|
||||||
OT_MIN_HOURS,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 通用工具 ----------
|
|
||||||
def _parse_dt(value: Any) -> Optional[datetime]:
|
|
||||||
"""解析 "YYYY-MM-DD HH:MM[:SS]" 格式时间,失败返回 None"""
|
|
||||||
if not value:
|
|
||||||
return None
|
|
||||||
for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M"):
|
|
||||||
try:
|
|
||||||
return datetime.strptime(str(value), fmt)
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _calc_delayed_hours(start: datetime, end: datetime) -> float:
|
|
||||||
"""
|
|
||||||
延时加班计时:1小时起算,超过1小时的部分按0.5小时累加,不足0.5小时舍去。
|
|
||||||
不足1小时返回0。
|
|
||||||
|
|
||||||
示例:1.0->1.0, 1.4->1.0, 1.5->1.5, 1.9->1.5, 2.0->2.0, 2.3->2.0, 2.5->2.5
|
|
||||||
"""
|
|
||||||
total = (end - start).total_seconds() / 3600
|
|
||||||
if total < 1:
|
|
||||||
return 0.0
|
|
||||||
return 1.0 + math.floor((total - 1) / 0.5) * 0.5
|
|
||||||
|
|
||||||
|
|
||||||
def _calc_flex_d(actual_checkout: datetime, flex_trigger: datetime) -> float:
|
|
||||||
"""
|
|
||||||
弹性额度 D 计算(基于实际下班打卡时间):
|
|
||||||
实际下班打卡 >= 23:00 时,D = 1 + floor((打卡-23:00)/0.5) * 0.5
|
|
||||||
"""
|
|
||||||
return 1.0 + math.floor((actual_checkout - flex_trigger).total_seconds() / 1800) * 0.5
|
|
||||||
|
|
||||||
|
|
||||||
def _calc_day_ot_threshold(days: float) -> float:
|
|
||||||
"""
|
|
||||||
休息日/法定假日加班打卡间隔阈值:8 * days + int(days)。
|
|
||||||
0.5天->4h, 1天->9h, 1.5天->13h, 2天->18h, 2.5天->22h
|
|
||||||
"""
|
|
||||||
return 8.0 * days + int(days)
|
|
||||||
|
|
||||||
|
|
||||||
def _next_day(date_str: str) -> str:
|
|
||||||
"""日期字符串 +1 天"""
|
|
||||||
d = datetime.strptime(date_str, "%Y-%m-%d")
|
|
||||||
return (d + timedelta(days=1)).strftime("%Y-%m-%d")
|
|
||||||
|
|
||||||
|
|
||||||
def _is_spring_festival(date_str: str) -> bool:
|
|
||||||
"""
|
|
||||||
判断日期是否为春节法定节假日(初一至初三)。
|
|
||||||
|
|
||||||
用 chinese_calendar 的 get_holiday_detail 判断 holiday_name == 'Spring Festival',
|
|
||||||
且 is_in_lieu=False(排除调休日),且非周末(排除正常周末)。
|
|
||||||
判定失败时按非春节处理(优雅降级)。
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
import chinese_calendar as cc
|
|
||||||
date = datetime.strptime(date_str, "%Y-%m-%d").date()
|
|
||||||
is_holiday, holiday_name = cc.get_holiday_detail(date)
|
|
||||||
return (is_holiday
|
|
||||||
and holiday_name == 'Spring Festival'
|
|
||||||
and not cc.is_in_lieu(date)
|
|
||||||
and date.weekday() < 5)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("春节法定假日判定失败(%s): %s", date_str, str(e))
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 排班 / 打卡 / 请假查询 ----------
|
|
||||||
def _get_shift(session: Any, staff_id: str, date_str: str) -> str:
|
|
||||||
"""获取指定日期员工的排班班次(自动处理跨月)"""
|
|
||||||
if not date_str or not staff_id:
|
|
||||||
return "未知"
|
|
||||||
try:
|
|
||||||
year = int(date_str[:4])
|
|
||||||
month = int(date_str[5:7])
|
|
||||||
html = get_attendance_html(session, staff_id, year, month)
|
|
||||||
attendance = parse_attendance_html(html)
|
|
||||||
return attendance.get(date_str, "无排班")
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("获取排班失败(%s): %s", date_str, str(e))
|
|
||||||
return "获取失败"
|
|
||||||
|
|
||||||
|
|
||||||
def _check_attendance(session: Any, staff_id: str, ot_date: str) -> Dict[str, Any]:
|
|
||||||
"""查询员工在加班日期的排班班次"""
|
|
||||||
return {"加班当天班次": _get_shift(session, staff_id, ot_date)}
|
|
||||||
|
|
||||||
|
|
||||||
def _check_punch_records(session: Any, staff_id: str, ot_date: str) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
查询员工在加班日及次日的打卡明细,按日汇总。
|
|
||||||
|
|
||||||
加班常跨天(如 18:00 至次日 00:00),下班打卡可能落在次日,因此查询
|
|
||||||
范围扩展到 ot_date 次日;次日最早打卡用于延时加班的弹性到岗兑换判定。
|
|
||||||
"""
|
|
||||||
if not ot_date or not staff_id:
|
|
||||||
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
|
|
||||||
"打卡备注": "缺少加班日期或员工ID"}
|
|
||||||
|
|
||||||
start = datetime.strptime(ot_date, "%Y-%m-%d")
|
|
||||||
next_day = (start + timedelta(days=1)).strftime("%Y-%m-%d")
|
|
||||||
|
|
||||||
try:
|
|
||||||
records = get_attendance_records(session, staff_id, ot_date, next_day)
|
|
||||||
summary = summarize_attendance_records(records)
|
|
||||||
day_summary = next((r for r in summary if r["attend_date"] == ot_date), None)
|
|
||||||
next_summary = next((r for r in summary if r["attend_date"] == next_day), None)
|
|
||||||
if not day_summary and not next_summary:
|
|
||||||
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
|
|
||||||
"打卡备注": "当天及次日无打卡记录"}
|
|
||||||
return {
|
|
||||||
"当日最早打卡": day_summary["first_check_in"] if day_summary else None,
|
|
||||||
"当日最晚打卡": day_summary["last_check_out"] if day_summary else None,
|
|
||||||
"次日最早打卡": next_summary["first_check_in"] if next_summary else None,
|
|
||||||
"打卡备注": "",
|
|
||||||
}
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("获取打卡明细失败: %s", str(e))
|
|
||||||
return {"当日最早打卡": None, "当日最晚打卡": None, "次日最早打卡": None,
|
|
||||||
"打卡备注": f"获取失败: {e}"}
|
|
||||||
|
|
||||||
|
|
||||||
def _check_leave_covers_morning(session: Any, staff_id: str, date_str: str) -> bool:
|
|
||||||
"""
|
|
||||||
判断指定日期是否有请假覆盖早上上班时间(用于弹性兑换触发判定)。
|
|
||||||
|
|
||||||
只要任意请假区间覆盖了当日 WORK_START_TIME(如 09:00),即视为早上无需到岗,
|
|
||||||
不触发弹性兑换。查询范围向前一天扩展,确保能查到跨天请假。
|
|
||||||
"""
|
|
||||||
prev_day = (datetime.strptime(date_str, "%Y-%m-%d") - timedelta(days=1)).strftime("%Y-%m-%d")
|
|
||||||
try:
|
|
||||||
records = get_leave_records(session, staff_id, prev_day, date_str)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("获取请假记录失败: %s", str(e))
|
|
||||||
return False
|
|
||||||
|
|
||||||
morning = datetime.strptime(f"{date_str} {WORK_START_TIME}", "%Y-%m-%d %H:%M")
|
|
||||||
for r in records:
|
|
||||||
start = _parse_dt(r.get("start_time"))
|
|
||||||
end = _parse_dt(r.get("end_time"))
|
|
||||||
if start and end and start <= morning <= end:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 规则一:延时加班 ----------
|
|
||||||
def _validate_delayed(
|
|
||||||
info: Dict[str, Any], punch: Dict[str, Any], session: Any, staff_id: str
|
|
||||||
) -> tuple:
|
|
||||||
"""
|
|
||||||
延时加班审批(按 aa.md 规则一):
|
|
||||||
|
|
||||||
(一)驳回门槛:
|
|
||||||
1. 日期匹配:加班开始时间所属日期 = 申请加班日期;
|
|
||||||
2. 时长达标:1小时起算,超1小时按0.5h累加,不足1h驳回;
|
|
||||||
3. 区间合规:开始时间 >= 规定下班时间(18:00),结束时间 <= 实际下班打卡时间。
|
|
||||||
|
|
||||||
(二)弹性到岗兑换(仅影响结算,校验不通过则驳回):
|
|
||||||
D 基于实际下班打卡时间计算,>= 23:00 时 D = 1 + floor((打卡-23:00)/0.5)*0.5。
|
|
||||||
次日休息/请假覆盖09:00/无打卡 -> 不触发兑换。
|
|
||||||
正常工作日按次日打卡 P 校验:P<=09:00 不扣;09:00<P<=09:00+D 扣 ceil(P-09:00);
|
|
||||||
P>09:00+D 扣 D。兑换校验:加班时长+晚到 <= 加班开始到次日打卡的总自然时长。
|
|
||||||
"""
|
|
||||||
ot_date = info.get("加班日期")
|
|
||||||
start = _parse_dt(info.get("加班开始时间"))
|
|
||||||
end = _parse_dt(info.get("加班结束时间"))
|
|
||||||
actual_checkout = _parse_dt(punch.get("当日最晚打卡"))
|
|
||||||
reasons = []
|
|
||||||
|
|
||||||
# 1. 日期校验
|
|
||||||
if start is None:
|
|
||||||
reasons.append("加班开始时间缺失")
|
|
||||||
elif start.strftime("%Y-%m-%d") != ot_date:
|
|
||||||
reasons.append(f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致")
|
|
||||||
|
|
||||||
# 2. 时长校验
|
|
||||||
hours = None
|
|
||||||
if end is None:
|
|
||||||
reasons.append("加班结束时间缺失")
|
|
||||||
elif start is not None:
|
|
||||||
hours = _calc_delayed_hours(start, end)
|
|
||||||
if hours < OT_MIN_HOURS:
|
|
||||||
reasons.append(f"加班时长为{hours:g}小时,不足{OT_MIN_HOURS}小时")
|
|
||||||
|
|
||||||
# 3. 区间合规校验:开始 >= 规定下班时间,结束 <= 实际下班打卡时间
|
|
||||||
work_end = datetime.strptime(f"{ot_date} {WORK_END_TIME}", "%Y-%m-%d %H:%M")
|
|
||||||
if start is not None and start < work_end:
|
|
||||||
reasons.append(f"申请开始时间({start:%H:%M})早于规定下班时间({WORK_END_TIME})")
|
|
||||||
if end is not None:
|
|
||||||
if actual_checkout is None:
|
|
||||||
reasons.append("当日无下班打卡记录,无法校验区间合规")
|
|
||||||
elif end > actual_checkout:
|
|
||||||
reasons.append(
|
|
||||||
f"申请结束时间({end:%H:%M})晚于实际下班打卡时间({actual_checkout:%H:%M:%S})"
|
|
||||||
)
|
|
||||||
|
|
||||||
info["计算加班时长(小时)"] = hours
|
|
||||||
if reasons:
|
|
||||||
info["弹性扣减(小时)"] = 0
|
|
||||||
info["有效加班时长(小时)"] = hours
|
|
||||||
info["弹性额度D(小时)"] = 0
|
|
||||||
return "不通过", ";".join(reasons)
|
|
||||||
|
|
||||||
# 4. 弹性到岗兑换(仅影响结算时长)
|
|
||||||
deduction = 0.0
|
|
||||||
flex_note = ""
|
|
||||||
d_hours = 0.0
|
|
||||||
flex_trigger = datetime.strptime(f"{ot_date} {FLEX_TRIGGER_TIME}", "%Y-%m-%d %H:%M")
|
|
||||||
|
|
||||||
if actual_checkout is not None and actual_checkout >= flex_trigger:
|
|
||||||
d_hours = _calc_flex_d(actual_checkout, flex_trigger)
|
|
||||||
next_day = _next_day(ot_date)
|
|
||||||
next_shift = _get_shift(session, staff_id, next_day)
|
|
||||||
|
|
||||||
if next_shift in ("休息", "无排班"):
|
|
||||||
flex_note = f"次日({next_day})为休息日,不触发弹性兑换"
|
|
||||||
elif next_shift in ("获取失败", "未知"):
|
|
||||||
flex_note = f"次日({next_day})排班获取失败,不触发弹性兑换"
|
|
||||||
elif _check_leave_covers_morning(session, staff_id, next_day):
|
|
||||||
flex_note = f"次日({next_day})请假覆盖早上上班时间,不触发弹性兑换"
|
|
||||||
else:
|
|
||||||
work_start = datetime.strptime(f"{next_day} {WORK_START_TIME}", "%Y-%m-%d %H:%M")
|
|
||||||
p = _parse_dt(punch.get("次日最早打卡"))
|
|
||||||
|
|
||||||
if p is None:
|
|
||||||
flex_note = f"次日({next_day})无打卡记录,不触发弹性兑换"
|
|
||||||
elif p <= work_start:
|
|
||||||
flex_note = f"次日打卡({p:%H:%M})准时或提前,无需兑换"
|
|
||||||
else:
|
|
||||||
# 有晚到,校验:加班时长 + 晚到 <= 加班开始到次日打卡的总自然时长
|
|
||||||
total_natural = (p - start).total_seconds() / 3600
|
|
||||||
|
|
||||||
if p <= work_start + timedelta(hours=d_hours):
|
|
||||||
# 09:00 < P <= 09:00+D:晚到时长 = ceil(P-09:00),不足1h按1h
|
|
||||||
late_hours = max(1, math.ceil((p - work_start).total_seconds() / 3600))
|
|
||||||
if hours + late_hours > total_natural:
|
|
||||||
info["弹性扣减(小时)"] = 0
|
|
||||||
info["有效加班时长(小时)"] = hours
|
|
||||||
info["弹性额度D(小时)"] = d_hours
|
|
||||||
return "不通过", (
|
|
||||||
f"弹性兑换校验不通过:申请加班{hours:g}h + 晚到{late_hours}h "
|
|
||||||
f"> 总自然时长{total_natural:.1f}h"
|
|
||||||
)
|
|
||||||
deduction = float(late_hours)
|
|
||||||
flex_note = f"次日打卡({p:%H:%M})晚到,兑换{late_hours}小时"
|
|
||||||
else:
|
|
||||||
# P > 09:00+D:兑换额度最高按D,超出部分交考勤处理
|
|
||||||
if hours + d_hours > total_natural:
|
|
||||||
info["弹性扣减(小时)"] = 0
|
|
||||||
info["有效加班时长(小时)"] = hours
|
|
||||||
info["弹性额度D(小时)"] = d_hours
|
|
||||||
return "不通过", (
|
|
||||||
f"弹性兑换校验不通过:申请加班{hours:g}h + 兑换额度{d_hours:g}h "
|
|
||||||
f"> 总自然时长{total_natural:.1f}h"
|
|
||||||
)
|
|
||||||
deduction = float(d_hours)
|
|
||||||
flex_note = (
|
|
||||||
f"次日打卡({p:%H:%M})超出弹性区间(D={d_hours:g}h),"
|
|
||||||
f"按D兑换,超出部分交考勤处理"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
if actual_checkout is not None:
|
|
||||||
flex_note = f"实际下班打卡({actual_checkout:%H:%M})早于{FLEX_TRIGGER_TIME},弹性额度D=0"
|
|
||||||
|
|
||||||
effective = max(0.0, float(hours) - deduction)
|
|
||||||
info["弹性扣减(小时)"] = deduction
|
|
||||||
info["有效加班时长(小时)"] = effective
|
|
||||||
info["弹性额度D(小时)"] = d_hours
|
|
||||||
note = f"审批通过,有效加班时长{effective:g}小时"
|
|
||||||
if flex_note:
|
|
||||||
note += f"({flex_note})"
|
|
||||||
return "通过", note
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 规则二/三:休息日 / 法定假日加班 ----------
|
|
||||||
def _validate_day_ot(
|
|
||||||
info: Dict[str, Any],
|
|
||||||
punch: Dict[str, Any],
|
|
||||||
session: Any,
|
|
||||||
staff_id: str,
|
|
||||||
require_holiday: bool,
|
|
||||||
) -> tuple:
|
|
||||||
"""
|
|
||||||
休息日/法定假日加班审批(任一条件不满足即不通过):
|
|
||||||
- 排班显示为休息;
|
|
||||||
- 法定假日(仅春节):申请日期必须为春节法定节假日;
|
|
||||||
- 加班时长 > 0;
|
|
||||||
- 当天有上下班打卡;
|
|
||||||
- 打卡时间间隔满足申报天数(0.5天>=4h, 1天>=9h, 1.5天>=13h, 2天>=18h...)。
|
|
||||||
"""
|
|
||||||
ot_date = info.get("加班日期")
|
|
||||||
reasons = []
|
|
||||||
|
|
||||||
# 排班须显示为休息;排班获取失败/未知时优雅降级
|
|
||||||
shift = info.get("加班当天班次", "")
|
|
||||||
if shift not in ("休息", "获取失败", "未知", "无排班"):
|
|
||||||
reasons.append(f"当天排班为'{shift}',非休息日")
|
|
||||||
|
|
||||||
if require_holiday and not _is_spring_festival(ot_date):
|
|
||||||
reasons.append(f"{ot_date}不在春节法定节假日列表中")
|
|
||||||
|
|
||||||
# 加班时长 > 0
|
|
||||||
ot_hour = info.get("加班时长(小时)") or info.get("系统判断加班时长(小时)")
|
|
||||||
try:
|
|
||||||
ot_hour = float(ot_hour)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
ot_hour = 0.0
|
|
||||||
if ot_hour <= 0:
|
|
||||||
reasons.append("加班时长为0或缺失")
|
|
||||||
|
|
||||||
# 当天有上下班打卡,且打卡时间间隔满足申报天数
|
|
||||||
first = _parse_dt(punch.get("当日最早打卡"))
|
|
||||||
last = _parse_dt(punch.get("当日最晚打卡"))
|
|
||||||
interval = None
|
|
||||||
if first is None or last is None:
|
|
||||||
reasons.append("当天缺少上班或下班打卡")
|
|
||||||
else:
|
|
||||||
interval = (last - first).total_seconds() / 3600
|
|
||||||
|
|
||||||
apply_days = info.get("加班天数(天)") or info.get("系统判断加班天数(天)")
|
|
||||||
try:
|
|
||||||
apply_days = float(apply_days)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
apply_days = 0.0
|
|
||||||
if apply_days <= 0:
|
|
||||||
reasons.append("申报天数缺失或为0")
|
|
||||||
elif interval is not None:
|
|
||||||
threshold = _calc_day_ot_threshold(apply_days)
|
|
||||||
if interval < threshold:
|
|
||||||
reasons.append(
|
|
||||||
f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时"
|
|
||||||
)
|
|
||||||
|
|
||||||
info["打卡时间间隔(小时)"] = interval
|
|
||||||
info["申报天数(天)"] = apply_days
|
|
||||||
if reasons:
|
|
||||||
return "不通过", ";".join(reasons)
|
|
||||||
return "通过", f"审批通过(申报{apply_days:g}天,打卡间隔{interval:.2f}小时)"
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 主入口 ----------
|
|
||||||
def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
|
||||||
"""
|
|
||||||
校验单张加班单据,返回审批决策(通过 / 不通过)。
|
|
||||||
|
|
||||||
按加班类型分派规则:
|
|
||||||
ot_type=1 延时加班;
|
|
||||||
ot_type=3 休息日加班;
|
|
||||||
ot_type=2 法定假日加班(仅春节法定节假日走规则三,非春节按休息日规则执行)。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
doc: 单据信息,含基本信息(title/creator/time/detail_url)
|
|
||||||
和审批引擎已获取的 taskId/businessKey/formId/formData(表单详情)
|
|
||||||
session: 已登录的 SessionPage 对象(用于调用排班/打卡/请假接口)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
校验结果,包含审批决策、原因说明及解析后的加班信息
|
|
||||||
"""
|
|
||||||
form_data = doc.get("formData", {}) or {}
|
|
||||||
overtime_info = parse_overtime_form(form_data)
|
|
||||||
|
|
||||||
staff_id = overtime_info.get("加班人员ID")
|
|
||||||
ot_date = overtime_info.get("加班日期")
|
|
||||||
|
|
||||||
attendance_info = _check_attendance(session, staff_id, ot_date)
|
|
||||||
punch_info = _check_punch_records(session, staff_id, ot_date)
|
|
||||||
overtime_info.update(attendance_info)
|
|
||||||
overtime_info.update(punch_info)
|
|
||||||
|
|
||||||
ot_type_code = str(form_data.get("ot_type") or "")
|
|
||||||
if ot_type_code == "1":
|
|
||||||
decision, note = _validate_delayed(overtime_info, punch_info, session, staff_id)
|
|
||||||
elif ot_type_code == "3":
|
|
||||||
decision, note = _validate_day_ot(
|
|
||||||
overtime_info, punch_info, session, staff_id, require_holiday=False
|
|
||||||
)
|
|
||||||
elif ot_type_code == "2":
|
|
||||||
# 法定假日加班:仅春节法定节假日适用规则三,非春节按休息日规则执行
|
|
||||||
require_holiday = _is_spring_festival(ot_date)
|
|
||||||
decision, note = _validate_day_ot(
|
|
||||||
overtime_info, punch_info, session, staff_id, require_holiday=require_holiday
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
decision, note = "不通过", f"无法识别加班类型: {ot_type_code}"
|
|
||||||
|
|
||||||
return {
|
|
||||||
"title": doc.get("title", ""),
|
|
||||||
"creator": doc.get("creator", ""),
|
|
||||||
"time": doc.get("time", ""),
|
|
||||||
"decision": decision,
|
|
||||||
"note": note,
|
|
||||||
"overtime_info": overtime_info,
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: utils
|
|
||||||
@FileName: __init__.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 17:00
|
|
||||||
@Description: 项目级通用工具包
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: hrbp.utils
|
|
||||||
@FileName: utils.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05 21:30
|
|
||||||
@Description: 项目级通用工具(重试装饰器)
|
|
||||||
@Version: 1.1.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import functools
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
from logger import get_logger
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class RetryExhaustedError(Exception):
|
|
||||||
"""重试耗尽后抛出的异常,保留原始异常链。"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def retry(max_attempts: int = 3) -> Callable:
|
|
||||||
"""
|
|
||||||
重试装饰器:内置指数退避 + 随机抖动,只暴露重试次数。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
max_attempts: 最大尝试次数(含首次执行),默认 3,必须 >= 1。
|
|
||||||
|
|
||||||
内部行为(对调用方透明):
|
|
||||||
- 捕获所有 Exception;
|
|
||||||
- 延迟策略:第 n 次重试等待 1.0 * 2^(n-1) 秒,并乘以 [0.5, 1.5] 随机因子;
|
|
||||||
- 全部失败后抛出 RetryExhaustedError,可通过 __cause__ 获取原始异常。
|
|
||||||
"""
|
|
||||||
if max_attempts < 1:
|
|
||||||
raise ValueError("max_attempts must be >= 1")
|
|
||||||
|
|
||||||
def decorator(func: Callable) -> Callable:
|
|
||||||
@functools.wraps(func)
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
last_exc = None
|
|
||||||
base_delay = 1.0
|
|
||||||
backoff = 2.0
|
|
||||||
|
|
||||||
for attempt in range(1, max_attempts + 1):
|
|
||||||
try:
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
except Exception as e:
|
|
||||||
last_exc = e
|
|
||||||
if attempt >= max_attempts:
|
|
||||||
logger.error(
|
|
||||||
"%s 连续 %d 次尝试失败,放弃并记录: %s",
|
|
||||||
func.__name__, max_attempts, e,
|
|
||||||
)
|
|
||||||
break
|
|
||||||
|
|
||||||
# 计算退避 + 抖动
|
|
||||||
delay = base_delay * (backoff ** (attempt - 1))
|
|
||||||
delay *= random.uniform(0.5, 1.5)
|
|
||||||
|
|
||||||
logger.warning(
|
|
||||||
"%s 第 %d 次执行失败: %s,%.2f 秒后重试",
|
|
||||||
func.__name__, attempt, e, delay,
|
|
||||||
)
|
|
||||||
time.sleep(delay)
|
|
||||||
|
|
||||||
raise RetryExhaustedError(
|
|
||||||
f"{func.__name__} failed after {max_attempts} attempts"
|
|
||||||
) from last_exc
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Module: utils.logger
|
|
||||||
@FileName: logger.py
|
|
||||||
@Author: 小布丁
|
|
||||||
@CreateTime: 2026-08-05
|
|
||||||
@Description: 项目统一日志配置:控制台彩色输出 + 文件持久化
|
|
||||||
@Version: 1.0.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import logging.handlers
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
_console_fmt = "%(asctime)s | %(levelname)-7s | %(name)s | %(message)s"
|
|
||||||
_file_fmt = "%(asctime)s | %(levelname)-7s | %(name)s | %(filename)s:%(lineno)d | %(message)s"
|
|
||||||
_date_fmt = "%Y-%m-%d %H:%M:%S"
|
|
||||||
|
|
||||||
_initialized = False
|
|
||||||
|
|
||||||
|
|
||||||
class _ColoredFormatter(logging.Formatter):
|
|
||||||
"""控制台彩色日志格式,不修改 record 本身,避免污染文件输出"""
|
|
||||||
|
|
||||||
_colors = {
|
|
||||||
logging.DEBUG: "\033[36m",
|
|
||||||
logging.INFO: "\033[32m",
|
|
||||||
logging.WARNING: "\033[33m",
|
|
||||||
logging.ERROR: "\033[31m",
|
|
||||||
logging.CRITICAL: "\033[35m",
|
|
||||||
}
|
|
||||||
_reset = "\033[0m"
|
|
||||||
|
|
||||||
def format(self, record: logging.LogRecord) -> str:
|
|
||||||
color = self._colors.get(record.levelno, "")
|
|
||||||
orig_levelname = record.levelname
|
|
||||||
record.levelname = f"{color}{record.levelname}{self._reset}"
|
|
||||||
result = super().format(record)
|
|
||||||
record.levelname = orig_levelname
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(
|
|
||||||
level: int = logging.INFO,
|
|
||||||
log_dir: str = None,
|
|
||||||
log_file: bool = True,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
初始化项目统一日志配置。只需在入口调用一次。
|
|
||||||
|
|
||||||
Args:
|
|
||||||
level: 日志级别,默认 INFO
|
|
||||||
log_dir: 日志文件目录,默认 app/logs/
|
|
||||||
log_file: 是否同时输出到文件,默认 True
|
|
||||||
"""
|
|
||||||
global _initialized
|
|
||||||
if _initialized:
|
|
||||||
return
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.setLevel(level)
|
|
||||||
logger.handlers.clear()
|
|
||||||
|
|
||||||
console_handler = logging.StreamHandler(sys.stdout)
|
|
||||||
console_handler.setLevel(level)
|
|
||||||
console_handler.setFormatter(_ColoredFormatter(_console_fmt, datefmt=_date_fmt))
|
|
||||||
logger.addHandler(console_handler)
|
|
||||||
|
|
||||||
if log_file:
|
|
||||||
if log_dir is None:
|
|
||||||
log_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "logs")
|
|
||||||
os.makedirs(log_dir, exist_ok=True)
|
|
||||||
log_path = os.path.join(log_dir, f"app_{datetime.now().strftime('%Y%m%d')}.log")
|
|
||||||
file_handler = logging.handlers.RotatingFileHandler(
|
|
||||||
log_path, maxBytes=5 * 1024 * 1024, backupCount=5, encoding="utf-8"
|
|
||||||
)
|
|
||||||
file_handler.setLevel(logging.DEBUG)
|
|
||||||
file_handler.setFormatter(logging.Formatter(_file_fmt, datefmt=_date_fmt))
|
|
||||||
logger.addHandler(file_handler)
|
|
||||||
|
|
||||||
_initialized = True
|
|
||||||
|
|
||||||
|
|
||||||
def get_logger(name: str) -> logging.Logger:
|
|
||||||
"""获取模块级 logger,用法:logger = get_logger(__name__)"""
|
|
||||||
return logging.getLogger(name)
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# 37du 新中心机控制面(cool-admin-midway + art-design-pro)本地开发忽略
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
*.log
|
||||||
|
.cache/
|
||||||
|
# MySQL/Redis 便携运行环境(含数据)不入库,实际安装位置 D:\work\env\(Windows 服务 37duMySQL / redis37du)
|
||||||
|
/mysql/
|
||||||
|
/redis/
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
*.html linguist-detectable=false
|
||||||
|
*.vue linguist-detectable=true
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
.cursorrules
|
||||||
|
|
||||||
|
# Auto-generated files
|
||||||
|
src/types/import/auto-imports.d.ts
|
||||||
|
src/types/import/components.d.ts
|
||||||
|
.auto-import.json
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pnpm dlx commitlint --edit $1
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pnpm run lint:lint-staged
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/node_modules/*
|
||||||
|
/dist/*
|
||||||
|
/src/main.ts
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 100,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false,
|
||||||
|
"vueIndentScriptAndStyle": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"quoteProps": "as-needed",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSameLine": false,
|
||||||
|
"jsxSingleQuote": false,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"insertPragma": false,
|
||||||
|
"requirePragma": false,
|
||||||
|
"proseWrap": "never",
|
||||||
|
"htmlWhitespaceSensitivity": "strict",
|
||||||
|
"endOfLine": "auto",
|
||||||
|
"rangeStart": 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
public
|
||||||
|
.husky
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
src/components/Layout/MenuLeft/index.vue
|
||||||
|
src/assets
|
||||||
|
stats.html
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
module.exports = {
|
||||||
|
// 继承推荐规范配置
|
||||||
|
extends: [
|
||||||
|
'stylelint-config-standard',
|
||||||
|
'stylelint-config-recommended-scss',
|
||||||
|
'stylelint-config-recommended-vue/scss',
|
||||||
|
'stylelint-config-html/vue',
|
||||||
|
'stylelint-config-recess-order'
|
||||||
|
],
|
||||||
|
// 指定不同文件对应的解析器
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ['**/*.{vue,html}'],
|
||||||
|
customSyntax: 'postcss-html'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['**/*.{css,scss}'],
|
||||||
|
customSyntax: 'postcss-scss'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// 自定义规则
|
||||||
|
rules: {
|
||||||
|
'import-notation': 'string', // 指定导入CSS文件的方式("string"|"url")
|
||||||
|
'selector-class-pattern': null, // 选择器类名命名规则
|
||||||
|
'custom-property-pattern': null, // 自定义属性命名规则
|
||||||
|
'keyframes-name-pattern': null, // 动画帧节点样式命名规则
|
||||||
|
'no-descending-specificity': null, // 允许无降序特异性
|
||||||
|
'no-empty-source': null, // 允许空样式
|
||||||
|
'property-no-vendor-prefix': null, // 允许属性前缀
|
||||||
|
// 允许 global 、export 、deep伪类
|
||||||
|
'selector-pseudo-class-no-unknown': [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
ignorePseudoClasses: ['global', 'export', 'deep']
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// 允许未知属性
|
||||||
|
'property-no-unknown': [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
ignoreProperties: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// 允许未知规则
|
||||||
|
'at-rule-no-unknown': [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
ignoreAtRules: [
|
||||||
|
'apply',
|
||||||
|
'use',
|
||||||
|
'mixin',
|
||||||
|
'include',
|
||||||
|
'extend',
|
||||||
|
'each',
|
||||||
|
'if',
|
||||||
|
'else',
|
||||||
|
'for',
|
||||||
|
'while',
|
||||||
|
'reference'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'scss/at-rule-no-unknown': [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
ignoreAtRules: [
|
||||||
|
'apply',
|
||||||
|
'use',
|
||||||
|
'mixin',
|
||||||
|
'include',
|
||||||
|
'extend',
|
||||||
|
'each',
|
||||||
|
'if',
|
||||||
|
'else',
|
||||||
|
'for',
|
||||||
|
'while',
|
||||||
|
'reference'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 SuperManTT
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
* commitlint 配置文件
|
||||||
|
* 文档
|
||||||
|
* https://commitlint.js.org/#/reference-rules
|
||||||
|
* https://cz-git.qbb.sh/zh/guide/
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
// 继承的规则
|
||||||
|
extends: ['@commitlint/config-conventional'],
|
||||||
|
// 自定义规则
|
||||||
|
rules: {
|
||||||
|
// 提交类型枚举,git提交type必须是以下类型
|
||||||
|
'type-enum': [
|
||||||
|
2,
|
||||||
|
'always',
|
||||||
|
[
|
||||||
|
'feat', // 新增功能
|
||||||
|
'fix', // 修复缺陷
|
||||||
|
'docs', // 文档变更
|
||||||
|
'style', // 代码格式(不影响功能,例如空格、分号等格式修正)
|
||||||
|
'refactor', // 代码重构(不包括 bug 修复、功能新增)
|
||||||
|
'perf', // 性能优化
|
||||||
|
'test', // 添加疏漏测试或已有测试改动
|
||||||
|
'build', // 构建流程、外部依赖变更(如升级 npm 包、修改 webpack 配置等)
|
||||||
|
'ci', // 修改 CI 配置、脚本
|
||||||
|
'revert', // 回滚 commit
|
||||||
|
'chore', // 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)
|
||||||
|
'wip' // 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'subject-case': [0] // subject大小写不做校验
|
||||||
|
},
|
||||||
|
|
||||||
|
prompt: {
|
||||||
|
messages: {
|
||||||
|
type: '选择你要提交的类型 :',
|
||||||
|
scope: '选择一个提交范围(可选):',
|
||||||
|
customScope: '请输入自定义的提交范围 :',
|
||||||
|
subject: '填写简短精炼的变更描述 :\n',
|
||||||
|
body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
|
||||||
|
breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
|
||||||
|
footerPrefixesSelect: '选择关联issue前缀(可选):',
|
||||||
|
customFooterPrefix: '输入自定义issue前缀 :',
|
||||||
|
footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
|
||||||
|
generatingByAI: '正在通过 AI 生成你的提交简短描述...',
|
||||||
|
generatedSelectByAI: '选择一个 AI 生成的简短描述:',
|
||||||
|
confirmCommit: '是否提交或修改commit ?'
|
||||||
|
},
|
||||||
|
// prettier-ignore
|
||||||
|
types: [
|
||||||
|
{ value: "feat", name: "feat: 新增功能" },
|
||||||
|
{ value: "fix", name: "fix: 修复缺陷" },
|
||||||
|
{ value: "docs", name: "docs: 文档变更" },
|
||||||
|
{ value: "style", name: "style: 代码格式(不影响功能,例如空格、分号等格式修正)" },
|
||||||
|
{ value: "refactor", name: "refactor: 代码重构(不包括 bug 修复、功能新增)" },
|
||||||
|
{ value: "perf", name: "perf: 性能优化" },
|
||||||
|
{ value: "test", name: "test: 添加疏漏测试或已有测试改动" },
|
||||||
|
{ value: "build", name: "build: 构建流程、外部依赖变更(如升级 npm 包、修改 vite 配置等)" },
|
||||||
|
{ value: "ci", name: "ci: 修改 CI 配置、脚本" },
|
||||||
|
{ value: "revert", name: "revert: 回滚 commit" },
|
||||||
|
{ value: "chore", name: "chore: 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)" },
|
||||||
|
],
|
||||||
|
useEmoji: true,
|
||||||
|
emojiAlign: 'center',
|
||||||
|
useAI: false,
|
||||||
|
aiNumber: 1,
|
||||||
|
themeColorCode: '',
|
||||||
|
scopes: [],
|
||||||
|
allowCustomScopes: true,
|
||||||
|
allowEmptyScopes: true,
|
||||||
|
customScopesAlign: 'bottom',
|
||||||
|
customScopesAlias: 'custom',
|
||||||
|
emptyScopesAlias: 'empty',
|
||||||
|
upperCaseSubject: false,
|
||||||
|
markBreakingChangeMode: false,
|
||||||
|
allowBreakingChanges: ['feat', 'fix'],
|
||||||
|
breaklineNumber: 100,
|
||||||
|
breaklineChar: '|',
|
||||||
|
skipQuestions: ['breaking', 'footerPrefix', 'footer'], // 跳过的步骤
|
||||||
|
issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES has been processed' }],
|
||||||
|
customIssuePrefixAlign: 'top',
|
||||||
|
emptyIssuePrefixAlias: 'skip',
|
||||||
|
customIssuePrefixAlias: 'custom',
|
||||||
|
allowCustomIssuePrefix: true,
|
||||||
|
allowEmptyIssuePrefix: true,
|
||||||
|
confirmColorize: true,
|
||||||
|
maxHeaderLength: Infinity,
|
||||||
|
maxSubjectLength: Infinity,
|
||||||
|
minSubjectLength: 0,
|
||||||
|
scopeOverrides: undefined,
|
||||||
|
defaultBody: '',
|
||||||
|
defaultIssues: '',
|
||||||
|
defaultScope: '',
|
||||||
|
defaultSubject: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// 从 URL 和路径模块中导入必要的功能
|
||||||
|
import fs from 'fs'
|
||||||
|
import path, { dirname } from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
// 从 ESLint 插件中导入推荐配置
|
||||||
|
import pluginJs from '@eslint/js'
|
||||||
|
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
|
||||||
|
import pluginVue from 'eslint-plugin-vue'
|
||||||
|
import globals from 'globals'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
|
||||||
|
// 使用 import.meta.url 获取当前模块的路径
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
|
// 读取 .auto-import.json 文件的内容,并将其解析为 JSON 对象
|
||||||
|
const autoImportConfig = JSON.parse(
|
||||||
|
fs.readFileSync(path.resolve(__dirname, '.auto-import.json'), 'utf-8')
|
||||||
|
)
|
||||||
|
|
||||||
|
export default [
|
||||||
|
// 指定文件匹配规则
|
||||||
|
{
|
||||||
|
files: ['**/*.{js,mjs,cjs,ts,tsx,vue}']
|
||||||
|
},
|
||||||
|
// 指定全局变量和环境
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
...globals.browser,
|
||||||
|
...globals.node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 扩展配置
|
||||||
|
pluginJs.configs.recommended,
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
...pluginVue.configs['flat/essential'],
|
||||||
|
// 自定义规则
|
||||||
|
{
|
||||||
|
// 针对所有 JavaScript、TypeScript 和 Vue 文件应用以下配置
|
||||||
|
files: ['**/*.{js,mjs,cjs,ts,tsx,vue}'],
|
||||||
|
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
// 合并从 autoImportConfig 中读取的全局变量配置
|
||||||
|
...autoImportConfig.globals,
|
||||||
|
// TypeScript 全局命名空间
|
||||||
|
Api: 'readonly'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
quotes: ['error', 'single'], // 使用单引号
|
||||||
|
semi: ['error', 'never'], // 语句末尾不加分号
|
||||||
|
'no-var': 'error', // 要求使用 let 或 const 而不是 var
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off', // 禁用 any 检查
|
||||||
|
'vue/multi-word-component-names': 'off', // 禁用对 Vue 组件名称的多词要求检查
|
||||||
|
'no-multiple-empty-lines': ['warn', { max: 1 }], // 不允许多个空行
|
||||||
|
'no-unexpected-multiline': 'error' // 禁止空余的多行
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// vue 规则
|
||||||
|
{
|
||||||
|
files: ['**/*.vue'],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: { parser: tseslint.parser }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 忽略文件
|
||||||
|
{
|
||||||
|
ignores: [
|
||||||
|
'node_modules',
|
||||||
|
'dist',
|
||||||
|
'public',
|
||||||
|
'.vscode/**',
|
||||||
|
'src/assets/**',
|
||||||
|
'src/utils/console.ts'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
// prettier 配置
|
||||||
|
eslintPluginPrettierRecommended
|
||||||
|
]
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>37du 控制台</title>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="37du 自动化平台控制台:插件分发、账号授权与运行监控"
|
||||||
|
/>
|
||||||
|
<link rel="shortcut icon" type="image/x-icon" href="src/assets/images/favicon.ico" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* 防止页面刷新时白屏的初始样式 */
|
||||||
|
html {
|
||||||
|
background-color: #fafbfc;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark {
|
||||||
|
background-color: #070707;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 初始化 html class 主题属性
|
||||||
|
;(function () {
|
||||||
|
try {
|
||||||
|
if (typeof Storage === 'undefined' || !window.localStorage) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const themeType = localStorage.getItem('sys-theme')
|
||||||
|
if (themeType === 'dark') {
|
||||||
|
document.documentElement.classList.add('dark')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to apply initial theme:', e)
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
{
|
||||||
|
"name": "art-design-pro",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.19.0",
|
||||||
|
"pnpm": ">=8.8.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite --open",
|
||||||
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
|
"serve": "vite preview",
|
||||||
|
"lint": "eslint",
|
||||||
|
"fix": "eslint --fix",
|
||||||
|
"lint:prettier": "prettier --write \"**/*.{js,cjs,ts,json,tsx,css,less,scss,vue,html,md}\"",
|
||||||
|
"lint:stylelint": "stylelint \"**/*.{css,scss,vue}\" --fix",
|
||||||
|
"lint:lint-staged": "lint-staged",
|
||||||
|
"prepare": "husky",
|
||||||
|
"commit": "git-cz",
|
||||||
|
"clean:dev": "tsx scripts/clean-dev.ts"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"commitizen": {
|
||||||
|
"path": "node_modules/cz-git"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{js,ts,mjs,mts,tsx}": [
|
||||||
|
"eslint --fix",
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{cjs,json,jsonc}": [
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.vue": [
|
||||||
|
"eslint --fix",
|
||||||
|
"stylelint --fix --allow-empty-input",
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{html,htm}": [
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{scss,css,less}": [
|
||||||
|
"stylelint --fix --allow-empty-input",
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{md,mdx}": [
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{yaml,yml}": [
|
||||||
|
"prettier --write"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@element-plus/icons-vue": "^2.3.2",
|
||||||
|
"@iconify/vue": "^5.0.0",
|
||||||
|
"@tailwindcss/vite": "^4.1.14",
|
||||||
|
"@vue/reactivity": "^3.5.21",
|
||||||
|
"@vueuse/core": "^13.9.0",
|
||||||
|
"@wangeditor/editor": "^5.1.23",
|
||||||
|
"@wangeditor/editor-for-vue": "next",
|
||||||
|
"axios": "^1.12.2",
|
||||||
|
"crypto-js": "^4.2.0",
|
||||||
|
"echarts": "^6.0.0",
|
||||||
|
"element-plus": "^2.11.2",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
|
"highlight.js": "^11.10.0",
|
||||||
|
"mitt": "^3.0.1",
|
||||||
|
"nprogress": "^0.2.0",
|
||||||
|
"ohash": "^2.0.11",
|
||||||
|
"pinia": "^3.0.3",
|
||||||
|
"pinia-plugin-persistedstate": "^4.3.0",
|
||||||
|
"qrcode.vue": "^3.6.0",
|
||||||
|
"tailwindcss": "^4.1.14",
|
||||||
|
"vue": "^3.5.21",
|
||||||
|
"vue-draggable-plus": "^0.6.0",
|
||||||
|
"vue-i18n": "^9.14.0",
|
||||||
|
"vue-router": "^4.5.1",
|
||||||
|
"xgplayer": "^3.0.20",
|
||||||
|
"xlsx": "^0.18.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^19.4.1",
|
||||||
|
"@commitlint/config-conventional": "^19.4.1",
|
||||||
|
"@eslint/js": "^9.9.1",
|
||||||
|
"@types/node": "^24.0.5",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^8.3.0",
|
||||||
|
"@typescript-eslint/parser": "^8.3.0",
|
||||||
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
|
"@vue/compiler-sfc": "^3.0.5",
|
||||||
|
"commitizen": "^4.3.0",
|
||||||
|
"cz-git": "^1.11.1",
|
||||||
|
"eslint": "^9.9.1",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
|
"eslint-plugin-vue": "^9.27.0",
|
||||||
|
"globals": "^15.9.0",
|
||||||
|
"husky": "^9.1.5",
|
||||||
|
"lint-staged": "^15.5.2",
|
||||||
|
"prettier": "^3.5.3",
|
||||||
|
"rollup-plugin-visualizer": "^5.12.0",
|
||||||
|
"sass": "^1.81.0",
|
||||||
|
"stylelint": "^16.20.0",
|
||||||
|
"stylelint-config-html": "^1.1.0",
|
||||||
|
"stylelint-config-recess-order": "^4.6.0",
|
||||||
|
"stylelint-config-recommended-scss": "^14.1.0",
|
||||||
|
"stylelint-config-recommended-vue": "^1.5.0",
|
||||||
|
"stylelint-config-standard": "^36.0.1",
|
||||||
|
"terser": "^5.36.0",
|
||||||
|
"tsx": "^4.20.3",
|
||||||
|
"typescript": "~5.6.3",
|
||||||
|
"typescript-eslint": "^8.9.0",
|
||||||
|
"unplugin-auto-import": "^20.2.0",
|
||||||
|
"unplugin-element-plus": "^0.10.0",
|
||||||
|
"unplugin-vue-components": "^29.1.0",
|
||||||
|
"vite": "^7.1.5",
|
||||||
|
"vite-plugin-compression": "^0.5.1",
|
||||||
|
"vite-plugin-vue-devtools": "^7.7.6",
|
||||||
|
"vue-demi": "^0.14.9",
|
||||||
|
"vue-img-cutter": "^3.0.5",
|
||||||
|
"vue-tsc": "~2.1.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
allowBuilds:
|
||||||
|
'@parcel/watcher': true
|
||||||
|
'@tailwindcss/oxide': true
|
||||||
|
core-js: true
|
||||||
|
es5-ext: true
|
||||||
|
esbuild: true
|
||||||
|
vue-demi: true
|
||||||
|
# pnpm 12 设置(onlyBuiltDependencies 从 package.json 移到这里)
|
||||||
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,838 @@
|
|||||||
|
// scripts/clean-dev.ts
|
||||||
|
import fs from 'fs/promises'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
|
// 现代化颜色主题
|
||||||
|
const theme = {
|
||||||
|
// 基础颜色
|
||||||
|
reset: '\x1b[0m',
|
||||||
|
bold: '\x1b[1m',
|
||||||
|
dim: '\x1b[2m',
|
||||||
|
|
||||||
|
// 前景色
|
||||||
|
primary: '\x1b[38;5;75m', // 亮蓝色
|
||||||
|
success: '\x1b[38;5;82m', // 亮绿色
|
||||||
|
warning: '\x1b[38;5;220m', // 亮黄色
|
||||||
|
error: '\x1b[38;5;196m', // 亮红色
|
||||||
|
info: '\x1b[38;5;159m', // 青色
|
||||||
|
purple: '\x1b[38;5;141m', // 紫色
|
||||||
|
orange: '\x1b[38;5;208m', // 橙色
|
||||||
|
gray: '\x1b[38;5;245m', // 灰色
|
||||||
|
white: '\x1b[38;5;255m', // 白色
|
||||||
|
|
||||||
|
// 背景色
|
||||||
|
bgDark: '\x1b[48;5;235m', // 深灰背景
|
||||||
|
bgBlue: '\x1b[48;5;24m', // 蓝色背景
|
||||||
|
bgGreen: '\x1b[48;5;22m', // 绿色背景
|
||||||
|
bgRed: '\x1b[48;5;52m' // 红色背景
|
||||||
|
}
|
||||||
|
|
||||||
|
// 现代化图标集
|
||||||
|
const icons = {
|
||||||
|
rocket: '🚀',
|
||||||
|
fire: '🔥',
|
||||||
|
star: '⭐',
|
||||||
|
gem: '💎',
|
||||||
|
crown: '👑',
|
||||||
|
magic: '✨',
|
||||||
|
warning: '⚠️',
|
||||||
|
success: '✅',
|
||||||
|
error: '❌',
|
||||||
|
info: 'ℹ️',
|
||||||
|
folder: '📁',
|
||||||
|
file: '📄',
|
||||||
|
image: '🖼️',
|
||||||
|
code: '💻',
|
||||||
|
data: '📊',
|
||||||
|
globe: '🌐',
|
||||||
|
map: '🗺️',
|
||||||
|
chat: '💬',
|
||||||
|
bolt: '⚡',
|
||||||
|
shield: '🛡️',
|
||||||
|
key: '🔑',
|
||||||
|
link: '🔗',
|
||||||
|
clean: '🧹',
|
||||||
|
trash: '🗑️',
|
||||||
|
check: '✓',
|
||||||
|
cross: '✗',
|
||||||
|
arrow: '→',
|
||||||
|
loading: '⏳'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化工具
|
||||||
|
const fmt = {
|
||||||
|
title: (text: string) => `${theme.bold}${theme.primary}${text}${theme.reset}`,
|
||||||
|
subtitle: (text: string) => `${theme.purple}${text}${theme.reset}`,
|
||||||
|
success: (text: string) => `${theme.success}${text}${theme.reset}`,
|
||||||
|
error: (text: string) => `${theme.error}${text}${theme.reset}`,
|
||||||
|
warning: (text: string) => `${theme.warning}${text}${theme.reset}`,
|
||||||
|
info: (text: string) => `${theme.info}${text}${theme.reset}`,
|
||||||
|
highlight: (text: string) => `${theme.bold}${theme.white}${text}${theme.reset}`,
|
||||||
|
dim: (text: string) => `${theme.dim}${theme.gray}${text}${theme.reset}`,
|
||||||
|
orange: (text: string) => `${theme.orange}${text}${theme.reset}`,
|
||||||
|
|
||||||
|
// 带背景的文本
|
||||||
|
badge: (text: string, bg: string = theme.bgBlue) =>
|
||||||
|
`${bg}${theme.white}${theme.bold} ${text} ${theme.reset}`,
|
||||||
|
|
||||||
|
// 渐变效果模拟
|
||||||
|
gradient: (text: string) => {
|
||||||
|
const colors = ['\x1b[38;5;75m', '\x1b[38;5;81m', '\x1b[38;5;87m', '\x1b[38;5;159m']
|
||||||
|
const chars = text.split('')
|
||||||
|
return chars.map((char, i) => `${colors[i % colors.length]}${char}`).join('') + theme.reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建现代化标题横幅
|
||||||
|
function createModernBanner() {
|
||||||
|
console.log()
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ╔══════════════════════════════════════════════════════════════════╗')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ║ ║')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
` ║ ${icons.rocket} ${fmt.title('ART DESIGN PRO')} ${fmt.subtitle('· 代码精简程序')} ${icons.magic} ║`
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
` ║ ${fmt.dim('为项目移除演示数据,快速切换至开发模式')} ║`
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ║ ║')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ╚══════════════════════════════════════════════════════════════════╝')
|
||||||
|
)
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建分割线
|
||||||
|
function createDivider(char = '─', color = theme.primary) {
|
||||||
|
console.log(`${color}${' ' + char.repeat(66)}${theme.reset}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建卡片样式容器
|
||||||
|
function createCard(title: string, content: string[]) {
|
||||||
|
console.log(` ${fmt.badge('', theme.bgBlue)} ${fmt.title(title)}`)
|
||||||
|
console.log()
|
||||||
|
content.forEach((line) => {
|
||||||
|
console.log(` ${line}`)
|
||||||
|
})
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 进度条动画
|
||||||
|
function createProgressBar(current: number, total: number, text: string, width = 40) {
|
||||||
|
const percentage = Math.round((current / total) * 100)
|
||||||
|
const filled = Math.round((current / total) * width)
|
||||||
|
const empty = width - filled
|
||||||
|
|
||||||
|
const filledBar = '█'.repeat(filled)
|
||||||
|
const emptyBar = '░'.repeat(empty)
|
||||||
|
|
||||||
|
process.stdout.write(
|
||||||
|
`\r ${fmt.info('进度')} [${theme.success}${filledBar}${theme.gray}${emptyBar}${theme.reset}] ${fmt.highlight(percentage + '%')})}`
|
||||||
|
)
|
||||||
|
|
||||||
|
if (current === total) {
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计信息
|
||||||
|
const stats = {
|
||||||
|
deletedFiles: 0,
|
||||||
|
deletedPaths: 0,
|
||||||
|
failedPaths: 0,
|
||||||
|
startTime: Date.now(),
|
||||||
|
totalFiles: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理目标
|
||||||
|
const targets = [
|
||||||
|
'README.md',
|
||||||
|
'README.zh-CN.md',
|
||||||
|
'CHANGELOG.md',
|
||||||
|
'CHANGELOG.zh-CN.md',
|
||||||
|
'src/views/change',
|
||||||
|
'src/views/safeguard',
|
||||||
|
'src/views/article',
|
||||||
|
'src/views/examples',
|
||||||
|
'src/views/system/nested',
|
||||||
|
'src/views/widgets',
|
||||||
|
'src/views/template',
|
||||||
|
'src/views/dashboard/analysis',
|
||||||
|
'src/views/dashboard/ecommerce',
|
||||||
|
'src/mock/json',
|
||||||
|
'src/mock/temp/articleList.ts',
|
||||||
|
'src/mock/temp/commentDetail.ts',
|
||||||
|
'src/mock/temp/commentList.ts',
|
||||||
|
'src/assets/images/cover',
|
||||||
|
'src/assets/images/safeguard',
|
||||||
|
'src/assets/images/3d',
|
||||||
|
'src/components/core/charts/art-map-chart',
|
||||||
|
'src/components/business/comment-widget'
|
||||||
|
]
|
||||||
|
|
||||||
|
// 递归统计文件数量
|
||||||
|
async function countFiles(targetPath: string): Promise<number> {
|
||||||
|
const fullPath = path.resolve(process.cwd(), targetPath)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const stat = await fs.stat(fullPath)
|
||||||
|
|
||||||
|
if (stat.isFile()) {
|
||||||
|
return 1
|
||||||
|
} else if (stat.isDirectory()) {
|
||||||
|
const entries = await fs.readdir(fullPath)
|
||||||
|
let count = 0
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
const entryPath = path.join(targetPath, entry)
|
||||||
|
count += await countFiles(entryPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计所有目标的文件数量
|
||||||
|
async function countAllFiles(): Promise<number> {
|
||||||
|
let totalCount = 0
|
||||||
|
|
||||||
|
for (const target of targets) {
|
||||||
|
const count = await countFiles(target)
|
||||||
|
totalCount += count
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalCount
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除文件和目录
|
||||||
|
async function remove(targetPath: string, index: number) {
|
||||||
|
const fullPath = path.resolve(process.cwd(), targetPath)
|
||||||
|
|
||||||
|
createProgressBar(index + 1, targets.length, targetPath)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const fileCount = await countFiles(targetPath)
|
||||||
|
await fs.rm(fullPath, { recursive: true, force: true })
|
||||||
|
stats.deletedFiles += fileCount
|
||||||
|
stats.deletedPaths++
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||||
|
} catch (err) {
|
||||||
|
stats.failedPaths++
|
||||||
|
console.log()
|
||||||
|
console.log(` ${icons.error} ${fmt.error('删除失败')}: ${fmt.highlight(targetPath)}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理路由模块
|
||||||
|
async function cleanRouteModules() {
|
||||||
|
const modulesPath = path.resolve(process.cwd(), 'src/router/modules')
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 删除演示相关的路由模块
|
||||||
|
const modulesToRemove = [
|
||||||
|
'template.ts',
|
||||||
|
'widgets.ts',
|
||||||
|
'examples.ts',
|
||||||
|
'article.ts',
|
||||||
|
'safeguard.ts',
|
||||||
|
'help.ts'
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const module of modulesToRemove) {
|
||||||
|
const modulePath = path.join(modulesPath, module)
|
||||||
|
try {
|
||||||
|
await fs.rm(modulePath, { force: true })
|
||||||
|
} catch {
|
||||||
|
// 文件不存在时忽略错误
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重写 dashboard.ts - 只保留 console
|
||||||
|
const dashboardContent = `import { AppRouteRecord } from '@/types/router'
|
||||||
|
|
||||||
|
export const dashboardRoutes: AppRouteRecord = {
|
||||||
|
name: 'Dashboard',
|
||||||
|
path: '/dashboard',
|
||||||
|
component: '/index/index',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.dashboard.title',
|
||||||
|
icon: 'ri:pie-chart-line',
|
||||||
|
roles: ['R_SUPER', 'R_ADMIN']
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'console',
|
||||||
|
name: 'Console',
|
||||||
|
component: '/dashboard/console',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.dashboard.console',
|
||||||
|
keepAlive: false,
|
||||||
|
fixedTab: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
await fs.writeFile(path.join(modulesPath, 'dashboard.ts'), dashboardContent, 'utf-8')
|
||||||
|
|
||||||
|
// 重写 system.ts - 移除 nested 嵌套菜单
|
||||||
|
const systemContent = `import { AppRouteRecord } from '@/types/router'
|
||||||
|
|
||||||
|
export const systemRoutes: AppRouteRecord = {
|
||||||
|
path: '/system',
|
||||||
|
name: 'System',
|
||||||
|
component: '/index/index',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.system.title',
|
||||||
|
icon: 'ri:user-3-line',
|
||||||
|
roles: ['R_SUPER', 'R_ADMIN']
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'user',
|
||||||
|
name: 'User',
|
||||||
|
component: '/system/user',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.system.user',
|
||||||
|
keepAlive: true,
|
||||||
|
roles: ['R_SUPER', 'R_ADMIN']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'role',
|
||||||
|
name: 'Role',
|
||||||
|
component: '/system/role',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.system.role',
|
||||||
|
keepAlive: true,
|
||||||
|
roles: ['R_SUPER']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'user-center',
|
||||||
|
name: 'UserCenter',
|
||||||
|
component: '/system/user-center',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.system.userCenter',
|
||||||
|
isHide: true,
|
||||||
|
keepAlive: true,
|
||||||
|
isHideTab: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'menu',
|
||||||
|
name: 'Menus',
|
||||||
|
component: '/system/menu',
|
||||||
|
meta: {
|
||||||
|
title: 'menus.system.menu',
|
||||||
|
keepAlive: true,
|
||||||
|
roles: ['R_SUPER'],
|
||||||
|
authList: [
|
||||||
|
{ title: '新增', authMark: 'add' },
|
||||||
|
{ title: '编辑', authMark: 'edit' },
|
||||||
|
{ title: '删除', authMark: 'delete' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
await fs.writeFile(path.join(modulesPath, 'system.ts'), systemContent, 'utf-8')
|
||||||
|
|
||||||
|
// 重写 index.ts - 只导入保留的模块
|
||||||
|
const indexContent = `import { AppRouteRecord } from '@/types/router'
|
||||||
|
import { dashboardRoutes } from './dashboard'
|
||||||
|
import { systemRoutes } from './system'
|
||||||
|
import { resultRoutes } from './result'
|
||||||
|
import { exceptionRoutes } from './exception'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出所有模块化路由
|
||||||
|
*/
|
||||||
|
export const routeModules: AppRouteRecord[] = [
|
||||||
|
dashboardRoutes,
|
||||||
|
systemRoutes,
|
||||||
|
resultRoutes,
|
||||||
|
exceptionRoutes
|
||||||
|
]
|
||||||
|
`
|
||||||
|
await fs.writeFile(path.join(modulesPath, 'index.ts'), indexContent, 'utf-8')
|
||||||
|
|
||||||
|
console.log(` ${icons.success} ${fmt.success('清理路由模块完成')}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error('清理路由模块失败')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理路由别名
|
||||||
|
async function cleanRoutesAlias() {
|
||||||
|
const routesAliasPath = path.resolve(process.cwd(), 'src/router/routesAlias.ts')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cleanedAlias = `/**
|
||||||
|
* 公共路由别名
|
||||||
|
# 存放系统级公共路由路径,如布局容器、登录页等
|
||||||
|
*/
|
||||||
|
export enum RoutesAlias {
|
||||||
|
Layout = '/index/index', // 布局容器
|
||||||
|
Login = '/auth/login' // 登录页
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
await fs.writeFile(routesAliasPath, cleanedAlias, 'utf-8')
|
||||||
|
console.log(` ${icons.success} ${fmt.success('重写路由别名配置完成')}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error('清理路由别名失败')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理变更日志
|
||||||
|
async function cleanChangeLog() {
|
||||||
|
const changeLogPath = path.resolve(process.cwd(), 'src/mock/upgrade/changeLog.ts')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cleanedChangeLog = `import { ref } from 'vue'
|
||||||
|
|
||||||
|
interface UpgradeLog {
|
||||||
|
version: string // 版本号
|
||||||
|
title: string // 更新标题
|
||||||
|
date: string // 更新日期
|
||||||
|
detail?: string[] // 更新内容
|
||||||
|
requireReLogin?: boolean // 是否需要重新登录
|
||||||
|
remark?: string // 备注
|
||||||
|
}
|
||||||
|
|
||||||
|
export const upgradeLogList = ref<UpgradeLog[]>([])
|
||||||
|
`
|
||||||
|
|
||||||
|
await fs.writeFile(changeLogPath, cleanedChangeLog, 'utf-8')
|
||||||
|
console.log(` ${icons.success} ${fmt.success('清空变更日志数据完成')}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error('清理变更日志失败')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理语言文件
|
||||||
|
async function cleanLanguageFiles() {
|
||||||
|
const languageFiles = [
|
||||||
|
{ path: 'src/locales/langs/zh.json', name: '中文语言文件' },
|
||||||
|
{ path: 'src/locales/langs/en.json', name: '英文语言文件' }
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const { path: langPath, name } of languageFiles) {
|
||||||
|
try {
|
||||||
|
const fullPath = path.resolve(process.cwd(), langPath)
|
||||||
|
const content = await fs.readFile(fullPath, 'utf-8')
|
||||||
|
const langData = JSON.parse(content)
|
||||||
|
|
||||||
|
const menusToRemove = [
|
||||||
|
'widgets',
|
||||||
|
'template',
|
||||||
|
'article',
|
||||||
|
'examples',
|
||||||
|
'safeguard',
|
||||||
|
'plan',
|
||||||
|
'help'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (langData.menus) {
|
||||||
|
menusToRemove.forEach((menuKey) => {
|
||||||
|
if (langData.menus[menuKey]) {
|
||||||
|
delete langData.menus[menuKey]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (langData.menus.dashboard) {
|
||||||
|
if (langData.menus.dashboard.analysis) {
|
||||||
|
delete langData.menus.dashboard.analysis
|
||||||
|
}
|
||||||
|
if (langData.menus.dashboard.ecommerce) {
|
||||||
|
delete langData.menus.dashboard.ecommerce
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (langData.menus.system) {
|
||||||
|
const systemKeysToRemove = [
|
||||||
|
'nested',
|
||||||
|
'menu1',
|
||||||
|
'menu2',
|
||||||
|
'menu21',
|
||||||
|
'menu3',
|
||||||
|
'menu31',
|
||||||
|
'menu32',
|
||||||
|
'menu321'
|
||||||
|
]
|
||||||
|
systemKeysToRemove.forEach((key) => {
|
||||||
|
if (langData.menus.system[key]) {
|
||||||
|
delete langData.menus.system[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(fullPath, JSON.stringify(langData, null, 2), 'utf-8')
|
||||||
|
console.log(` ${icons.success} ${fmt.success(`清理${name}完成`)}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error(`清理${name}失败`)}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理快速入口组件
|
||||||
|
async function cleanFastEnterComponent() {
|
||||||
|
const fastEnterPath = path.resolve(process.cwd(), 'src/config/fastEnter.ts')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cleanedFastEnter = `/**
|
||||||
|
* 快速入口配置
|
||||||
|
* 包含:应用列表、快速链接等配置
|
||||||
|
*/
|
||||||
|
import { WEB_LINKS } from '@/utils/constants'
|
||||||
|
import type { FastEnterConfig } from '@/types/config'
|
||||||
|
|
||||||
|
const fastEnterConfig: FastEnterConfig = {
|
||||||
|
// 显示条件(屏幕宽度)
|
||||||
|
minWidth: 1200,
|
||||||
|
// 应用列表
|
||||||
|
applications: [
|
||||||
|
{
|
||||||
|
name: '工作台',
|
||||||
|
description: '系统概览与数据统计',
|
||||||
|
icon: 'ri:pie-chart-line',
|
||||||
|
iconColor: '#377dff',
|
||||||
|
enabled: true,
|
||||||
|
order: 1,
|
||||||
|
routeName: 'Console'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '官方文档',
|
||||||
|
description: '使用指南与开发文档',
|
||||||
|
icon: 'ri:bill-line',
|
||||||
|
iconColor: '#ffb100',
|
||||||
|
enabled: true,
|
||||||
|
order: 2,
|
||||||
|
link: WEB_LINKS.DOCS
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '技术支持',
|
||||||
|
description: '技术支持与问题反馈',
|
||||||
|
icon: 'ri:user-location-line',
|
||||||
|
iconColor: '#ff6b6b',
|
||||||
|
enabled: true,
|
||||||
|
order: 3,
|
||||||
|
link: WEB_LINKS.COMMUNITY
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '哔哩哔哩',
|
||||||
|
description: '技术分享与交流',
|
||||||
|
icon: 'ri:bilibili-line',
|
||||||
|
iconColor: '#FB7299',
|
||||||
|
enabled: true,
|
||||||
|
order: 4,
|
||||||
|
link: WEB_LINKS.BILIBILI
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// 快速链接
|
||||||
|
quickLinks: [
|
||||||
|
{
|
||||||
|
name: '登录',
|
||||||
|
enabled: true,
|
||||||
|
order: 1,
|
||||||
|
routeName: 'Login'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '注册',
|
||||||
|
enabled: true,
|
||||||
|
order: 2,
|
||||||
|
routeName: 'Register'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '忘记密码',
|
||||||
|
enabled: true,
|
||||||
|
order: 3,
|
||||||
|
routeName: 'ForgetPassword'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '个人中心',
|
||||||
|
enabled: true,
|
||||||
|
order: 4,
|
||||||
|
routeName: 'UserCenter'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Object.freeze(fastEnterConfig)
|
||||||
|
`
|
||||||
|
|
||||||
|
await fs.writeFile(fastEnterPath, cleanedFastEnter, 'utf-8')
|
||||||
|
console.log(` ${icons.success} ${fmt.success('清理快速入口配置完成')}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error('清理快速入口配置失败')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新菜单接口
|
||||||
|
async function updateMenuApi() {
|
||||||
|
const apiPath = path.resolve(process.cwd(), 'src/api/system-manage.ts')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const content = await fs.readFile(apiPath, 'utf-8')
|
||||||
|
const updatedContent = content.replace(
|
||||||
|
"url: '/api/v3/system/menus'",
|
||||||
|
"url: '/api/v3/system/menus/simple'"
|
||||||
|
)
|
||||||
|
|
||||||
|
await fs.writeFile(apiPath, updatedContent, 'utf-8')
|
||||||
|
console.log(` ${icons.success} ${fmt.success('更新菜单接口完成')}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(` ${icons.error} ${fmt.error('更新菜单接口失败')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户确认函数
|
||||||
|
async function getUserConfirmation(): Promise<boolean> {
|
||||||
|
const { createInterface } = await import('readline')
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const rl = createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
` ${fmt.highlight('请输入')} ${fmt.success('yes')} ${fmt.highlight('确认执行清理操作,或按 Enter 取消')}`
|
||||||
|
)
|
||||||
|
console.log()
|
||||||
|
process.stdout.write(` ${icons.arrow} `)
|
||||||
|
|
||||||
|
rl.question('', (answer: string) => {
|
||||||
|
rl.close()
|
||||||
|
resolve(answer.toLowerCase().trim() === 'yes')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示清理警告
|
||||||
|
async function showCleanupWarning() {
|
||||||
|
createCard('安全警告', [
|
||||||
|
`${fmt.warning('此操作将永久删除以下演示内容,且无法恢复!')}`,
|
||||||
|
`${fmt.dim('请仔细阅读清理列表,确认后再继续操作')}`
|
||||||
|
])
|
||||||
|
|
||||||
|
const cleanupItems = [
|
||||||
|
{
|
||||||
|
icon: icons.image,
|
||||||
|
name: '图片资源',
|
||||||
|
desc: '演示用的封面图片、3D图片、运维图片等',
|
||||||
|
color: theme.orange
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: icons.file,
|
||||||
|
name: '演示页面',
|
||||||
|
desc: 'widgets、template、article、examples、safeguard等页面',
|
||||||
|
color: theme.purple
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: icons.code,
|
||||||
|
name: '路由模块文件',
|
||||||
|
desc: '删除演示路由模块,只保留核心模块(dashboard、system、result、exception)',
|
||||||
|
color: theme.primary
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: icons.link,
|
||||||
|
name: '路由别名',
|
||||||
|
desc: '重写routesAlias.ts,移除演示路由别名',
|
||||||
|
color: theme.info
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: icons.data,
|
||||||
|
name: 'Mock数据',
|
||||||
|
desc: '演示用的JSON数据、文章列表、评论数据等',
|
||||||
|
color: theme.success
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: icons.globe,
|
||||||
|
name: '多语言文件',
|
||||||
|
desc: '清理中英文语言包中的演示菜单项',
|
||||||
|
color: theme.warning
|
||||||
|
},
|
||||||
|
{ icon: icons.map, name: '地图组件', desc: '移除art-map-chart地图组件', color: theme.error },
|
||||||
|
{ icon: icons.chat, name: '评论组件', desc: '移除comment-widget评论组件', color: theme.orange },
|
||||||
|
{
|
||||||
|
icon: icons.bolt,
|
||||||
|
name: '快速入口',
|
||||||
|
desc: '移除分析页、礼花效果、聊天、更新日志、定价、留言管理等无效项目',
|
||||||
|
color: theme.purple
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('', theme.bgRed)} ${fmt.title('将要清理的内容')}`)
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
cleanupItems.forEach((item, index) => {
|
||||||
|
console.log(` ${item.color}${theme.reset} ${fmt.highlight(`${index + 1}. ${item.name}`)}`)
|
||||||
|
console.log(` ${fmt.dim(item.desc)}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
console.log(` ${fmt.badge('', theme.bgGreen)} ${fmt.title('保留的功能模块')}`)
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
const preservedModules = [
|
||||||
|
{ name: 'Dashboard', desc: '工作台页面' },
|
||||||
|
{ name: 'System', desc: '系统管理模块' },
|
||||||
|
{ name: 'Result', desc: '结果页面' },
|
||||||
|
{ name: 'Exception', desc: '异常页面' },
|
||||||
|
{ name: 'Auth', desc: '登录注册功能' },
|
||||||
|
{ name: 'Core Components', desc: '核心组件库' }
|
||||||
|
]
|
||||||
|
|
||||||
|
preservedModules.forEach((module) => {
|
||||||
|
console.log(` ${icons.check} ${fmt.success(module.name)} ${fmt.dim(`- ${module.desc}`)}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
createDivider()
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示统计信息
|
||||||
|
async function showStats() {
|
||||||
|
const duration = Date.now() - stats.startTime
|
||||||
|
const seconds = (duration / 1000).toFixed(2)
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
createCard('清理统计', [
|
||||||
|
`${fmt.success('成功删除')}: ${fmt.highlight(stats.deletedFiles.toString())} 个文件`,
|
||||||
|
`${fmt.info('涉及路径')}: ${fmt.highlight(stats.deletedPaths.toString())} 个目录/文件`,
|
||||||
|
...(stats.failedPaths > 0
|
||||||
|
? [
|
||||||
|
`${icons.error} ${fmt.error('删除失败')}: ${fmt.highlight(stats.failedPaths.toString())} 个路径`
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
`${fmt.info('耗时')}: ${fmt.highlight(seconds)} 秒`
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建成功横幅
|
||||||
|
function createSuccessBanner() {
|
||||||
|
console.log()
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ╔══════════════════════════════════════════════════════════════════╗')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ║ ║')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
` ║ ${icons.star} ${fmt.success('清理完成!项目已准备就绪')} ${icons.rocket} ║`
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
` ║ ${fmt.dim('现在可以开始您的开发之旅了!')} ║`
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ║ ║')
|
||||||
|
)
|
||||||
|
console.log(
|
||||||
|
fmt.gradient(' ╚══════════════════════════════════════════════════════════════════╝')
|
||||||
|
)
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主函数
|
||||||
|
async function main() {
|
||||||
|
// 清屏并显示横幅
|
||||||
|
console.clear()
|
||||||
|
createModernBanner()
|
||||||
|
|
||||||
|
// 显示清理警告
|
||||||
|
await showCleanupWarning()
|
||||||
|
|
||||||
|
// 统计文件数量
|
||||||
|
console.log(` ${fmt.info('正在统计文件数量...')}`)
|
||||||
|
stats.totalFiles = await countAllFiles()
|
||||||
|
|
||||||
|
console.log(` ${fmt.info('即将清理')}: ${fmt.highlight(stats.totalFiles.toString())} 个文件`)
|
||||||
|
console.log(` ${fmt.dim(`涉及 ${targets.length} 个目录/文件路径`)}`)
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
// 用户确认
|
||||||
|
const confirmed = await getUserConfirmation()
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
console.log(` ${fmt.warning('操作已取消,清理中止')}`)
|
||||||
|
console.log()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
console.log(` ${icons.check} ${fmt.success('确认成功,开始清理...')}`)
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
// 开始清理过程
|
||||||
|
console.log(` ${fmt.badge('步骤 1/6', theme.bgBlue)} ${fmt.title('删除演示文件')}`)
|
||||||
|
console.log()
|
||||||
|
for (let i = 0; i < targets.length; i++) {
|
||||||
|
await remove(targets[i], i)
|
||||||
|
}
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 2/6', theme.bgBlue)} ${fmt.title('清理路由模块')}`)
|
||||||
|
console.log()
|
||||||
|
await cleanRouteModules()
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 3/6', theme.bgBlue)} ${fmt.title('重写路由别名')}`)
|
||||||
|
console.log()
|
||||||
|
await cleanRoutesAlias()
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 4/6', theme.bgBlue)} ${fmt.title('清空变更日志')}`)
|
||||||
|
console.log()
|
||||||
|
await cleanChangeLog()
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 5/6', theme.bgBlue)} ${fmt.title('清理语言文件')}`)
|
||||||
|
console.log()
|
||||||
|
await cleanLanguageFiles()
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 6/7', theme.bgBlue)} ${fmt.title('清理快速入口')}`)
|
||||||
|
console.log()
|
||||||
|
await cleanFastEnterComponent()
|
||||||
|
console.log()
|
||||||
|
|
||||||
|
console.log(` ${fmt.badge('步骤 7/7', theme.bgBlue)} ${fmt.title('更新菜单接口')}`)
|
||||||
|
console.log()
|
||||||
|
await updateMenuApi()
|
||||||
|
|
||||||
|
// 显示统计信息
|
||||||
|
await showStats()
|
||||||
|
|
||||||
|
// 显示成功横幅
|
||||||
|
createSuccessBanner()
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((err) => {
|
||||||
|
console.log()
|
||||||
|
console.log(` ${icons.error} ${fmt.error('清理脚本执行出错')}`)
|
||||||
|
console.log(` ${fmt.dim('错误详情: ' + err)}`)
|
||||||
|
console.log()
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<template>
|
||||||
|
<ElConfigProvider
|
||||||
|
size="default"
|
||||||
|
:locale="locales[language]"
|
||||||
|
:z-index="3000"
|
||||||
|
:card="{
|
||||||
|
shadow: 'never'
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<RouterView></RouterView>
|
||||||
|
</ElConfigProvider>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useUserStore } from './store/modules/user'
|
||||||
|
import zh from 'element-plus/es/locale/lang/zh-cn'
|
||||||
|
import en from 'element-plus/es/locale/lang/en'
|
||||||
|
import { systemUpgrade } from './utils/sys'
|
||||||
|
import { toggleTransition } from './utils/ui/animation'
|
||||||
|
import { checkStorageCompatibility } from './utils/storage'
|
||||||
|
import { initializeTheme } from './hooks/core/useTheme'
|
||||||
|
|
||||||
|
const userStore = useUserStore()
|
||||||
|
const { language } = storeToRefs(userStore)
|
||||||
|
|
||||||
|
const locales = {
|
||||||
|
zh: zh,
|
||||||
|
en: en
|
||||||
|
}
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
toggleTransition(true)
|
||||||
|
initializeTheme()
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
checkStorageCompatibility()
|
||||||
|
toggleTransition(false)
|
||||||
|
systemUpgrade()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import request from '@/utils/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证 API(37du 重构版,对接 cool-admin 后端 /api/admin/*)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 登录(统一账户,POST /api/admin/auth) */
|
||||||
|
export function fetchLogin(params: Api.Auth.LoginParams) {
|
||||||
|
return request.post<Api.Auth.LoginResponse>({
|
||||||
|
url: '/api/admin/auth',
|
||||||
|
data: { account: params.account, password: params.password }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前账号信息(GET /api/admin/me) */
|
||||||
|
export function fetchGetUserInfo() {
|
||||||
|
return request.get<Api.Auth.UserInfo>({
|
||||||
|
url: '/api/admin/me'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前账号的业务菜单树 + 权限标识(GET /api/admin/me/menus) */
|
||||||
|
export function fetchUserMenus() {
|
||||||
|
return request.get<Api.Auth.MenuData>({
|
||||||
|
url: '/api/admin/me/menus'
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import request from '@/utils/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 37du 控制台业务 API(对接 cool-admin 后端 /api/admin/*)
|
||||||
|
* 响应统一由请求层归一:cool-admin 信封 / 裸数据均返回业务数据本体
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 概览 */
|
||||||
|
export function fetchOverview() {
|
||||||
|
return request.get<any>({ url: '/api/admin/overview' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 数据看板 */
|
||||||
|
export function fetchStats() {
|
||||||
|
return request.get<any>({ url: '/api/admin/stats' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 插件列表 */
|
||||||
|
export function fetchPlugins(params: { page?: number; page_size?: number; q?: string }) {
|
||||||
|
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/plugins', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 上传发布插件包(multipart) */
|
||||||
|
export function uploadPlugin(file: File, params: { plugin_id: string; name?: string; version: string }) {
|
||||||
|
const fd = new FormData()
|
||||||
|
fd.append('file', file)
|
||||||
|
return request.post<any>({ url: '/api/admin/pkg', data: fd, params, timeout: 300000 })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除插件 */
|
||||||
|
export function deletePlugin(plugin_id: string) {
|
||||||
|
return request.post<any>({ url: '/api/admin/plugin/delete', data: { plugin_id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新插件元信息/状态/强制更新 */
|
||||||
|
export function patchPlugin(plugin_id: string, body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/plugin/patch', params: { plugin_id }, data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 账号列表 */
|
||||||
|
export function fetchAccounts(params: { page?: number; page_size?: number; q?: string }) {
|
||||||
|
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/accounts', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新建账号 */
|
||||||
|
export function createAccount(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新账号 */
|
||||||
|
export function updateAccount(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account/update', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置密码 */
|
||||||
|
export function resetAccountPwd(body: { account: string; new_password: string }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account/reset_pwd', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除账号 */
|
||||||
|
export function deleteAccount(account: string) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account/delete', data: { account } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 授权页数据(插件 + 账号) */
|
||||||
|
export function fetchGrantData() {
|
||||||
|
return request.get<{ plugins: any[]; accounts: any[] }>({ url: '/api/admin/grant_data' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 某账号授权明细 */
|
||||||
|
export function fetchAccountGrants(account: string) {
|
||||||
|
return request.get<any>({ url: '/api/admin/account_grants', params: { account } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 授予/撤销插件(granted=false 即撤销整行) */
|
||||||
|
export function grantPlugin(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account_plugins', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 授予/撤销平台 */
|
||||||
|
export function grantPlatform(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/account_platforms', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 双向批量授权(新授权工作台) ====================
|
||||||
|
|
||||||
|
/** 授权矩阵总览(账号 × 插件 + 平台白名单,一次拉全量) */
|
||||||
|
export function fetchGrantsMatrix() {
|
||||||
|
return request.get<any>({ url: '/api/admin/grants/matrix' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 插件维度:该插件已授权账号列表 */
|
||||||
|
export function fetchPluginGrants(pluginId: string) {
|
||||||
|
return request.get<any>({ url: '/api/admin/plugin_grants', params: { plugin_id: pluginId } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量授权/更新(事务 upsert) */
|
||||||
|
export function batchPluginGrants(body: { plugin_id: string; items: { account: string; can_download: boolean; can_run: boolean }[] }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/plugin_grants/batch', data: body, timeout: 60000 })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量撤销 */
|
||||||
|
export function revokePluginGrants(body: { plugin_id: string; accounts: string[] }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/plugin_grants/revoke', data: body, timeout: 60000 })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 审计日志 */
|
||||||
|
export function fetchAudit(params: { page?: number; page_size?: number; action?: string; q?: string }) {
|
||||||
|
return request.get<{ items: any[]; total: number; today: number }>({ url: '/api/admin/audit', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 运行记录 */
|
||||||
|
export function fetchReports(params: { page?: number; page_size?: number; status?: string; q?: string }) {
|
||||||
|
return request.get<{ items: any[]; total: number; today: number; failed: number }>({ url: '/api/admin/reports', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设备列表 */
|
||||||
|
export function fetchDevices(params: { page?: number; page_size?: number }) {
|
||||||
|
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/devices', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设备汇总(升级进度) */
|
||||||
|
export function fetchDevicesSummary() {
|
||||||
|
return request.get<any>({ url: '/api/admin/devices/summary' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 通知列表(管理) */
|
||||||
|
export function fetchNotifications(params: { page?: number; page_size?: number; q?: string }) {
|
||||||
|
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/notifications', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 最新有效通知(页眉通知中心,active 且未过期) */
|
||||||
|
export function fetchLatestNotifications(limit: number = 30) {
|
||||||
|
return request.get<{ items: any[] }>({ url: '/api/admin/notifications/latest', params: { limit } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建通知 */
|
||||||
|
export function createNotification(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/notifications', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 启停通知 */
|
||||||
|
export function toggleNotification(id: number, active: boolean) {
|
||||||
|
return request.put<any>({ url: `/api/admin/notifications/${id}`, params: { active } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除通知 */
|
||||||
|
export function deleteNotification(id: number) {
|
||||||
|
return request.del<any>({ url: `/api/admin/notifications/${id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 凭证管理列表 */
|
||||||
|
export function fetchCredsManage(params: { page?: number; page_size?: number }) {
|
||||||
|
return request.get<any>({ url: '/api/admin/creds/manage', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 录入凭证明文源 */
|
||||||
|
export function seedCreds(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/creds/seed', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 大文件源列表 */
|
||||||
|
export function fetchFileSources(params: { category?: string; page?: number; page_size?: number }) {
|
||||||
|
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/file-sources', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 登记/覆盖大文件源 */
|
||||||
|
export function upsertFileSource(body: any) {
|
||||||
|
return request.post<any>({ url: '/api/admin/file-sources', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 启停/改说明 */
|
||||||
|
export function patchFileSource(id: number, body: any) {
|
||||||
|
return request.put<any>({ url: `/api/admin/file-sources/${id}`, data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除大文件源 */
|
||||||
|
export function deleteFileSource(id: number) {
|
||||||
|
return request.del<any>({ url: `/api/admin/file-sources/${id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 个人中心(自助) ====================
|
||||||
|
|
||||||
|
/** 自助修改密码(旧密码校验,新密码≥8位,成功后 must_change_pwd 清零) */
|
||||||
|
export function changePassword(body: { account: string; old_password: string; new_password: string }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/password', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 上传头像(multipart,file 字段) */
|
||||||
|
export function uploadAvatar(file: File, account: string) {
|
||||||
|
const fd = new FormData()
|
||||||
|
fd.append('file', file)
|
||||||
|
return request.post<any>({ url: '/api/admin/avatar', data: fd, params: { account }, timeout: 30000 })
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
import request from '@/utils/http'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统管理 API(37du 控制台侧封装,走 /api/admin/sys/*)
|
||||||
|
* 身份统一为控制台管理员票据(requireAdmin),管理 cool-admin RBAC 表(base_sys_*)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 控制台用户(base_sys_user,含部门名/角色) */
|
||||||
|
export function sysUsers() {
|
||||||
|
return request.get<{ items: any[] }>({ url: '/api/admin/sys/users' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 角色 */
|
||||||
|
export function sysRoles() {
|
||||||
|
return request.get<{ items: any[] }>({ url: '/api/admin/sys/roles' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 菜单(树) */
|
||||||
|
export function sysMenus() {
|
||||||
|
return request.get<{ items: any[] }>({ url: '/api/admin/sys/menus' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 部门(树) */
|
||||||
|
export function sysDepartments() {
|
||||||
|
return request.get<{ items: any[] }>({ url: '/api/admin/sys/departments' })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 用户管理 ====================
|
||||||
|
|
||||||
|
/** 用户详情(含 roleIdList,不含密码) */
|
||||||
|
export function sysUserInfo(id: number) {
|
||||||
|
return request.get<any>({ url: '/api/admin/sys/user/info', params: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增用户 */
|
||||||
|
export function sysUserAdd(body: {
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
nickName?: string
|
||||||
|
name?: string
|
||||||
|
phone?: string
|
||||||
|
departmentId?: number | null
|
||||||
|
status?: number
|
||||||
|
roleIdList?: number[]
|
||||||
|
remark?: string
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/user/add', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑用户(username 不可改;password 留空不改) */
|
||||||
|
export function sysUserEdit(body: {
|
||||||
|
id: number
|
||||||
|
nickName?: string
|
||||||
|
name?: string
|
||||||
|
phone?: string
|
||||||
|
departmentId?: number | null
|
||||||
|
status?: number
|
||||||
|
roleIdList?: number[]
|
||||||
|
remark?: string
|
||||||
|
password?: string
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/user/edit', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除用户(内置 admin 保护) */
|
||||||
|
export function sysUserDel(id: number) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/user/del', data: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 角色管理 ====================
|
||||||
|
|
||||||
|
/** 角色详情(含 menuIdList/departmentIdList) */
|
||||||
|
export function sysRoleInfo(id: number) {
|
||||||
|
return request.get<any>({ url: '/api/admin/sys/role/info', params: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增角色(可带授权) */
|
||||||
|
export function sysRoleAdd(body: {
|
||||||
|
name: string
|
||||||
|
label?: string
|
||||||
|
remark?: string
|
||||||
|
relevance?: boolean
|
||||||
|
menuIdList?: number[]
|
||||||
|
departmentIdList?: number[]
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/role/add', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑角色(含授权) */
|
||||||
|
export function sysRoleEdit(body: {
|
||||||
|
id: number
|
||||||
|
name?: string
|
||||||
|
label?: string
|
||||||
|
remark?: string
|
||||||
|
relevance?: boolean
|
||||||
|
menuIdList?: number[]
|
||||||
|
departmentIdList?: number[]
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/role/edit', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除角色(内置超管保护) */
|
||||||
|
export function sysRoleDel(id: number) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/role/del', data: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 菜单管理 ====================
|
||||||
|
|
||||||
|
/** 新增菜单(type: 0目录 1菜单 2按钮) */
|
||||||
|
export function sysMenuAdd(body: {
|
||||||
|
parentId?: number | null
|
||||||
|
name: string
|
||||||
|
router?: string
|
||||||
|
perms?: string
|
||||||
|
icon?: string
|
||||||
|
type: number
|
||||||
|
orderNum?: number
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/menu/add', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑菜单 */
|
||||||
|
export function sysMenuEdit(body: {
|
||||||
|
id: number
|
||||||
|
parentId?: number | null
|
||||||
|
name?: string
|
||||||
|
router?: string
|
||||||
|
perms?: string
|
||||||
|
icon?: string
|
||||||
|
type?: number
|
||||||
|
orderNum?: number
|
||||||
|
}) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/menu/edit', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除菜单(有子级拒绝) */
|
||||||
|
export function sysMenuDel(id: number) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/menu/del', data: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 部门管理 ====================
|
||||||
|
|
||||||
|
/** 新增部门 */
|
||||||
|
export function sysDeptAdd(body: { parentId?: number | null; name: string; orderNum?: number }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/dept/add', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 编辑部门 */
|
||||||
|
export function sysDeptEdit(body: { id: number; parentId?: number | null; name?: string; orderNum?: number }) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/dept/edit', data: body })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除部门(有子级或在用用户拒绝) */
|
||||||
|
export function sysDeptDel(id: number) {
|
||||||
|
return request.post<any>({ url: '/api/admin/sys/dept/del', data: { id } })
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import request from '@/utils/http'
|
||||||
|
import { AppRouteRecord } from '@/types/router'
|
||||||
|
|
||||||
|
// 获取用户列表
|
||||||
|
export function fetchGetUserList(params: Api.SystemManage.UserSearchParams) {
|
||||||
|
return request.get<Api.SystemManage.UserList>({
|
||||||
|
url: '/api/user/list',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取角色列表
|
||||||
|
export function fetchGetRoleList(params: Api.SystemManage.RoleSearchParams) {
|
||||||
|
return request.get<Api.SystemManage.RoleList>({
|
||||||
|
url: '/api/role/list',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取菜单列表
|
||||||
|
export function fetchGetMenuList() {
|
||||||
|
return request.get<AppRouteRecord[]>({
|
||||||
|
url: '/api/v3/system/menus/simple'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 954 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 944 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 810 B |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 514 B |
|
After Width: | Height: | Size: 409 B |
|
After Width: | Height: | Size: 431 B |
|
After Width: | Height: | Size: 439 B |
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 286 B |
|
After Width: | Height: | Size: 293 B |
|
After Width: | Height: | Size: 448 B |
|
After Width: | Height: | Size: 416 B |
|
After Width: | Height: | Size: 509 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg viewBox="0 0 400 300" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="94" y="34" width="212" height="233"><path d="M306 34H94v233h212V34Z" fill="#fff"/></mask><g mask="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M234.427 155.64h38.36V69.6h-38.36v86.04ZM113.326 155.64h121.1V69.6h-121.1v86.04Z" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M130.126 155.354h104.2v-72.95h-104.2v72.95ZM236.369 71.05s0 3.3 1.65 5.05c2.33 2.52 7.38-.2 7.38-.2s-1.75 5.15-1.55 10.19c.29 8.24 6.99 9.51 10 4.75 4.56 4.85 8.94-.29 9.52-2.62 4.27 4.76 9.32-.87 9.32-.87v-6.3l-23.99-12.13-12.33 2.13Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M234.429 155.641h-121.1l-15.93 32.11h121.1l15.93-32.11Z" fill="#fff"/><path d="M234.427 69.6h38.46v86.04M113.326 146.52V69.6h121.1M234.429 155.641l-15.93 32.11h-121.1l15.93-32.11h111.39" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M226.37 159.715H116.82l-12.04 23.86H215l11.37-23.86Z" fill="#006EFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="m288.807 187.751-15.92-32.11h-38.46l16.02 32.11h38.36Z" fill="#fff"/><path d="m238.607 163.981 11.84 23.77h38.36l-15.92-32.11h-38.46" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M207.336 223.734c-3.69-13.77-15.44-23.86-29.33-23.86h-8.65s-27.09 14.94-27.09 33.27c0 18.34 25.44 33.18 25.44 33.18h10.4c13.79-.1 25.44-10.19 29.13-23.87 1.75-12.51 0-18.62.1-18.72Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M243.459 240.421c3.98 0 7.28-3.3 7.28-7.27 0-3.98-3.3-7.28-7.28-7.28h-31.08c-3.98 0-7.28 3.3-7.28 7.28 0 3.97 3.3 7.27 7.28 7.27h31.08Z" fill="#C7DEFF"/><path d="M210.342 223.737c-4.08-13.87-16.9-23.96-32.05-23.96H168.972s-29.62 14.94-29.62 33.37 27.87 33.37 27.87 33.37h11.27c15.05-.1 27.77-10.19 31.75-23.96" stroke="#071F4D"/><path d="M212.379 240.421c-3.98 0-7.28-3.3-7.28-7.27m0 0c0-3.98 3.3-7.28 7.28-7.28" stroke="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M168.781 199.777c-18.45 0-33.41 14.94-33.41 33.37s14.96 33.37 33.41 33.37c18.45 0 33.4-14.94 33.4-33.37s-14.95-33.37-33.4-33.37Z" fill="#006EFF"/><path d="M168.781 199.777c-18.45 0-33.41 14.94-33.41 33.37s14.96 33.37 33.41 33.37c18.45 0 33.4-14.94 33.4-33.37s-14.95-33.37-33.4-33.37Z" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M168.775 209.38c-13.14 0-23.79 10.64-23.79 23.77 0 13.12 10.65 23.76 23.79 23.76 13.14 0 23.8-10.64 23.8-23.76 0-13.13-10.66-23.77-23.8-23.77Z" fill="#00E4E5"/><path d="M162.174 223.736a17.48 17.48 0 0 1 14.76-8.05M159.455 231.982c.1-1.36.29-2.62.68-3.88" stroke="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M173.535 209.87c-1.55-.3-3.11-.49-4.76-.49-13.11 0-23.79 10.67-23.79 23.77 0 13.09 10.68 23.76 23.79 23.76 1.65 0 3.21-.19 4.76-.48-10.88-2.23-19.03-11.84-19.03-23.28 0-11.45 8.15-21.05 19.03-23.28Z" fill="#071F4D"/><path d="M219.957 225.774h23.6c4.08 0 7.38 3.3 7.38 7.37m0 0c0 4.08-3.3 7.37-7.38 7.37h-20.1M212.091 225.774h3.3" stroke="#071F4D"/><path d="m248.894 34.485-.19 18.24c0 4.07-.39 5.23-2.14 6.79-8.15 6.88-10.97 9.02-9.22 12.9 1.45 3.2 6.79 2.23 9.61-1.55-.39 4.56-5.24 15.32-.58 18.04 4.37 2.52 6.89-3.49 6.89-3.49s.49 3.49 4.47 3.49c3.69 0 5.24-4.75 5.24-4.75s2.14 3.49 6.22 1.35c3.11-1.55 5.44-7.08 5.44-26.67v-24.35" fill="#fff"/><path d="m248.894 34.485-.19 18.24c0 4.07-.39 5.23-2.14 6.79-8.15 6.88-10.97 9.02-9.22 12.9 1.45 3.2 6.79 2.23 9.61-1.55-.39 4.56-5.24 15.32-.58 18.04 4.37 2.52 6.89-3.49 6.89-3.49s.49 3.49 4.47 3.49c3.69 0 5.24-4.75 5.24-4.75s2.14 3.49 6.22 1.35c3.11-1.55 5.44-7.08 5.44-26.67v-24.35" stroke="#071F4D"/><path d="M255.307 75.71s-.39 5.43-2.04 9.6l2.04-9.6Z" fill="#fff"/><path d="M255.307 75.71s-.39 5.43-2.04 9.6" stroke="#071F4D"/><path d="M264.921 75.323s-.68 5.24-2.04 8.63l2.04-8.63Z" fill="#fff"/><path d="M264.921 75.323s-.68 5.24-2.04 8.63M147.801 34.485v34.92M121.775 34.485v34.92M102.546 204.724v13.97M102.546 222.379v.87M102.546 197.934v3.49M115.268 206.955v26.29M115.268 239.451v5.34M244.43 197.643v11.93M244.43 213.939v3.49M270.359 201.232v33.76M115.369 47.774h-13.6M94.486 47.774h3.4M241.516 47.774h-84.1M280.168 47.774h25.35" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m282.497 183.575-12.04-23.86h-27.29l11.36 23.86h27.97Z" fill="#00E4E5"/><path d="M234.427 134.88V69.6M234.427 140.412v7.66" stroke="#071F4D"/><path d="M220.831 228.684h16.99M240.934 228.684h2.43" stroke="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="m223.842 187.462 21.46-.2-10.97-20.66-10.49 20.86Z" fill="#071F4D"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<svg
|
||||||
|
viewBox="0 0 400 300"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="47" y="38" width="307" height="224"><path d="M353.3 38H47.5v223.8h305.8V38Z" fill="#fff"/></mask><g mask="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M299.2 200.6H61.6v5.1h240.3l-2.7-5.1Z" fill="#C7DEFF"/><path d="m308.9 185.8-6.5 20H183.7M332.3 127.6h10.6l-5 16.7-14.8-.1-7.2 21.1M328.8 127.4l13.6-39.6M307.6 166 337 84.7H180.6l-9.8 26.9h-10.5M296.6 196l4.3-11.8M157.2 149.2l6.4-17.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-34.8 95.8h136.4l34.7-95.8ZM169.9 166.2l5-13.6-5 13.6Z" fill="#fff"/><path d="m169.9 166.2 5-13.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-4 11.7h135.8l4.5-11.7Z" fill="#006EFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M102.6 159.5h38.3l2.7 36.6h-38.4c-10.1 0-20.9-8.2-20.9-18.3 0-10.1 8.2-18.3 18.3-18.3Z" fill="#DEEBFC"/><path fill-rule="evenodd" clip-rule="evenodd" d="M84.3 174.102c2.5 3.4 10 5 17.9 2.8 16.6-6.5 23.8-3.9 23.8-3.9s.5-3.4 1.3-5c-5.8-3-15.4.3-26.1 3.1-10.7 2.8-15.8-2.5-15.8-2.5-.4 0-1.1 2.8-1.1 5.5Z" fill="#fff"/><path d="M96.5 194.2c-7.2-3.3-12.2-10.5-12.2-19m0 0c0-11.5 9.3-20.8 20.8-20.8h29.4" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8l14.5 19.8Zm-14.5-19.8c0-11.5 9.3-20.8 20.8-20.8l-20.8 20.8Zm20.8-20.8c11.5 0 20.8 9.3 20.8 20.8l-20.8-20.8Zm20.8 20.8c0 8.4-5 15.6-12.1 18.9l12.1-18.9Z" fill="#fff"/><path d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8m0 0c0-11.5 9.3-20.8 20.8-20.8m0 0c11.5 0 20.8 9.3 20.8 20.8m0 0c0 8.4-5 15.6-12.1 18.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M161.5 177.2c0-7.7-6.3-14-14-14s-14 6.3-14 14c0 5.8 3.5 10.8 8.6 12.9.1 0 5.8 1.6 10.7 0 5.3-1.7 8.7-7.1 8.7-12.9Z" fill="#00E4E5"/><path d="M140.5 190.1c-5.8-2.4-9.9-8.2-9.9-14.9 0-8.9 7.2-16.1 16.1-16.1 8.9 0 16.1 7.2 16.1 16.1 0 6.8-4.2 12.5-10.1 14.9M88.4 170.604c2.9 1.3 7.7 2.6 13.6.3 14.7-5.7 22.3-4.3 24.6-3.5M84.5 174.599s5.9 6.5 19 1.7c9.2-3.4 15.3-3.9 18.8-3.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M340.6 112.3h-55.2l-2.7 6.2H338l2.6-6.2Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M236.8 117.9c-16.13 0-29.2 13.07-29.2 29.2s13.07 29.2 29.2 29.2 29.2-13.07 29.2-29.2-13.07-29.2-29.2-29.2Z" fill="#00E4E5"/><path d="M265 123.3c13.1 13.1 13.1 34.4 0 47.6M306 205.9h19.2M61.7 205.9h32.9M181.2 196.2h115.2M47.5 205.9h10v-9.7h73.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M146.7 179.2c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M169.5 196.2c3.9 0 7.1 3.2 7.1 7.1 0 3.9-3.2 7.1-7.1 7.1H144c-2.1 0-3.9 1.7-3.9 3.9v1c0 2.1 1.7 3.9 3.9 3.9h48c5.1 0 9.2 4.1 9.2 9.2s-4.1 9.3-9.2 9.2h-33.8c-2.3 0-4.1 1.8-4.1 4.1s1.8 4.1 4.1 4.1h4.2c4.4 0 8 3.6 8 8s-3.6 8-8 8H111c-3.7 0-6.8-3-6.8-6.8 0-3.7 3-6.8 6.8-6.8h.3c2.3 0 4.1-1.8 4.1-4.1s-1.8-4.1-4.1-4.1H79c-4.5 0-8.1-3.6-8.1-8.1s3.6-8.1 8.1-8.1h37.7c2.1 0 3.9-1.7 3.9-3.9 0-2.1-1.7-3.9-3.9-3.9h-7.9c-4.4 0-7.9-3.5-7.9-7.9s3.5-7.9 7.9-7.9h30.4c2.2 0 3.9-1.8 3.9-3.9V187c0-1.9 1.6-3.5 3.5-3.5s3.5 1.6 3.5 3.5v5.3c0 2.2 1.8 3.9 3.9 3.9h15.5Z" fill="#006EFF"/><path d="m227.8 138.5 18.7 18.7M227.8 157.2l18.7-18.7" stroke="#fff" stroke-width="6"/><path fill-rule="evenodd" clip-rule="evenodd" d="M194.8 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8ZM202.9 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8Z" fill="#fff"/><path d="m291.7 184.3-1.6 4.6h-121M298.1 166.7l22.5-61.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m193 134.1 2.2-5.1h-19.4l-2.3 5.1H193ZM313.2 123.5l2.2-5.1h-24.5l-2.3 5.1h24.6Z" fill="#DEEBFC"/><path d="m164.5 159.2 19.8-54.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M199.6 119.8h-53.2l-4.4 9.3h53.2l4.4-9.3Z" fill="#00E4E5"/><path d="M151.3 129.1H142l4.4-9.3h16.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M353.3 169.4h-67.4l-4.8 12.2h67.3l4.9-12.2Z" fill="#006EFF"/><path d="M332.4 169.4h20.9l-4.9 12.2h-39.7M242.7 235.5v-4.8c0-3.8 3.1-7 7-7h20.2c3.8 0 7 3.1 7 7" stroke="#071F4D"/><path d="M261.1 235.5v-4.8c0-3.8 3.1-7 7-7h13.7c3.8 0 7 3.1 7 7v4.8M242.6 230.7h13.7M235.2 237.7h63.3M224 237.7h6.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.1 141.3H335l3.3-10.7h-10.2l-4 10.7Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M288.3 230.4c0-3.6-2.9-6.5-6.5-6.5h-14.2c-3.6 0-6.5 2.9-6.5 6.5v5.3h27.2v-5.3Z" fill="#071F4D"/><path d="M80.4 228.5H83M87.7 228.5h19.2M146.3 195.8v2c0 3.6-2.9 6.6-6.6 6.6H138M133.4 204.3h1.5M154 249.9h9.4" stroke="#DEEBFC"/><path d="m299.4 141.9 5.1-13.9" stroke="#071F4D"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 4.8 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg viewBox="0 0 400 300" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="44" y="42" width="312" height="217"><path d="M355.3 42H44v216.9h311.3V42Z" fill="#fff"/></mask><g mask="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M288.2 248.4h25.1v-30h-25.1v30Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M304.498 238.199c-1.5-3.9-5.9-15.4-4-21.6-2.9.8-3.3.1-5-.1-1.7-.1 0 10.7 2.2 16.4 1.7 4.5 2.1 11.1 2.1 13.6h5.4c.2-1.9.3-5.5-.7-8.3Z" fill="#fff"/><path d="M311.5 214.7v-1.6c0-.7-.6-1.3-1.3-1.3h-22.8c-.7 0-1.3.6-1.3 1.3v1.6" fill="#fff"/><path d="M311.5 214.7v-1.6c0-.7-.6-1.3-1.3-1.3h-22.8c-.7 0-1.3.6-1.3 1.3v1.6M290.2 214.7h21.4c1 0 1.8.8 1.8 1.8v29" stroke="#071F4D" stroke-width="1.096"/><path d="M284.3 245.6v-29c0-1 .8-1.8 1.8-1.8h1.6" fill="#fff"/><path d="M284.3 245.6v-29c0-1 .8-1.8 1.8-1.8h1.6" stroke="#071F4D" stroke-width="1.096"/><path d="M295.402 216.5c-.9 4.2-.4 9.7 2.8 17.5 2.4 5.9 1.9 10.2 1.8 12.3M300.502 216.5c-.9 4.2-.4 9.7 2.8 17.5 2.4 5.9 1.9 10.2 1.8 12.3" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m331 258.4-.3-5.2H88.5l-1.2 5.2H331Z" fill="#C7DEFF"/><path d="M252.9 248.7H331M216.6 258.4H331M47.1 139.3l-2.6 1.5 42.7 117.6h129.2v-6.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m247.2 248.6-40.4-111.3H50.5l40.3 111.3h156.4Z" fill="#fff"/><path d="m247.2 248.6-40.4-111.3H50.5l40.3 111.3h156.4Z" stroke="#071F4D"/><path d="m203.2 153.2 32.2 88.7H97.8l-32.3-88.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M72.2 146.9c-.77 0-1.4.63-1.4 1.4 0 .77.63 1.4 1.4 1.4.77 0 1.4-.63 1.4-1.4 0-.77-.63-1.4-1.4-1.4ZM79.3 146.9c-.77 0-1.4.63-1.4 1.4 0 .77.63 1.4 1.4 1.4.77 0 1.4-.63 1.4-1.4 0-.77-.63-1.4-1.4-1.4Z" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M263.5 171.2h80.3v-63.7h-80.3v63.7Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M290 143.9h-45.6l12.5 51.3H290v-51.3Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M286 117.4h-29.3v77.8h92.9v-67.6l-55.9.6-7.7-10.8Z" fill="#00E4E5"/><path d="m332.6 127.6-38.9.6-7.7-10.8h-11.7M308.9 195.2h45.9M250.3 195.2h28.5M287.3 195.2h12.3" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M130.5 211.4H186v-44h-55.5v44Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M148.7 192.5h-31.6l8.7 35.5h22.9v-35.5Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M145.9 174.2h-20.2V228h64.1v-46.7l-38.6.4-5.3-7.5Z" fill="#006EFF"/><path d="m179 181.3-27.8.4-5.3-7.5h-7.7M176.2 201.7h19.2M163.2 210.7H195M172.1 228h-54.2M184.8 228h8.1M174.9 228h5.4" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m293.2 155.7-6.4 6.3 15.3 15.3 22.7-22.6-6.4-6.4-16.3 16.3-8.9-8.9Z" fill="#fff"/><path d="M57.2 258.4h283.6M345.9 258.4h8.1M55.4 258.4h220.5M160.1 118.8l-1.2 2.7M156.7 127c-.3.8-.7 1.8-1.1 2.8M222 68.5c-1 .2-1.9.5-2.9.8M214.1 70.7c-5.8 1.9-11.3 4.4-16.5 7.4M195.4 79.5c-.9.5-1.7 1.1-2.5 1.6M314.2 98.5c-.6-.8-1.3-1.5-2-2.3M308.9 92.8c-4-4-8.3-7.6-13-10.8M293.9 80.7c-.8-.5-1.7-1.1-2.5-1.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M251.296 71.203c-3.6-1.5-18.5-2.9-21.8-1.9-1 5.8 4.9 13.5 4.9 13.5s6-9.9 16.9-11.6Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M251.3 42.704c-6.5 6.7-7.8 13-8.8 19.3 24.4-1.1 36.3 13 42.8 20 3.2-9.1 7.8-23 7.2-29-7.1-6.4-20-11.7-41.2-10.3Z" fill="#C7DEFF"/><path d="M230 69.3c36.2-3.8 52 21.1 52 21.1s11.4-28.2 10.5-37.4c-7.3-6.5-23.3-12-45.6-10.1-9 6.3-15.6 18.7-16.9 26.4Z" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M161.604 70.7c-6 8.4-9.9 21.9-8.8 33.8 8.4 5.3 32.3 10.5 43.6 11.5 6.1-7.9 15.9-26 15.9-26s-32-4.8-50.7-19.3Z" fill="#C7DEFF"/><path d="M193.103 119.5c4.8-2.7 19.2-29.5 19.2-29.5s-35.8-5.4-53.7-21.8c-9.3 6.1-16.4 24.3-15 40.1 10.6 6.7 45.8 13.3 49.5 11.2Z" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M189.5 111.6c-3 5.2-5.7 7.2-9.8 6.6 12.2 2.6 13.5 1.2 15.6-1.1 2.2-2.4 4.2-6.6 4.2-6.6s-3.1 2.5-10 1.1Z" fill="#071F4D"/><path d="M331 251.8v6.6M77 165.4l-2.7-6.7h7.8M222.8 228.9l2.8 6.6h-7.9" stroke="#071F4D"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,292 @@
|
|||||||
|
// 全局样式
|
||||||
|
// 顶部进度条颜色
|
||||||
|
#nprogress .bar {
|
||||||
|
z-index: 2400;
|
||||||
|
background-color: color-mix(in srgb, var(--theme-color) 70%, white);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nprogress .peg {
|
||||||
|
box-shadow:
|
||||||
|
0 0 10px var(--theme-color),
|
||||||
|
0 0 5px var(--theme-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nprogress .spinner-icon {
|
||||||
|
border-top-color: var(--theme-color) !important;
|
||||||
|
border-left-color: var(--theme-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理移动端组件兼容性
|
||||||
|
@media screen and (max-width: 640px) {
|
||||||
|
* {
|
||||||
|
cursor: default !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 背景滤镜
|
||||||
|
*,
|
||||||
|
::before,
|
||||||
|
::after {
|
||||||
|
--tw-backdrop-blur: ;
|
||||||
|
--tw-backdrop-brightness: ;
|
||||||
|
--tw-backdrop-contrast: ;
|
||||||
|
--tw-backdrop-grayscale: ;
|
||||||
|
--tw-backdrop-hue-rotate: ;
|
||||||
|
--tw-backdrop-invert: ;
|
||||||
|
--tw-backdrop-opacity: ;
|
||||||
|
--tw-backdrop-saturate: ;
|
||||||
|
--tw-backdrop-sepia: ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 色弱模式
|
||||||
|
.color-weak {
|
||||||
|
filter: invert(80%);
|
||||||
|
-webkit-filter: invert(80%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#noop {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 语言切换选中样式
|
||||||
|
.langDropDownStyle {
|
||||||
|
// 选中项背景颜色
|
||||||
|
.is-selected {
|
||||||
|
background-color: var(--art-el-active-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 语言切换按钮菜单样式优化
|
||||||
|
.lang-btn-item {
|
||||||
|
.el-dropdown-menu__item {
|
||||||
|
padding-left: 13px !important;
|
||||||
|
padding-right: 6px !important;
|
||||||
|
margin-bottom: 3px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
.el-dropdown-menu__item {
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-txt {
|
||||||
|
min-width: 60px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
i {
|
||||||
|
font-size: 10px;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 盒子默认边框
|
||||||
|
.page-content {
|
||||||
|
border: 1px solid var(--art-card-border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin art-card-base($border-color, $shadow: none, $radius-diff: 4px) {
|
||||||
|
background: var(--default-box-color);
|
||||||
|
border: 1px solid #{$border-color} !important;
|
||||||
|
border-radius: calc(var(--custom-radius) + #{$radius-diff}) !important;
|
||||||
|
box-shadow: #{$shadow} !important;
|
||||||
|
|
||||||
|
--el-card-border-color: var(--default-border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card,
|
||||||
|
.art-card-sm,
|
||||||
|
.art-card-xs {
|
||||||
|
border: 1px solid var(--art-card-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 盒子边框
|
||||||
|
[data-box-mode='border-mode'] {
|
||||||
|
.page-content,
|
||||||
|
.art-table-card {
|
||||||
|
border: 1px solid var(--art-card-border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card {
|
||||||
|
@include art-card-base(var(--art-card-border), none, 4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card-sm {
|
||||||
|
@include art-card-base(var(--art-card-border), none, 0px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card-xs {
|
||||||
|
@include art-card-base(var(--art-card-border), none, -4px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 盒子阴影
|
||||||
|
[data-box-mode='shadow-mode'] {
|
||||||
|
.page-content,
|
||||||
|
.art-table-card {
|
||||||
|
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.04) !important;
|
||||||
|
border: 1px solid var(--art-gray-200) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-sidebar {
|
||||||
|
border-right: 1px solid var(--art-card-border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card {
|
||||||
|
@include art-card-base(
|
||||||
|
var(--art-gray-200),
|
||||||
|
(0 1px 3px 0 rgba(0, 0, 0, 0.03), 0 1px 2px -1px rgba(0, 0, 0, 0.08)),
|
||||||
|
4px
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card-sm {
|
||||||
|
@include art-card-base(
|
||||||
|
var(--art-gray-200),
|
||||||
|
(0 1px 3px 0 rgba(0, 0, 0, 0.03), 0 1px 2px -1px rgba(0, 0, 0, 0.08)),
|
||||||
|
2px
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-card-xs {
|
||||||
|
@include art-card-base(
|
||||||
|
var(--art-gray-200),
|
||||||
|
(0 1px 2px 0 rgba(0, 0, 0, 0.03), 0 1px 1px -1px rgba(0, 0, 0, 0.08)),
|
||||||
|
-4px
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 元素全屏
|
||||||
|
.el-full-screen {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 100vw !important;
|
||||||
|
height: 100% !important;
|
||||||
|
z-index: 2300;
|
||||||
|
margin-top: 0;
|
||||||
|
padding: 15px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-color: var(--default-box-color);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表格卡片
|
||||||
|
.art-table-card {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 12px;
|
||||||
|
border-radius: calc(var(--custom-radius) / 2 + 2px) !important;
|
||||||
|
|
||||||
|
.el-card__body {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 容器全高
|
||||||
|
.art-full-height {
|
||||||
|
height: var(--art-full-height);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 徽章样式
|
||||||
|
.art-badge {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 20px;
|
||||||
|
bottom: 0;
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
margin: auto;
|
||||||
|
background: #ff3860;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: breathe 1.5s ease-in-out infinite;
|
||||||
|
|
||||||
|
&.art-badge-horizontal {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.art-badge-mixed {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.art-badge-dual {
|
||||||
|
right: 5px;
|
||||||
|
top: 5px;
|
||||||
|
bottom: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文字徽章样式
|
||||||
|
.art-text-badge {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 12px;
|
||||||
|
bottom: 0;
|
||||||
|
min-width: 20px;
|
||||||
|
height: 18px;
|
||||||
|
line-height: 17px;
|
||||||
|
padding: 0 5px;
|
||||||
|
margin: auto;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
background: #fd4e4e;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes breathe {
|
||||||
|
0% {
|
||||||
|
opacity: 0.7;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0.7;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修复老机型 loading 定位问题
|
||||||
|
.art-loading-fix {
|
||||||
|
position: fixed !important;
|
||||||
|
top: 0 !important;
|
||||||
|
left: 0 !important;
|
||||||
|
right: 0 !important;
|
||||||
|
bottom: 0 !important;
|
||||||
|
width: 100vw !important;
|
||||||
|
height: 100vh !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
justify-content: center !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-loading-fix .el-loading-spinner {
|
||||||
|
position: static !important;
|
||||||
|
top: auto !important;
|
||||||
|
left: auto !important;
|
||||||
|
transform: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去除移动端点击背景色
|
||||||
|
@media screen and (max-width: 1180px) {
|
||||||
|
* {
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 深色主题
|
||||||
|
* 单页面移除深色主题 document.getElementsByTagName("html")[0].removeAttribute('class')
|
||||||
|
*/
|
||||||
|
|
||||||
|
$font-color: rgba(#ffffff, 0.85);
|
||||||
|
|
||||||
|
/* 覆盖element-plus默认深色背景色 */
|
||||||
|
html.dark {
|
||||||
|
// element-plus
|
||||||
|
--el-bg-color: var(--default-box-color);
|
||||||
|
--el-text-color-regular: #{$font-color};
|
||||||
|
|
||||||
|
// 富文本编辑器
|
||||||
|
// 工具栏背景颜色
|
||||||
|
--w-e-toolbar-bg-color: #18191c;
|
||||||
|
// 输入区域背景颜色
|
||||||
|
--w-e-textarea-bg-color: #090909;
|
||||||
|
// 工具栏文字颜色
|
||||||
|
--w-e-toolbar-color: var(--art-gray-600);
|
||||||
|
// 选中菜单颜色
|
||||||
|
--w-e-toolbar-active-bg-color: #25262b;
|
||||||
|
// 弹窗边框颜色
|
||||||
|
--w-e-toolbar-border-color: var(--default-border-dashed);
|
||||||
|
// 分割线颜色
|
||||||
|
--w-e-textarea-border-color: var(--default-border-dashed);
|
||||||
|
// 链接输入框边框颜色
|
||||||
|
--w-e-modal-button-border-color: var(--default-border-dashed);
|
||||||
|
// 表格头颜色
|
||||||
|
--w-e-textarea-slight-bg-color: #090909;
|
||||||
|
// 按钮背景颜色
|
||||||
|
--w-e-modal-button-bg-color: #090909;
|
||||||
|
// hover toolbar 背景颜色
|
||||||
|
--w-e-toolbar-active-color: var(--art-gray-800);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
.page-content .article-list .item .left .outer > div {
|
||||||
|
border-right-color: var(--dark-border-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 富文本编辑器
|
||||||
|
.editor-wrapper {
|
||||||
|
*:not(pre code *) {
|
||||||
|
color: inherit !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 分隔线
|
||||||
|
.w-e-bar-divider {
|
||||||
|
background-color: var(--art-gray-300) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.w-e-select-list,
|
||||||
|
.w-e-drop-panel,
|
||||||
|
.w-e-bar-item-group .w-e-bar-item-menus-container,
|
||||||
|
.w-e-text-container [data-slate-editor] pre > code {
|
||||||
|
border: 1px solid var(--default-border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下拉选择框
|
||||||
|
.w-e-select-list {
|
||||||
|
background-color: var(--default-box-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 下拉选择框 hover 样式调整 */
|
||||||
|
.w-e-select-list ul li:hover,
|
||||||
|
/* 工具栏 hover 按钮背景颜色 */
|
||||||
|
.w-e-bar-item button:hover {
|
||||||
|
background-color: #090909 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 代码块 */
|
||||||
|
.w-e-text-container [data-slate-editor] pre > code {
|
||||||
|
background-color: #25262b !important;
|
||||||
|
text-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 引用 */
|
||||||
|
.w-e-text-container [data-slate-editor] blockquote {
|
||||||
|
border-left: 4px solid var(--default-border-dashed) !important;
|
||||||
|
background-color: var(--art-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-wrapper {
|
||||||
|
.w-e-text-container [data-slate-editor] .table-container th:last-of-type {
|
||||||
|
border-right: 1px solid var(--default-border-dashed) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.w-e-modal {
|
||||||
|
background-color: var(--art-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// 导入暗黑主题
|
||||||
|
@use 'element-plus/theme-chalk/src/dark/css-vars.scss' as *;
|
||||||