hn-workflow-components 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,259 @@
1
- # Simple Workflow
1
+ # hn-workflow-components
2
+
3
+ 一个基于 React + TypeScript 的可视化工作流编排组件库,提供工作流编辑器与执行进度查看器两种模式。
4
+
5
+ [![React](https://img.shields.io/badge/React-%5E17.0.0%20%7C%20%5E18.0.0-blue)](https://react.dev/)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-%5E5.7.0-blue)](https://www.typescriptlang.org/)
7
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](./LICENSE)
8
+
9
+ ---
10
+
11
+ ## ✨ 功能特性
12
+
13
+ - 🎨 **可视化编排** — 拖拽式节点编辑,支持画布缩放与拖拽浏览
14
+ - 🔄 **撤销/重做** — 完整的操作历史栈(undo/redo)
15
+ - 🌲 **分支支持** — 条件分支、并行分支、包容分支三种分支类型
16
+ - 📊 **执行追踪** — 独立的进度查看器,支持节点状态着色与图例
17
+ - 🧩 **物料扩展** — 可自定义节点类型、属性面板与校验规则
18
+ - 🎭 **主题适配** — 支持 Ant Design 主题 token 注入与暗黑模式
19
+ - 📱 **响应式画布** — 自适应缩放,支持鼠标拖拽平移
20
+
21
+ ---
22
+
23
+ ## 📦 安装
24
+
25
+ ```bash
26
+ npm install hn-workflow-components
27
+ # 或
28
+ yarn add hn-workflow-components
29
+ # 或
30
+ pnpm add hn-workflow-components
31
+ ```
32
+
33
+ ### 对等依赖
34
+
35
+ 请确保项目中已安装以下依赖:
36
+
37
+ ```bash
38
+ npm install react react-dom antd styled-components @ant-design/icons
39
+ ```
40
+
41
+ > React 版本要求:>=17 <19
42
+
43
+ ---
44
+
45
+ ## 🚀 快速开始
46
+
47
+ ### 1. 工作流编辑器
48
+
49
+ 用于设计流程图,支持节点增删改、分支配置与保存发布。
50
+
51
+ ```tsx
52
+ import { WorkflowComponents } from 'hn-workflow-components'
53
+
54
+ function App() {
55
+ return (
56
+ <WorkflowComponents
57
+ processKey="leave-approval"
58
+ processName="请假审批流程"
59
+ baseUrl="https://api.example.com"
60
+ customHeaders={{
61
+ Authorization: 'Bearer xxx',
62
+ }}
63
+ />
64
+ )
65
+ }
66
+ ```
67
+
68
+ ### 2. 工作流查看器
69
+
70
+ 用于展示流程执行进度,节点按状态着色。
71
+
72
+ ```tsx
73
+ import { WorkflowViewerComponents } from 'hn-workflow-components'
74
+
75
+ function App() {
76
+ return (
77
+ <WorkflowViewerComponents
78
+ processKey="instance-123"
79
+ baseUrl="https://api.example.com"
80
+ statusColors={{
81
+ completed: '#52c41a',
82
+ processing: '#faad14',
83
+ pending: '#d9d9d9',
84
+ }}
85
+ />
86
+ )
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 📖 API 文档
93
+
94
+ ### WorkflowComponents(编辑器)
95
+
96
+ | 属性 | 类型 | 必填 | 说明 |
97
+ |------|------|------|------|
98
+ | `processKey` | `string` | ✅ | 流程定义唯一标识 |
99
+ | `processName` | `string` | ✅ | 流程显示名称 |
100
+ | `baseUrl` | `string` | ✅ | 后端 API 基础地址 |
101
+ | `customHeaders` | `Record<string, string>` | ❌ | 自定义请求头 |
102
+
103
+ ### WorkflowViewerComponents(查看器)
104
+
105
+ | 属性 | 类型 | 必填 | 说明 |
106
+ |------|------|------|------|
107
+ | `processKey` | `string` | ✅ | 流程实例标识(用于查询执行状态) |
108
+ | `baseUrl` | `string` | ✅ | 后端 API 基础地址 |
109
+ | `customHeaders` | `Record<string, string>` | ❌ | 自定义请求头 |
110
+ | `statusColors` | `StatusColors` | ❌ | 自定义状态颜色 |
111
+
112
+ ### StatusColors
113
+
114
+ ```ts
115
+ interface StatusColors {
116
+ completed?: string // 已处理(默认 #52c41a)
117
+ processing?: string // 处理中(默认 #faad14)
118
+ pending?: string // 待处理(默认 #d9d9d9)
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 🧩 内置节点类型
125
+
126
+ | 节点类型 | 说明 | 在物料板显示 |
127
+ |----------|------|--------------|
128
+ | `start` | 发起人节点 | ❌ |
129
+ | `approver` | 审批人 | ✅ |
130
+ | `notifier` | 抄送人 | ✅ |
131
+ | `exclusive` | 条件分支 | ✅ |
132
+ | `parallel` | 并行分支 | ✅ |
133
+ | `inclusive` | 包容分支 | ❌ |
134
+ | `subProcess` | 子流程 | ✅ |
135
+ | `dispatcher` | 分发节点 | ✅ |
136
+ | `message` | 消息通知 | ❌ |
137
+ | `service` | 服务节点 | ❌ |
138
+ | `asyncSubProcess` | 异步子流程 | ❌ |
139
+ | `trigger` | 触发器 | ❌ |
140
+
141
+ ---
142
+
143
+ ## 🏗️ 自定义物料与 UI
144
+
145
+ 如需自定义节点内容或属性面板,可通过 `materialUis` 传入:
146
+
147
+ ```tsx
148
+ import type { IMaterialUIs } from 'hn-workflow-components'
149
+
150
+ const myMaterialUis: IMaterialUIs = {
151
+ approver: {
152
+ // 节点卡片内容渲染
153
+ viewContent: (node) => (
154
+ <div>{node.config?.approverType === 'countersign' ? '会签' : '或签'}</div>
155
+ ),
156
+ // 校验规则
157
+ validate: (node, { t }) => {
158
+ if (!node.config?.groupType) {
159
+ return t('请选择审批人')
160
+ }
161
+ return true
162
+ },
163
+ },
164
+ }
165
+
166
+ // 在业务层封装中使用
167
+ <WorkflowComponents
168
+ processKey="xxx"
169
+ processName="xxx"
170
+ baseUrl="xxx"
171
+ />
172
+ ```
173
+
174
+ ---
175
+
176
+ ## 🔌 后端接口约定
177
+
178
+ 组件库内置调用以下接口,请确保后端按约定实现:
179
+
180
+ | 接口 | 方法 | 路径 | 说明 |
181
+ |------|------|------|------|
182
+ | 查询用户与角色 | POST | `/bpmn/approval/action/queryUserAndRoleData` | 获取可选审批人数据 |
183
+ | 获取流程定义 | POST | `/bpmn/json/getBpmnJson` | 根据 processKey 获取 JSON 流程图 |
184
+ | 获取执行状态 | POST | `/bpmn/process/queryBpmnJsonAndNodeStatus` | 获取节点执行状态 |
185
+ | 获取业务表单字段 | POST | `/bpmn/json/bizForm` | 用于条件配置 |
186
+ | 保存流程图 | POST | `/bpmn/json/saveBpmnJson` | 保存 JSON 流程定义 |
187
+ | 发布流程图 | POST | `/bpmn/json/bpmnJsonToXml` | 转换为 XML 并发布 |
188
+ | 查询版本历史 | POST | `/bpmn/json/queryBpmnJsonVersion` | 获取历史版本 |
189
+
190
+ ---
191
+
192
+ ## 🛠️ 本地开发
193
+
194
+ ```bash
195
+ # 克隆仓库
196
+ git clone <repo-url>
197
+ cd simple-workflow
198
+
199
+ # 安装依赖
200
+ pnpm install
201
+
202
+ # 启动开发服务器
203
+ pnpm dev
204
+
205
+ # 构建库
206
+ pnpm build:lib
207
+
208
+ # ESLint 检查
209
+ pnpm lint
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 📁 目录结构
215
+
216
+ ```
217
+ src/
218
+ ├── core/workflow-editor/ # 核心编辑器引擎
219
+ │ ├── classes/ # EditorEngine 状态管理类
220
+ │ ├── components/ # 通用 UI 组件(工具栏、表达式输入等)
221
+ │ ├── FlowEditor/ # 编辑器画布、物料板、设置面板
222
+ │ ├── ProgressViewer/ # 只读进度查看器
223
+ │ ├── nodes/ # 节点渲染组件(普通节点、分支节点等)
224
+ │ ├── interfaces/ # TypeScript 类型定义
225
+ │ ├── reducers/ # Redux 状态切片
226
+ │ ├── hooks/ # React Hooks
227
+ │ └── utils/ # 工具函数(API、UUID、颜色等)
228
+ ├── demo/ # 业务层封装(可直接使用的高阶组件)
229
+ │ ├── WorkflowEditor/ # 编辑器业务封装
230
+ │ ├── WorkflowViwer/ # 查看器业务封装
231
+ │ └── ShellContainer.tsx # 外壳容器
232
+ ├── index.ts # 库入口,导出 WorkflowComponents / WorkflowViewerComponents
233
+ └── App.tsx / main.tsx # 本地调试入口
234
+ ```
235
+
236
+ ---
237
+
238
+ ## ⚠️ 已知限制
239
+
240
+ - 当前仅支持 React 17/18,尚未适配 React 19
241
+ - 全局配置(`baseUrl`、`headers`)通过模块级变量存储,多实例场景下可能互相影响
242
+ - 分支节点标题硬编码截取前两个字符(如"添加条件分支" → "条件分支"),需确保 `getRouteNodeName` 返回格式一致
243
+ - 进度查看器尚未实现路由节点(`exclusive`/`parallel`/`inclusive`)的状态徽章展示
244
+
245
+ ---
246
+
247
+ ## 🤝 贡献
248
+
249
+ 欢迎提交 Issue 与 PR。提交前请确保:
250
+
251
+ 1. 代码通过 `pnpm lint` 检查
252
+ 2. 保持与现有代码风格一致
253
+ 3. 如涉及 UI 变动,请在 PR 中附截图
254
+
255
+ ---
256
+
257
+ ## 📄 License
258
+
259
+ [MIT](./LICENSE)