amis-editor 4.1.0-beta.2 → 4.1.0-beta.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. package/dist/component/Breadcrumb.d.ts +23 -2
  2. package/dist/component/Editor.d.ts +19 -0
  3. package/dist/component/Panel/RenderersPanel.d.ts +1 -2
  4. package/dist/component/RegionWrapper.d.ts +4 -0
  5. package/dist/component/VRenderer.d.ts +4 -0
  6. package/dist/component/base/SearchCustomRendererPanel.d.ts +15 -0
  7. package/dist/component/base/SearchPanel.d.ts +83 -0
  8. package/dist/component/base/SearchRendererPanel.d.ts +2 -42
  9. package/dist/exports.min.js +1 -1
  10. package/dist/index.d.ts +4 -1
  11. package/dist/index.min.js +1 -1
  12. package/dist/manager.d.ts +14 -3
  13. package/dist/plugin/Card.d.ts +1 -0
  14. package/dist/plugin/Cards.d.ts +1 -0
  15. package/dist/plugin/Carousel.d.ts +1 -0
  16. package/dist/plugin/Chart.d.ts +1 -0
  17. package/dist/plugin/Collapse.d.ts +1 -0
  18. package/dist/plugin/Custom.d.ts +3 -0
  19. package/dist/plugin/CustomRegion.d.ts +43 -0
  20. package/dist/plugin/Flex.d.ts +1 -0
  21. package/dist/plugin/Form/Control.d.ts +1 -0
  22. package/dist/plugin/Form/Form.d.ts +19 -3
  23. package/dist/plugin/Form/InputURL.d.ts +1 -0
  24. package/dist/plugin/Grid.d.ts +1 -0
  25. package/dist/plugin/HBox.d.ts +1 -0
  26. package/dist/plugin/Json.d.ts +1 -0
  27. package/dist/plugin/List.d.ts +1 -0
  28. package/dist/plugin/Mapping.d.ts +1 -0
  29. package/dist/plugin/Markdown.d.ts +1 -0
  30. package/dist/plugin/Nav.d.ts +1 -0
  31. package/dist/plugin/Panel/Outline.d.ts +8 -0
  32. package/dist/plugin/Progress.d.ts +1 -0
  33. package/dist/plugin/QRCode.d.ts +1 -0
  34. package/dist/plugin/Reset.d.ts +0 -1
  35. package/dist/plugin/Service.d.ts +1 -0
  36. package/dist/plugin/Sparkline.d.ts +1 -0
  37. package/dist/plugin/Status.d.ts +1 -0
  38. package/dist/plugin/Steps.d.ts +1 -0
  39. package/dist/plugin/Submit.d.ts +0 -1
  40. package/dist/plugin/TableView.d.ts +1 -0
  41. package/dist/plugin/Tasks.d.ts +1 -0
  42. package/dist/plugin/TooltipWrapper.d.ts +1 -0
  43. package/dist/plugin/Video.d.ts +1 -0
  44. package/dist/plugin/WebComponent.d.ts +1 -0
  45. package/dist/plugin/Wizard.d.ts +11 -2
  46. package/dist/plugin/Wrapper.d.ts +1 -0
  47. package/dist/plugin.d.ts +2 -2
  48. package/dist/store/editor.d.ts +20 -2
  49. package/dist/store/node.d.ts +6 -0
  50. package/dist/style.css +1 -1
  51. package/dist/util.d.ts +7 -2
  52. package/package.json +6 -3
  53. package/src/component/schemaTpl.tsx +2155 -0
  54. package/src/plugin/Alert.tsx +87 -0
  55. package/src/plugin/AnchorNav.tsx +233 -0
  56. package/src/plugin/Audio.tsx +161 -0
  57. package/src/plugin/Avatar.tsx +77 -0
  58. package/src/plugin/Breadcrumb.tsx +107 -0
  59. package/src/plugin/Button.tsx +283 -0
  60. package/src/plugin/ButtonGroup.tsx +88 -0
  61. package/src/plugin/ButtonToolbar.tsx +89 -0
  62. package/src/plugin/CRUD.tsx +1832 -0
  63. package/src/plugin/Card.tsx +290 -0
  64. package/src/plugin/Cards.tsx +315 -0
  65. package/src/plugin/Carousel.tsx +386 -0
  66. package/src/plugin/Chart.tsx +218 -0
  67. package/src/plugin/CodeView.tsx +60 -0
  68. package/src/plugin/Collapse.tsx +143 -0
  69. package/src/plugin/CollapseGroup.tsx +167 -0
  70. package/src/plugin/Container.tsx +44 -0
  71. package/src/plugin/Custom.tsx +128 -0
  72. package/src/plugin/CustomRegion.tsx +150 -0
  73. package/src/plugin/Date.tsx +81 -0
  74. package/src/plugin/Datetime.tsx +75 -0
  75. package/src/plugin/Dialog.tsx +178 -0
  76. package/src/plugin/Divider.tsx +36 -0
  77. package/src/plugin/Drawer.tsx +217 -0
  78. package/src/plugin/DropDownButton.tsx +234 -0
  79. package/src/plugin/Each.tsx +152 -0
  80. package/src/plugin/ErrorRenderer.tsx +15 -0
  81. package/src/plugin/Flex.tsx +156 -0
  82. package/src/plugin/Form/ButtonGroupSelect.tsx +86 -0
  83. package/src/plugin/Form/ButtonToolbar.tsx +121 -0
  84. package/src/plugin/Form/ChainedSelect.tsx +70 -0
  85. package/src/plugin/Form/Checkbox.tsx +87 -0
  86. package/src/plugin/Form/Checkboxes.tsx +167 -0
  87. package/src/plugin/Form/CodeEditor.tsx +91 -0
  88. package/src/plugin/Form/Combo.tsx +582 -0
  89. package/src/plugin/Form/ConditionBuilder.tsx +324 -0
  90. package/src/plugin/Form/Control.tsx +139 -0
  91. package/src/plugin/Form/DiffEditor.tsx +117 -0
  92. package/src/plugin/Form/FieldSet.tsx +175 -0
  93. package/src/plugin/Form/Form.tsx +692 -0
  94. package/src/plugin/Form/Formula.tsx +91 -0
  95. package/src/plugin/Form/Group.tsx +300 -0
  96. package/src/plugin/Form/Hidden.tsx +56 -0
  97. package/src/plugin/Form/InputArray.tsx +228 -0
  98. package/src/plugin/Form/InputCity.tsx +93 -0
  99. package/src/plugin/Form/InputColor.tsx +123 -0
  100. package/src/plugin/Form/InputDate.tsx +175 -0
  101. package/src/plugin/Form/InputDateRange.tsx +225 -0
  102. package/src/plugin/Form/InputDateTime.tsx +183 -0
  103. package/src/plugin/Form/InputDateTimeRange.tsx +221 -0
  104. package/src/plugin/Form/InputEmail.tsx +33 -0
  105. package/src/plugin/Form/InputExcel.tsx +85 -0
  106. package/src/plugin/Form/InputFile.tsx +228 -0
  107. package/src/plugin/Form/InputGroup.tsx +105 -0
  108. package/src/plugin/Form/InputImage.tsx +277 -0
  109. package/src/plugin/Form/InputKV.tsx +72 -0
  110. package/src/plugin/Form/InputMonth.tsx +35 -0
  111. package/src/plugin/Form/InputMonthRange.tsx +195 -0
  112. package/src/plugin/Form/InputNumber.tsx +97 -0
  113. package/src/plugin/Form/InputPassword.tsx +33 -0
  114. package/src/plugin/Form/InputQuarter.tsx +35 -0
  115. package/src/plugin/Form/InputQuarterRange.tsx +195 -0
  116. package/src/plugin/Form/InputRange.tsx +121 -0
  117. package/src/plugin/Form/InputRating.tsx +78 -0
  118. package/src/plugin/Form/InputRepeat.tsx +69 -0
  119. package/src/plugin/Form/InputRichText.tsx +197 -0
  120. package/src/plugin/Form/InputSubForm.tsx +198 -0
  121. package/src/plugin/Form/InputTable.tsx +434 -0
  122. package/src/plugin/Form/InputTag.tsx +81 -0
  123. package/src/plugin/Form/InputText.tsx +186 -0
  124. package/src/plugin/Form/InputTime.tsx +95 -0
  125. package/src/plugin/Form/InputTree.tsx +240 -0
  126. package/src/plugin/Form/InputURL.tsx +34 -0
  127. package/src/plugin/Form/InputYear.tsx +35 -0
  128. package/src/plugin/Form/Item.tsx +325 -0
  129. package/src/plugin/Form/ListSelect.tsx +84 -0
  130. package/src/plugin/Form/LocationPicker.tsx +75 -0
  131. package/src/plugin/Form/MatrixCheckboxes.tsx +147 -0
  132. package/src/plugin/Form/NestedSelect.tsx +222 -0
  133. package/src/plugin/Form/Picker.tsx +217 -0
  134. package/src/plugin/Form/Radios.tsx +130 -0
  135. package/src/plugin/Form/Select.tsx +216 -0
  136. package/src/plugin/Form/Static.tsx +335 -0
  137. package/src/plugin/Form/Switch.tsx +116 -0
  138. package/src/plugin/Form/TabsTransfer.tsx +270 -0
  139. package/src/plugin/Form/Textarea.tsx +94 -0
  140. package/src/plugin/Form/Transfer.tsx +379 -0
  141. package/src/plugin/Form/TreeSelect.tsx +263 -0
  142. package/src/plugin/Form/UUID.tsx +48 -0
  143. package/src/plugin/Grid.tsx +799 -0
  144. package/src/plugin/HBox.tsx +727 -0
  145. package/src/plugin/IFrame.tsx +72 -0
  146. package/src/plugin/Image.tsx +318 -0
  147. package/src/plugin/Images.tsx +238 -0
  148. package/src/plugin/Json.tsx +76 -0
  149. package/src/plugin/Link.tsx +95 -0
  150. package/src/plugin/List.tsx +278 -0
  151. package/src/plugin/ListItem.tsx +233 -0
  152. package/src/plugin/Log.tsx +52 -0
  153. package/src/plugin/Mapping.tsx +156 -0
  154. package/src/plugin/Markdown.tsx +47 -0
  155. package/src/plugin/Nav.tsx +186 -0
  156. package/src/plugin/Operation.tsx +97 -0
  157. package/src/plugin/Others/Action.tsx +428 -0
  158. package/src/plugin/Others/BasicToolbar.tsx +591 -0
  159. package/src/plugin/Others/DataDebug.tsx +134 -0
  160. package/src/plugin/Others/TableCell.tsx +480 -0
  161. package/src/plugin/Others/Unknown.tsx +37 -0
  162. package/src/plugin/Page.tsx +308 -0
  163. package/src/plugin/Panel/AvailableRenderers.tsx +41 -0
  164. package/src/plugin/Panel/Code.tsx +44 -0
  165. package/src/plugin/Panel/Name.tsx +26 -0
  166. package/src/plugin/Panel/Outline.tsx +40 -0
  167. package/src/plugin/Panel.tsx +243 -0
  168. package/src/plugin/Plain.tsx +91 -0
  169. package/src/plugin/Progress.tsx +132 -0
  170. package/src/plugin/Property.tsx +139 -0
  171. package/src/plugin/QRCode.tsx +98 -0
  172. package/src/plugin/Reset.tsx +23 -0
  173. package/src/plugin/Service.tsx +167 -0
  174. package/src/plugin/Sparkline.tsx +40 -0
  175. package/src/plugin/Status.tsx +78 -0
  176. package/src/plugin/Steps.tsx +140 -0
  177. package/src/plugin/Submit.tsx +23 -0
  178. package/src/plugin/Table.tsx +440 -0
  179. package/src/plugin/TableView.tsx +711 -0
  180. package/src/plugin/Tabs.tsx +364 -0
  181. package/src/plugin/Tasks.tsx +276 -0
  182. package/src/plugin/Time.tsx +75 -0
  183. package/src/plugin/TooltipWrapper.tsx +193 -0
  184. package/src/plugin/Tpl.tsx +162 -0
  185. package/src/plugin/Video.tsx +160 -0
  186. package/src/plugin/WebComponent.tsx +56 -0
  187. package/src/plugin/Wizard.tsx +743 -0
  188. package/src/plugin/Wrapper.tsx +107 -0
  189. package/src/plugin.ts +1046 -0
  190. package/dist/150a58f3318ca7541ed9.png +0 -0
  191. package/dist/471adb97c322b226e589.png +0 -0
  192. package/dist/4de5f42360bc5946c3c2.png +0 -0
  193. package/dist/4e9968bba3855f088fed.png +0 -0
  194. package/dist/7f09c38ebc687fea847a.png +0 -0
  195. package/dist/c94073576487510314ea.png +0 -0
