@cicctencent/formily 0.0.0-stage → 0.0.1

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 (308) hide show
  1. package/.eslintrc.js +40 -0
  2. package/.prettierrc.js +28 -0
  3. package/.vscode/launch.json +23 -0
  4. package/CHANGELOG.md +8 -0
  5. package/README.md +22 -2
  6. package/babel.config.js +3 -0
  7. package/build/build.js +96 -0
  8. package/build/rollup.config.bundle.js +63 -0
  9. package/build/update.version.js +35 -0
  10. package/dist/index.css +2516 -0
  11. package/dist/index.js +8377 -0
  12. package/dist/schema-field/index.css +2466 -0
  13. package/dist/schema-field/index.js +8213 -0
  14. package/dist/transform/index.js +551 -0
  15. package/dist/validate/index.js +1104 -0
  16. package/dist/vue-form/index.css +2516 -0
  17. package/dist/vue-form/index.js +8359 -0
  18. package/docs/.vuepress/client.ts +15 -0
  19. package/docs/.vuepress/components/code-preview.vue +203 -0
  20. package/docs/.vuepress/components/highlight.ts +53 -0
  21. package/docs/.vuepress/config.ts +39 -0
  22. package/docs/.vuepress/util.ts +7 -0
  23. package/docs/README.md +30 -0
  24. package/docs/components/anyOf.md +26 -0
  25. package/docs/components/array-cards.md +12 -0
  26. package/docs/components/array-collapse.md +12 -0
  27. package/docs/components/array-items.md +12 -0
  28. package/docs/components/array-table.md +12 -0
  29. package/docs/components/array-tabs.md +16 -0
  30. package/docs/components/cascader.md +12 -0
  31. package/docs/components/checkbox.md +12 -0
  32. package/docs/components/event.md +27 -0
  33. package/docs/components/hotArea.md +25 -0
  34. package/docs/components/index.md +4 -0
  35. package/docs/components/input.md +30 -0
  36. package/docs/components/layout-group.md +19 -0
  37. package/docs/components/link.md +22 -0
  38. package/docs/components/oneOf.md +8 -0
  39. package/docs/components/radio.md +12 -0
  40. package/docs/components/rich-editor.md +21 -0
  41. package/docs/components/select.md +34 -0
  42. package/docs/components/space.md +11 -0
  43. package/docs/components/switch.md +20 -0
  44. package/docs/components/text.md +21 -0
  45. package/docs/components/time-picker.md +11 -0
  46. package/docs/components/transfer.md +14 -0
  47. package/docs/components/upload-button.md +28 -0
  48. package/docs/demos/any-of/index.vue +66 -0
  49. package/docs/demos/array-cards/index.vue +105 -0
  50. package/docs/demos/array-collapse/index.vue +155 -0
  51. package/docs/demos/array-items/index.vue +171 -0
  52. package/docs/demos/array-table/index.vue +115 -0
  53. package/docs/demos/array-tabs/index.vue +56 -0
  54. package/docs/demos/cascader/index.vue +297 -0
  55. package/docs/demos/checkbox/index.vue +39 -0
  56. package/docs/demos/event/index.vue +436 -0
  57. package/docs/demos/hotArea/index.vue +240 -0
  58. package/docs/demos/index.vue +36 -0
  59. package/docs/demos/input/index.vue +46 -0
  60. package/docs/demos/layout-group/index.vue +51 -0
  61. package/docs/demos/link/index.vue +32 -0
  62. package/docs/demos/radio/index.vue +36 -0
  63. package/docs/demos/rich-editor/index.vue +22 -0
  64. package/docs/demos/select/index.vue +76 -0
  65. package/docs/demos/space/index.vue +93 -0
  66. package/docs/demos/switch/index.vue +31 -0
  67. package/docs/demos/text/index.vue +38 -0
  68. package/docs/demos/time-picker/index.vue +39 -0
  69. package/docs/demos/transfer/index.vue +26 -0
  70. package/docs/demos/upload-button/index.vue +27 -0
  71. package/docs/demos/x-data/add-button-title.vue +101 -0
  72. package/docs/demos/x-data/send-message.vue +33 -0
  73. package/docs/demos/x-reactions/any-of.vue +40 -0
  74. package/docs/demos/x-reactions/x-reactions.vue +39 -0
  75. package/docs/guide/component-extend.md +23 -0
  76. package/docs/guide/extra-bury-report.md +64 -0
  77. package/docs/guide/schema.md +22 -0
  78. package/docs/guide/x-data.md +41 -0
  79. package/docs/guide/x-reactions.md +20 -0
  80. package/example/.browserslistrc +4 -0
  81. package/example/.eslintrc.js +20 -0
  82. package/example/README.md +24 -0
  83. package/example/index.html +15 -0
  84. package/example/jest.config.js +26 -0
  85. package/example/package.json +50 -0
  86. package/example/public/favicon.ico +0 -0
  87. package/example/public/index.html +17 -0
  88. package/example/src/App.vue +25 -0
  89. package/example/src/assets/logo.png +0 -0
  90. package/example/src/components/HelloWorld.vue +148 -0
  91. package/example/src/components/group/index.vue +16 -0
  92. package/example/src/components/uploadBtn/index.vue +44 -0
  93. package/example/src/components/uploadBtn/upload-icon.svg +6 -0
  94. package/example/src/layout/component/Aside.vue +39 -0
  95. package/example/src/layout/component/Main.vue +9 -0
  96. package/example/src/layout/index.vue +15 -0
  97. package/example/src/main.ts +17 -0
  98. package/example/src/router/index.ts +99 -0
  99. package/example/src/shims-vue.d.ts +6 -0
  100. package/example/src/store/index.ts +9 -0
  101. package/example/src/views/demo/any-of/data.ts +38 -0
  102. package/example/src/views/demo/any-of/index.vue +35 -0
  103. package/example/src/views/demo/array-cards/data.ts +65 -0
  104. package/example/src/views/demo/array-cards/index.vue +33 -0
  105. package/example/src/views/demo/array-items/data.ts +29 -0
  106. package/example/src/views/demo/array-items/index.vue +33 -0
  107. package/example/src/views/demo/cloud-button/data.ts +14 -0
  108. package/example/src/views/demo/cloud-button/index.vue +22 -0
  109. package/example/src/views/demo/color-group/data.ts +15 -0
  110. package/example/src/views/demo/color-group/index.vue +22 -0
  111. package/example/src/views/demo/color-picker/data.ts +21 -0
  112. package/example/src/views/demo/color-picker/index.vue +33 -0
  113. package/example/src/views/demo/datatime/data.ts +62 -0
  114. package/example/src/views/demo/datatime/index.vue +22 -0
  115. package/example/src/views/demo/event/data.ts +184 -0
  116. package/example/src/views/demo/event/index.vue +33 -0
  117. package/example/src/views/demo/hot-area/data.ts +196 -0
  118. package/example/src/views/demo/hot-area/index.vue +33 -0
  119. package/example/src/views/demo/input/data.ts +39 -0
  120. package/example/src/views/demo/input/index.vue +33 -0
  121. package/example/src/views/demo/link/data.ts +23 -0
  122. package/example/src/views/demo/link/index.vue +22 -0
  123. package/example/src/views/demo/one-of/data.ts +139 -0
  124. package/example/src/views/demo/one-of/index.vue +33 -0
  125. package/example/src/views/demo/rich-editor/data.ts +12 -0
  126. package/example/src/views/demo/rich-editor/index.vue +24 -0
  127. package/example/src/views/demo/select/data.ts +38 -0
  128. package/example/src/views/demo/select/index.vue +33 -0
  129. package/example/src/views/demo/upload-button/data1.ts +11 -0
  130. package/example/src/views/demo/upload-button/data2.ts +12 -0
  131. package/example/src/views/demo/upload-button/index.vue +42 -0
  132. package/example/tsconfig.json +32 -0
  133. package/example/vite.config.ts +12 -0
  134. package/jest.config.js +4 -0
  135. package/package.json +92 -4
  136. package/src/components/__builtins__/configs/index.ts +1 -0
  137. package/src/components/__builtins__/index.ts +2 -0
  138. package/src/components/__builtins__/shared/create-context.ts +54 -0
  139. package/src/components/__builtins__/shared/index.ts +7 -0
  140. package/src/components/__builtins__/shared/loading.ts +20 -0
  141. package/src/components/__builtins__/shared/portal.ts +43 -0
  142. package/src/components/__builtins__/shared/resolve-component.ts +22 -0
  143. package/src/components/__builtins__/shared/transform-component.ts +33 -0
  144. package/src/components/__builtins__/shared/types.ts +8 -0
  145. package/src/components/__builtins__/shared/utils.ts +35 -0
  146. package/src/components/__builtins__/styles/common.scss +22 -0
  147. package/src/components/__builtins__/styles/element-plus.scss +1094 -0
  148. package/src/components/any-of/index.ts +20 -0
  149. package/src/components/array-base/index.ts +413 -0
  150. package/src/components/array-base/style.scss +53 -0
  151. package/src/components/array-base/style.ts +2 -0
  152. package/src/components/array-cards/index.ts +253 -0
  153. package/src/components/array-cards/style.scss +33 -0
  154. package/src/components/array-cards/style.ts +7 -0
  155. package/src/components/array-collapse/index.ts +381 -0
  156. package/src/components/array-collapse/style.scss +38 -0
  157. package/src/components/array-collapse/style.ts +10 -0
  158. package/src/components/array-items/index.ts +213 -0
  159. package/src/components/array-items/style.scss +82 -0
  160. package/src/components/array-items/style.ts +4 -0
  161. package/src/components/array-table/index.ts +567 -0
  162. package/src/components/array-table/style.scss +84 -0
  163. package/src/components/array-table/style.ts +11 -0
  164. package/src/components/array-tabs/index.ts +141 -0
  165. package/src/components/array-tabs/style.scss +16 -0
  166. package/src/components/array-tabs/style.ts +5 -0
  167. package/src/components/base/AnyOf/index.ts +155 -0
  168. package/src/components/base/AnyOf/index.vue +111 -0
  169. package/src/components/base/CloudButton/index.ts +46 -0
  170. package/src/components/base/CloudButton/index.vue +128 -0
  171. package/src/components/base/ColorGroup/index.ts +57 -0
  172. package/src/components/base/ColorGroup/index.vue +30 -0
  173. package/src/components/base/ColorPicker/index.ts +45 -0
  174. package/src/components/base/ColorPicker/index.vue +50 -0
  175. package/src/components/base/Container/index.vue +39 -0
  176. package/src/components/base/HotArea/index.ts +698 -0
  177. package/src/components/base/HotArea/index.vue +565 -0
  178. package/src/components/base/HotArea/type.ts +18 -0
  179. package/src/components/base/Input/index.vue +150 -0
  180. package/src/components/base/LayoutGroup/index.vue +40 -0
  181. package/src/components/base/Link/index.vue +43 -0
  182. package/src/components/base/Middleware/index.ts +235 -0
  183. package/src/components/base/Middleware/index.vue +169 -0
  184. package/src/components/base/OneOf/index.ts +105 -0
  185. package/src/components/base/OneOf/index.vue +85 -0
  186. package/src/components/base/RichEditor/index.ts +13 -0
  187. package/src/components/base/RichEditor/index.vue +120 -0
  188. package/src/components/base/RichEditor/options.ts +24 -0
  189. package/src/components/base/Select/index.ts +106 -0
  190. package/src/components/base/Select/index.vue +161 -0
  191. package/src/components/base/Switch/index.vue +42 -0
  192. package/src/components/base/Text/index.vue +47 -0
  193. package/src/components/base/event/index.ts +226 -0
  194. package/src/components/base/event/index.vue +356 -0
  195. package/src/components/cascader/index.ts +48 -0
  196. package/src/components/cascader/style.ts +5 -0
  197. package/src/components/checkbox/index.ts +166 -0
  198. package/src/components/checkbox/style.ts +5 -0
  199. package/src/components/cloud-button/index.ts +21 -0
  200. package/src/components/color-group/index.ts +18 -0
  201. package/src/components/color-picker/index.ts +18 -0
  202. package/src/components/container/index.ts +18 -0
  203. package/src/components/data-time/index.ts +24 -0
  204. package/src/components/date-picker/index.ts +51 -0
  205. package/src/components/date-picker/style.ts +4 -0
  206. package/src/components/editable/index.ts +261 -0
  207. package/src/components/editable/style.scss +55 -0
  208. package/src/components/editable/style.ts +5 -0
  209. package/src/components/el-form-item/index.ts +21 -0
  210. package/src/components/el-form-item/style.ts +3 -0
  211. package/src/components/event/index.ts +16 -0
  212. package/src/components/form/index.ts +94 -0
  213. package/src/components/form/style.scss +0 -0
  214. package/src/components/form/style.ts +3 -0
  215. package/src/components/form-button-group/index.ts +74 -0
  216. package/src/components/form-button-group/style.scss +0 -0
  217. package/src/components/form-button-group/style.ts +4 -0
  218. package/src/components/form-collapse/index.ts +215 -0
  219. package/src/components/form-collapse/style.scss +6 -0
  220. package/src/components/form-collapse/style.ts +4 -0
  221. package/src/components/form-dialog/index.ts +433 -0
  222. package/src/components/form-dialog/style.ts +4 -0
  223. package/src/components/form-drawer/index.ts +424 -0
  224. package/src/components/form-drawer/style.scss +21 -0
  225. package/src/components/form-drawer/style.ts +4 -0
  226. package/src/components/form-grid/index.ts +181 -0
  227. package/src/components/form-grid/style.scss +5 -0
  228. package/src/components/form-grid/style.ts +1 -0
  229. package/src/components/form-item/animation.scss +72 -0
  230. package/src/components/form-item/grid.scss +171 -0
  231. package/src/components/form-item/index.ts +642 -0
  232. package/src/components/form-item/style.scss +521 -0
  233. package/src/components/form-item/style.ts +2 -0
  234. package/src/components/form-item/var.scss +17 -0
  235. package/src/components/form-layout/index.ts +161 -0
  236. package/src/components/form-layout/style.scss +6 -0
  237. package/src/components/form-layout/style.ts +1 -0
  238. package/src/components/form-layout/useResponsiveFormLayout.ts +118 -0
  239. package/src/components/form-step/index.ts +210 -0
  240. package/src/components/form-step/style.ts +2 -0
  241. package/src/components/form-tab/index.ts +172 -0
  242. package/src/components/form-tab/style.scss +6 -0
  243. package/src/components/form-tab/style.ts +4 -0
  244. package/src/components/hot-area/index.ts +20 -0
  245. package/src/components/index.ts +49 -0
  246. package/src/components/input/index.ts +35 -0
  247. package/src/components/input/style.ts +4 -0
  248. package/src/components/input-number/index.ts +36 -0
  249. package/src/components/input-number/style.ts +3 -0
  250. package/src/components/layout-group/index.ts +18 -0
  251. package/src/components/link/index.ts +18 -0
  252. package/src/components/middleware/index.ts +21 -0
  253. package/src/components/one-of/index.ts +20 -0
  254. package/src/components/placeholder-input/index.ts +21 -0
  255. package/src/components/placeholder-input/index.vue +87 -0
  256. package/src/components/preview-text/index.ts +303 -0
  257. package/src/components/preview-text/style.ts +9 -0
  258. package/src/components/radio/index.ts +109 -0
  259. package/src/components/radio/style.ts +3 -0
  260. package/src/components/reset/index.ts +52 -0
  261. package/src/components/reset/style.ts +1 -0
  262. package/src/components/rich-editor/index.ts +18 -0
  263. package/src/components/row/index.ts +20 -0
  264. package/src/components/row/index.vue +53 -0
  265. package/src/components/select/index.ts +19 -0
  266. package/src/components/select/style.ts +5 -0
  267. package/src/components/space/index.ts +98 -0
  268. package/src/components/space/style.scss +24 -0
  269. package/src/components/space/style.ts +1 -0
  270. package/src/components/submit/index.ts +59 -0
  271. package/src/components/submit/style.ts +1 -0
  272. package/src/components/switch/index.ts +9 -0
  273. package/src/components/switch/style.ts +1 -0
  274. package/src/components/text/index.ts +21 -0
  275. package/src/components/time-picker/index.ts +21 -0
  276. package/src/components/time-picker/style.ts +4 -0
  277. package/src/components/transfer/index.ts +12 -0
  278. package/src/components/transfer/style.ts +1 -0
  279. package/src/components/upload/index.ts +136 -0
  280. package/src/components/upload/style.ts +2 -0
  281. package/src/components/upload-button/index.ts +21 -0
  282. package/src/components/upload-button/index.vue +199 -0
  283. package/src/createScemaField.ts +14 -0
  284. package/src/index.ts +41 -0
  285. package/src/schema-field/index.ts +11 -0
  286. package/src/scope.ts +29 -0
  287. package/src/transform/core.ts +404 -0
  288. package/src/transform/index.ts +11 -0
  289. package/src/transform/transform.ts +59 -0
  290. package/src/transform/utils/constant.ts +79 -0
  291. package/src/transform/utils/func.ts +145 -0
  292. package/src/typings/common.ts +37 -0
  293. package/src/typings/vue-shim.d.ts +7 -0
  294. package/src/typings/vue-test-utils.d.ts +11 -0
  295. package/src/utils/anyof_utils.ts +95 -0
  296. package/src/utils/common.ts +15 -0
  297. package/src/validate/index.ts +648 -0
  298. package/src/validate/utils/constant.ts +2 -0
  299. package/src/vue-form/index.ts +18 -0
  300. package/src/vue-form/index.vue +106 -0
  301. package/src/vue-form/useForm.ts +112 -0
  302. package/tests/data/anyof.ts +40 -0
  303. package/tests/data/image.ts +472 -0
  304. package/tests/fixtures/validate.ts +63 -0
  305. package/tests/unit/transform.spec.ts +253 -0
  306. package/tests/unit/utils.spec.ts +10 -0
  307. package/tests/unit/validate.spec.ts +256 -0
  308. package/tsconfig.json +23 -0
