amis 1.9.1-beta.1 → 1.9.1-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. package/lib/RootRenderer.js +10 -2
  2. package/lib/RootRenderer.js.map +2 -2
  3. package/lib/Schema.d.ts +3 -2
  4. package/lib/Schema.js.map +1 -1
  5. package/lib/components/Alert2.d.ts +10 -10
  6. package/lib/components/Button.d.ts +11 -10
  7. package/lib/components/Button.js +2 -2
  8. package/lib/components/Button.js.map +2 -2
  9. package/lib/components/CalendarMobile.d.ts +40 -40
  10. package/lib/components/Checkbox.js +1 -1
  11. package/lib/components/Checkbox.js.map +2 -2
  12. package/lib/components/ContextMenu.d.ts +4 -0
  13. package/lib/components/ContextMenu.js +23 -7
  14. package/lib/components/ContextMenu.js.map +2 -2
  15. package/lib/components/DatePicker.d.ts +40 -40
  16. package/lib/components/DateRangePicker.d.ts +40 -40
  17. package/lib/components/Form.d.ts +22 -0
  18. package/lib/components/Form.js +44 -0
  19. package/lib/components/Form.js.map +13 -0
  20. package/lib/components/FormField.d.ts +65 -0
  21. package/lib/components/FormField.js +48 -0
  22. package/lib/components/FormField.js.map +13 -0
  23. package/lib/components/InputBox.d.ts +10 -10
  24. package/lib/components/InputBox.js +4 -3
  25. package/lib/components/InputBox.js.map +2 -2
  26. package/lib/components/InputBoxWithSuggestion.d.ts +280 -0
  27. package/lib/components/InputBoxWithSuggestion.js +65 -0
  28. package/lib/components/InputBoxWithSuggestion.js.map +13 -0
  29. package/lib/components/ListGroup.d.ts +10 -10
  30. package/lib/components/PickerContainer.d.ts +4 -2
  31. package/lib/components/PickerContainer.js +28 -5
  32. package/lib/components/PickerContainer.js.map +2 -2
  33. package/lib/components/Radios.d.ts +10 -10
  34. package/lib/components/ResultBox.d.ts +40 -40
  35. package/lib/components/SearchBox.d.ts +40 -40
  36. package/lib/components/Select.d.ts +195 -202
  37. package/lib/components/Select.js +7 -3
  38. package/lib/components/Select.js.map +2 -2
  39. package/lib/components/Textarea.d.ts +568 -2
  40. package/lib/components/Textarea.js +129 -1
  41. package/lib/components/Textarea.js.map +2 -2
  42. package/lib/components/Toast.js +11 -9
  43. package/lib/components/Toast.js.map +2 -2
  44. package/lib/components/UserSelect.d.ts +500 -0
  45. package/lib/components/UserSelect.js +559 -0
  46. package/lib/components/UserSelect.js.map +13 -0
  47. package/lib/components/UserTabSelect.d.ts +320 -0
  48. package/lib/components/UserTabSelect.js +163 -0
  49. package/lib/components/UserTabSelect.js.map +13 -0
  50. package/lib/components/WithRemoteConfig.d.ts +7 -0
  51. package/lib/components/WithRemoteConfig.js +17 -11
  52. package/lib/components/WithRemoteConfig.js.map +2 -2
  53. package/lib/components/calendar/DaysView.d.ts +26 -1
  54. package/lib/components/calendar/DaysView.js +48 -14
  55. package/lib/components/calendar/DaysView.js.map +2 -2
  56. package/lib/components/calendar/TimeView.d.ts +1 -1
  57. package/lib/components/calendar/TimeView.js +8 -2
  58. package/lib/components/calendar/TimeView.js.map +2 -2
  59. package/lib/components/icons.d.ts +7 -1
  60. package/lib/components/icons.js +17 -1
  61. package/lib/components/icons.js.map +2 -2
  62. package/lib/components/index.d.ts +2 -1
  63. package/lib/components/index.js +3 -1
  64. package/lib/components/index.js.map +2 -2
  65. package/lib/components/json-schema/Array.d.ts +3 -0
  66. package/lib/components/json-schema/Array.js +125 -0
  67. package/lib/components/json-schema/Array.js.map +13 -0
  68. package/lib/components/json-schema/Item.d.ts +3 -0
  69. package/lib/components/json-schema/Item.js +34 -0
  70. package/lib/components/json-schema/Item.js.map +13 -0
  71. package/lib/components/json-schema/Object.d.ts +3 -0
  72. package/lib/components/json-schema/Object.js +178 -0
  73. package/lib/components/json-schema/Object.js.map +13 -0
  74. package/lib/components/json-schema/index.d.ts +279 -0
  75. package/lib/components/json-schema/index.js +16 -0
  76. package/lib/components/json-schema/index.js.map +13 -0
  77. package/lib/components/schema-editor/Array.js +2 -2
  78. package/lib/components/schema-editor/Array.js.map +2 -2
  79. package/lib/components/schema-editor/Common.d.ts +2 -0
  80. package/lib/components/schema-editor/Common.js +39 -3
  81. package/lib/components/schema-editor/Common.js.map +2 -2
  82. package/lib/components/schema-editor/Object.js +2 -2
  83. package/lib/components/schema-editor/Object.js.map +2 -2
  84. package/lib/components/schema-editor/index.d.ts +45 -41
  85. package/lib/components/schema-editor/index.js +5 -5
  86. package/lib/components/schema-editor/index.js.map +2 -2
  87. package/lib/hooks/use-validation-resolver.d.ts +1 -0
  88. package/lib/hooks/use-validation-resolver.js +49 -0
  89. package/lib/hooks/use-validation-resolver.js.map +13 -0
  90. package/lib/icons/department.js +17 -0
  91. package/lib/icons/menu.js +9 -0
  92. package/lib/icons/post.js +15 -0
  93. package/lib/icons/role.js +14 -0
  94. package/lib/icons/user-remove.js +12 -0
  95. package/lib/index.d.ts +2 -0
  96. package/lib/index.js +3 -1
  97. package/lib/index.js.map +2 -2
  98. package/lib/locale/de-DE.js +11 -1
  99. package/lib/locale/de-DE.js.map +2 -2
  100. package/lib/locale/en-US.js +12 -1
  101. package/lib/locale/en-US.js.map +2 -2
  102. package/lib/locale/zh-CN.js +14 -3
  103. package/lib/locale/zh-CN.js.map +2 -2
  104. package/lib/renderers/Action.js +25 -11
  105. package/lib/renderers/Action.js.map +2 -2
  106. package/lib/renderers/CRUD.js +5 -1
  107. package/lib/renderers/CRUD.js.map +2 -2
  108. package/lib/renderers/Dialog.js +9 -3
  109. package/lib/renderers/Dialog.js.map +2 -2
  110. package/lib/renderers/Drawer.js +5 -1
  111. package/lib/renderers/Drawer.js.map +2 -2
  112. package/lib/renderers/Form/InputDate.d.ts +2 -2
  113. package/lib/renderers/Form/InputDate.js.map +2 -2
  114. package/lib/renderers/Form/JSONSchema.d.ts +23 -0
  115. package/lib/renderers/Form/JSONSchema.js +44 -0
  116. package/lib/renderers/Form/JSONSchema.js.map +13 -0
  117. package/lib/renderers/Form/JSONSchemaEditor.d.ts +2 -3
  118. package/lib/renderers/Form/JSONSchemaEditor.js +9 -24
  119. package/lib/renderers/Form/JSONSchemaEditor.js.map +2 -2
  120. package/lib/renderers/Form/Textarea.d.ts +1 -8
  121. package/lib/renderers/Form/Textarea.js +11 -75
  122. package/lib/renderers/Form/Textarea.js.map +2 -2
  123. package/lib/renderers/Form/UserSelect.d.ts +54 -0
  124. package/lib/renderers/Form/UserSelect.js +197 -0
  125. package/lib/renderers/Form/UserSelect.js.map +13 -0
  126. package/lib/renderers/Form/index.d.ts +1 -1
  127. package/lib/renderers/Form/index.js +88 -42
  128. package/lib/renderers/Form/index.js.map +2 -2
  129. package/lib/renderers/Log.d.ts +13 -1
  130. package/lib/renderers/Log.js +82 -16
  131. package/lib/renderers/Log.js.map +2 -2
  132. package/lib/renderers/Page.js +5 -1
  133. package/lib/renderers/Page.js.map +2 -2
  134. package/lib/renderers/Service.js +5 -1
  135. package/lib/renderers/Service.js.map +2 -2
  136. package/lib/renderers/Wizard.js +37 -14
  137. package/lib/renderers/Wizard.js.map +2 -2
  138. package/lib/store/form.js +65 -45
  139. package/lib/store/form.js.map +2 -2
  140. package/lib/themes/ang-ie11.css +561 -21
  141. package/lib/themes/ang.css +538 -9
  142. package/lib/themes/ang.css.map +1 -1
  143. package/lib/themes/antd-ie11.css +561 -21
  144. package/lib/themes/antd.css +538 -9
  145. package/lib/themes/antd.css.map +1 -1
  146. package/lib/themes/cxd-ie11.css +561 -21
  147. package/lib/themes/cxd.css +538 -9
  148. package/lib/themes/cxd.css.map +1 -1
  149. package/lib/themes/dark-ie11.css +561 -21
  150. package/lib/themes/dark.css +538 -9
  151. package/lib/themes/dark.css.map +1 -1
  152. package/lib/themes/default-ie11.css +561 -21
  153. package/lib/themes/default.css +538 -9
  154. package/lib/themes/default.css.map +1 -1
  155. package/lib/utils/api.js +1 -1
  156. package/lib/utils/api.js.map +2 -2
  157. package/lib/utils/renderer-event.js.map +2 -2
  158. package/package.json +2 -1
  159. package/schema.json +539 -3
  160. package/scss/_properties.scss +20 -8
  161. package/scss/components/_input-box.scss +22 -1
  162. package/scss/components/_json-schema.scss +124 -0
  163. package/scss/components/_log.scss +37 -5
  164. package/scss/components/form/_date-range.scss +1 -0
  165. package/scss/components/form/_select.scss +9 -0
  166. package/scss/components/form/_user-select.scss +422 -0
  167. package/scss/themes/_common.scss +2 -0
  168. package/sdk/ang-ie11.css +651 -21
  169. package/sdk/ang.css +628 -9
  170. package/sdk/antd-ie11.css +651 -21
  171. package/sdk/antd.css +628 -9
  172. package/sdk/barcode.js +51 -51
  173. package/sdk/charts.js +14 -14
  174. package/sdk/codemirror.js +7 -7
  175. package/sdk/color-picker.js +65 -65
  176. package/sdk/cropperjs.js +2 -2
  177. package/sdk/cxd-ie11.css +651 -21
  178. package/sdk/cxd.css +628 -9
  179. package/sdk/dark-ie11.css +651 -21
  180. package/sdk/dark.css +628 -9
  181. package/sdk/exceljs.js +1 -1
  182. package/sdk/locale/de-DE.js +11 -1
  183. package/sdk/markdown.js +69 -69
  184. package/sdk/papaparse.js +1 -1
  185. package/sdk/renderers/Form/CityDB.js +1 -1
  186. package/sdk/rest.js +16 -16
  187. package/sdk/rich-text.js +62 -62
  188. package/sdk/sdk-ie11.css +651 -21
  189. package/sdk/sdk.css +628 -9
  190. package/sdk/sdk.js +1655 -1643
  191. package/sdk/thirds/hls.js/hls.js +1 -1
  192. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  193. package/sdk/tinymce.js +57 -57
  194. package/src/RootRenderer.tsx +27 -15
  195. package/src/Schema.ts +5 -1
  196. package/src/components/Button.tsx +3 -0
  197. package/src/components/Checkbox.tsx +2 -1
  198. package/src/components/ContextMenu.tsx +25 -7
  199. package/src/components/Form.tsx +70 -0
  200. package/src/components/FormField.tsx +127 -0
  201. package/src/components/InputBox.tsx +4 -1
  202. package/src/components/InputBoxWithSuggestion.tsx +113 -0
  203. package/src/components/PickerContainer.tsx +20 -5
  204. package/src/components/Select.tsx +18 -10
  205. package/src/components/Textarea.tsx +234 -2
  206. package/src/components/Toast.tsx +19 -18
  207. package/src/components/UserSelect.tsx +850 -0
  208. package/src/components/UserTabSelect.tsx +261 -0
  209. package/src/components/WithRemoteConfig.tsx +22 -7
  210. package/src/components/calendar/DaysView.tsx +53 -16
  211. package/src/components/calendar/TimeView.tsx +10 -5
  212. package/src/components/icons.tsx +17 -1
  213. package/src/components/index.tsx +3 -1
  214. package/src/components/json-schema/Array.tsx +216 -0
  215. package/src/components/json-schema/Item.tsx +47 -0
  216. package/src/components/json-schema/Object.tsx +339 -0
  217. package/src/components/json-schema/index.tsx +44 -0
  218. package/src/components/schema-editor/Array.tsx +3 -1
  219. package/src/components/schema-editor/Common.tsx +61 -4
  220. package/src/components/schema-editor/Object.tsx +3 -1
  221. package/src/components/schema-editor/index.tsx +12 -5
  222. package/src/hooks/use-validation-resolver.ts +45 -0
  223. package/src/icons/department.svg +17 -0
  224. package/src/icons/menu.svg +2 -0
  225. package/src/icons/post.svg +15 -0
  226. package/src/icons/role.svg +14 -0
  227. package/src/icons/user-remove.svg +12 -0
  228. package/src/index.tsx +2 -0
  229. package/src/locale/de-DE.ts +11 -1
  230. package/src/locale/en-US.ts +12 -1
  231. package/src/locale/zh-CN.ts +14 -3
  232. package/src/renderers/Action.tsx +10 -9
  233. package/src/renderers/CRUD.tsx +5 -1
  234. package/src/renderers/Dialog.tsx +9 -3
  235. package/src/renderers/Drawer.tsx +5 -1
  236. package/src/renderers/Form/InputDate.tsx +9 -4
  237. package/src/renderers/Form/JSONSchema.tsx +56 -0
  238. package/src/renderers/Form/JSONSchemaEditor.tsx +8 -27
  239. package/src/renderers/Form/Textarea.tsx +7 -117
  240. package/src/renderers/Form/UserSelect.tsx +263 -0
  241. package/src/renderers/Form/index.tsx +28 -18
  242. package/src/renderers/Log.tsx +148 -13
  243. package/src/renderers/Page.tsx +6 -1
  244. package/src/renderers/Service.tsx +5 -1
  245. package/src/renderers/Wizard.tsx +24 -10
  246. package/src/store/form.ts +24 -17
  247. package/src/utils/api.ts +1 -1
  248. package/src/utils/renderer-event.ts +0 -2
