@hw-component/form 0.0.1 → 0.0.2-bate

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.
Files changed (326) hide show
  1. package/LICENSE +201 -0
  2. package/es/CheckboxGroup/CheckBox/index.d.ts +4 -0
  3. package/es/CheckboxGroup/CheckBox/index.js +40 -0
  4. package/es/CheckboxGroup/hooks.d.ts +5 -0
  5. package/es/CheckboxGroup/hooks.js +123 -0
  6. package/es/CheckboxGroup/index.d.ts +3 -0
  7. package/es/CheckboxGroup/index.js +89 -0
  8. package/es/CheckboxGroup/modal.d.ts +13 -0
  9. package/es/Form/Context/FormConfigProvider.d.ts +5 -0
  10. package/es/Form/Context/FormConfigProvider.js +47 -0
  11. package/es/Form/Context/index.d.ts +5 -0
  12. package/es/Form/Context/index.js +11 -0
  13. package/es/Form/FormItem/BasicItem.d.ts +4 -0
  14. package/es/Form/FormItem/BasicItem.js +73 -0
  15. package/es/Form/FormItem/Helper.d.ts +7 -0
  16. package/es/Form/FormItem/Helper.js +24 -0
  17. package/es/Form/FormItem/RegularFormItem.d.ts +4 -0
  18. package/es/Form/FormItem/RegularFormItem.js +15 -0
  19. package/es/Form/FormItem/UpFormItem.d.ts +4 -0
  20. package/es/Form/FormItem/UpFormItem.js +31 -0
  21. package/es/Form/FormItem/hooks.d.ts +10 -0
  22. package/es/Form/FormItem/hooks.js +38 -0
  23. package/es/Form/FormItem/index.d.ts +4 -0
  24. package/es/Form/FormItem/index.js +11 -0
  25. package/es/Form/HFormConnect.d.ts +6 -0
  26. package/es/Form/HFormConnect.js +54 -0
  27. package/es/Form/InitSet.d.ts +6 -0
  28. package/es/Form/InitSet.js +16 -0
  29. package/es/Form/Label.d.ts +10 -0
  30. package/es/Form/Label.js +46 -0
  31. package/es/Form/config.d.ts +28 -0
  32. package/es/Form/config.js +43 -0
  33. package/es/Form/hooks/index.d.ts +12 -0
  34. package/es/Form/hooks/index.js +77 -0
  35. package/es/Form/hooks/useHForm.d.ts +3 -0
  36. package/es/Form/hooks/useHForm.js +111 -0
  37. package/es/Form/hooks/useInitConfigData.d.ts +4 -0
  38. package/es/Form/hooks/useInitConfigData.js +124 -0
  39. package/es/Form/index.d.ts +4 -0
  40. package/es/Form/index.js +73 -0
  41. package/es/Form/modal.d.ts +92 -0
  42. package/es/Input/ButtonInput.d.ts +4 -0
  43. package/es/Input/ButtonInput.js +80 -0
  44. package/es/Input/InputNumber.d.ts +4 -0
  45. package/es/Input/InputNumber.js +20 -0
  46. package/es/Input/SelectInput.d.ts +9 -0
  47. package/es/Input/SelectInput.js +94 -0
  48. package/es/Input/defaultConfig.d.ts +7 -0
  49. package/es/Input/defaultConfig.js +11 -0
  50. package/es/Input/index.d.ts +4 -0
  51. package/es/Input/index.js +13 -0
  52. package/es/Input/modal.d.ts +25 -0
  53. package/es/PageHandler/ErrorComponent.d.ts +4 -0
  54. package/es/PageHandler/ErrorComponent.js +33 -0
  55. package/es/PageHandler/LoadingComponent.d.ts +3 -0
  56. package/es/PageHandler/LoadingComponent.js +18 -0
  57. package/es/PageHandler/index.d.ts +4 -0
  58. package/es/PageHandler/index.js +24 -0
  59. package/es/PageHandler/modal.d.ts +6 -0
  60. package/es/RadioGroup/index.d.ts +9 -0
  61. package/es/RadioGroup/index.js +48 -0
  62. package/es/Select/components/AllSelect.d.ts +3 -3
  63. package/es/Select/components/AllSelect.js +31 -15
  64. package/es/Select/components/CheckBoxOption.js +2 -2
  65. package/es/Select/components/DropdownComponent.js +2 -2
  66. package/es/Select/components/NoFindItem.js +2 -2
  67. package/es/Select/components/NotFoundContent.js +3 -5
  68. package/es/Select/defaultConfig.d.ts +0 -1
  69. package/es/Select/defaultConfig.js +3 -7
  70. package/es/Select/hooks/changeHooks.d.ts +1 -1
  71. package/es/Select/hooks/changeHooks.js +9 -5
  72. package/es/Select/hooks/norHooks.d.ts +4 -6
  73. package/es/Select/hooks/norHooks.js +20 -37
  74. package/es/Select/index.d.ts +1 -1
  75. package/es/Select/index.js +31 -19
  76. package/es/Select/modal.d.ts +2 -2
  77. package/es/Select/utils.d.ts +2 -0
  78. package/es/Select/utils.js +39 -0
  79. package/es/Submit/index.d.ts +8 -0
  80. package/es/Submit/index.js +28 -0
  81. package/es/Switch/index.d.ts +11 -0
  82. package/es/Switch/index.js +45 -0
  83. package/es/TDPicker/RangePicker.d.ts +8 -0
  84. package/es/TDPicker/RangePicker.js +119 -0
  85. package/es/TDPicker/TimePicker.d.ts +4 -0
  86. package/es/TDPicker/TimePicker.js +31 -0
  87. package/es/TDPicker/hooks.d.ts +33 -0
  88. package/es/TDPicker/hooks.js +132 -0
  89. package/es/TDPicker/index.d.ts +4 -0
  90. package/es/TDPicker/index.js +33 -0
  91. package/es/TDPicker/modal.d.ts +28 -0
  92. package/es/TextArea/index.d.ts +4 -0
  93. package/es/Upload/Btn.d.ts +4 -0
  94. package/es/Upload/Btn.js +31 -0
  95. package/es/Upload/MediaTypeEle/TypeEle.d.ts +10 -0
  96. package/es/Upload/MediaTypeEle/TypeEle.js +40 -0
  97. package/es/Upload/MediaTypeEle/index.d.ts +4 -0
  98. package/es/Upload/MediaTypeEle/index.js +36 -0
  99. package/es/Upload/Preview/index.d.ts +6 -0
  100. package/es/Upload/Preview/index.js +21 -0
  101. package/es/Upload/UrlUpload/index.d.ts +4 -0
  102. package/es/Upload/UrlUpload/index.js +119 -0
  103. package/es/Upload/enums.d.ts +5 -0
  104. package/es/Upload/enums.js +10 -0
  105. package/es/Upload/hooks/change.d.ts +3 -0
  106. package/es/Upload/hooks/change.js +109 -0
  107. package/es/Upload/hooks/customRequest.d.ts +3 -0
  108. package/es/Upload/hooks/customRequest.js +69 -0
  109. package/es/Upload/hooks/propsMaker.d.ts +2 -0
  110. package/es/Upload/hooks/propsMaker.js +37 -0
  111. package/es/Upload/index.d.ts +4 -0
  112. package/es/Upload/index.js +106 -0
  113. package/es/Upload/modal.d.ts +28 -0
  114. package/es/Upload/util.d.ts +5 -0
  115. package/es/Upload/util.js +34 -0
  116. package/es/config.d.ts +2 -0
  117. package/es/config.js +64 -0
  118. package/es/hooks/index.d.ts +13 -0
  119. package/es/hooks/index.js +75 -0
  120. package/es/index.css +33 -1
  121. package/es/index.d.ts +20 -1
  122. package/es/index.js +25 -3
  123. package/es/modal.d.ts +15 -0
  124. package/lib/CheckboxGroup/CheckBox/index.d.ts +4 -0
  125. package/lib/CheckboxGroup/CheckBox/index.js +43 -0
  126. package/lib/CheckboxGroup/hooks.d.ts +5 -0
  127. package/lib/CheckboxGroup/hooks.js +124 -0
  128. package/lib/CheckboxGroup/index.d.ts +3 -0
  129. package/lib/CheckboxGroup/index.js +92 -0
  130. package/lib/CheckboxGroup/modal.d.ts +13 -0
  131. package/lib/Form/Context/FormConfigProvider.d.ts +5 -0
  132. package/lib/Form/Context/FormConfigProvider.js +51 -0
  133. package/lib/Form/Context/index.d.ts +5 -0
  134. package/lib/Form/Context/index.js +14 -0
  135. package/lib/Form/FormItem/BasicItem.d.ts +4 -0
  136. package/lib/Form/FormItem/BasicItem.js +76 -0
  137. package/lib/Form/FormItem/Helper.d.ts +7 -0
  138. package/lib/Form/FormItem/Helper.js +27 -0
  139. package/lib/Form/FormItem/RegularFormItem.d.ts +4 -0
  140. package/lib/Form/FormItem/RegularFormItem.js +18 -0
  141. package/lib/Form/FormItem/UpFormItem.d.ts +4 -0
  142. package/lib/Form/FormItem/UpFormItem.js +34 -0
  143. package/lib/Form/FormItem/hooks.d.ts +10 -0
  144. package/lib/Form/FormItem/hooks.js +41 -0
  145. package/lib/Form/FormItem/index.d.ts +4 -0
  146. package/lib/Form/FormItem/index.js +14 -0
  147. package/lib/Form/HFormConnect.d.ts +6 -0
  148. package/lib/Form/HFormConnect.js +57 -0
  149. package/lib/Form/InitSet.d.ts +6 -0
  150. package/lib/Form/InitSet.js +19 -0
  151. package/lib/Form/Label.d.ts +10 -0
  152. package/lib/Form/Label.js +49 -0
  153. package/lib/Form/config.d.ts +28 -0
  154. package/lib/Form/config.js +47 -0
  155. package/lib/Form/hooks/index.d.ts +12 -0
  156. package/lib/Form/hooks/index.js +80 -0
  157. package/lib/Form/hooks/useHForm.d.ts +3 -0
  158. package/lib/Form/hooks/useHForm.js +114 -0
  159. package/lib/Form/hooks/useInitConfigData.d.ts +4 -0
  160. package/lib/Form/hooks/useInitConfigData.js +127 -0
  161. package/lib/Form/index.d.ts +4 -0
  162. package/lib/Form/index.js +76 -0
  163. package/lib/Form/modal.d.ts +92 -0
  164. package/lib/Input/ButtonInput.d.ts +4 -0
  165. package/lib/Input/ButtonInput.js +83 -0
  166. package/lib/Input/InputNumber.d.ts +4 -0
  167. package/lib/Input/InputNumber.js +23 -0
  168. package/lib/Input/SelectInput.d.ts +9 -0
  169. package/lib/Input/SelectInput.js +98 -0
  170. package/lib/Input/defaultConfig.d.ts +7 -0
  171. package/lib/Input/defaultConfig.js +13 -0
  172. package/lib/Input/index.d.ts +4 -0
  173. package/lib/Input/index.js +16 -0
  174. package/lib/Input/modal.d.ts +25 -0
  175. package/lib/PageHandler/ErrorComponent.d.ts +4 -0
  176. package/lib/PageHandler/ErrorComponent.js +36 -0
  177. package/lib/PageHandler/LoadingComponent.d.ts +3 -0
  178. package/lib/PageHandler/LoadingComponent.js +21 -0
  179. package/lib/PageHandler/index.d.ts +4 -0
  180. package/lib/PageHandler/index.js +27 -0
  181. package/lib/PageHandler/modal.d.ts +6 -0
  182. package/lib/RadioGroup/index.d.ts +9 -0
  183. package/lib/RadioGroup/index.js +51 -0
  184. package/lib/Select/components/AllSelect.d.ts +3 -3
  185. package/lib/Select/components/AllSelect.js +29 -13
  186. package/lib/Select/components/NotFoundContent.js +1 -3
  187. package/lib/Select/defaultConfig.d.ts +0 -1
  188. package/lib/Select/defaultConfig.js +0 -5
  189. package/lib/Select/hooks/changeHooks.d.ts +1 -1
  190. package/lib/Select/hooks/changeHooks.js +7 -3
  191. package/lib/Select/hooks/norHooks.d.ts +4 -6
  192. package/lib/Select/hooks/norHooks.js +18 -35
  193. package/lib/Select/index.d.ts +1 -1
  194. package/lib/Select/index.js +26 -14
  195. package/lib/Select/modal.d.ts +2 -2
  196. package/lib/Select/utils.d.ts +2 -0
  197. package/lib/Select/utils.js +41 -0
  198. package/lib/Submit/index.d.ts +8 -0
  199. package/lib/Submit/index.js +31 -0
  200. package/lib/Switch/index.d.ts +11 -0
  201. package/lib/Switch/index.js +48 -0
  202. package/lib/TDPicker/RangePicker.d.ts +8 -0
  203. package/lib/TDPicker/RangePicker.js +122 -0
  204. package/lib/TDPicker/TimePicker.d.ts +4 -0
  205. package/lib/TDPicker/TimePicker.js +34 -0
  206. package/lib/TDPicker/hooks.d.ts +33 -0
  207. package/lib/TDPicker/hooks.js +139 -0
  208. package/lib/TDPicker/index.d.ts +4 -0
  209. package/lib/TDPicker/index.js +36 -0
  210. package/lib/TDPicker/modal.d.ts +28 -0
  211. package/lib/TextArea/index.d.ts +4 -0
  212. package/lib/Upload/Btn.d.ts +4 -0
  213. package/lib/Upload/Btn.js +34 -0
  214. package/lib/Upload/MediaTypeEle/TypeEle.d.ts +10 -0
  215. package/lib/Upload/MediaTypeEle/TypeEle.js +43 -0
  216. package/lib/Upload/MediaTypeEle/index.d.ts +4 -0
  217. package/lib/Upload/MediaTypeEle/index.js +39 -0
  218. package/lib/Upload/Preview/index.d.ts +6 -0
  219. package/lib/Upload/Preview/index.js +24 -0
  220. package/lib/Upload/UrlUpload/index.d.ts +4 -0
  221. package/lib/Upload/UrlUpload/index.js +122 -0
  222. package/lib/Upload/enums.d.ts +5 -0
  223. package/lib/Upload/enums.js +9 -0
  224. package/lib/Upload/hooks/change.d.ts +3 -0
  225. package/lib/Upload/hooks/change.js +110 -0
  226. package/lib/Upload/hooks/customRequest.d.ts +3 -0
  227. package/lib/Upload/hooks/customRequest.js +70 -0
  228. package/lib/Upload/hooks/propsMaker.d.ts +2 -0
  229. package/lib/Upload/hooks/propsMaker.js +38 -0
  230. package/lib/Upload/index.d.ts +4 -0
  231. package/lib/Upload/index.js +109 -0
  232. package/lib/Upload/modal.d.ts +28 -0
  233. package/lib/Upload/util.d.ts +5 -0
  234. package/lib/Upload/util.js +38 -0
  235. package/lib/config.d.ts +2 -0
  236. package/lib/config.js +65 -0
  237. package/lib/hooks/index.d.ts +13 -0
  238. package/lib/hooks/index.js +78 -0
  239. package/lib/index.css +33 -1
  240. package/lib/index.d.ts +20 -1
  241. package/lib/index.js +38 -3
  242. package/lib/modal.d.ts +15 -0
  243. package/package.json +4 -3
  244. package/scripts/rollup.config.js +3 -8
  245. package/scripts/webpack.config.js +6 -2
  246. package/src/Layout.tsx +4 -4
  247. package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
  248. package/src/components/CheckboxGroup/hooks.ts +102 -0
  249. package/src/components/CheckboxGroup/index.tsx +79 -0
  250. package/src/components/CheckboxGroup/modal.ts +15 -0
  251. package/src/components/Form/Context/FormConfigProvider.tsx +38 -0
  252. package/src/components/Form/Context/index.tsx +14 -0
  253. package/src/components/Form/FormItem/BasicItem.tsx +70 -0
  254. package/src/components/Form/FormItem/Helper.tsx +26 -0
  255. package/src/components/Form/FormItem/RegularFormItem.tsx +7 -0
  256. package/src/components/Form/FormItem/UpFormItem.tsx +20 -0
  257. package/src/components/Form/FormItem/hooks.tsx +44 -0
  258. package/src/components/Form/FormItem/index.tsx +8 -0
  259. package/src/components/Form/HFormConnect.tsx +49 -0
  260. package/src/components/Form/InitSet.tsx +12 -0
  261. package/src/components/Form/Label.tsx +50 -0
  262. package/src/components/Form/config.ts +40 -0
  263. package/src/components/Form/hooks/index.ts +42 -0
  264. package/src/components/Form/hooks/useHForm.ts +89 -0
  265. package/src/components/Form/hooks/useInitConfigData.tsx +100 -0
  266. package/src/components/Form/index.less +22 -0
  267. package/src/components/Form/index.tsx +61 -0
  268. package/src/components/Form/modal.ts +142 -0
  269. package/src/components/Input/ButtonInput.tsx +41 -0
  270. package/src/components/Input/InputNumber.tsx +5 -0
  271. package/src/components/Input/SelectInput.tsx +74 -0
  272. package/src/components/Input/defaultConfig.ts +8 -0
  273. package/src/components/Input/index.tsx +6 -0
  274. package/src/components/Input/modal.ts +31 -0
  275. package/src/components/PageHandler/ErrorComponent.tsx +20 -0
  276. package/src/components/PageHandler/LoadingComponent.tsx +9 -0
  277. package/src/components/PageHandler/index.tsx +14 -0
  278. package/src/components/PageHandler/modal.ts +6 -0
  279. package/src/components/RadioGroup/index.tsx +45 -0
  280. package/src/components/Select/components/AllSelect.tsx +32 -16
  281. package/src/components/Select/components/DropdownComponent.tsx +1 -0
  282. package/src/components/Select/components/NotFoundContent.tsx +1 -1
  283. package/src/components/Select/defaultConfig.tsx +0 -5
  284. package/src/components/Select/hooks/changeHooks.tsx +14 -4
  285. package/src/components/Select/hooks/norHooks.ts +8 -19
  286. package/src/components/Select/index.less +20 -3
  287. package/src/components/Select/index.tsx +29 -17
  288. package/src/components/Select/modal.ts +9 -9
  289. package/src/components/Select/utils.ts +18 -0
  290. package/src/components/Submit/index.tsx +28 -0
  291. package/src/components/Switch/index.tsx +52 -0
  292. package/src/components/TDPicker/RangePicker.tsx +106 -0
  293. package/src/components/TDPicker/TimePicker.tsx +15 -0
  294. package/src/components/TDPicker/hooks.ts +150 -0
  295. package/src/components/TDPicker/index.tsx +22 -0
  296. package/src/components/TDPicker/modal.ts +30 -0
  297. package/src/components/TextArea/index.tsx +8 -0
  298. package/src/components/Upload/Btn.tsx +24 -0
  299. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +26 -0
  300. package/src/components/Upload/MediaTypeEle/index.tsx +34 -0
  301. package/src/components/Upload/Preview/index.tsx +14 -0
  302. package/src/components/Upload/UrlUpload/index.tsx +91 -0
  303. package/src/components/Upload/enums.ts +5 -0
  304. package/src/components/Upload/hooks/change.ts +79 -0
  305. package/src/components/Upload/hooks/customRequest.ts +44 -0
  306. package/src/components/Upload/hooks/propsMaker.ts +20 -0
  307. package/src/components/Upload/index.tsx +85 -0
  308. package/src/components/Upload/modal.ts +31 -0
  309. package/src/components/Upload/util.ts +27 -0
  310. package/src/components/config.ts +40 -0
  311. package/src/components/hooks/index.ts +53 -0
  312. package/src/components/index.tsx +21 -1
  313. package/src/components/modal.ts +15 -0
  314. package/src/components/styles/index.less +2 -0
  315. package/src/components/styles/local.less +1 -0
  316. package/src/pages/Checkbox/index.tsx +15 -0
  317. package/src/pages/DatePicker/index.tsx +33 -0
  318. package/src/pages/Form/index.tsx +146 -0
  319. package/src/pages/Input/index.tsx +22 -0
  320. package/src/pages/Radio/index.tsx +18 -0
  321. package/src/pages/Select/index.tsx +7 -4
  322. package/src/pages/Switch/index.tsx +18 -0
  323. package/src/pages/Upload/index.tsx +14 -0
  324. package/src/routes.tsx +45 -12
  325. package/es/Select/index.less.js +0 -5
  326. package/lib/Select/index.less.js +0 -8
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import type { HItemProps } from "@/components/Form/modal";
3
+ import type { FormInstance } from "antd";
4
+ import { Typography, Row } from "antd";
5
+ import { useFormContext } from "../Context";
6
+
7
+ interface HelperProps {
8
+ helper?: HItemProps["helper"];
9
+ }
10
+
11
+ const Index: React.FC<HelperProps> = ({ helper }) => {
12
+ const { form } = useFormContext();
13
+ if (!helper) {
14
+ return null;
15
+ }
16
+ if (typeof helper === "function") {
17
+ return (
18
+ <Typography.Text type={"secondary"}>
19
+ {helper(form as FormInstance)}
20
+ </Typography.Text>
21
+ );
22
+ }
23
+ return <Typography.Text type={"secondary"}>{helper}</Typography.Text>;
24
+ };
25
+
26
+ export default Index;
@@ -0,0 +1,7 @@
1
+ import BasicItem from "./BasicItem";
2
+ import type { FormItemWithRender } from "../modal";
3
+
4
+ export default (props: FormItemWithRender) => {
5
+ const { type, colon } = props;
6
+ return <BasicItem {...props} colon={type === "submit" ? false : colon} />;
7
+ };
@@ -0,0 +1,20 @@
1
+ import { Form } from "antd";
2
+ import type { FormItemWithRender } from "../modal";
3
+ import BasicItem from "./BasicItem";
4
+ import { useShouldUpdate } from "./hooks";
5
+ const { Item } = Form;
6
+ export default ({
7
+ shouldUpdate,
8
+ dependencies,
9
+ hide,
10
+ ...props
11
+ }: FormItemWithRender) => {
12
+ const resultShouldUpdate = useShouldUpdate({ shouldUpdate, hide });
13
+ return (
14
+ <Item shouldUpdate={resultShouldUpdate} dependencies={dependencies}>
15
+ {() => {
16
+ return <BasicItem hide={hide} {...props} />;
17
+ }}
18
+ </Item>
19
+ );
20
+ };
@@ -0,0 +1,44 @@
1
+ import UpFormItem from "./UpFormItem";
2
+ import RegularFormItem from "./RegularFormItem";
3
+ import { useMemo } from "react";
4
+ import type {
5
+ FormItemWithRender,
6
+ HFormInstance,
7
+ } from "@/components/Form/modal";
8
+ import type { HItemProps } from "@/components/Form/modal";
9
+
10
+ export const useFormItemDomControl = ({
11
+ shouldUpdate,
12
+ hide,
13
+ dependencies,
14
+ }: FormItemWithRender) => {
15
+ return useMemo(() => {
16
+ if (shouldUpdate || typeof hide === "function" || dependencies) {
17
+ return UpFormItem;
18
+ }
19
+ return RegularFormItem;
20
+ }, [shouldUpdate, hide]);
21
+ }; //更新或者不更新组件
22
+
23
+ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
24
+ form: HFormInstance;
25
+ }
26
+ export const useShouldUpdate = ({
27
+ hide,
28
+ shouldUpdate,
29
+ }: Omit<HItemProps, "name">) => {
30
+ if (typeof hide === "function" && !shouldUpdate) {
31
+ return true;
32
+ }
33
+ return shouldUpdate;
34
+ };
35
+
36
+ export const useHide = ({ hide, form }: UseHideUpItemModal) => {
37
+ if (hide === true) {
38
+ return true;
39
+ }
40
+ if (typeof hide === "function") {
41
+ return hide(form);
42
+ }
43
+ return !!hide;
44
+ };
@@ -0,0 +1,8 @@
1
+ import { useFormItemDomControl } from "./hooks";
2
+ import React from "react";
3
+ import type { FormItemWithRender } from "../modal";
4
+
5
+ export default (props: FormItemWithRender) => {
6
+ const Component = useFormItemDomControl(props);
7
+ return <Component {...props} />;
8
+ };
@@ -0,0 +1,49 @@
1
+ import { useFormContext } from "./Context";
2
+ import type { HFormItemProps } from "@/components/Form/modal";
3
+ import React, { useEffect } from "react";
4
+ import type { ConnectConfigModal } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { ConnectResultProps } from "@/components/Form/modal";
7
+
8
+ const formatMaker = (
9
+ itemProps: HFormItemProps,
10
+ formats?: addFormatItemModal
11
+ ) => {
12
+ if (!formats) {
13
+ return formats;
14
+ }
15
+ const { inputValue, outputValue } = formats;
16
+ return {
17
+ inputValue: (value) => {
18
+ return inputValue(itemProps, value);
19
+ },
20
+ outputValue: (value) => {
21
+ return outputValue(itemProps, value);
22
+ },
23
+ };
24
+ };
25
+
26
+ export default (
27
+ Component: React.FunctionComponent | React.ComponentClass,
28
+ config: ConnectConfigModal = {}
29
+ ) => {
30
+ const { format = {} } = config;
31
+ return (props: HFormItemProps) => {
32
+ const { name } = props;
33
+
34
+ const { form, valueType = "float" } = useFormContext();
35
+
36
+ useEffect(() => {
37
+ form?.addFormat(name, formatMaker(props, format[valueType]));
38
+ }, [valueType, props]);
39
+
40
+ const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
41
+ form?.addFormat(name, formatMaker(props, aFormat[valueType]));
42
+ };
43
+
44
+ return React.createElement<ConnectResultProps>(Component, {
45
+ ...props,
46
+ addFormat,
47
+ });
48
+ };
49
+ };
@@ -0,0 +1,12 @@
1
+ import { useFormContext } from "./Context";
2
+ import { useEffect } from "react";
3
+ interface InitSetProps {
4
+ initValues?: Record<string, any>;
5
+ }
6
+ export default ({ initValues }: InitSetProps) => {
7
+ const { form } = useFormContext();
8
+ useEffect(() => {
9
+ form.initValues(initValues);
10
+ }, []);
11
+ return <></>;
12
+ };
@@ -0,0 +1,50 @@
1
+ import type { HoverModal } from "./modal";
2
+ import React from "react";
3
+ import { QuestionCircleOutlined } from "@ant-design/icons";
4
+ import { Tooltip } from "antd";
5
+ import { useClassName } from "../hooks";
6
+
7
+ interface IProps {
8
+ labelWidth?: number;
9
+ hover?: string | HoverModal;
10
+ colon?: boolean;
11
+ required?: boolean;
12
+ }
13
+ const useHover = ({ hover }: IProps) => {
14
+ if (!hover || typeof hover === "string") {
15
+ return {
16
+ text: hover,
17
+ icon: <QuestionCircleOutlined />,
18
+ };
19
+ }
20
+ return hover;
21
+ };
22
+ const Index: React.FC<IProps> = ({
23
+ labelWidth,
24
+ children,
25
+ colon,
26
+ required,
27
+ hover,
28
+ }) => {
29
+ const { text, icon } = useHover({ hover });
30
+ const array = [
31
+ colon ? "hw-form-item-colon" : "",
32
+ required ? "hw-form-item-required" : "",
33
+ ];
34
+
35
+ const className = useClassName(array);
36
+ return (
37
+ <div style={{ width: labelWidth }} className={className}>
38
+ {children}
39
+ {text && (
40
+ <span style={{ marginLeft: 4 }}>
41
+ <Tooltip placement="top" title={text}>
42
+ {icon}
43
+ </Tooltip>
44
+ </span>
45
+ )}
46
+ </div>
47
+ );
48
+ };
49
+
50
+ export default Index;
@@ -0,0 +1,40 @@
1
+ import HSelect from "../Select";
2
+ import HInput from "../Input";
3
+ import HInputNumber from "../Input/InputNumber";
4
+ import HSelectInput from "../Input/SelectInput";
5
+ import HButtonInput from "../Input/ButtonInput";
6
+ import HCheckboxGroup from "../CheckboxGroup";
7
+ import HCheckBox from "../CheckboxGroup/CheckBox";
8
+ import HRadioGroup from "../RadioGroup";
9
+ import HSwitch from "../Switch";
10
+ import HDatePicker from "../TDPicker";
11
+ import HRangePicker from "../TDPicker/RangePicker";
12
+ import HTimePicker from "../TDPicker/TimePicker";
13
+ import HUpload from "../Upload";
14
+ import HUrlUpload from "../Upload/UrlUpload";
15
+ import HSubmit from "../Submit";
16
+ import FormConfigProvider from "../Form/Context/FormConfigProvider";
17
+
18
+ export const placeholderConfig = {
19
+ inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
20
+ selectType: ["select", "datePicker", "timePicker"],
21
+ };
22
+
23
+ export default {
24
+ select: HSelect,
25
+ inputNumber: HInputNumber,
26
+ selectInput: HSelectInput,
27
+ buttonInput: HButtonInput,
28
+ checkboxGroup: HCheckboxGroup,
29
+ checkBox: HCheckBox,
30
+ radioGroup: HRadioGroup,
31
+ switch: HSwitch,
32
+ datePicker: HDatePicker,
33
+ rangePicker: HRangePicker,
34
+ timePicker: HTimePicker,
35
+ input: HInput,
36
+ upload: HUpload,
37
+ urlUpload: HUrlUpload,
38
+ submit: HSubmit,
39
+ formConfigProvider: FormConfigProvider,
40
+ };
@@ -0,0 +1,42 @@
1
+ import { useRequest } from "ahooks";
2
+ import type { HFormProps } from "@/components/Form/modal";
3
+ import useHForm from "./useHForm";
4
+ import type { HFormInstance } from "@/components/Form/modal";
5
+ export const useCurrentForm = (form?: HFormInstance) => {
6
+ const selfForm = useHForm();
7
+ return form || selfForm;
8
+ };
9
+ type ParamsModal = Omit<HFormProps, "configData">;
10
+
11
+ export const useSub = ({ request, onFinish, form }: ParamsModal) => {
12
+ return useRequest(
13
+ async (value) => {
14
+ const subVal = form?.outputValues(value);
15
+ if (request) {
16
+ await request(subVal);
17
+ }
18
+ onFinish?.(subVal);
19
+ },
20
+ { manual: true }
21
+ );
22
+ }; //提交
23
+
24
+ export const useInit = ({ infoRequest, initialValues = {} }: ParamsModal) => {
25
+ const {
26
+ run: infoRun,
27
+ loading: infoLoading,
28
+ error: infoErr,
29
+ data: infoData,
30
+ } = useRequest(async () => {
31
+ if (infoRequest) {
32
+ return infoRequest();
33
+ }
34
+ return initialValues;
35
+ });
36
+ return {
37
+ infoRun,
38
+ infoLoading,
39
+ infoErr,
40
+ infoData,
41
+ };
42
+ }; //初始化
@@ -0,0 +1,89 @@
1
+ import { useMemo } from "react";
2
+ import { Form } from "antd";
3
+ import type { FormatItemModal, HFormInstance } from "../modal";
4
+
5
+ export default () => {
6
+ const [form] = Form.useForm();
7
+ return useMemo<HFormInstance>(() => {
8
+ const formatSourceData: Record<string, FormatItemModal> = {};
9
+ let dispatchSourceData: Record<string, VoidFunction[]> = {};
10
+ return {
11
+ addFormat(name: string, format?: FormatItemModal) {
12
+ if (!format) {
13
+ return;
14
+ }
15
+ const { inputValue, outputValue } = format;
16
+ formatSourceData[name] = {
17
+ inputValue,
18
+ outputValue,
19
+ };
20
+ }, //注册转化方法
21
+ formatValues(value = {}, formatKey = "inputValue") {
22
+ const valKeys = Object.keys(value).length;
23
+ if (!valKeys) {
24
+ return {};
25
+ }
26
+ let newValue = { ...value };
27
+ const keys = Object.keys(formatSourceData);
28
+ keys.forEach((key) => {
29
+ const format = formatSourceData[key]?.[formatKey];
30
+ if (!format) {
31
+ return;
32
+ }
33
+ const resultValue = format(value);
34
+ Reflect.deleteProperty(newValue, key);
35
+ newValue = {
36
+ ...newValue,
37
+ ...resultValue,
38
+ };
39
+ });
40
+ return newValue;
41
+ }, //转化方法
42
+ dispatch(key) {
43
+ const items = dispatchSourceData[key];
44
+ if (!items) {
45
+ return;
46
+ }
47
+ items.forEach((fn) => {
48
+ fn();
49
+ });
50
+ },
51
+ addDispatchListener(key, fn) {
52
+ const items = dispatchSourceData[key];
53
+ if (!items) {
54
+ dispatchSourceData[key] = [fn];
55
+ return;
56
+ }
57
+ items.push(fn);
58
+ dispatchSourceData[key] = items;
59
+ },
60
+ removeDispatchListener(key) {
61
+ if (!key) {
62
+ dispatchSourceData = {};
63
+ return;
64
+ }
65
+ Reflect.deleteProperty(dispatchSourceData, key);
66
+ },
67
+ initValues(value = {}) {
68
+ const newValue = this.formatValues(value);
69
+ form.setFieldsValue(newValue);
70
+ },
71
+ outputValues(value) {
72
+ return this.formatValues(value, "outputValue");
73
+ },
74
+ ...form,
75
+ setFieldsValue(values) {
76
+ const newValue = this.formatValues(values);
77
+ form.setFieldsValue(newValue);
78
+ },
79
+ validateFields(nameList) {
80
+ return new Promise((resolve) => {
81
+ form.validateFields(nameList).then((value) => {
82
+ const result = this.formatValues(value, "outputValue");
83
+ return resolve(result);
84
+ });
85
+ });
86
+ },
87
+ };
88
+ }, []);
89
+ };
@@ -0,0 +1,100 @@
1
+ import { useMemo } from "react";
2
+ import type {
3
+ FormItemWithRender,
4
+ HFormItemProps,
5
+ HFormProps,
6
+ HItemProps,
7
+ } from "@/components/Form/modal";
8
+ import FormConfig, { placeholderConfig } from "../config";
9
+ import type { Rule } from "rc-field-form/lib/interface";
10
+ import type { FormInstance } from "antd";
11
+
12
+ const mathRequired = (configItem: HFormItemProps, form: FormInstance) => {
13
+ const { required, placeholder, rules, type = "input" } = configItem;
14
+ let resultRequired = false;
15
+ const dom = FormConfig[type];
16
+ const resultRules = rules?.map((item) => {
17
+ let eachItem = item;
18
+ if (typeof item === "function") {
19
+ eachItem = item(form);
20
+ }
21
+
22
+ const { required: itemRequired, message } = eachItem as any;
23
+ if (itemRequired) {
24
+ resultRequired = itemRequired;
25
+ }
26
+ if (itemRequired && !message) {
27
+ return {
28
+ ...eachItem,
29
+ required: itemRequired,
30
+ message: !!dom?.requiredErrMsg
31
+ ? dom.requiredErrMsg(configItem)
32
+ : placeholder,
33
+ };
34
+ }
35
+ return eachItem;
36
+ });
37
+ return {
38
+ required: typeof required === "boolean" ? required : resultRequired,
39
+ rules: resultRules as Rule[],
40
+ };
41
+ }; //是否必填
42
+ const matchDefaultPlaceholder = (props: HFormItemProps) => {
43
+ const { label, placeholder, type = "input" } = props;
44
+ const dom = FormConfig[type];
45
+ if (placeholder) {
46
+ return placeholder;
47
+ }
48
+ if (dom?.placeholder) {
49
+ return dom.placeholder(props);
50
+ }
51
+ if (placeholderConfig.inputType.indexOf(type) !== -1) {
52
+ return `请输入${label}`;
53
+ }
54
+ return `请选择${label}`;
55
+ }; //自动构建
56
+ const defaultRenderMaker = (props: HFormItemProps) => {
57
+ const { render, type = "input", itemProps = {}, ...componentProps } = props;
58
+ const dom = FormConfig[type];
59
+ return (form: FormInstance) => {
60
+ const Component = !!dom?.Component ? dom.Component : dom;
61
+ const node = Component && (
62
+ <Component {...componentProps} {...itemProps} form={form} />
63
+ );
64
+ if (render) {
65
+ return render(props, node, form);
66
+ }
67
+ return node;
68
+ };
69
+ };
70
+
71
+ const defaultPlaceholderPropsMaker = (props: HFormItemProps) => {
72
+ const placeholder = matchDefaultPlaceholder(props);
73
+ return {
74
+ ...props,
75
+ placeholder,
76
+ render: defaultRenderMaker({ ...props, placeholder }),
77
+ };
78
+ }; //组装参数
79
+ const itemControl = (
80
+ item: HItemProps,
81
+ form: FormInstance
82
+ ): FormItemWithRender => {
83
+ const { render, ...defaultProps } = defaultPlaceholderPropsMaker(item);
84
+ const { rules, required } = mathRequired(defaultProps, form);
85
+ return {
86
+ ...defaultProps,
87
+ required,
88
+ rules,
89
+ render,
90
+ };
91
+ };
92
+ type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
93
+
94
+ export default ({ configData, form }: InitConfigModal) => {
95
+ return useMemo(() => {
96
+ return configData.map((item) => {
97
+ return itemControl(item, form);
98
+ });
99
+ }, [configData]);
100
+ };
@@ -0,0 +1,22 @@
1
+ @import "../styles/local.less";
2
+ .@{ant-prefix}-hw-form-item-colon:after {
3
+ position: relative;
4
+ top: -0.5px;
5
+ margin: 0 8px 0 2px;
6
+ content: ":";
7
+ }
8
+ .@{ant-prefix}-hw-form-item-required:before {
9
+ display: inline-block;
10
+ margin-right: 4px;
11
+ color: #ff4d4f;
12
+ font-size: 14px;
13
+ font-family: SimSun, sans-serif;
14
+ line-height: 1;
15
+ content: "*";
16
+ }
17
+
18
+ .@{ant-prefix}-hw-form-base-item {
19
+ display: flex;
20
+ align-items: center;
21
+ min-height: 32px;
22
+ }
@@ -0,0 +1,61 @@
1
+ import { Form } from "antd";
2
+ import type { HFormProps } from "./modal";
3
+ import Item from "./FormItem";
4
+ import { useCurrentForm, useInit, useSub } from "./hooks";
5
+ import { FormContext } from "./Context";
6
+ import PageHandler from "../PageHandler";
7
+ import useInitConfigData from "./hooks/useInitConfigData";
8
+ import InitSet from "./InitSet";
9
+ export default ({
10
+ configData,
11
+ labelWidth,
12
+ form,
13
+ request,
14
+ onFinish,
15
+ infoRequest,
16
+ valueType = "float",
17
+ initialValues,
18
+ ...props
19
+ }: HFormProps) => {
20
+ const hForm = useCurrentForm(form);
21
+ const newConfigData = useInitConfigData({
22
+ configData,
23
+ form: hForm,
24
+ });
25
+ const { run, loading } = useSub({
26
+ request,
27
+ onFinish,
28
+ valueType,
29
+ form: hForm,
30
+ });
31
+
32
+ const { infoRun, infoLoading, infoErr, infoData } = useInit({
33
+ infoRequest,
34
+ initialValues,
35
+ });
36
+
37
+ return (
38
+ <PageHandler
39
+ loading={infoLoading}
40
+ error={infoErr}
41
+ data={infoData}
42
+ reload={infoRun}
43
+ >
44
+ <FormContext.Provider value={{ loading, form: hForm, valueType }}>
45
+ <Form form={hForm} onFinish={run} {...props}>
46
+ {newConfigData.map((itemData, index) => {
47
+ const { labelWidth: itemLabelWidth } = itemData;
48
+ return (
49
+ <Item
50
+ {...itemData}
51
+ key={index}
52
+ labelWidth={itemLabelWidth || labelWidth}
53
+ />
54
+ );
55
+ })}
56
+ </Form>
57
+ <InitSet initValues={infoData} />
58
+ </FormContext.Provider>
59
+ </PageHandler>
60
+ );
61
+ };