@@ -0,0 +1,567 @@
1
+ import { computed, defineComponent, ref, Ref, h } from 'vue';
2
+ import {
3
+ GeneralField,
4
+ IVoidFieldFactoryProps,
5
+ FieldDisplayTypes,
6
+ ArrayField,
7
+ } from '@formily/core';
8
+ import {
9
+ useField,
10
+ useFieldSchema,
11
+ RecursionField as _RecursionField,
12
+ FragmentComponent,
13
+ } from '@formily/vue';
14
+ import { observer } from '@formily/reactive-vue';
15
+ import { isArr, isBool } from '@formily/shared';
16
+ import type { Schema } from '@formily/json-schema';
17
+ import type { VNode, Component } from 'vue';
18
+ import {
19
+ ElTable,
20
+ ElTableColumn,
21
+ ElPagination,
22
+ ElSelect,
23
+ ElOption,
24
+ ElBadge,
25
+ } from '@cicctencent/jtui';
26
+ // todo 完善any类型
27
+ import { Space } from '../space';
28
+ import { ArrayBase } from '../array-base';
29
+ import { stylePrefix } from '../__builtins__/configs';
30
+ import { composeExport } from '../__builtins__/shared';
31
+ import './style.scss';
32
+ type ElTableProps = typeof ElTable;
33
+ type ElColumnProps = typeof ElTableColumn;
34
+ type ElPaginationProps = typeof ElPagination;
35
+
36
+ const RecursionField = _RecursionField as unknown as Component;
37
+
38
+ type ArrayTableProps = ElTableProps & {
39
+ pagination?: ElPaginationProps | boolean;
40
+ };
41
+
42
+ interface ObservableColumnSource {
43
+ field: GeneralField;
44
+ fieldProps: IVoidFieldFactoryProps<any, any>;
45
+ columnProps: ElColumnProps & { title: string; asterisk: boolean };
46
+ schema: Schema;
47
+ display: FieldDisplayTypes;
48
+ required: boolean;
49
+ name: string;
50
+ }
51
+
52
+ type ColumnProps = ElColumnProps & {
53
+ key: string | number;
54
+ asterisk: boolean;
55
+ render?: (
56
+ startIndex?: Ref<number>
57
+ ) => (props: {
58
+ row: Record<string, any>;
59
+ column: ElColumnProps;
60
+ $index: number;
61
+ }) => VNode;
62
+ };
63
+
64
+ const isColumnComponent = (schema: Schema) => {
65
+ return schema['x-component']?.indexOf('Column') > -1;
66
+ };
67
+
68
+ const isOperationsComponent = (schema: Schema) => {
69
+ return schema['x-component']?.indexOf('Operations') > -1;
70
+ };
71
+
72
+ const isAdditionComponent = (schema: Schema) => {
73
+ return schema['x-component']?.indexOf('Addition') > -1;
74
+ };
75
+
76
+ const getArrayTableSources = (
77
+ arrayFieldRef: Ref<ArrayField>,
78
+ schemaRef: Ref<Schema>
79
+ ) => {
80
+ const arrayField = arrayFieldRef.value;
81
+ const parseSources = (schema: Schema): ObservableColumnSource[] => {
82
+ if (
83
+ isColumnComponent(schema) ||
84
+ isOperationsComponent(schema) ||
85
+ isAdditionComponent(schema)
86
+ ) {
87
+ if (!schema['x-component-props']?.['prop'] && !schema['name'])
88
+ return [];
89
+ const name =
90
+ schema['x-component-props']?.['prop'] || schema['name'];
91
+ const field = arrayField
92
+ .query(arrayField.address.concat(name))
93
+ .take();
94
+ const fieldProps = field?.props || schema.toFieldProps();
95
+ const columnProps =
96
+ (field?.component as any[])?.[1] ||
97
+ schema['x-component-props'] ||
98
+ {};
99
+ const display = field?.display || schema['x-display'];
100
+ const required = schema.reduceProperties((required, property) => {
101
+ if (required) {
102
+ return required;
103
+ }
104
+ return !!property.required;
105
+ }, false);
106
+
107
+ return [
108
+ {
109
+ name,
110
+ display,
111
+ required,
112
+ field,
113
+ fieldProps:fieldProps as any,
114
+ schema,
115
+ columnProps,
116
+ },
117
+ ];
118
+ } else if (schema.properties) {
119
+ return schema.reduceProperties((buf: any[], schema) => {
120
+ return buf.concat(parseSources(schema));
121
+ }, []);
122
+ } else {
123
+ return [];
124
+ }
125
+ };
126
+
127
+ const parseArrayTable = (schema: Schema['items']) => {
128
+ if (!schema) return [];
129
+ const sources: ObservableColumnSource[] = [];
130
+ const items = isArr(schema) ? schema : ([schema] as Schema[]);
131
+ return items.reduce((columns, schema) => {
132
+ const item = parseSources(schema);
133
+ if (item) {
134
+ return columns.concat(item);
135
+ }
136
+ return columns;
137
+ }, sources);
138
+ };
139
+
140
+ if (!schemaRef.value) throw new Error('can not found schema object');
141
+
142
+ return parseArrayTable(schemaRef.value.items);
143
+ };
144
+
145
+ const getArrayTableColumns = (
146
+ sources: ObservableColumnSource[]
147
+ ): ColumnProps[] => {
148
+ return sources.reduce(
149
+ (
150
+ buf: ColumnProps[],
151
+ { name, columnProps, schema, display, required },
152
+ key
153
+ ) => {
154
+ const { title, asterisk, ...props } = columnProps;
155
+ if (display !== 'visible') return buf;
156
+ if (!isColumnComponent(schema)) return buf;
157
+
158
+ const render = (startIndex?: Ref<number>) => {
159
+ return columnProps?.type && columnProps?.type !== 'default'
160
+ ? undefined
161
+ : (props: {
162
+ row: Record<string, any>;
163
+ column: ElColumnProps;
164
+ $index: number;
165
+ }): VNode => {
166
+ const index = (startIndex?.value ?? 0) + props.$index;
167
+ // const index = reactiveDataSource.value.indexOf(props.row)
168
+ const children = h(
169
+ ArrayBase.Item,
170
+ {
171
+ index,
172
+ record: props.row,
173
+ key: `${key}${index}`,
174
+ },
175
+ {
176
+ default: () => {
177
+ return h(
178
+ RecursionField as any,
179
+ {
180
+ schema,
181
+ name: index,
182
+ onlyRenderProperties: true,
183
+ },
184
+ {}
185
+ );
186
+ },
187
+ }
188
+ );
189
+ return children;
190
+ };
191
+ };
192
+
193
+ return (buf as any).concat({
194
+ label: title,
195
+ ...props,
196
+ key,
197
+ prop: name,
198
+ asterisk: asterisk ?? required,
199
+ render,
200
+ });
201
+ },
202
+ []
203
+ );
204
+ };
205
+
206
+ const renderAddition = () => {
207
+ const schema = useFieldSchema();
208
+ return schema.value.reduceProperties((addition, schema) => {
209
+ if (isAdditionComponent(schema as any)) {
210
+ return h(
211
+ RecursionField as any,
212
+ {
213
+ schema,
214
+ name: 'addition',
215
+ },
216
+ {}
217
+ );
218
+ }
219
+ return addition;
220
+ }, null);
221
+ };
222
+
223
+ const schedulerRequest: { request: number } = {
224
+ request: 0,
225
+ };
226
+
227
+ const StatusSelect = observer(
228
+ defineComponent({
229
+ props: {
230
+ value: Number,
231
+ onChange: Function,
232
+ options: Array,
233
+ pageSize: Number,
234
+ },
235
+ setup(props) {
236
+ const fieldRef = useField<ArrayField>();
237
+ const prefixCls = `${stylePrefix}-array-table`;
238
+
239
+ return () => {
240
+ const field = fieldRef.value;
241
+ const width = String(props.options?.length).length * 15;
242
+ const errors = field.errors;
243
+ const parseIndex = (address: string) => {
244
+ return Number(
245
+ address
246
+ .slice(
247
+ address.indexOf(field.address.toString()) + 1
248
+ )
249
+ .match(/(\d+)/)?.[1]
250
+ );
251
+ };
252
+
253
+ return h(
254
+ ElSelect as any,
255
+ {
256
+ style: {
257
+ width: `${width < 60 ? 60 : width}px`,
258
+ },
259
+ class: [
260
+ `${prefixCls}-status-select`,
261
+ {
262
+ 'has-error': errors?.length,
263
+ },
264
+ ],
265
+ modelValue: props.value,
266
+ popperClass: `${prefixCls}-status-select-dropdown`,
267
+ onChange: props.onChange,
268
+ },
269
+ {
270
+ default: () => {
271
+ return (
272
+ props.options as {
273
+ label: string;
274
+ value: number;
275
+ }[]
276
+ )?.map(({ label, value }) => {
277
+ const hasError = errors.some(({ address }) => {
278
+ const currentIndex = parseIndex(address!);
279
+ const startIndex =
280
+ (value - 1) * props.pageSize!;
281
+ const endIndex = value * props.pageSize!;
282
+ return (
283
+ currentIndex >= startIndex &&
284
+ currentIndex <= endIndex
285
+ );
286
+ });
287
+
288
+ return h(
289
+ ElOption as any,
290
+ {
291
+ key: value,
292
+ label,
293
+ value,
294
+ },
295
+ {
296
+ default: () => {
297
+ if (hasError) {
298
+ return h(
299
+ ElBadge,
300
+ {
301
+ isDot: true,
302
+ },
303
+ { default: () => label }
304
+ );
305
+ }
306
+
307
+ return label;
308
+ },
309
+ }
310
+ );
311
+ });
312
+ },
313
+ }
314
+ );
315
+ };
316
+ },
317
+ }),
318
+ {
319
+ scheduler: update => {
320
+ clearTimeout(schedulerRequest.request as unknown as number);
321
+ schedulerRequest.request = setTimeout(() => {
322
+ update();
323
+ }, 100) as unknown as number;
324
+ },
325
+ }
326
+ );
327
+
328
+ const ArrayTablePagination = defineComponent({
329
+ inheritAttrs: false,
330
+ props: ['pageSize', 'dataSource', 'onChange'],
331
+ setup(props, { attrs, slots }) {
332
+ const prefixCls = `${stylePrefix}-array-table`;
333
+ const current = ref(1);
334
+ const pageSize = computed(() => props.pageSize || 10);
335
+ const dataSource = computed(() => props.dataSource || []);
336
+ const startIndex = computed(() => (current.value - 1) * pageSize.value);
337
+ const endIndex = computed(() => startIndex.value + pageSize.value - 1);
338
+ const total = computed(() => dataSource.value?.length || 0);
339
+ const totalPage = computed(() =>
340
+ Math.ceil(total.value / pageSize.value)
341
+ );
342
+ const pages = computed(() => {
343
+ return Array.from(new Array(totalPage.value)).map((_, index) => {
344
+ const page = index + 1;
345
+ return {
346
+ label: page,
347
+ value: page,
348
+ };
349
+ });
350
+ });
351
+
352
+ const renderPagination = function () {
353
+ if (totalPage.value <= 1) return;
354
+ return h(
355
+ 'div',
356
+ {
357
+ class: [`${prefixCls}-pagination`],
358
+ },
359
+ h(
360
+ Space,
361
+ {},
362
+ {
363
+ default: () => [
364
+ h(
365
+ StatusSelect,
366
+ {
367
+ value: current.value,
368
+ onChange: (val: number) => {
369
+ current.value = val;
370
+ },
371
+ pageSize: pageSize.value,
372
+ options: pages.value,
373
+ },
374
+ {}
375
+ ),
376
+ h(
377
+ ElPagination,
378
+ {
379
+ background: true,
380
+ layout: 'prev, pager, next',
381
+ ...attrs,
382
+ pageSize: pageSize.value,
383
+ pageCount: totalPage.value,
384
+ currentPage: current.value,
385
+ onCurrentChange: (val: number) => {
386
+ current.value = val;
387
+ },
388
+ },
389
+ {}
390
+ ),
391
+ ],
392
+ }
393
+ )
394
+ );
395
+ };
396
+
397
+ return () => {
398
+ return h(
399
+ FragmentComponent,
400
+ {},
401
+ {
402
+ default: () =>
403
+ slots?.default?.(
404
+ dataSource.value?.slice(
405
+ startIndex.value,
406
+ endIndex.value + 1
407
+ ),
408
+ renderPagination,
409
+ startIndex
410
+ ),
411
+ }
412
+ );
413
+ };
414
+ },
415
+ });
416
+
417
+ const ArrayTableInner = observer(
418
+ defineComponent({
419
+ name: 'FArrayTable',
420
+ inheritAttrs: false,
421
+ props: ['onChange'],
422
+ setup(props, { attrs, slots }) {
423
+ const fieldRef = useField<ArrayField>();
424
+ const schemaRef = useFieldSchema();
425
+ const prefixCls = `${stylePrefix}-array-table`;
426
+ // @ts-ignore
427
+ const { getKey, keyMap } = ArrayBase.useKey(schemaRef.value as any);
428
+
429
+ const defaultRowKey = (record: any, index: number) => {
430
+ return getKey(record, index);
431
+ };
432
+
433
+ return () => {
434
+ const props = attrs as unknown as ArrayTableProps;
435
+ const field = fieldRef.value;
436
+ const dataSource = Array.isArray(field.value)
437
+ ? field.value.slice()
438
+ : [];
439
+ const pagination = props.pagination;
440
+ const sources = getArrayTableSources(fieldRef as any, schemaRef as any);
441
+ const columns = getArrayTableColumns(sources);
442
+
443
+ const renderColumns = (startIndex?: Ref<number>) => {
444
+ return columns.map(
445
+ ({ key, render, asterisk, ...props }) => {
446
+ const children = {} as Record<string, any>;
447
+ if (render) {
448
+ children.default = render(startIndex);
449
+ }
450
+ if (asterisk) {
451
+ children.header = ({
452
+ column,
453
+ }: {
454
+ column: ElColumnProps;
455
+ }) =>
456
+ h('span', {}, [
457
+ h(
458
+ 'span',
459
+ { class: `${prefixCls}-asterisk` },
460
+ '*'
461
+ // { default: () => ['*'] }
462
+ ),
463
+ column.label,
464
+ ]);
465
+ }
466
+ return h(
467
+ ElTableColumn as any,
468
+ {
469
+ ...props,
470
+ key,
471
+ },
472
+ children
473
+ );
474
+ }
475
+ );
476
+ };
477
+
478
+ const renderStateManager = () =>
479
+ sources.map((column, key) => {
480
+ //专门用来承接对Column的状态管理
481
+ if (!isColumnComponent(column.schema)) return;
482
+ return h(
483
+ RecursionField as any,
484
+ {
485
+ name: column.name,
486
+ schema: column.schema,
487
+ onlyRenderSelf: true,
488
+ key,
489
+ },
490
+ {}
491
+ );
492
+ });
493
+
494
+ const renderTable = (
495
+ dataSource?: any[],
496
+ pager?: () => VNode,
497
+ startIndex?: Ref<number>
498
+ ) => {
499
+ return h(
500
+ 'div',
501
+ { class: prefixCls },
502
+ h(
503
+ ArrayBase,
504
+ {
505
+ keyMap,
506
+ },
507
+ {
508
+ default: () => [
509
+ h(
510
+ ElTable as any,
511
+ {
512
+ rowKey: defaultRowKey,
513
+ ...attrs,
514
+ data: dataSource,
515
+ },
516
+ {
517
+ ...slots,
518
+ default: () =>
519
+ renderColumns(startIndex),
520
+ }
521
+ ),
522
+ pager?.(),
523
+ renderStateManager(),
524
+ renderAddition(),
525
+ ],
526
+ }
527
+ )
528
+ );
529
+ };
530
+
531
+ if (!pagination) {
532
+ return renderTable(dataSource);
533
+ }
534
+ return h(
535
+ ArrayTablePagination,
536
+ {
537
+ ...(isBool(pagination) ? {} : pagination),
538
+ dataSource,
539
+ },
540
+ { default: renderTable }
541
+ );
542
+ };
543
+ },
544
+ })
545
+ );
546
+
547
+ const ArrayTableColumn: Component = {
548
+ name: 'FArrayTableColumn',
549
+ render() {
550
+ return null;
551
+ },
552
+ };
553
+ // @ts-ignore
554
+ export const ArrayTable = composeExport(ArrayTableInner, {
555
+ Column: ArrayTableColumn,
556
+ Index: ArrayBase.Index,
557
+ SortHandle: ArrayBase.SortHandle,
558
+ Addition: ArrayBase.Addition,
559
+ Remove: ArrayBase.Remove,
560
+ MoveDown: ArrayBase.MoveDown,
561
+ MoveUp: ArrayBase.MoveUp,
562
+ useArray: ArrayBase.useArray,
563
+ useIndex: ArrayBase.useIndex,
564
+ useRecord: ArrayBase.useRecord,
565
+ });
566
+
567
+ export default ArrayTable;
@@ -0,0 +1,84 @@
1
+ @import '../__builtins__/styles/common.scss';
2
+
3
+ $array-table-prefix-cls: '#{$formily-prefix}-array-table';
4
+
5
+ .#{$array-table-prefix-cls} {
6
+ .#{$formily-prefix}-form-item:not(.#{$formily-prefix}-form-item-feedback-layout-popover) {
7
+ margin-bottom: 0 !important;
8
+ }
9
+
10
+ &-status-select-dropdown {
11
+ .#{$namespace}-badge {
12
+ line-height: 1;
13
+ }
14
+ }
15
+
16
+ &-pagination {
17
+ display: flex;
18
+ justify-content: center;
19
+ margin-top: 8px;
20
+
21
+ .#{$array-table-prefix-cls}-status-select.has-error {
22
+ .#{$namespace}-input__inner {
23
+ border-color: $--color-danger !important;
24
+ }
25
+ }
26
+ }
27
+
28
+ .#{$namespace}-table {
29
+ .cell {
30
+ overflow: visible;
31
+ }
32
+
33
+ .cell.el-tooltip {
34
+ overflow: hidden;
35
+ }
36
+
37
+ &__fixed {
38
+ box-shadow: 10px 0 10px -10px rgb(0 0 0 / 12%);
39
+ }
40
+
41
+ &__fixed-right {
42
+ box-shadow: -10px 0 10px -10px rgb(0 0 0 / 12%);
43
+ }
44
+ }
45
+
46
+ .#{$formily-prefix}-form-item-help {
47
+ position: absolute;
48
+ font-size: 12px;
49
+ top: 100%;
50
+ background: #fff;
51
+ width: 100%;
52
+ margin-top: 3px;
53
+ padding: 3px;
54
+ z-index: 2;
55
+ border-radius: 3px;
56
+ box-shadow: 0 0 10px #eee;
57
+ }
58
+
59
+ .#{$formily-prefix}-array-base-addition {
60
+ margin-top: 8px;
61
+ width: 100%;
62
+ border: $--border-width-base dashed $--border-color-base;
63
+
64
+ &:hover {
65
+ background-color: $--color-white;
66
+ border-color: $--border-color-hover;
67
+ }
68
+
69
+ &:active,
70
+ &:focus {
71
+ background-color: $--color-white;
72
+ border-color: $--color-primary;
73
+ }
74
+ }
75
+
76
+ .#{$formily-prefix}-form-item-feedback-layout-popover {
77
+ margin-bottom: 0;
78
+ }
79
+
80
+ &-inner-asterisk {
81
+ color: $--color-danger;
82
+ font-weight: $--font-weight-primary;
83
+ }
84
+ }
@@ -0,0 +1,11 @@
1
+ import './style.scss'
2
+
3
+ import '@cicctencent/jtui/theme-chalk/src/table.scss'
4
+ import '@cicctencent/jtui/theme-chalk/src/table-column.scss'
5
+ import '@cicctencent/jtui/theme-chalk/src/button.scss'
6
+ import '@cicctencent/jtui/theme-chalk/src/select.scss'
7
+ import '@cicctencent/jtui/theme-chalk/src/badge.scss'
8
+
9
+ // 依赖
10
+ import '../array-base/style'
11
+ import '../space/style'