@@ -22,7 +22,7 @@ export interface JSONSchemaEditorControlSchema extends FormBaseControl {
22
22
  type:
23
23
  | 'string'
24
24
  | 'number'
25
- | 'interger'
25
+ | 'integer'
26
26
  | 'object'
27
27
  | 'array'
28
28
  | 'boolean'
@@ -79,39 +79,21 @@ export default class JSONSchemaEditorControl extends React.PureComponent<JSONSch
79
79
  enableAdvancedSetting: false
80
80
  };
81
81
 
82
- // todo 完善这块配置
83
- settings: any = {
84
- common: [
85
- {
86
- type: 'input-text',
87
- name: 'title',
88
- label: this.props.translate('JSONSchema.title')
89
- },
90
-
91
- {
92
- type: 'textarea',
93
- name: 'description',
94
- label: this.props.translate('JSONSchema.description')
95
- }
96
- ]
97
- };
98
-
99
82
  @autobind
100
- renderModalProps({value, onChange}: any) {
83
+ renderModalProps(value: any, onChange: (value: any) => void) {
101
84
  const {render, advancedSettings} = this.props;
85
+ const fields = advancedSettings?.[value?.type] || [];
102
86
  return render(
103
87
  `modal`,
104
88
  {
105
89
  type: 'form',
106
90
  wrapWithPanel: false,
107
- body: [
108
- ...(this.settings[value?.type] || this.settings.common),
109
- ...(advancedSettings?.[value?.type] || [])
110
- ]
91
+ body: fields,
92
+ submitOnChange: true
111
93
  },
112
94
  {
113
95
  data: value,
114
- onChange: (value: any) => onChange(value)
96
+ onSubmit: (value: any) => onChange(value)
115
97
  }
116
98
  );
117
99
  }
@@ -122,9 +104,8 @@ export default class JSONSchemaEditorControl extends React.PureComponent<JSONSch
122
104
  return (
123
105
  <JSONSchemaEditor
124
106
  {...rest}
125
- renderModalProps={
126
- enableAdvancedSetting ? this.renderModalProps : undefined
127
- }
107
+ enableAdvancedSetting={enableAdvancedSetting}
108
+ renderModalProps={this.renderModalProps}
128
109
  />
129
110
  );
130
111
  }
