@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.
- package/.eslintrc.js +40 -0
- package/.prettierrc.js +28 -0
- package/.vscode/launch.json +23 -0
- package/CHANGELOG.md +8 -0
- package/README.md +22 -2
- package/babel.config.js +3 -0
- package/build/build.js +96 -0
- package/build/rollup.config.bundle.js +63 -0
- package/build/update.version.js +35 -0
- package/dist/index.css +2516 -0
- package/dist/index.js +8377 -0
- package/dist/schema-field/index.css +2466 -0
- package/dist/schema-field/index.js +8213 -0
- package/dist/transform/index.js +551 -0
- package/dist/validate/index.js +1104 -0
- package/dist/vue-form/index.css +2516 -0
- package/dist/vue-form/index.js +8359 -0
- package/docs/.vuepress/client.ts +15 -0
- package/docs/.vuepress/components/code-preview.vue +203 -0
- package/docs/.vuepress/components/highlight.ts +53 -0
- package/docs/.vuepress/config.ts +39 -0
- package/docs/.vuepress/util.ts +7 -0
- package/docs/README.md +30 -0
- package/docs/components/anyOf.md +26 -0
- package/docs/components/array-cards.md +12 -0
- package/docs/components/array-collapse.md +12 -0
- package/docs/components/array-items.md +12 -0
- package/docs/components/array-table.md +12 -0
- package/docs/components/array-tabs.md +16 -0
- package/docs/components/cascader.md +12 -0
- package/docs/components/checkbox.md +12 -0
- package/docs/components/event.md +27 -0
- package/docs/components/hotArea.md +25 -0
- package/docs/components/index.md +4 -0
- package/docs/components/input.md +30 -0
- package/docs/components/layout-group.md +19 -0
- package/docs/components/link.md +22 -0
- package/docs/components/oneOf.md +8 -0
- package/docs/components/radio.md +12 -0
- package/docs/components/rich-editor.md +21 -0
- package/docs/components/select.md +34 -0
- package/docs/components/space.md +11 -0
- package/docs/components/switch.md +20 -0
- package/docs/components/text.md +21 -0
- package/docs/components/time-picker.md +11 -0
- package/docs/components/transfer.md +14 -0
- package/docs/components/upload-button.md +28 -0
- package/docs/demos/any-of/index.vue +66 -0
- package/docs/demos/array-cards/index.vue +105 -0
- package/docs/demos/array-collapse/index.vue +155 -0
- package/docs/demos/array-items/index.vue +171 -0
- package/docs/demos/array-table/index.vue +115 -0
- package/docs/demos/array-tabs/index.vue +56 -0
- package/docs/demos/cascader/index.vue +297 -0
- package/docs/demos/checkbox/index.vue +39 -0
- package/docs/demos/event/index.vue +436 -0
- package/docs/demos/hotArea/index.vue +240 -0
- package/docs/demos/index.vue +36 -0
- package/docs/demos/input/index.vue +46 -0
- package/docs/demos/layout-group/index.vue +51 -0
- package/docs/demos/link/index.vue +32 -0
- package/docs/demos/radio/index.vue +36 -0
- package/docs/demos/rich-editor/index.vue +22 -0
- package/docs/demos/select/index.vue +76 -0
- package/docs/demos/space/index.vue +93 -0
- package/docs/demos/switch/index.vue +31 -0
- package/docs/demos/text/index.vue +38 -0
- package/docs/demos/time-picker/index.vue +39 -0
- package/docs/demos/transfer/index.vue +26 -0
- package/docs/demos/upload-button/index.vue +27 -0
- package/docs/demos/x-data/add-button-title.vue +101 -0
- package/docs/demos/x-data/send-message.vue +33 -0
- package/docs/demos/x-reactions/any-of.vue +40 -0
- package/docs/demos/x-reactions/x-reactions.vue +39 -0
- package/docs/guide/component-extend.md +23 -0
- package/docs/guide/extra-bury-report.md +64 -0
- package/docs/guide/schema.md +22 -0
- package/docs/guide/x-data.md +41 -0
- package/docs/guide/x-reactions.md +20 -0
- package/example/.browserslistrc +4 -0
- package/example/.eslintrc.js +20 -0
- package/example/README.md +24 -0
- package/example/index.html +15 -0
- package/example/jest.config.js +26 -0
- package/example/package.json +50 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +17 -0
- package/example/src/App.vue +25 -0
- package/example/src/assets/logo.png +0 -0
- package/example/src/components/HelloWorld.vue +148 -0
- package/example/src/components/group/index.vue +16 -0
- package/example/src/components/uploadBtn/index.vue +44 -0
- package/example/src/components/uploadBtn/upload-icon.svg +6 -0
- package/example/src/layout/component/Aside.vue +39 -0
- package/example/src/layout/component/Main.vue +9 -0
- package/example/src/layout/index.vue +15 -0
- package/example/src/main.ts +17 -0
- package/example/src/router/index.ts +99 -0
- package/example/src/shims-vue.d.ts +6 -0
- package/example/src/store/index.ts +9 -0
- package/example/src/views/demo/any-of/data.ts +38 -0
- package/example/src/views/demo/any-of/index.vue +35 -0
- package/example/src/views/demo/array-cards/data.ts +65 -0
- package/example/src/views/demo/array-cards/index.vue +33 -0
- package/example/src/views/demo/array-items/data.ts +29 -0
- package/example/src/views/demo/array-items/index.vue +33 -0
- package/example/src/views/demo/cloud-button/data.ts +14 -0
- package/example/src/views/demo/cloud-button/index.vue +22 -0
- package/example/src/views/demo/color-group/data.ts +15 -0
- package/example/src/views/demo/color-group/index.vue +22 -0
- package/example/src/views/demo/color-picker/data.ts +21 -0
- package/example/src/views/demo/color-picker/index.vue +33 -0
- package/example/src/views/demo/datatime/data.ts +62 -0
- package/example/src/views/demo/datatime/index.vue +22 -0
- package/example/src/views/demo/event/data.ts +184 -0
- package/example/src/views/demo/event/index.vue +33 -0
- package/example/src/views/demo/hot-area/data.ts +196 -0
- package/example/src/views/demo/hot-area/index.vue +33 -0
- package/example/src/views/demo/input/data.ts +39 -0
- package/example/src/views/demo/input/index.vue +33 -0
- package/example/src/views/demo/link/data.ts +23 -0
- package/example/src/views/demo/link/index.vue +22 -0
- package/example/src/views/demo/one-of/data.ts +139 -0
- package/example/src/views/demo/one-of/index.vue +33 -0
- package/example/src/views/demo/rich-editor/data.ts +12 -0
- package/example/src/views/demo/rich-editor/index.vue +24 -0
- package/example/src/views/demo/select/data.ts +38 -0
- package/example/src/views/demo/select/index.vue +33 -0
- package/example/src/views/demo/upload-button/data1.ts +11 -0
- package/example/src/views/demo/upload-button/data2.ts +12 -0
- package/example/src/views/demo/upload-button/index.vue +42 -0
- package/example/tsconfig.json +32 -0
- package/example/vite.config.ts +12 -0
- package/jest.config.js +4 -0
- package/package.json +92 -4
- package/src/components/__builtins__/configs/index.ts +1 -0
- package/src/components/__builtins__/index.ts +2 -0
- package/src/components/__builtins__/shared/create-context.ts +54 -0
- package/src/components/__builtins__/shared/index.ts +7 -0
- package/src/components/__builtins__/shared/loading.ts +20 -0
- package/src/components/__builtins__/shared/portal.ts +43 -0
- package/src/components/__builtins__/shared/resolve-component.ts +22 -0
- package/src/components/__builtins__/shared/transform-component.ts +33 -0
- package/src/components/__builtins__/shared/types.ts +8 -0
- package/src/components/__builtins__/shared/utils.ts +35 -0
- package/src/components/__builtins__/styles/common.scss +22 -0
- package/src/components/__builtins__/styles/element-plus.scss +1094 -0
- package/src/components/any-of/index.ts +20 -0
- package/src/components/array-base/index.ts +413 -0
- package/src/components/array-base/style.scss +53 -0
- package/src/components/array-base/style.ts +2 -0
- package/src/components/array-cards/index.ts +253 -0
- package/src/components/array-cards/style.scss +33 -0
- package/src/components/array-cards/style.ts +7 -0
- package/src/components/array-collapse/index.ts +381 -0
- package/src/components/array-collapse/style.scss +38 -0
- package/src/components/array-collapse/style.ts +10 -0
- package/src/components/array-items/index.ts +213 -0
- package/src/components/array-items/style.scss +82 -0
- package/src/components/array-items/style.ts +4 -0
- package/src/components/array-table/index.ts +567 -0
- package/src/components/array-table/style.scss +84 -0
- package/src/components/array-table/style.ts +11 -0
- package/src/components/array-tabs/index.ts +141 -0
- package/src/components/array-tabs/style.scss +16 -0
- package/src/components/array-tabs/style.ts +5 -0
- package/src/components/base/AnyOf/index.ts +155 -0
- package/src/components/base/AnyOf/index.vue +111 -0
- package/src/components/base/CloudButton/index.ts +46 -0
- package/src/components/base/CloudButton/index.vue +128 -0
- package/src/components/base/ColorGroup/index.ts +57 -0
- package/src/components/base/ColorGroup/index.vue +30 -0
- package/src/components/base/ColorPicker/index.ts +45 -0
- package/src/components/base/ColorPicker/index.vue +50 -0
- package/src/components/base/Container/index.vue +39 -0
- package/src/components/base/HotArea/index.ts +698 -0
- package/src/components/base/HotArea/index.vue +565 -0
- package/src/components/base/HotArea/type.ts +18 -0
- package/src/components/base/Input/index.vue +150 -0
- package/src/components/base/LayoutGroup/index.vue +40 -0
- package/src/components/base/Link/index.vue +43 -0
- package/src/components/base/Middleware/index.ts +235 -0
- package/src/components/base/Middleware/index.vue +169 -0
- package/src/components/base/OneOf/index.ts +105 -0
- package/src/components/base/OneOf/index.vue +85 -0
- package/src/components/base/RichEditor/index.ts +13 -0
- package/src/components/base/RichEditor/index.vue +120 -0
- package/src/components/base/RichEditor/options.ts +24 -0
- package/src/components/base/Select/index.ts +106 -0
- package/src/components/base/Select/index.vue +161 -0
- package/src/components/base/Switch/index.vue +42 -0
- package/src/components/base/Text/index.vue +47 -0
- package/src/components/base/event/index.ts +226 -0
- package/src/components/base/event/index.vue +356 -0
- package/src/components/cascader/index.ts +48 -0
- package/src/components/cascader/style.ts +5 -0
- package/src/components/checkbox/index.ts +166 -0
- package/src/components/checkbox/style.ts +5 -0
- package/src/components/cloud-button/index.ts +21 -0
- package/src/components/color-group/index.ts +18 -0
- package/src/components/color-picker/index.ts +18 -0
- package/src/components/container/index.ts +18 -0
- package/src/components/data-time/index.ts +24 -0
- package/src/components/date-picker/index.ts +51 -0
- package/src/components/date-picker/style.ts +4 -0
- package/src/components/editable/index.ts +261 -0
- package/src/components/editable/style.scss +55 -0
- package/src/components/editable/style.ts +5 -0
- package/src/components/el-form-item/index.ts +21 -0
- package/src/components/el-form-item/style.ts +3 -0
- package/src/components/event/index.ts +16 -0
- package/src/components/form/index.ts +94 -0
- package/src/components/form/style.scss +0 -0
- package/src/components/form/style.ts +3 -0
- package/src/components/form-button-group/index.ts +74 -0
- package/src/components/form-button-group/style.scss +0 -0
- package/src/components/form-button-group/style.ts +4 -0
- package/src/components/form-collapse/index.ts +215 -0
- package/src/components/form-collapse/style.scss +6 -0
- package/src/components/form-collapse/style.ts +4 -0
- package/src/components/form-dialog/index.ts +433 -0
- package/src/components/form-dialog/style.ts +4 -0
- package/src/components/form-drawer/index.ts +424 -0
- package/src/components/form-drawer/style.scss +21 -0
- package/src/components/form-drawer/style.ts +4 -0
- package/src/components/form-grid/index.ts +181 -0
- package/src/components/form-grid/style.scss +5 -0
- package/src/components/form-grid/style.ts +1 -0
- package/src/components/form-item/animation.scss +72 -0
- package/src/components/form-item/grid.scss +171 -0
- package/src/components/form-item/index.ts +642 -0
- package/src/components/form-item/style.scss +521 -0
- package/src/components/form-item/style.ts +2 -0
- package/src/components/form-item/var.scss +17 -0
- package/src/components/form-layout/index.ts +161 -0
- package/src/components/form-layout/style.scss +6 -0
- package/src/components/form-layout/style.ts +1 -0
- package/src/components/form-layout/useResponsiveFormLayout.ts +118 -0
- package/src/components/form-step/index.ts +210 -0
- package/src/components/form-step/style.ts +2 -0
- package/src/components/form-tab/index.ts +172 -0
- package/src/components/form-tab/style.scss +6 -0
- package/src/components/form-tab/style.ts +4 -0
- package/src/components/hot-area/index.ts +20 -0
- package/src/components/index.ts +49 -0
- package/src/components/input/index.ts +35 -0
- package/src/components/input/style.ts +4 -0
- package/src/components/input-number/index.ts +36 -0
- package/src/components/input-number/style.ts +3 -0
- package/src/components/layout-group/index.ts +18 -0
- package/src/components/link/index.ts +18 -0
- package/src/components/middleware/index.ts +21 -0
- package/src/components/one-of/index.ts +20 -0
- package/src/components/placeholder-input/index.ts +21 -0
- package/src/components/placeholder-input/index.vue +87 -0
- package/src/components/preview-text/index.ts +303 -0
- package/src/components/preview-text/style.ts +9 -0
- package/src/components/radio/index.ts +109 -0
- package/src/components/radio/style.ts +3 -0
- package/src/components/reset/index.ts +52 -0
- package/src/components/reset/style.ts +1 -0
- package/src/components/rich-editor/index.ts +18 -0
- package/src/components/row/index.ts +20 -0
- package/src/components/row/index.vue +53 -0
- package/src/components/select/index.ts +19 -0
- package/src/components/select/style.ts +5 -0
- package/src/components/space/index.ts +98 -0
- package/src/components/space/style.scss +24 -0
- package/src/components/space/style.ts +1 -0
- package/src/components/submit/index.ts +59 -0
- package/src/components/submit/style.ts +1 -0
- package/src/components/switch/index.ts +9 -0
- package/src/components/switch/style.ts +1 -0
- package/src/components/text/index.ts +21 -0
- package/src/components/time-picker/index.ts +21 -0
- package/src/components/time-picker/style.ts +4 -0
- package/src/components/transfer/index.ts +12 -0
- package/src/components/transfer/style.ts +1 -0
- package/src/components/upload/index.ts +136 -0
- package/src/components/upload/style.ts +2 -0
- package/src/components/upload-button/index.ts +21 -0
- package/src/components/upload-button/index.vue +199 -0
- package/src/createScemaField.ts +14 -0
- package/src/index.ts +41 -0
- package/src/schema-field/index.ts +11 -0
- package/src/scope.ts +29 -0
- package/src/transform/core.ts +404 -0
- package/src/transform/index.ts +11 -0
- package/src/transform/transform.ts +59 -0
- package/src/transform/utils/constant.ts +79 -0
- package/src/transform/utils/func.ts +145 -0
- package/src/typings/common.ts +37 -0
- package/src/typings/vue-shim.d.ts +7 -0
- package/src/typings/vue-test-utils.d.ts +11 -0
- package/src/utils/anyof_utils.ts +95 -0
- package/src/utils/common.ts +15 -0
- package/src/validate/index.ts +648 -0
- package/src/validate/utils/constant.ts +2 -0
- package/src/vue-form/index.ts +18 -0
- package/src/vue-form/index.vue +106 -0
- package/src/vue-form/useForm.ts +112 -0
- package/tests/data/anyof.ts +40 -0
- package/tests/data/image.ts +472 -0
- package/tests/fixtures/validate.ts +63 -0
- package/tests/unit/transform.spec.ts +253 -0
- package/tests/unit/utils.spec.ts +10 -0
- package/tests/unit/validate.spec.ts +256 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { isArr, isValid } from '@formily/shared'
|
|
2
|
+
import { onMounted, Ref, ref, getCurrentInstance } from 'vue'
|
|
3
|
+
import type, { ComponentInternalInstance } from 'vue'
|
|
4
|
+
|
|
5
|
+
interface IProps {
|
|
6
|
+
breakpoints?: number[]
|
|
7
|
+
layout?:
|
|
8
|
+
| 'vertical'
|
|
9
|
+
| 'horizontal'
|
|
10
|
+
| 'inline'
|
|
11
|
+
| ('vertical' | 'horizontal' | 'inline')[]
|
|
12
|
+
labelCol?: number | number[]
|
|
13
|
+
wrapperCol?: number | number[]
|
|
14
|
+
labelAlign?: 'right' | 'left' | ('right' | 'left')[]
|
|
15
|
+
wrapperAlign?: 'right' | 'left' | ('right' | 'left')[]
|
|
16
|
+
[props: string]: any
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ICalcBreakpointIndex {
|
|
20
|
+
(originalBreakpoints: number[], width: number): number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ICalculateProps {
|
|
24
|
+
(target: Element, props: IProps): IProps
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IUseResponsiveFormLayout {
|
|
28
|
+
(props: IProps): {
|
|
29
|
+
props: Ref<IProps>
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const calcBreakpointIndex: ICalcBreakpointIndex = (breakpoints, width) => {
|
|
34
|
+
for (let i = 0; i < breakpoints.length; i++) {
|
|
35
|
+
if (width <= breakpoints[i]) {
|
|
36
|
+
return i
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return -1
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const calcFactor = <T>(value: T | T[], breakpointIndex: number): T => {
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
if (breakpointIndex === -1) return value[0]
|
|
45
|
+
return value[breakpointIndex] ?? value[value.length - 1]
|
|
46
|
+
} else {
|
|
47
|
+
return value
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const factor = <T>(value: T | T[], breakpointIndex: number): T =>
|
|
52
|
+
isValid(value) ? calcFactor(value as any, breakpointIndex) : value
|
|
53
|
+
|
|
54
|
+
const calculateProps: ICalculateProps = (target, props) => {
|
|
55
|
+
const { clientWidth } = target
|
|
56
|
+
const {
|
|
57
|
+
breakpoints,
|
|
58
|
+
layout,
|
|
59
|
+
labelAlign,
|
|
60
|
+
wrapperAlign,
|
|
61
|
+
labelCol,
|
|
62
|
+
wrapperCol,
|
|
63
|
+
...otherProps
|
|
64
|
+
} = props
|
|
65
|
+
const breakpointIndex = calcBreakpointIndex(
|
|
66
|
+
breakpoints as number[],
|
|
67
|
+
clientWidth
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
layout: factor(layout, breakpointIndex),
|
|
72
|
+
labelAlign: factor(labelAlign, breakpointIndex),
|
|
73
|
+
wrapperAlign: factor(wrapperAlign, breakpointIndex),
|
|
74
|
+
labelCol: factor(labelCol, breakpointIndex),
|
|
75
|
+
wrapperCol: factor(wrapperCol, breakpointIndex),
|
|
76
|
+
...otherProps,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const useRefs = (): Record<string, unknown> => {
|
|
81
|
+
const vm: ComponentInternalInstance | null = getCurrentInstance()
|
|
82
|
+
return vm?.refs || {}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const useResponsiveFormLayout = (props: any) => {
|
|
86
|
+
const { breakpoints } = props
|
|
87
|
+
if (!isArr(breakpoints)) {
|
|
88
|
+
return {
|
|
89
|
+
props: ref(props),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const layoutProps = ref<IProps>({})
|
|
93
|
+
|
|
94
|
+
const updateUI = (target: HTMLElement) => {
|
|
95
|
+
layoutProps.value = calculateProps(target, props)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onMounted(() => {
|
|
99
|
+
const { root } = useRefs()
|
|
100
|
+
const observer = () => {
|
|
101
|
+
updateUI(root as HTMLElement)
|
|
102
|
+
}
|
|
103
|
+
const resizeObserver = new ResizeObserver(observer)
|
|
104
|
+
if (root) {
|
|
105
|
+
resizeObserver.observe(root as Element)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
updateUI(root as HTMLElement)
|
|
109
|
+
|
|
110
|
+
return () => {
|
|
111
|
+
resizeObserver.disconnect()
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
props: layoutProps,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { defineComponent, PropType } from 'vue';
|
|
2
|
+
import { action, model, observable } from '@formily/reactive';
|
|
3
|
+
import { VoidField, Form } from '@formily/core';
|
|
4
|
+
import { observer } from '@formily/reactive-vue';
|
|
5
|
+
import {
|
|
6
|
+
h,
|
|
7
|
+
useField,
|
|
8
|
+
useFieldSchema,
|
|
9
|
+
RecursionField,
|
|
10
|
+
Fragment,
|
|
11
|
+
} from '@formily/vue';
|
|
12
|
+
import { Schema, SchemaKey } from '@formily/json-schema';
|
|
13
|
+
import { ElSteps, ElStep } from '@cicctencent/jtui';
|
|
14
|
+
import { stylePrefix, composeExport } from '../__builtins__';
|
|
15
|
+
|
|
16
|
+
export interface IFormStep {
|
|
17
|
+
connect: (steps: SchemaStep[], field: VoidField) => void;
|
|
18
|
+
current: number;
|
|
19
|
+
allowNext: boolean;
|
|
20
|
+
allowBack: boolean;
|
|
21
|
+
setCurrent(key: number): void;
|
|
22
|
+
submit: Form['submit'];
|
|
23
|
+
next(): void;
|
|
24
|
+
back(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IFormStepProps {
|
|
28
|
+
formStep?: IFormStep;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type SchemaStep = {
|
|
32
|
+
name: SchemaKey;
|
|
33
|
+
props: any;
|
|
34
|
+
schema: Schema;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type FormStepEnv = {
|
|
38
|
+
form: Form;
|
|
39
|
+
field: VoidField;
|
|
40
|
+
steps: SchemaStep[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const parseSteps = (schema: Schema) => {
|
|
44
|
+
const steps: SchemaStep[] = [];
|
|
45
|
+
schema.mapProperties((schema, name) => {
|
|
46
|
+
if (schema['x-component']?.indexOf('StepPane') > -1) {
|
|
47
|
+
steps.push({
|
|
48
|
+
name,
|
|
49
|
+
props: schema['x-component-props'],
|
|
50
|
+
schema,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return steps;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const createFormStep = (defaultCurrent = 0): IFormStep => {
|
|
58
|
+
const env: FormStepEnv = observable({
|
|
59
|
+
form: null,
|
|
60
|
+
field: null,
|
|
61
|
+
steps: [],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const setDisplay = action.bound((target: number) => {
|
|
65
|
+
const currentStep = env.steps[target];
|
|
66
|
+
env.steps.forEach(({ name }) => {
|
|
67
|
+
env.form.query(`${env.field.address}.${name}`).take(field => {
|
|
68
|
+
if (name === currentStep.name) {
|
|
69
|
+
field.setDisplay('visible');
|
|
70
|
+
} else {
|
|
71
|
+
field.setDisplay('hidden');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const next = action.bound(() => {
|
|
78
|
+
if (formStep.allowNext) {
|
|
79
|
+
setDisplay(formStep.current + 1);
|
|
80
|
+
formStep.setCurrent(formStep.current + 1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const back = action.bound(() => {
|
|
85
|
+
if (formStep.allowBack) {
|
|
86
|
+
setDisplay(formStep.current - 1);
|
|
87
|
+
formStep.setCurrent(formStep.current - 1);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const formStep: IFormStep = model({
|
|
92
|
+
connect(steps, field) {
|
|
93
|
+
env.steps = steps;
|
|
94
|
+
env.form = field?.form;
|
|
95
|
+
env.field = field;
|
|
96
|
+
},
|
|
97
|
+
current: defaultCurrent,
|
|
98
|
+
setCurrent(key: number) {
|
|
99
|
+
formStep.current = key;
|
|
100
|
+
},
|
|
101
|
+
get allowNext() {
|
|
102
|
+
return formStep.current < env.steps.length - 1;
|
|
103
|
+
},
|
|
104
|
+
get allowBack() {
|
|
105
|
+
return formStep.current > 0;
|
|
106
|
+
},
|
|
107
|
+
async next() {
|
|
108
|
+
try {
|
|
109
|
+
await env.form.validate();
|
|
110
|
+
next();
|
|
111
|
+
} catch {}
|
|
112
|
+
},
|
|
113
|
+
async back() {
|
|
114
|
+
back();
|
|
115
|
+
},
|
|
116
|
+
async submit(onSubmit) {
|
|
117
|
+
return env.form?.submit?.(onSubmit);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return formStep;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const FormStepInner = observer(
|
|
124
|
+
defineComponent({
|
|
125
|
+
name: 'FFormStep',
|
|
126
|
+
props: {
|
|
127
|
+
formStep: {
|
|
128
|
+
type: Object as PropType<IFormStep>,
|
|
129
|
+
default() {
|
|
130
|
+
return {
|
|
131
|
+
current: 0,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
setup(props: any, { attrs }) {
|
|
137
|
+
const field = useField<VoidField>().value;
|
|
138
|
+
const prefixCls = `${stylePrefix}-form-step`;
|
|
139
|
+
const fieldSchemaRef = useFieldSchema();
|
|
140
|
+
|
|
141
|
+
const steps = parseSteps(fieldSchemaRef.value as any);
|
|
142
|
+
|
|
143
|
+
props.formStep.connect?.(steps, field);
|
|
144
|
+
|
|
145
|
+
return () => {
|
|
146
|
+
const current = props.active || props.formStep?.current || 0;
|
|
147
|
+
|
|
148
|
+
const renderSteps = (steps: SchemaStep[], callback) => {
|
|
149
|
+
return steps.map(callback);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return h(
|
|
153
|
+
'div',
|
|
154
|
+
{
|
|
155
|
+
class: [prefixCls],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
default: () => [
|
|
159
|
+
h(
|
|
160
|
+
ElSteps,
|
|
161
|
+
{
|
|
162
|
+
...attrs,
|
|
163
|
+
active: current,
|
|
164
|
+
style: [
|
|
165
|
+
{ marginBottom: '10px' },
|
|
166
|
+
attrs.style,
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
default: () =>
|
|
171
|
+
renderSteps(steps, ({ props }, key) => {
|
|
172
|
+
return h(
|
|
173
|
+
ElStep,
|
|
174
|
+
{ props, key },
|
|
175
|
+
{}
|
|
176
|
+
);
|
|
177
|
+
}),
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
|
|
181
|
+
renderSteps(steps, ({ name, schema }, key) => {
|
|
182
|
+
if (key !== current) return;
|
|
183
|
+
return h(
|
|
184
|
+
RecursionField,
|
|
185
|
+
{ props: { name, schema }, key },
|
|
186
|
+
{}
|
|
187
|
+
);
|
|
188
|
+
}),
|
|
189
|
+
],
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const StepPane = defineComponent({
|
|
198
|
+
name: 'FFormStepPane',
|
|
199
|
+
inheritAttrs: false,
|
|
200
|
+
setup(_props, { slots }) {
|
|
201
|
+
return () => h(Fragment, {}, slots);
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export const FormStep = composeExport(FormStepInner, {
|
|
206
|
+
StepPane,
|
|
207
|
+
createFormStep,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
export default FormStep;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { defineComponent, reactive, computed, PropType } from 'vue';
|
|
2
|
+
import { observer } from '@formily/reactive-vue';
|
|
3
|
+
import { model } from '@formily/reactive';
|
|
4
|
+
import {
|
|
5
|
+
h,
|
|
6
|
+
useField,
|
|
7
|
+
useFieldSchema,
|
|
8
|
+
RecursionField,
|
|
9
|
+
Fragment,
|
|
10
|
+
} from '@formily/vue';
|
|
11
|
+
import { Schema, SchemaKey } from '@formily/json-schema';
|
|
12
|
+
import { ElTabs, ElTabPane, ElBadge } from '@cicctencent/jtui';
|
|
13
|
+
import { stylePrefix, composeExport } from '../__builtins__';
|
|
14
|
+
|
|
15
|
+
export interface IFormTab {
|
|
16
|
+
activeKey: string;
|
|
17
|
+
setActiveKey(key: string): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IFormTabProps {
|
|
21
|
+
formTab?: IFormTab;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IFormTabPaneProps {
|
|
25
|
+
key: string | number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Tabs = { name: SchemaKey; props: any; schema: Schema }[];
|
|
29
|
+
|
|
30
|
+
const useTabs = () => {
|
|
31
|
+
const tabsField = useField();
|
|
32
|
+
const schema = useFieldSchema();
|
|
33
|
+
const tabs: Tabs = reactive([]);
|
|
34
|
+
schema.value.mapProperties((schema, name) => {
|
|
35
|
+
const field = tabsField.value
|
|
36
|
+
.query(tabsField.value.address.concat(name))
|
|
37
|
+
.take();
|
|
38
|
+
if (field?.display === 'none' || field?.display === 'hidden') return;
|
|
39
|
+
|
|
40
|
+
if (schema['x-component']?.indexOf('TabPane') > -1) {
|
|
41
|
+
tabs.push({
|
|
42
|
+
name,
|
|
43
|
+
props: {
|
|
44
|
+
name: schema?.['x-component-props']?.name || name,
|
|
45
|
+
...schema?.['x-component-props'],
|
|
46
|
+
},
|
|
47
|
+
schema:schema as any,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return tabs;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const createFormTab = (defaultActiveKey?: string) => {
|
|
55
|
+
const formTab = model({
|
|
56
|
+
activeKey: defaultActiveKey,
|
|
57
|
+
setActiveKey(key: string) {
|
|
58
|
+
formTab.activeKey = key;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
return formTab;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const FormTab = observer(
|
|
65
|
+
defineComponent({
|
|
66
|
+
inheritAttrs: false,
|
|
67
|
+
props: {
|
|
68
|
+
formTab: { type: Object as PropType<IFormTab> },
|
|
69
|
+
value: {
|
|
70
|
+
type: String,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
setup(props, { attrs, emit }: any) {
|
|
74
|
+
const field = useField();
|
|
75
|
+
const prefixCls = `${stylePrefix}-form-tab`;
|
|
76
|
+
const formTabRef = computed(() => props.formTab ?? createFormTab());
|
|
77
|
+
|
|
78
|
+
const takeActiveKey = (tabs: Tabs) => {
|
|
79
|
+
return (
|
|
80
|
+
props?.value ||
|
|
81
|
+
formTabRef.value?.activeKey ||
|
|
82
|
+
tabs?.[0]?.name
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const badgedHeader = (key: SchemaKey, props: any) => {
|
|
87
|
+
const errors = field.value.form.queryFeedbacks({
|
|
88
|
+
type: 'error',
|
|
89
|
+
address: `${field.value.address.concat(key)}.*`,
|
|
90
|
+
});
|
|
91
|
+
if (errors.length) {
|
|
92
|
+
return h(
|
|
93
|
+
ElBadge,
|
|
94
|
+
{
|
|
95
|
+
class: [`${prefixCls}-errors-badge`],
|
|
96
|
+
value: errors.length,
|
|
97
|
+
},
|
|
98
|
+
{ default: () => props.label }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return props.label;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return () => {
|
|
105
|
+
const tabs = useTabs();
|
|
106
|
+
const activeKey = takeActiveKey(tabs);
|
|
107
|
+
|
|
108
|
+
return h(
|
|
109
|
+
ElTabs,
|
|
110
|
+
{
|
|
111
|
+
...attrs,
|
|
112
|
+
class: [prefixCls],
|
|
113
|
+
modelValue: activeKey,
|
|
114
|
+
onChange: (key: string) => {
|
|
115
|
+
emit('input', key);
|
|
116
|
+
formTabRef.value.setActiveKey?.(key);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
default: () =>
|
|
121
|
+
tabs.map(({ props, schema, name }, key) => {
|
|
122
|
+
return h(
|
|
123
|
+
ElTabPane,
|
|
124
|
+
{
|
|
125
|
+
key,
|
|
126
|
+
...props,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
default: () =>
|
|
130
|
+
h(
|
|
131
|
+
RecursionField,
|
|
132
|
+
{ schema, name },
|
|
133
|
+
{}
|
|
134
|
+
),
|
|
135
|
+
label: () =>
|
|
136
|
+
h(
|
|
137
|
+
'div',
|
|
138
|
+
{},
|
|
139
|
+
{
|
|
140
|
+
default: () => [
|
|
141
|
+
badgedHeader(
|
|
142
|
+
name,
|
|
143
|
+
props
|
|
144
|
+
),
|
|
145
|
+
],
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}),
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const FormTabPane = defineComponent<IFormTabPaneProps>({
|
|
159
|
+
name: 'FFormTabPane',
|
|
160
|
+
inheritAttrs: false,
|
|
161
|
+
setup(_props, { slots }) {
|
|
162
|
+
return () => h(Fragment, {}, slots);
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export const composeFormTab = composeExport(FormTab, {
|
|
167
|
+
TabPane: FormTabPane,
|
|
168
|
+
createFormTab,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
export { composeFormTab as FormTab };
|
|
172
|
+
export default composeFormTab;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { transformComponent } from '../__builtins__';
|
|
2
|
+
import { connect, mapProps } from '@formily/vue';
|
|
3
|
+
|
|
4
|
+
import ElHotArea from '../base/HotArea/index.vue';
|
|
5
|
+
|
|
6
|
+
export type ElHotAreaProps = typeof ElHotArea;
|
|
7
|
+
|
|
8
|
+
const TransformHotArea = transformComponent<ElHotAreaProps>(ElHotArea, {
|
|
9
|
+
change: 'update:modelValue',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const HotArea = connect(
|
|
13
|
+
TransformHotArea,
|
|
14
|
+
mapProps({
|
|
15
|
+
value: 'modelValue',
|
|
16
|
+
readOnly: 'readonly',
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default HotArea;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export * from './input';
|
|
2
|
+
export * from './select';
|
|
3
|
+
export * from './time-picker';
|
|
4
|
+
export * from './date-picker';
|
|
5
|
+
export * from './cascader';
|
|
6
|
+
export * from './el-form-item';
|
|
7
|
+
export * from './form-layout';
|
|
8
|
+
export * from './submit';
|
|
9
|
+
export * from './preview-text';
|
|
10
|
+
export * from './space';
|
|
11
|
+
export * from './form-grid';
|
|
12
|
+
export * from './form-item';
|
|
13
|
+
export * from './array-base';
|
|
14
|
+
export * from './array-cards';
|
|
15
|
+
export * from './array-collapse';
|
|
16
|
+
export * from './array-items';
|
|
17
|
+
export * from './array-table';
|
|
18
|
+
export * from './array-tabs';
|
|
19
|
+
export * from './upload';
|
|
20
|
+
export * from './transfer';
|
|
21
|
+
export * from './switch';
|
|
22
|
+
export * from './reset';
|
|
23
|
+
export * from './radio';
|
|
24
|
+
export * from './input-number';
|
|
25
|
+
export * from './form-tab';
|
|
26
|
+
export * from './form-step';
|
|
27
|
+
export * from './form-drawer';
|
|
28
|
+
export * from './form-dialog';
|
|
29
|
+
export * from './form-collapse';
|
|
30
|
+
export * from './form-button-group';
|
|
31
|
+
export * from './form';
|
|
32
|
+
export * from './editable';
|
|
33
|
+
export * from './checkbox';
|
|
34
|
+
export * from './upload-button';
|
|
35
|
+
export * from './hot-area';
|
|
36
|
+
export * from './one-of';
|
|
37
|
+
export * from './any-of';
|
|
38
|
+
export * from './rich-editor';
|
|
39
|
+
export * from './data-time';
|
|
40
|
+
export * from './color-group';
|
|
41
|
+
export * from './link';
|
|
42
|
+
export * from './event';
|
|
43
|
+
export * from './layout-group';
|
|
44
|
+
export * from './text';
|
|
45
|
+
export * from './cloud-button';
|
|
46
|
+
export * from './color-picker';
|
|
47
|
+
export * from './middleware';
|
|
48
|
+
export * from './row';
|
|
49
|
+
export * from './placeholder-input';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { composeExport, transformComponent } from '../__builtins__';
|
|
2
|
+
import { connect, mapProps, mapReadPretty } from '@formily/vue';
|
|
3
|
+
import { PreviewText } from '../preview-text';
|
|
4
|
+
import ElInput from '../base/Input/index.vue';
|
|
5
|
+
|
|
6
|
+
export type InputProps = typeof ElInput;
|
|
7
|
+
|
|
8
|
+
const TransformElInput = transformComponent<InputProps>(ElInput, {
|
|
9
|
+
change: 'update:modelValue',
|
|
10
|
+
});
|
|
11
|
+
export const Input = connect(
|
|
12
|
+
TransformElInput,
|
|
13
|
+
mapProps({
|
|
14
|
+
value: 'modelValue',
|
|
15
|
+
readOnly: 'readonly',
|
|
16
|
+
}),
|
|
17
|
+
mapReadPretty(PreviewText.Input)
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// const TextArea = connect(
|
|
21
|
+
// InnerInput,
|
|
22
|
+
// mapProps(props => {
|
|
23
|
+
// return {
|
|
24
|
+
// ...props,
|
|
25
|
+
// type: 'textarea',
|
|
26
|
+
// };
|
|
27
|
+
// }),
|
|
28
|
+
// mapReadPretty(PreviewText.Input)
|
|
29
|
+
// );
|
|
30
|
+
|
|
31
|
+
// export const Input = composeExport(InnerInput, {
|
|
32
|
+
// TextArea,
|
|
33
|
+
// });
|
|
34
|
+
|
|
35
|
+
export default Input;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { transformComponent } from '../__builtins__';
|
|
2
|
+
import { connect, mapProps, mapReadPretty } from '@formily/vue';
|
|
3
|
+
import { ElInputNumber } from '@cicctencent/jtui';
|
|
4
|
+
import { PreviewText } from '../preview-text';
|
|
5
|
+
|
|
6
|
+
export type InputNumberProps = typeof ElInputNumber;
|
|
7
|
+
|
|
8
|
+
const TransformElInputNumber = transformComponent<InputNumberProps>(
|
|
9
|
+
ElInputNumber,
|
|
10
|
+
{
|
|
11
|
+
change: 'update:modelValue',
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const InputNumber = connect(
|
|
16
|
+
TransformElInputNumber,
|
|
17
|
+
mapProps(
|
|
18
|
+
{
|
|
19
|
+
value: 'modelValue',
|
|
20
|
+
readOnly: 'readonly',
|
|
21
|
+
},
|
|
22
|
+
props => {
|
|
23
|
+
let controlsPosition = '';
|
|
24
|
+
if (props.controlsPosition) {
|
|
25
|
+
controlsPosition = props.controlsPosition;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
controlsPosition,
|
|
29
|
+
modelValue: props.modelValue,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
),
|
|
33
|
+
mapReadPretty(PreviewText.Input)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export default InputNumber;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { transformComponent } from '../__builtins__';
|
|
2
|
+
import { connect, mapProps } from '@formily/vue';
|
|
3
|
+
|
|
4
|
+
import JtLayoutGroup from '../base/LayoutGroup/index.vue';
|
|
5
|
+
|
|
6
|
+
export type JtLayoutGroupProps = typeof JtLayoutGroup;
|
|
7
|
+
|
|
8
|
+
const TransformLayoutGroup = transformComponent<JtLayoutGroupProps>(JtLayoutGroup);
|
|
9
|
+
|
|
10
|
+
export const LayoutGroup = connect(
|
|
11
|
+
TransformLayoutGroup,
|
|
12
|
+
mapProps({
|
|
13
|
+
value: 'modelValue',
|
|
14
|
+
readOnly: 'readonly',
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default LayoutGroup;
|