form-design-v3 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,186 @@
1
+ # form-design-v3
2
+
3
+ 流程表单设计器 / 渲染器(Vue3 + TypeScript),以 npm 包形式交付,支持两种使用方式:
4
+
5
+ - **插件方式**:注册全局组件 `<FdDesigner>`,用于表单设计页面
6
+ - **命令式渲染**:`renderForm(options)`,由宿主传入容器与数据直接挂载,用于表单运行态渲染
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ npm install form-design-v3
12
+ ```
13
+
14
+ peer 依赖(需宿主项目自行安装):
15
+
16
+ ```bash
17
+ npm install vue@^3.5.0 pinia@^2.3.0 element-plus@^2.14.0 lucide-vue-next@^1.0.0 monaco-editor@^0.56.0
18
+ ```
19
+
20
+ > `element-plus` 为局部按需引入(仅 `ElSelect` / `ElInputNumber` 等少量组件及对应样式);
21
+ > `monaco-editor` 仅在打开「编写处理函数」代码编辑器时按需加载。
22
+
23
+ ## 使用
24
+
25
+ ### 1. 设计器(插件方式)
26
+
27
+ ```ts
28
+ import { createApp } from 'vue'
29
+ import { createPinia } from 'pinia'
30
+ import DesignerPlugin from 'form-design-v3'
31
+ import 'form-design-v3/style.css' // 库构建不自动注入 CSS,必须显式引入
32
+ import App from './App.vue'
33
+ const app = createApp(App)
34
+ app.use(createPinia())
35
+ app.use(DesignerPlugin, {
36
+ // 可选:覆盖接口模块与基础模块,默认 apiModule = 'form-designer'
37
+ apiModule: 'form-designer',
38
+ baseModule: ''
39
+ })
40
+ app.mount('#app')
41
+ ```
42
+
43
+ ```vue
44
+ <template>
45
+ <!-- 表单 ID 也可通过 URL query ?id=xxx 传入(与后端 / 老设计器一致) -->
46
+ <FdDesigner :form-id="formId" />
47
+ </template>
48
+ ```
49
+
50
+ ### 2. 渲染器(命令式渲染)
51
+
52
+ ```ts
53
+ import { renderForm } from 'form-design-v3'
54
+ import 'form-design-v3/style.css'
55
+
56
+ const handle = renderForm({
57
+ container: document.getElementById('form')!,
58
+ widgets: schema.widgets, // 来自接口返回的表单 Schema
59
+ formMode: 'approval', // start / approval / view,缺省按控件配置全显
60
+ formData: { contract_no: 'HT20260001' },
61
+ events: schema.events, // 生命周期钩子 + 自定义事件
62
+ formId: schema.formId,
63
+ apiModule: 'form-designer', // 可选
64
+ baseModule: '' // 可选
65
+ })
66
+
67
+ handle.fireEvent('myCustomEvent', payload) // 触发自定义事件
68
+ handle.unmount() // 销毁实例
69
+ ```
70
+
71
+ ### 3. 渲染器(组件式渲染)
72
+
73
+ 适合需要注入宿主插槽内容(审批页头、操作栏等)的场景:直接使用 `Renderer` 组件,
74
+ 插槽控件渲染为 `<slot>`,宿主按 `slotName` 注入内容。
75
+
76
+ ```vue
77
+ <script setup lang="ts">
78
+ import { Renderer, loadFormFromLocal, type FormSchema } from 'form-design-v3'
79
+
80
+ // 本地调试:读取设计器保存的表单(localStorage 键 fd:form:{formId})
81
+ const schema: FormSchema | null = loadFormFromLocal(formId)
82
+ const formData = { contract_no: 'HT20260001' }
83
+ </script>
84
+
85
+ <template>
86
+ <Renderer
87
+ v-if="schema"
88
+ :form-id="schema.formId"
89
+ :widgets="schema.widgets"
90
+ :form-mode="'approval'"
91
+ :form-data="formData"
92
+ :events="schema.events"
93
+ >
94
+ <!-- 插槽名需与表单中「插槽」控件的 slotName 一致 -->
95
+ <template #header>
96
+ <ApprovalHeader />
97
+ </template>
98
+ <template #footer>
99
+ <ApprovalBar />
100
+ </template>
101
+ </Renderer>
102
+ </template>
103
+ ```
104
+
105
+ ### 4. 接口地址配置
106
+
107
+ 接口路径规则:`{baseUrl}/api/formdesigner/v1/{action}`(bpmapi 后端契约),默认 `baseUrl = '/bpmapi-uat'`。
108
+
109
+ ```ts
110
+ import { configureApi, setBaseUrl } from 'form-design-v3'
111
+
112
+ // 方式一:安装时配置(见上文插件安装的 baseUrl)
113
+ // 方式二:运行时覆盖
114
+ setBaseUrl('/bpmapi-test')
115
+ ```
116
+
117
+ 联调需在宿主 dev-server 配置 bpmapi 代理(后端无 CORS),详见
118
+ [docs/integration-assessment.md](./docs/integration-assessment.md) 第 6 章。
119
+
120
+ 接口文档已按设计态 / 运行态拆分:设计器接口见 [docs/designer-api.md](./docs/designer-api.md),渲染器接口见 [docs/renderer-api.md](./docs/renderer-api.md)。
121
+
122
+ ## 本地开发
123
+
124
+ ```bash
125
+ npm install
126
+ npm run dev # 设计器页面(8098 被占用时自动顺延)
127
+ ```
128
+
129
+ 联调地址(需 hosts 将 kapi.xincheng.com 指向 127.0.0.1):
130
+
131
+ ```
132
+ http://kapi.xincheng.com:8098/?id=<表单GUID>&FormVersion=<版本GUID>
133
+ ```
134
+
135
+ URL 参数:`id` 表单 ID(GUID,必填)、`FormVersion` 来源版本 ID、`openType`(`newEdit` 新建版本 / `edit` 编辑指定版本,**无默认值,缺省时后端返回「OpenType无效!」**;老写法 `OpenType` 亦可)、
136
+ `baseUrl` 接口前缀(默认 `/bpmapi-uat`,本地后端联调传 `/bpmapi-local`)。
137
+
138
+ **保存语义(按 API-backend.md 的 1+1+1 交互)**:
139
+
140
+ 打开时 `opendesigner` 先建版本并返回**工作表单 ID**,后续操作均基于它:
141
+
142
+ | 操作 | 请求 id | 行为 |
143
+ | --- | --- | --- |
144
+ | 保存 | 工作表单 ID | 写入工作表单(临时记录 Status=4),后端**同步回写版本行** |
145
+ | 另存为 | 源 = 工作表单 ID | 以工作表单为源复制成新表单(含最新保存的设计),返回新表单 ID |
146
+ | 发布 | 工作表单 ID | 回写版本行置 Status=1 + 一口收直写业务库 |
147
+
148
+ > 打开设计器为三步流程:`opendesigner` → `formconfig` → `allfields`(见 docs/designer-api.md 第 6 章);
149
+ > 本地 mock(`src/api/mock.ts`)已移除,未配置后端时设计器显示加载失败提示。
150
+ > 真实数据联调记录见 [docs/integration-assessment.md](./docs/integration-assessment.md) 1.3 节。
151
+
152
+ ## 构建与发布
153
+
154
+ ```bash
155
+ npm run build:lib # 类型声明(vue-tsc)+ 库构建,输出 dist-lib/
156
+ npm pack --dry-run # 预览发布包内容
157
+ npm publish # 发布到 npm(prepublishOnly 会自动先执行 build:lib)
158
+ ```
159
+
160
+ 完整的发布流程(令牌配置、版本管理、问题排查)与消费方接入指引见
161
+ [docs/npm-guide.md](./docs/npm-guide.md)。
162
+
163
+ 产物结构:
164
+
165
+ ```
166
+ dist-lib/
167
+ ├── form-design-v3.es.js # ESM 产物(主入口)
168
+ ├── form-design-v3.umd.cjs # UMD 产物(require 引入)
169
+ ├── style.css # 全局样式(CSS 变量 + 基础样式)
170
+ └── index.d.ts # 类型声明入口(含 components/ widgets/ types/ 等)
171
+ ```
172
+
173
+ ## 目录说明
174
+
175
+ | 目录 | 说明 |
176
+ | --- | --- |
177
+ | `src/api` | 接口封装与 mock(Schema 存取、子表元数据) |
178
+ | `src/components/designer` | 设计器(工具栏 / 画布 / 属性面板 / 组件树) |
179
+ | `src/components/renderer` | 运行态渲染器 |
180
+ | `src/widgets` | 内置控件(card / label / subtable / slot / grid / text) |
181
+ | `src/stores` | 设计器状态管理(撤销重做 / 拖拽 / Schema 装载) |
182
+ | `src/types` | TypeScript 类型定义 |
183
+ | `docs/designer-api.md` | 设计器接口文档(设计态) |
184
+ | `docs/renderer-api.md` | 渲染器接口文档(运行态) |
185
+ | `docs/API-backend.md` | 后端现有实现说明(对接参考) |
186
+ | `docs/integration-assessment.md` | 设计器接入评估(bpmapi 对接) |
package/package.json CHANGED
@@ -1,12 +1,75 @@
1
1
  {
2
2
  "name": "form-design-v3",
3
- "version": "1.0.1",
4
- "main": "CodeEditor-CJeYvarM.js",
3
+ "version": "1.0.3",
4
+ "description": "流程表单设计器 / 渲染器 (Vue3 + TS)",
5
+ "type": "module",
6
+ "main": "./dist-lib/form-design-v3.umd.cjs",
7
+ "module": "./dist-lib/form-design-v3.es.js",
8
+ "types": "./dist-lib/index.d.ts",
9
+ "style": "./dist-lib/form-design-v3.css",
10
+ "sideEffects": [
11
+ "**/*.css"
12
+ ],
13
+ "files": [
14
+ "dist-lib"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist-lib/index.d.ts",
19
+ "import": "./dist-lib/form-design-v3.es.js",
20
+ "require": "./dist-lib/form-design-v3.umd.cjs"
21
+ },
22
+ "./style.css": "./dist-lib/form-design-v3.css",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
5
29
  "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
30
+ "dev": "vite",
31
+ "build": "vue-tsc -b && vite build",
32
+ "build:types": "vue-tsc -p tsconfig.build.json",
33
+ "bundle:types": "node scripts/strip-css-dts.mjs && rollup -c dts.config.mjs && node scripts/prune-dts.mjs",
34
+ "build:lib": "npm run build:types && vite build --mode lib && npm run bundle:types",
35
+ "preview": "vite preview",
36
+ "prepublishOnly": "npm run build:lib"
37
+ },
38
+ "keywords": [
39
+ "form",
40
+ "designer",
41
+ "renderer",
42
+ "vue3",
43
+ "form-engine",
44
+ "bpm"
45
+ ],
46
+ "license": "MIT",
47
+ "author": "mt",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "http://code.xincheng.com/oa/bpm_2.0.git",
51
+ "directory": "designer"
52
+ },
53
+ "peerDependencies": {
54
+ "element-plus": "^2.14.0",
55
+ "lucide-vue-next": "^1.0.0",
56
+ "monaco-editor": "^0.56.0",
57
+ "pinia": "^2.3.0",
58
+ "vue": "^3.5.0"
7
59
  },
8
- "keywords": [],
9
- "author": "",
10
- "license": "ISC",
11
- "description": ""
60
+ "devDependencies": {
61
+ "@types/node": "^20.19.43",
62
+ "@vitejs/plugin-vue": "^5.2.1",
63
+ "element-plus": "^2.14.6",
64
+ "lucide-vue-next": "^1.0.0",
65
+ "monaco-editor": "^0.56.0",
66
+ "pinia": "^2.3.0",
67
+ "rollup-plugin-dts": "^6.5.1",
68
+ "typescript": "^5.7.2",
69
+ "vite": "^6.0.0",
70
+ "vite-plugin-dts": "^4.5.4",
71
+ "vite-plugin-monaco-editor": "^1.1.0",
72
+ "vue": "^3.5.13",
73
+ "vue-tsc": "^2.1.10"
74
+ }
12
75
  }
File without changes