@@ -86,60 +86,22 @@ export default class TextAreaControl extends React.Component<
86
86
  clearable: false
87
87
  };
88
88
 
89
- state = {
90
- focused: false
91
- };
92
-
93
- input?: HTMLInputElement;
94
- inputRef = (ref: any) => (this.input = findDOMNode(ref) as HTMLInputElement);
89
+ inputRef = React.createRef<any>();
95
90
 
96
91
  doAction(action: ListenerAction, args: any) {
97
92
  const actionType = action?.actionType as string;
93
+ const onChange = this.props.onChange;
98
94
 
99
95
  if (!!~['clear', 'reset'].indexOf(actionType)) {
100
- this.handleClear();
96
+ onChange?.(this.props.resetValue);
97
+ this.focus();
101
98
  } else if (actionType === 'focus') {
102
99
  this.focus();
103
100
  }
104
101
  }
105
102
 
106
- valueToString(value: any) {
107
- return typeof value === 'undefined' || value === null
108
- ? ''
109
- : typeof value === 'string'
110
- ? value
111
- : JSON.stringify(value);
112
- }
113
-
114
103
  focus() {
115
- if (!this.input) {
116
- return;
117
- }
118
-
119
- this.setState(
120
- {
121
- focused: true
122
- },
123
- () => {
124
- if (!this.input) {
125
- return;
126
- }
127
-
128
- this.input.focus();
129
-
130
- // 光标放到最后
131
- const len = this.input.value.length;
132
- len && this.input.setSelectionRange(len, len);
133
- }
134
- );
135
- }
136
-
137
- @autobind
138
- handleChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
139
- const {onChange} = this.props;
140
- let value = e.currentTarget.value;
141
-
142
- onChange?.(value);
104
+ this.inputRef.current?.focus();
143
105
  }
