@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,141 @@
1
+ import { defineComponent, ref, h } from 'vue';
2
+ import { observer } from '@formily/reactive-vue';
3
+ import { ArrayField } from '@formily/core';
4
+ import { useField, useFieldSchema, RecursionField } from '@formily/vue';
5
+ import { ElTabs, ElTabPane, ElBadge } from '@cicctencent/jtui';
6
+ import { stylePrefix } from '../__builtins__/configs';
7
+ // todo 完善any类型
8
+ import './style.scss';
9
+ export const ArrayTabs = observer(
10
+ defineComponent({
11
+ name: 'ArrayTabs',
12
+ props: ['onChange'],
13
+ setup(props, { attrs }) {
14
+ const fieldRef = useField<ArrayField>();
15
+ const schemaRef = useFieldSchema();
16
+
17
+ const prefixCls = `${stylePrefix}-array-tabs`;
18
+ const activeKey = ref('tab-0');
19
+
20
+ return () => {
21
+ const field = fieldRef.value;
22
+ const schema = schemaRef.value;
23
+ const value = Array.isArray(field.value) ? field.value : [];
24
+ const dataSource = value?.length ? value : [{}];
25
+
26
+ const onEdit = (targetKey: any, type: 'add' | 'remove') => {
27
+ if (type == 'add') {
28
+ const id = dataSource.length;
29
+ if (field?.value?.length) {
30
+ field.push(null);
31
+ } else {
32
+ field.push(null, null);
33
+ }
34
+ activeKey.value = `tab-${id}`;
35
+ } else if (type == 'remove') {
36
+ const index = targetKey.match(/-(\d+)/)?.[1];
37
+ field.remove(Number(index));
38
+ if (activeKey.value === targetKey) {
39
+ activeKey.value = `tab-${index - 1}`;
40
+ }
41
+ }
42
+ };
43
+
44
+ const badgedTab = (index: number) => {
45
+ const tab = `${field.title || 'Untitled'} ${index + 1}`;
46
+ const path = field.address.concat(index);
47
+ const errors = field.form.queryFeedbacks({
48
+ type: 'error',
49
+ address: `${path}.**`,
50
+ });
51
+ if (errors.length) {
52
+ return h(
53
+ 'span',
54
+ {},
55
+ {
56
+ default: () => [
57
+ h(
58
+ ElBadge,
59
+ {
60
+ class: [
61
+ `${prefixCls}-errors-badge`,
62
+ ],
63
+ value: errors.length,
64
+ },
65
+ {
66
+ default: () => [tab],
67
+ }
68
+ ),
69
+ ],
70
+ }
71
+ );
72
+ }
73
+ return h(
74
+ 'span',
75
+ {},
76
+ {
77
+ default: () => [tab],
78
+ }
79
+ );
80
+ };
81
+
82
+ const renderItems = () =>
83
+ dataSource?.map((item, index) => {
84
+ const items = Array.isArray(schema.items)
85
+ ? schema.items[index]
86
+ : schema.items;
87
+ const key = `tab-${index}`;
88
+
89
+ return h(
90
+ ElTabPane,
91
+ {
92
+ key,
93
+ closable: index !== 0,
94
+ name: key,
95
+ },
96
+ {
97
+ default: () =>
98
+ h(
99
+ RecursionField,
100
+ {
101
+ schema: items,
102
+ name: index,
103
+ },
104
+ {}
105
+ ),
106
+
107
+ label: () => [badgedTab(index)],
108
+ }
109
+ );
110
+ });
111
+ return h(
112
+ ElTabs as any,
113
+ {
114
+ class: [prefixCls],
115
+ ...attrs,
116
+ type: 'card',
117
+ modelValue: activeKey.value,
118
+ addable: true,
119
+ 'onUpdata:modelValue': (key: any) => {
120
+ activeKey.value = key;
121
+ },
122
+ onModel: (target: any) => {
123
+ onEdit(target, 'remove');
124
+ !(attrs as any)?.['tab-remove']?.(target);
125
+ },
126
+ onTabAdd: () => {
127
+ onEdit(null, 'add');
128
+ !(attrs as any)?.['tab-add']?.();
129
+ },
130
+ onChange: (...args: any[]) => {},
131
+ },
132
+ {
133
+ default: () => [renderItems()],
134
+ }
135
+ );
136
+ };
137
+ },
138
+ })
139
+ );
140
+
141
+ export default ArrayTabs;
@@ -0,0 +1,16 @@
1
+ @import '../__builtins__/styles/common.scss';
2
+
3
+ $array-table-prefix-cls: '#{$formily-prefix}-array-tabs';
4
+
5
+ .#{$array-table-prefix-cls} {
6
+ .#{$formily-prefix}-array-tabs-addition {
7
+ position: absolute;
8
+ right: -56px;
9
+ top: -1px;
10
+ }
11
+
12
+ .#{$array-table-prefix-cls}-errors-badge {
13
+ line-height: 1;
14
+ vertical-align: initial;
15
+ }
16
+ }
@@ -0,0 +1,5 @@
1
+ import './style.scss'
2
+ import '@cicctencent/jtui/theme-chalk/src/tabs.scss'
3
+ import '@cicctencent/jtui/theme-chalk/src/tab-pane.scss'
4
+ import '@cicctencent/jtui/theme-chalk/src/badge.scss'
5
+ import '@cicctencent/jtui/theme-chalk/src/button.scss'
@@ -0,0 +1,155 @@
1
+ import {
2
+ createForm,
3
+ Form,
4
+ onFormInit,
5
+ onFormValuesChange,
6
+ onFormMount
7
+ } from '@formily/core';
8
+ import { computed, getCurrentInstance, ref, onMounted, watch, nextTick } from 'vue';
9
+ import { transformSchema } from '../../../transform';
10
+ import { isEqual, log } from '@cicctencent/ark-util'
11
+ import { getAnyOfConfig } from '../../../utils/anyof_utils';
12
+ const infoLog = log('[any of component]')
13
+ export default function (props, emit) {
14
+ /** vue实例 */
15
+ const ctx = getCurrentInstance();
16
+ /** */
17
+ const radioValue = ref();
18
+ let mountFlag = false;
19
+
20
+ /** schema 配置 */
21
+ const schemaConfig = ref({});
22
+ /** form表单实例 */
23
+ const form = ref<Form>();
24
+
25
+ /** switch */
26
+ //switch 状态为 on 时的值
27
+ const switchActiveValue = ref(true);
28
+ const switchInactiveValue= ref(false);
29
+
30
+ onMounted(() => {
31
+ init();
32
+ });
33
+
34
+ watch(()=> props.modelValue,(newVal,oldVal)=>{
35
+ if(!isEqual(newVal,oldVal)){
36
+ nextTick(()=>{
37
+ form.value && form.value.setValues(newVal)
38
+ })
39
+ }
40
+ })
41
+
42
+ const schemaList = computed(() =>{
43
+ return JSON.parse(props?.list ?? '[]');
44
+ })
45
+
46
+ // 是否是空的Propeities
47
+ const isEmpuyProperties = computed(()=>{
48
+ return isEqual(curProperties.value?.properties ?? {}, {})
49
+ })
50
+
51
+ function onRadioChange(){
52
+ emit('change',{ anyOf_val: radioValue.value})
53
+ mountFlag = false;
54
+ // updateFlag = true;
55
+ form.value = null;
56
+ setTimeout(()=>{
57
+ generateSchema();
58
+ generateForm();
59
+ },100)
60
+ }
61
+ // 获取当前的schema
62
+ const curProperties = computed(() => {
63
+ if(!Array.isArray(schemaList.value)||!schemaList.value.length||!radioValue.value){
64
+ return {};
65
+ }
66
+ for(let i = 0; i < schemaList.value.length; ++i){
67
+ if(schemaList.value[i]?.title === radioValue.value){
68
+ return {
69
+ type:'object',
70
+ properties:schemaList.value[i]?.properties ?? {},
71
+ }
72
+ }
73
+ }
74
+ return {}
75
+ })
76
+ // 获取radioGroup options
77
+ const radioOptions = computed(() => {
78
+ if(!Array.isArray(schemaList.value)||!schemaList.value.length){
79
+ return [];
80
+ }
81
+ const options = [];
82
+ schemaList.value.forEach((item, index) =>{
83
+ options.push({ label: item.title ?? '',key: index })
84
+ })
85
+ return options;
86
+ })
87
+ // 生成表单
88
+ function generateSchema(){
89
+ infoLog('generateSchema',curProperties.value)
90
+ schemaConfig.value = transformSchema({ schema: curProperties.value, ctx });
91
+ }
92
+ /**
93
+ * 获取默认选择项
94
+ * @param data
95
+ * @returns
96
+ */
97
+ function isActivity(data){
98
+ if('x-data' in data){
99
+ return data['x-data']?.activity ? true : false;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ function init(){
105
+
106
+ let config = getAnyOfConfig(schemaList.value,props.modelValue)
107
+ infoLog('init',config)
108
+
109
+ // 处理switch模式的 switch value
110
+ if(props.type === 'switch'){
111
+ if(Array.isArray(schemaList.value) && schemaList.value.length === 2){
112
+ switchActiveValue.value = schemaList.value[0].title
113
+ switchInactiveValue.value = schemaList.value[1].title
114
+ }
115
+ }
116
+
117
+ radioValue.value = config?.title
118
+ // 生成表单
119
+ generateSchema();
120
+ generateForm();
121
+ }
122
+
123
+ function generateForm(){
124
+ form.value = null;
125
+ form.value = createForm({
126
+ effects(){
127
+ onFormInit(form => {
128
+ form.setValues(props.modelValue);
129
+ })
130
+ onFormMount(form => {
131
+ mountFlag = true;
132
+ form.setValues(Object.assign({},props.modelValue,form.values))
133
+ })
134
+ onFormValuesChange(form => {
135
+ if(mountFlag){
136
+ const result = { ...form.values}
137
+ result['anyOf_val'] = radioValue.value;
138
+ emit('change', result);
139
+ }
140
+ })
141
+ },
142
+ readOnly: props.readOnly,
143
+ })
144
+ }
145
+ return {
146
+ onRadioChange,
147
+ isEmpuyProperties,
148
+ radioValue,
149
+ form,
150
+ schemaConfig,
151
+ radioOptions,
152
+ switchActiveValue,
153
+ switchInactiveValue
154
+ }
155
+ }
@@ -0,0 +1,111 @@
1
+ <template>
2
+ <div class="any-of-wrap">
3
+ <div class="any-of-wrap--header">
4
+ <FormItem :label="type ==='switch'? title : ''" :asterisk="required" :layout="type === 'switch'?'horizontal' :'vertical'" label-align="left">
5
+ <template v-if="type === 'radio'">
6
+ <el-radio-group v-model="radioValue" :disabled="readOnly" @change="onRadioChange">
7
+ <el-radio
8
+ v-for="item in radioOptions"
9
+ :key="item.key"
10
+ :label="item.label"
11
+ >
12
+ {{ item.label }}
13
+ </el-radio>
14
+ </el-radio-group>
15
+ </template>
16
+ <template v-else-if="type === 'switch'">
17
+ <div class="any-of-wrap--switch-box">
18
+ <el-switch :disabled="readOnly" :inactive-value="switchInactiveValue" :active-value="switchActiveValue" v-model="radioValue" @change="onRadioChange" />
19
+ </div>
20
+ </template>
21
+ </FormItem>
22
+ </div>
23
+ <!-- formily -->
24
+ <div class="any-of-wrap--content" :class="{'padding': !isEmpuyProperties}">
25
+ <FormProvider :form="form" >
26
+ <SchemaField :schema="schemaConfig" />
27
+ </FormProvider>
28
+ </div>
29
+ </div>
30
+ </template>
31
+
32
+ <script lang="ts" setup>
33
+ //@ts-ignore
34
+ import useAny from './index';
35
+ // @ts-ignore
36
+ import { defineComponent } from 'vue';
37
+ import { FormProvider, createSchemaField } from '@formily/vue';
38
+ import FormItem from '../../form-item';
39
+
40
+ defineComponent({
41
+ name:'AnyOf'
42
+ })
43
+
44
+ const props = defineProps({
45
+ list: {
46
+ type: String,
47
+ default: () => '[]',
48
+ },
49
+ modelValue: {
50
+ type: Object,
51
+ default: () => {},
52
+ },
53
+ title: {
54
+ type: String,
55
+ default: '',
56
+ },
57
+ defaultValue: String,
58
+ required: {
59
+ type: Boolean,
60
+ default: true,
61
+ },
62
+ type:{
63
+ type: String,
64
+ default: 'radio',
65
+ },
66
+ readOnly: {
67
+ type: Boolean,
68
+ default: false,
69
+ }
70
+ });
71
+
72
+ const emits = defineEmits(['change', 'error', 'fileModalOpen']);
73
+
74
+ const {
75
+ radioValue,
76
+ radioOptions,
77
+ form,
78
+ schemaConfig,
79
+ onRadioChange,
80
+ switchActiveValue,
81
+ switchInactiveValue,
82
+ isEmpuyProperties
83
+ } = useAny(props, emits);
84
+ </script>
85
+
86
+ <style lang="scss">
87
+ .any-of-wrap{
88
+ padding: 0 !important;
89
+ background-color: transparent !important;
90
+ &--switch-box{
91
+ width: 100%;
92
+ display: flex;
93
+ justify-content: flex-end;
94
+ vertical-align: bottom;
95
+ .el-switch{
96
+ height: 20px !important;
97
+ vertical-align: top;
98
+ }
99
+ }
100
+ &--content{
101
+ // background-color: #f5f6f7;
102
+
103
+ &.padding{
104
+ padding:16px 17px;
105
+ }
106
+ }
107
+ &--header{
108
+ }
109
+ }
110
+
111
+ </style>
@@ -0,0 +1,46 @@
1
+ import { useField } from "@formily/vue";
2
+ import { isEqual } from "lodash-es";
3
+ import { computed, onMounted } from "vue"
4
+
5
+ export default function(props,emits){
6
+
7
+ const field:any = useField()
8
+
9
+ onMounted(()=>{
10
+ // 存在云组件链接,进行预加载
11
+ props.exportUrl && emits('preload',props.exportUrl)
12
+ })
13
+ /** 编辑状态 */
14
+ const editorState = computed(() => {
15
+ return !!props.modelValue && !isEqual(props.modelValue,{})
16
+ })
17
+
18
+ const required = computed( ()=> field.value?.required)
19
+
20
+ /** 禁用状态 */
21
+ const disabled = computed(() => {
22
+ return !props.exportUrl || isEqual(props.exportUrl,'') || props.readonly
23
+ })
24
+
25
+ /** 点击事件处理 */
26
+ let timer = null;
27
+ function onClick(){
28
+ if(timer){
29
+ clearTimeout(timer);
30
+ timer = null;
31
+ }
32
+ timer = setTimeout(()=>{
33
+ if(props?.exportUrl){
34
+ const data = Object.assign({}, props?.data ?? {}, props?.modelValue ?? {});
35
+ emits('openCloud', { exportUrl: props.exportUrl, data,readonly: props.readonly }, (res)=>{
36
+ // 只读模式不允许更新数据
37
+ if(!disabled.value){
38
+ emits('update:modelValue', res);
39
+ }
40
+ })
41
+ }
42
+ console.log('onClick CloudButton')
43
+ },1000)
44
+ }
45
+ return { editorState, disabled, onClick, required }
46
+ }
@@ -0,0 +1,128 @@
1
+ <template>
2
+ <div class="formily-cloud">
3
+ <div class="formily-cloud--cell">
4
+ <span class="formily-cloud--cell--label" :class="{'editor-class' : editorState,'formily-cloud--cell--required': required }">{{ label }}</span>
5
+ <span :style="{ opacity : editorState ? '.6' : '1' }" class="formily-cloud--cell--value" @click="onClick">编辑</span>
6
+ </div>
7
+ <div class="formily-cloud--button" @click="onClick">{{ label }}</div>
8
+ </div>
9
+ </template>
10
+
11
+ <script lang="ts" setup>
12
+ // @ts-ignore
13
+ import { defineComponent } from 'vue';
14
+ // @ts-ignore
15
+ import useCloudButton from './index';
16
+ defineComponent({
17
+ name:'FormilyCloudButton'
18
+ })
19
+ const props = defineProps({
20
+ modelValue: {
21
+ type: Object,
22
+ default: null
23
+ },
24
+ data:{
25
+ type: Object,
26
+ default: ()=> {
27
+ return {}
28
+ }
29
+ },
30
+ exportUrl:{
31
+ type: String,
32
+ default: ''
33
+ },
34
+ label:{
35
+ type: String,
36
+ default: ''
37
+ },
38
+ readonly:{
39
+ type: Boolean,
40
+ default: false
41
+ },
42
+ });
43
+ const emits = defineEmits(['update:modelValue', 'change', 'openCloud', 'preload']);
44
+
45
+ const { editorState, disabled, onClick, required } = useCloudButton(props, emits);
46
+ </script>
47
+
48
+ <style lang="scss">
49
+ .formily-cloud{
50
+ &--button{
51
+ display: none;
52
+ background: #F9F4EE;
53
+ width: 120px;
54
+ padding: 5px 16px;
55
+ border: 1px solid #C79156;
56
+ border-radius: 4px;
57
+ box-sizing: border-box;
58
+ color: #C79156;
59
+ font-weight: 500;
60
+ font-size: 14px;
61
+ line-height: 22px;
62
+ text-align: center;
63
+ cursor: pointer;
64
+ &:hover{
65
+ background-color: #f6e3cd;
66
+ }
67
+ }
68
+ &--cell {
69
+ display: flex;
70
+ align-items: center;
71
+ justify-content: space-between;
72
+ // border-top: 1px solid rgba(0, 0, 0, 0.1);
73
+ // border-bottom: 1px solid rgba(0, 0, 0, 0.1);
74
+ // padding: 16px 18px;
75
+ border: none !important;
76
+ padding: 0 18px 16px 18px ;
77
+ margin: 0 !important;
78
+ &__disabled{
79
+ cursor: not-allowed;
80
+ pointer-events: none;
81
+ background-image: none;
82
+ }
83
+ &--value {
84
+ font-style: normal;
85
+ font-weight: 400;
86
+ font-size: 14px;
87
+ line-height: 20px;
88
+ /* identical to box height */
89
+ color: #4B515E;
90
+ &:hover {
91
+ cursor: pointer;
92
+ }
93
+ }
94
+
95
+ &--label {
96
+ color: rgba(2, 2, 2, 0.4);
97
+ font-size: 16px;
98
+ line-height: 24px;
99
+ font-weight: 600;
100
+ font-style: normal;
101
+ &.editor-class{
102
+ color: #020202 !important;
103
+ }
104
+ }
105
+
106
+ &--required{
107
+ position: relative;
108
+ &::before{
109
+ content: '*';
110
+ position: absolute;
111
+ left: -12px;
112
+ top: 0px;
113
+ color: #f56c6c;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ /* 通过样式切换不同类型的风格 */
119
+ .dialog-cloud{
120
+ .formily-cloud--button{
121
+ display: block;
122
+ }
123
+ .formily-cloud--cell{
124
+ display: none;
125
+ }
126
+ }
127
+
128
+ </style>
@@ -0,0 +1,57 @@
1
+ import { getCurrentInstance, onMounted, ref, watch, computed, reactive } from 'vue';
2
+ import { TransformCore } from '../../../transform';
3
+ import {
4
+ createForm,
5
+ onFormInit,
6
+ onFormInputChange,
7
+ onFormMount,
8
+ onFormValuesChange,
9
+ } from '@formily/core';
10
+ import { isEqual } from '@cicctencent/ark-util';
11
+
12
+ export default function (props, emit) {
13
+ const ctx = getCurrentInstance();
14
+ // 挂载标识
15
+ let mountFlag = false;
16
+ // 创建formily表单
17
+ const form = reactive(createForm({
18
+ effects() {
19
+ onFormMount(form => {
20
+ form.setValues({ ...props.modelValue });
21
+ setTimeout(() => {
22
+ mountFlag = true;
23
+ }, 10);
24
+ });
25
+ onFormInputChange(form => {
26
+ // if (mountFlag) {
27
+ emit('change', { ...form.values });
28
+ // }
29
+ });
30
+ },
31
+ }));
32
+ // schema配置
33
+ const schemaConfig = ref({});
34
+
35
+ onMounted(() => {
36
+ try {
37
+ // 因为存在 "x-component"特殊字段,传过来的是JSON字符串,这里需要parse
38
+ schemaConfig.value = new TransformCore({ schema: JSON.parse(props.schema ?? {}), ctx }).compile();
39
+ } catch (err) {
40
+ console.error(err);
41
+ }
42
+ });
43
+ watch(
44
+ () => props.modelValue,
45
+ (val, oldValue) => {
46
+ // 数据回显,有些场景组件渲染的时候, data的值还没有,这里监听modelValue数据首次为非{}的情况下,进行初始化(回显)操作
47
+ if(!isEqual(val, oldValue)){
48
+ form.setValues(val)
49
+ }
50
+ },{
51
+ deep:true,
52
+ immediate:true
53
+ }
54
+ );
55
+
56
+ return { form, schemaConfig };
57
+ }
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <div class="color-group">
3
+ <slot></slot>
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts" setup></script>
8
+
9
+ <style lang="scss">
10
+ .color-group {
11
+ display: flex;
12
+ padding: 16px;
13
+ margin-bottom: 16px;
14
+ box-sizing: border-box;
15
+ background-color: rgba(216, 220, 230, 0.2);
16
+ border-radius: 4px;
17
+ overflow: hidden;
18
+ flex-direction: row;
19
+ flex-wrap: wrap;
20
+ .formily-color-picker {
21
+ width: 140px;
22
+ }
23
+ .formily-element-plus-form-item{
24
+ margin-right: 10px;
25
+ &:last-child {
26
+ margin-right: 0;
27
+ }
28
+ }
29
+ }
30
+ </style>