@@ -0,0 +1,692 @@
1
+ import {SchemaObject} from 'amis';
2
+ import {RendererConfig} from 'amis/lib/factory';
3
+ import flatten from 'lodash/flatten';
4
+ import {ContainerWrapper} from '../../component/ContainerWrapper';
5
+ import {registerEditorPlugin} from '../../manager';
6
+ import {
7
+ BasePlugin,
8
+ BasicRendererInfo,
9
+ ChangeEventContext,
10
+ BaseEventContext,
11
+ PluginEvent,
12
+ RegionConfig,
13
+ ScaffoldForm
14
+ } from '../../plugin';
15
+ import {defaultValue, getSchemaTpl} from '../../component/schemaTpl';
16
+ import {setVariable} from 'amis/lib/utils/helper';
17
+
18
+ // 用于脚手架的常用表单控件
19
+ const formItemOptions = [
20
+ {
21
+ name: 'type',
22
+ label: '控件类型',
23
+ type: 'select',
24
+ required: true,
25
+ options: [
26
+ {
27
+ label: '单行文本框',
28
+ value: 'input-text'
29
+ },
30
+ {
31
+ label: '多行文本',
32
+ value: 'textarea'
33
+ },
34
+ {
35
+ label: '分组',
36
+ value: 'group'
37
+ },
38
+ {
39
+ label: '数字输入',
40
+ value: 'input-number'
41
+ },
42
+ {
43
+ label: '单选框',
44
+ value: 'radios'
45
+ },
46
+ {
47
+ label: '勾选框',
48
+ value: 'checkbox'
49
+ },
50
+ {
51
+ label: '复选框',
52
+ value: 'checkboxes'
53
+ },
54
+ {
55
+ label: '下拉框',
56
+ value: 'select'
57
+ },
58
+ {
59
+ label: '开关',
60
+ value: 'switch'
61
+ },
62
+ {
63
+ label: '日期',
64
+ value: 'input-date'
65
+ },
66
+ {
67
+ label: '表格',
68
+ value: 'input-table'
69
+ },
70
+ {
71
+ label: '文件上传',
72
+ value: 'input-file'
73
+ },
74
+ {
75
+ label: '图片上传',
76
+ value: 'input-image'
77
+ },
78
+ {
79
+ label: '富文本编辑器',
80
+ value: 'input-rich-text'
81
+ }
82
+ ]
83
+ },
84
+ {
85
+ name: 'label',
86
+ label: '显示名称',
87
+ type: 'input-text',
88
+ hiddenOn: 'data.type === "group"'
89
+ },
90
+ {
91
+ name: 'name',
92
+ label: '提交字段名',
93
+ required: true,
94
+ type: 'input-text',
95
+ hiddenOn: 'data.type === "group"'
96
+ }
97
+ ];
98
+
99
+ export class FormPlugin extends BasePlugin {
100
+ // 关联渲染器名字
101
+ rendererName = 'form';
102
+ $schema = '/schemas/FormSchema.json';
103
+
104
+ order = -999;
105
+
106
+ // 组件名称
107
+ name = '表单';
108
+ isBaseComponent = true;
109
+ description =
110
+ '可用于新建、编辑或者展示数据,配置初始化接口可从远端加载数据,配置提交接口可将数据发送远端。另外也可以将数据提交给其他组件,与其他组件通信。';
111
+ docLink = '/amis/zh-CN/components/form/index';
112
+ tags = ['功能'];
113
+ icon = 'fa fa-list-alt';
114
+ scaffold = {
115
+ type: 'form',
116
+ title: '表单',
117
+ body: [
118
+ {
119
+ label: '文本框',
120
+ type: 'input-text',
121
+ name: 'text'
122
+ }
123
+ ]
124
+ };
125
+ previewSchema = {
126
+ type: 'form',
127
+ panelClassName: 'Panel--default text-left m-b-none',
128
+ mode: 'horizontal',
129
+ body: [
130
+ {
131
+ label: '文本',
132
+ name: 'a',
133
+ type: 'input-text'
134
+ }
135
+ ]
136
+ };
137
+
138
+ scaffoldForm: ScaffoldForm = {
139
+ title: '快速创建表单',
140
+ body: [
141
+ getSchemaTpl('api', {
142
+ label: '提交地址'
143
+ }),
144
+ {
145
+ name: 'mode',
146
+ label: '文字与输入框展示模式',
147
+ type: 'button-group-select',
148
+ pipeIn: defaultValue('normal', false),
149
+ options: [
150
+ {
151
+ label: '上下',
152
+ value: 'normal'
153
+ },
154
+ {
155
+ label: '左右摆放',
156
+ value: 'horizontal'
157
+ },
158
+ {
159
+ label: '内联',
160
+ value: 'inline'
161
+ }
162
+ ]
163
+ },
164
+ {
165
+ label: '表单控件',
166
+ type: 'combo',
167
+ name: 'body',
168
+ multiple: true,
169
+ draggable: true,
170
+ multiLine: false,
171
+ items: [
172
+ ...formItemOptions,
173
+ {
174
+ visibleOn: 'data.type === "group"',
175
+ type: 'combo',
176
+ name: 'body',
177
+ label: '分组内的控件',
178
+ multiple: true,
179
+ draggable: true,
180
+ multiLine: true,
181
+ items: [...formItemOptions]
182
+ }
183
+ ]
184
+ }
185
+ ]
186
+ };
187
+
188
+ // scaffoldForm: ScaffoldForm = {
189
+ // title: '配置表单信息',
190
+ // body: [getSchemaTpl('api')],
191
+ // canRebuild: true
192
+ // };
193
+
194
+ // 容器配置
195
+ regions: Array<RegionConfig> = [
196
+ {
197
+ key: 'body',
198
+ label: '表单集合',
199
+ matchRegion: (elem: JSX.Element) => !!elem?.props.noValidate,
200
+ renderMethod: 'renderBody',
201
+ preferTag: '表单项'
202
+ },
203
+
204
+ {
205
+ label: '按钮组',
206
+ key: 'actions',
207
+ preferTag: '按钮'
208
+ }
209
+ ];
210
+
211
+ panelTitle = '表单';
212
+ panelBodyCreator = (context: BaseEventContext) => {
213
+ const isCRUDFilter: boolean = /\/crud\/filter\/form$/.test(context.path);
214
+ const isInDialog: boolean = /(?:\/|^)dialog\/.+$/.test(context.path);
215
+
216
+ return [
217
+ getSchemaTpl('tabs', [
218
+ {
219
+ title: '常规',
220
+ body: [
221
+ {
222
+ name: 'title',
223
+ type: 'input-text',
224
+ label: '标题',
225
+ visibleOn: `this.wrapWithPanel !== false`
226
+ },
227
+ {
228
+ name: 'submitText',
229
+ type: 'input-text',
230
+ label: '提交按钮名称',
231
+ pipeIn: defaultValue('提交'),
232
+ visibleOn: `this.wrapWithPanel !== false && !this.actions && (!Array.isArray(this.body) || !this.body.some(function(item) {return !!~['submit','button','reset','button-group'].indexOf(item.type);}))`,
233
+ description: '当没有自定义按钮时有效。'
234
+ },
235
+
236
+ {
237
+ name: 'autoFocus',
238
+ type: 'switch',
239
+ label: '自动聚焦',
240
+ mode: 'inline',
241
+ className: 'block',
242
+ labelRemark: {
243
+ className: 'm-l-xs',
244
+ trigger: 'click',
245
+ rootClose: true,
246
+ content: '设置后将让表单的第一个可输入的表单项获得焦点',
247
+ placement: 'left'
248
+ }
249
+ },
250
+
251
+ getSchemaTpl('submitOnChange'),
252
+
253
+ {
254
+ label: '提交完后重置表单',
255
+ type: 'switch',
256
+ name: 'resetAfterSubmit',
257
+ mode: 'inline',
258
+ className: 'block',
259
+ labelRemark: {
260
+ className: 'm-l-xs',
261
+ trigger: 'click',
262
+ rootClose: true,
263
+ content: '即表单提交完后,让所有表单项的值还原成初始值',
264
+ placement: 'left'
265
+ }
266
+ },
267
+
268
+ isCRUDFilter
269
+ ? null
270
+ : {
271
+ label: '初始化后提交一次',
272
+ type: 'switch',
273
+ name: 'submitOnInit',
274
+ mode: 'inline',
275
+ className: 'block',
276
+ labelRemark: {
277
+ className: 'm-l-xs',
278
+ trigger: 'click',
279
+ rootClose: true,
280
+ content: '开启后,表单初始完成便会触发一次提交。',
281
+ placement: 'left'
282
+ }
283
+ },
284
+
285
+ isInDialog
286
+ ? {
287
+ label: '提交后是否关闭对话框',
288
+ type: 'switch',
289
+ name: 'closeDialogOnSubmit',
290
+ mode: 'inline',
291
+ className: 'block',
292
+ pipeIn: (value: any) => value !== false
293
+ }
294
+ : null,
295
+
296
+ isCRUDFilter
297
+ ? null
298
+ : {
299
+ label: '提交给其他组件',
300
+ name: 'target',
301
+ type: 'input-text',
302
+ description:
303
+ '可以通过设置此属性,把当前表单的值提交给目标组件,而不是自己来通过接口保存,请填写目标组件的 <code>name</code> 属性,多个组件请用逗号隔开。当 <code>target</code> 为 <code>window</code> 时,则把表单数据附属到地址栏。'
304
+ },
305
+
306
+ getSchemaTpl('reload', {
307
+ test: !isCRUDFilter
308
+ }),
309
+
310
+ isCRUDFilter
311
+ ? null
312
+ : {
313
+ label: '跳转',
314
+ name: 'redirect',
315
+ type: 'input-text',
316
+ description: '当设置此值后,表单提交完后跳转到目标地址。'
317
+ },
318
+
319
+ {
320
+ name: 'canAccessSuperData',
321
+ label: '是否自动填充父级同名变量',
322
+ type: 'switch',
323
+ pipeIn: defaultValue(true),
324
+ mode: 'inline',
325
+ className: 'block'
326
+ },
327
+
328
+ {
329
+ name: 'persistData',
330
+ label: '是否开启本地缓存',
331
+ type: 'switch',
332
+ pipeIn: defaultValue(false),
333
+ mode: 'inline',
334
+ className: 'block',
335
+ labelRemark: {
336
+ className: 'm-l-xs',
337
+ trigger: 'click',
338
+ rootClose: true,
339
+ content:
340
+ '开启后,表单的数据会缓存在浏览器中,切换页面或关闭弹框不会清空当前表单内的数据',
341
+ placement: 'left'
342
+ }
343
+ },
344
+
345
+ {
346
+ name: 'clearPersistDataAfterSubmit',
347
+ label: '提交成功后清空本地缓存',
348
+ type: 'switch',
349
+ pipeIn: defaultValue(false),
350
+ mode: 'inline',
351
+ className: 'block',
352
+ visibleOn: 'data.persistData',
353
+ labelRemark: {
354
+ className: 'm-l-xs',
355
+ trigger: 'click',
356
+ rootClose: true,
357
+ content:
358
+ '开启本地缓存并开启本配置项后,表单提交成功后,会自动清除浏览器中当前表单的缓存数据',
359
+ placement: 'left'
360
+ }
361
+ },
362
+
363
+ {
364
+ name: 'rules',
365
+ label: '表单组合校验',
366
+ type: 'combo',
367
+ multiple: true,
368
+ multiLine: true,
369
+ items: [
370
+ {
371
+ name: 'rule',
372
+ label: '校验规则',
373
+ type: 'input-text'
374
+ },
375
+ {
376
+ name: 'message',
377
+ label: '报错提示',
378
+ type: 'input-text'
379
+ }
380
+ ]
381
+ }
382
+ ]
383
+ },
384
+
385
+ isCRUDFilter
386
+ ? null
387
+ : {
388
+ title: '接口',
389
+ body: [
390
+ getSchemaTpl('api', {
391
+ label: '保存接口',
392
+ description: '用来保存表单数据',
393
+ sampleBuilder: (schema: any) => `{
394
+ "status": 0,
395
+ "msg": "",
396
+
397
+ // 可以不返回,如果返回了数据将被 merge 进来。
398
+ data: {}
399
+ }`
400
+ // test: !this.isCRUDFilter
401
+ }),
402
+
403
+ {
404
+ label: '采用异步方式?',
405
+ remark: {
406
+ trigger: 'click',
407
+ rootClose: true,
408
+ title: '什么是异步方式?',
409
+ content:
410
+ '异步方式主要用来解决请求超时问题,启用异步方式后,程序会在请求完后,定时轮询请求额外的接口用来咨询操作是否完成。所以接口可以快速的返回,而不需要等待流程真正完成。',
411
+ placement: 'left'
412
+ },
413
+ type: 'switch',
414
+ name: 'asyncApi',
415
+ visibleOn: 'data.api',
416
+ pipeIn: (value: any) => value != null,
417
+ pipeOut: (value: any) => (value ? '' : undefined),
418
+ mode: 'inline',
419
+ className: 'block'
420
+ },
421
+
422
+ getSchemaTpl('api', {
423
+ name: 'asyncApi',
424
+ label: '异步检测接口',
425
+ visibleOn: 'data.asyncApi != null',
426
+ description:
427
+ '设置此属性后,表单提交发送保存接口后,还会继续轮训请求该接口,直到返回 finished 属性为 true 才 结束'
428
+ }),
429
+
430
+ {
431
+ type: 'divider'
432
+ },
433
+
434
+ getSchemaTpl('api', {
435
+ name: 'initApi',
436
+ label: '初始化接口',
437
+ description: '用来初始化表单数据',
438
+ sampleBuilder: (schema: any) => {
439
+ const data = {};
440
+
441
+ if (Array.isArray(schema.body)) {
442
+ schema.body.forEach((control: any) => {
443
+ if (
444
+ control.name &&
445
+ !~['combo', 'input-array', 'form'].indexOf(
446
+ control.type
447
+ )
448
+ ) {
449
+ setVariable(data, control.name, 'sample');
450
+ }
451
+ });
452
+ }
453
+
454
+ return JSON.stringify(
455
+ {
456
+ status: 0,
457
+ msg: '',
458
+ data: data
459
+ },
460
+ null,
461
+ 2
462
+ );
463
+ }
464
+ }),
465
+
466
+ {
467
+ label: '开启定时刷新',
468
+ type: 'switch',
469
+ name: 'interval',
470
+ visibleOn: 'data.initApi',
471
+ pipeIn: (value: any) => !!value,
472
+ pipeOut: (value: any) => (value ? 3000 : undefined),
473
+ mode: 'inline'
474
+ },
475
+
476
+ {
477
+ name: 'interval',
478
+ type: 'input-number',
479
+ visibleOn: 'data.interval',
480
+ step: 500,
481
+ className: 'm-t-n-sm',
482
+ description: '设置后将自动定时刷新,单位 ms'
483
+ },
484
+
485
+ {
486
+ name: 'silentPolling',
487
+ label: '静默刷新',
488
+ type: 'switch',
489
+ mode: 'inline',
490
+ visibleOn: '!!data.interval',
491
+ description: '设置自动定时刷新时是否显示loading'
492
+ },
493
+
494
+ {
495
+ name: 'stopAutoRefreshWhen',
496
+ label: '停止定时刷新检测表达式',
497
+ type: 'input-text',
498
+ visibleOn: '!!data.interval',
499
+ description:
500
+ '定时刷新一旦设置会一直刷新,除非给出表达式,条件满足后则不刷新了。'
501
+ },
502
+
503
+ {
504
+ label: '采用异步方式?',
505
+ remark: {
506
+ trigger: 'click',
507
+ rootClose: true,
508
+ title: '什么是异步方式?',
509
+ content:
510
+ '异步方式主要用来解决请求超时问题,启用异步方式后,程序会在请求完后,定时轮询请求额外的接口用来咨询操作是否完成。所以接口可以快速的返回,而不需要等待流程真正完成。',
511
+ placement: 'left'
512
+ },
513
+ type: 'switch',
514
+ name: 'initAsyncApi',
515
+ visibleOn: 'data.initApi',
516
+ pipeIn: (value: any) => value != null,
517
+ pipeOut: (value: any) => (value ? '' : undefined),
518
+ mode: 'inline'
519
+ },
520
+
521
+ getSchemaTpl('api', {
522
+ name: 'initAsyncApi',
523
+ label: '异步检测接口',
524
+ visibleOn: 'data.initAsyncApi != null',
525
+ description:
526
+ '设置此属性后,表单请求 initApi 后,还会继续轮训请求该接口,直到返回 finished 属性为 true 才 结束'
527
+ }),
528
+
529
+ {
530
+ type: 'divider'
531
+ },
532
+
533
+ isCRUDFilter
534
+ ? {
535
+ name: 'messages',
536
+ pipeIn: defaultValue({
537
+ fetchFailed: '初始化失败'
538
+ }),
539
+ label: '默认消息信息',
540
+ type: 'combo',
541
+ multiLine: true,
542
+ description:
543
+ '可以不设置,接口返回的 msg 字段,优先级更高',
544
+ items: [
545
+ {
546
+ label: '获取成功提示',
547
+ name: 'fetchSuccess',
548
+ type: 'input-text'
549
+ },
550
+ {
551
+ label: '获取失败提示',
552
+ name: 'fetchFailed',
553
+ type: 'input-text'
554
+ }
555
+ ]
556
+ }
557
+ : {
558
+ name: 'messages',
559
+ pipeIn: defaultValue({
560
+ fetchFailed: '初始化失败',
561
+ saveSuccess: '保存成功',
562
+ saveFailed: '保存失败'
563
+ }),
564
+ label: '默认消息提示',
565
+ type: 'combo',
566
+ multiLine: true,
567
+ description:
568
+ '可以不设置,接口返回的 msg 字段,优先级更高',
569
+ items: [
570
+ {
571
+ label: '获取成功提示',
572
+ name: 'fetchSuccess',
573
+ type: 'input-text'
574
+ },
575
+ {
576
+ label: '获取失败提示',
577
+ name: 'fetchFailed',
578
+ type: 'input-text'
579
+ },
580
+ {
581
+ label: '保存成功提示',
582
+ name: 'saveSuccess',
583
+ type: 'input-text'
584
+ },
585
+ {
586
+ label: '保存失败提示',
587
+ name: 'saveFailed',
588
+ type: 'input-text'
589
+ },
590
+ {
591
+ label: '验证失败提示',
592
+ name: 'validateFailed',
593
+ type: 'input-text'
594
+ }
595
+ ]
596
+ }
597
+ ]
598
+ },
599
+
600
+ {
601
+ title: '外观',
602
+ body: [
603
+ {
604
+ name: 'wrapWithPanel',
605
+ type: 'switch',
606
+ mode: 'inline',
607
+ className: 'block',
608
+ label: '用 Panel 包裹',
609
+ pipeIn: defaultValue(true),
610
+ labelRemark: {
611
+ className: 'm-l-xs',
612
+ trigger: 'click',
613
+ rootClose: true,
614
+ content: '关闭后,表单只会展示表单项,标题和操作栏将不会显示。',
615
+ placement: 'left'
616
+ }
617
+ },
618
+
619
+ {
620
+ name: 'mode',
621
+ label: '展示模式',
622
+ type: 'button-group-select',
623
+ size: 'sm',
624
+ // mode: 'inline',
625
+ // className: 'block',
626
+ pipeIn: defaultValue('normal', false),
627
+ options: [
628
+ {
629
+ label: '默认',
630
+ value: 'normal'
631
+ },
632
+ {
633
+ label: '左右摆放',
634
+ value: 'horizontal'
635
+ },
636
+ {
637
+ label: '内联',
638
+ value: 'inline'
639
+ }
640
+ ]
641
+ },
642
+
643
+ getSchemaTpl('horizontal', {
644
+ visibleOn: 'this.mode == "horizontal"'
645
+ }),
646
+
647
+ getSchemaTpl('className'),
648
+
649
+ getSchemaTpl('className', {
650
+ name: 'panelClassName',
651
+ visibleOn: 'this.wrapWithPanel !== false',
652
+ label: 'Panel 的 CSS 类名',
653
+ description: '可以设置 Panel--info 之类的'
654
+ })
655
+ ]
656
+ },
657
+
658
+ {
659
+ title: '其他',
660
+ body: [
661
+ getSchemaTpl('ref'),
662
+ getSchemaTpl('name', {
663
+ test: !isCRUDFilter
664
+ }),
665
+ {
666
+ name: 'debug',
667
+ label: '开启调试',
668
+ type: 'switch',
669
+ mode: 'inline',
670
+ labelRemark: '显示当前表单的数据在表单顶部'
671
+ },
672
+ getSchemaTpl('disabled'),
673
+ getSchemaTpl('visible')
674
+ ]
675
+ }
676
+ ])
677
+ ];
678
+ };
679
+
680
+ afterUpdate(event: PluginEvent<ChangeEventContext>) {
681
+ const context = event.context;
682
+
683
+ if (
684
+ context.info.renderer.name === 'form' &&
685
+ context.diff?.some(change => change.path?.join('.') === 'wrapWithPanel')
686
+ ) {
687
+ this.manager.buildPanels();
688
+ }
689
+ }
690
+ }
691
+
692
+ registerEditorPlugin(FormPlugin);