144
106
 
145
107
  @autobind
@@ -176,83 +138,11 @@ export default class TextAreaControl extends React.Component<
176
138
  );
177
139
  }
178
140
 
179
- @autobind
180
- async handleClear() {
181
- const {onChange, resetValue} = this.props;
182
-
183
- onChange?.(resetValue);
184
- this.focus();
185
- }
186
-
187
141
  render() {
188
- const {
189
- className,
190
- classPrefix: ns,
191
- value,
192
- type,
193
- placeholder,
194
- disabled,
195
- minRows,
196
- maxRows,
197
- readOnly,
198
- name,
199
- borderMode,
200
- classnames: cx,
201
- maxLength,
202
- showCounter,
203
- clearable
204
- } = this.props;
205
- const counter = showCounter ? this.valueToString(value).length : 0;
142
+ const {...rest} = this.props;
206
143
 
207
144
  return (
208
- <div
209
- className={cx(
210
- `TextareaControl`,
211
- {
212
- [`TextareaControl--border${ucFirst(borderMode)}`]: borderMode,
213
- 'is-focused': this.state.focused,
214
- 'is-disabled': disabled
215
- },
216
- className
217
- )}
218
- >
219
- <Textarea
220
- className={cx(`TextareaControl-input`)}
221
- autoComplete="off"
222
- ref={this.inputRef}
223
- name={name}
224
- disabled={disabled}
225
- value={this.valueToString(value)}
226
- placeholder={placeholder}
227
- autoCorrect="off"
228
- spellCheck="false"
229
- readOnly={readOnly}
230
- minRows={minRows || undefined}
231
- maxRows={maxRows || undefined}
232
- onChange={this.handleChange}
233
- onFocus={this.handleFocus}
234
- onBlur={this.handleBlur}
235
- />
236
-
237
- {clearable && !disabled && value ? (
238
- <a onClick={this.handleClear} className={cx('TextareaControl-clear')}>
239
- <Icon icon="input-clear" className="icon" />
240
- </a>
241
- ) : null}
242
-
243
- {showCounter ? (
244
- <span
245
- className={cx('TextareaControl-counter', {
246
- 'is-empty': counter === 0,
247
- 'is-clearable': clearable && !disabled && value
248
- })}
249
- >
250
- {`${counter}${
251
- typeof maxLength === 'number' && maxLength ? `/${maxLength}` : ''
252
- }`}
253
- </span>
254
- ) : null}
255
- </div>
145
+ <Textarea {...rest} onFocus={this.handleFocus} onBlur={this.handleBlur} />
256
146
  );
257
147
  }
258
148
  }
@@ -0,0 +1,263 @@
1
+ import React from 'react';
2
+ import cx from 'classnames';
3
+ import {
4
+ OptionsControl,
5
+ OptionsControlProps,
6
+ Option,
7
+ FormOptionsControl
8
+ } from './Options';
9
+ import UserSelect from '../../components/UserSelect';
10
+ import UserTabSelect from '../../components/UserTabSelect';
11
+ import {isEffectiveApi} from '../../utils/api';
12
+ import find from 'lodash/find';
13
+ import {createObject, autobind} from '../../utils/helper';
14
+ import {PlainObject} from '../../types';
15
+
16
+ /**
17
+ * UserSelect 移动端人员选择。
18
+ */
19
+ export interface UserSelectControlSchema extends FormOptionsControl {
20
+ type: 'users-select';
21
+ }
22
+
23
+ export interface UserSelectProps extends OptionsControlProps {
24
+ /**
25
+ * 部门可选
26
+ */
27
+ isDep?: boolean;
28
+ /**
29
+ * 人员可选
30
+ */
31
+ isRef?: boolean;
32
+ /**
33
+ *
34
+ */
35
+ showNav?: boolean;
36
+ /**
37
+ * 导航头标题
38
+ */
39
+ navTitle?: string;
40
+ /**
41
+ * 选项卡模式
42
+ */
43
+ tabMode?: boolean;
44
+ tabOptions?: Array<any>;
45
+ /**
46
+ * 搜索字段
47
+ */
48
+ searchTerm?: string;
49
+ /**
50
+ * 搜索携带的额外参数
51
+ */
52
+ searchParam?: PlainObject;
53
+ }
54
+
55
+ export default class UserSelectControl extends React.Component<
56
+ UserSelectProps,
57
+ any
58
+ > {
59
+ static defaultProps: Partial<UserSelectProps> = {
60
+ showNav: true
61
+ };
62
+ input?: HTMLInputElement;
63
+ unHook: Function;
64
+ lazyloadRemote: Function;
65
+
66
+ constructor(props: UserSelectProps) {
67
+ super(props);
68
+ }
69
+
70
+ componentWillUnmount() {
71
+ this.unHook && this.unHook();
72
+ }
73
+
74
+ @autobind
75
+ async onSearch(input: string, cancelExecutor: Function, param?: PlainObject) {
76
+ let {searchApi, setLoading, env} = this.props;
77
+ searchApi = param?.searchApi || searchApi;
78
+ let searchTerm = param?.searchTerm || this.props.searchTerm || 'term';
79
+ let searchObj = param?.searchParam || this.props.searchParam || {};
80
+
81
+ const ctx = {
82
+ [searchTerm]: input,
83
+ ...searchObj
84
+ };
85
+
86
+ if (!isEffectiveApi(searchApi, ctx)) {
87
+ return Promise.resolve([]);
88
+ }
89
+
90
+ setLoading(true);
91
+ try {
92
+ const ret = await env.fetcher(searchApi, ctx, {
93
+ cancelExecutor,
94
+ autoAppend: true
95
+ });
96
+ let options = (ret.data && (ret.data as any).options) || ret.data || [];
97
+
98
+ return options;
99
+ } finally {
100
+ setLoading(false);
101
+ }
102
+ }
103
+
104
+ @autobind
105
+ async deferLoad(data?: Object, isRef?: boolean, param?: PlainObject) {
106
+ let {env, deferApi, setLoading, formInited, addHook} = this.props;
107
+
108
+ deferApi = param?.deferApi || deferApi;
109
+
110
+ if (!env || !env.fetcher) {
111
+ throw new Error('fetcher is required');
112
+ }
113
+
114
+ const ctx = createObject(data, {});
115
+
116
+ if (!isEffectiveApi(deferApi, ctx)) {
117
+ return Promise.resolve([]);
118
+ }
119
+
120
+ try {
121
+ const ret = await env.fetcher(deferApi, ctx);
122
+
123
+ let options = (ret.data && (ret.data as any).options) || ret.data || [];
124
+
125
+ if (isRef) {
126
+ options.forEach((option: Option) => {
127
+ option.isRef = true;
128
+ });
129
+ }
130
+ return options;
131
+ } finally {
132
+ setLoading(false);
133
+ }
134
+ }
135
+
136
+ @autobind
137
+ async changeValue(value: Option | Array<Option> | string | void) {
138
+ const {
139
+ joinValues,
140
+ extractValue,
141
+ delimiter,
142
+ multiple,
143
+ valueField,
144
+ onChange,
145
+ options,
146
+ setOptions,
147
+ data,
148
+ dispatchEvent
149
+ } = this.props;
150
+ let newValue: string | Option | Array<Option> | void = value;
151
+ let additonalOptions: Array<any> = [];
152
+ (Array.isArray(value) ? value : value ? [value] : []).forEach(
153
+ (option: any) => {
154
+ let resolved = find(
155
+ options,
156
+ (item: any) =>
157
+ item[valueField || 'value'] == option[valueField || 'value']
158
+ );
159
+ resolved || additonalOptions.push(option);
160
+ }
161
+ );
162
+
163
+ if (joinValues) {
164
+ if (multiple) {
165
+ newValue = Array.isArray(value)
166
+ ? (value
167
+ .map(item => item[valueField || 'value'])
168
+ .join(delimiter) as string)
169
+ : value
170
+ ? (value as Option)[valueField || 'value']
171
+ : '';
172
+ } else {
173
+ newValue = newValue ? (newValue as Option)[valueField || 'value'] : '';
174
+ }
175
+ } else if (extractValue) {
176
+ if (multiple) {
177
+ newValue = Array.isArray(value)
178
+ ? value.map(item => item[valueField || 'value'])
179
+ : value
180
+ ? [(value as Option)[valueField || 'value']]
181
+ : [];
182
+ } else {
183
+ newValue = newValue ? (newValue as Option)[valueField || 'value'] : '';
184
+ }
185
+ }
186
+
187
+ const rendererEvent = await dispatchEvent(
188
+ 'change',
189
+ createObject(data, {
190
+ value: newValue,
191
+ options
192
+ })
193
+ );
194
+ if (rendererEvent?.prevented) {
195
+ return;
196
+ }
197
+
198
+ onChange(newValue);
199
+ }
200
+
201
+ render() {
202
+ let {
203
+ showNav,
204
+ navTitle,
205
+ searchable,
206
+ options,
207
+ className,
208
+ selectedOptions,
209
+ tabOptions,
210
+ multi,
211
+ multiple,
212
+ isDep,
213
+ isRef,
214
+ placeholder,
215
+ searchPlaceholder,
216
+ tabMode,
217
+ data
218
+ } = this.props;
219
+ tabOptions?.forEach((item: any) => {
220
+ item.deferLoad = this.deferLoad;
221
+ item.onChange = this.changeValue;
222
+ item.onSearch = this.onSearch;
223
+ });
224
+
225
+ return (
226
+ <div className={cx(`UserSelectControl`, className)}>
227
+ {tabMode ? (
228
+ <UserTabSelect
229
+ selection={selectedOptions}
230
+ tabOptions={tabOptions}
231
+ multiple={multiple}
232
+ onChange={this.changeValue}
233
+ onSearch={this.onSearch}
234
+ deferLoad={this.deferLoad}
235
+ data={data}
236
+ />
237
+ ) : (
238
+ <UserSelect
239
+ showNav={showNav}
240
+ navTitle={navTitle}
241
+ selection={selectedOptions}
242
+ options={options}
243
+ multi={multi}
244
+ multiple={multiple}
245
+ searchable={searchable}
246
+ placeholder={placeholder}
247
+ searchPlaceholder={searchPlaceholder}
248
+ deferLoad={this.deferLoad}
249
+ onChange={this.changeValue}
250
+ onSearch={this.onSearch}
251
+ isDep={isDep}
252
+ isRef={isRef}
253
+ />
254
+ )}
255
+ </div>
256
+ );
257
+ }
258
+ }
259
+
260
+ @OptionsControl({
261
+ type: 'users-select'
262
+ })
263
+ export class UserSelectControlRenderer extends UserSelectControl {}
@@ -663,7 +663,7 @@ export default class Form extends React.Component<FormProps, object> {
663
663
  }
664
664
 
665
665
  // 派发init事件,参数为初始化数据
666
- const dispatcher = dispatchEvent(
666
+ const dispatcher = await dispatchEvent(
667
667
  'inited',
668
668
  createObject(this.props.data, data)
669
669
  );
@@ -767,7 +767,7 @@ export default class Form extends React.Component<FormProps, object> {
767
767
  if (result) {
768
768
  dispatchEvent('validateSucc', data);
769
769
  } else {
770
- dispatchEvent('validateFail', data);
770
+ dispatchEvent('validateError', data);
771
771
  }
772
772
  return result;
773
773
  });
@@ -794,9 +794,7 @@ export default class Form extends React.Component<FormProps, object> {
794
794
  submit(fn?: (values: object) => Promise<any>): Promise<any> {
795
795
  const {store, messages, translate: __, dispatchEvent, data} = this.props;
796
796
  this.flush();
797
- const validateErrCb = () => {
798
- dispatchEvent('validateFail', data);
799
- };
797
+ const validateErrCb = () => dispatchEvent('validateError', data);
800
798
  return store.submit(
801
799
  fn,
802
800
  this.hooks['validate'] || [],
@@ -871,13 +869,13 @@ export default class Form extends React.Component<FormProps, object> {
871
869
  };
872
870
  }
873
871
 
874
- emitChange(submit: boolean) {
872
+ async emitChange(submit: boolean) {
875
873
  const {onChange, store, submitOnChange, dispatchEvent, data} = this.props;
876
874
 
877
875
  if (!isAlive(store)) {
878
876
  return;
879
877
  }
880
- const dispatcher = dispatchEvent('change', createObject(data, store.data));
878
+ const dispatcher = await dispatchEvent('change', createObject(data, store.data));
881
879
  if (!dispatcher?.prevented) {
882
880
  onChange &&
883
881
  onChange(
@@ -980,10 +978,12 @@ export default class Form extends React.Component<FormProps, object> {
980
978
  data = store.data;
981
979
  }
982
980
  if (Array.isArray(action.required) && action.required.length) {
983
- return store.validateFields(action.required).then(result => {
981
+ return store.validateFields(action.required).then(async result => {
984
982
  if (!result) {
985
- dispatchEvent('validateError', this.props.data);
986
- env.notify('error', __('Form.validateFailed'));
983
+ const dispatcher = await dispatchEvent('validateError', this.props.data);
984
+ if (!dispatcher?.prevented) {
985
+ env.notify('error', __('Form.validateFailed'));
986
+ }
987
987
  } else {
988
988
  dispatchEvent('validateSucc', this.props.data);
989
989
  this.handleAction(
@@ -1039,9 +1039,9 @@ export default class Form extends React.Component<FormProps, object> {
1039
1039
  .saveRemote(action.api || (api as Api), values, {
1040
1040
  successMessage: saveSuccess,
1041
1041
  errorMessage: saveFailed,
1042
- onSuccess: (result: Payload) => {
1042
+ onSuccess: async (result: Payload) => {
1043
1043
  // result为提交接口返回的内容
1044
- dispatchEvent(
1044
+ const dispatcher = await dispatchEvent(
1045
1045
  'submitSucc',
1046
1046
  createObject(this.props.data, {result})
1047
1047
  );
@@ -1049,20 +1049,30 @@ export default class Form extends React.Component<FormProps, object> {
1049
1049
  !isEffectiveApi(finnalAsyncApi, store.data) ||
1050
1050
  store.data[finishedField || 'finished']
1051
1051
  ) {
1052
- return;
1052
+ return {
1053
+ cbResult: null,
1054
+ dispatcher
1055
+ };
1053
1056
  }
1054
- return until(
1057
+ const cbResult = until(
1055
1058
  () => store.checkRemote(finnalAsyncApi as Api, store.data),
1056
1059
  (ret: any) => ret && ret[finishedField || 'finished'],
1057
1060
  cancel => (this.asyncCancel = cancel),
1058
1061
  checkInterval
1059
- );
1062
+ )
1063
+ return {
1064
+ cbResult,
1065
+ dispatcher
1066
+ };
1060
1067
  },
1061
- onFailed: (result: Payload) => {
1062
- dispatchEvent(
1068
+ onFailed: async (result: Payload) => {
1069
+ const dispatcher = await dispatchEvent(
1063
1070
  'submitFail',
1064
1071
  createObject(this.props.data, {error: result})
1065
1072
  );
1073
+ return {
1074
+ dispatcher
1075
+ };
1066
1076
  }
1067
1077
  })
1068
1078
  .then(async response => {
@@ -1183,7 +1193,7 @@ export default class Form extends React.Component<FormProps, object> {
1183
1193
  })
1184
1194
  .catch(e => {
1185
1195
  onFailed && onFailed(e, store.errors);
1186
- if (throwErrors) {
1196
+ if (throwErrors || action.countDown) {
1187
1197
  throw e;
1188
1198
  }
1189
1199
  });