@xiaohaih/json-form-vant 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 (213) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +807 -0
  3. package/TODO.md +36 -0
  4. package/components/area/index.ts +6 -0
  5. package/components/area/index.vue +120 -0
  6. package/components/area/types.ts +84 -0
  7. package/components/cascader/index.ts +6 -0
  8. package/components/cascader/index.vue +146 -0
  9. package/components/cascader/types.ts +75 -0
  10. package/components/checkbox/index.ts +6 -0
  11. package/components/checkbox/index.vue +59 -0
  12. package/components/checkbox/types.ts +54 -0
  13. package/components/checkbox-group/index.ts +6 -0
  14. package/components/checkbox-group/index.vue +67 -0
  15. package/components/checkbox-group/types.ts +63 -0
  16. package/components/component-definition/components.ts +29 -0
  17. package/components/component-definition/definition.ts +25 -0
  18. package/components/component-definition/index.ts +4 -0
  19. package/components/custom-render/index.ts +6 -0
  20. package/components/custom-render/index.vue +66 -0
  21. package/components/custom-render/types.ts +43 -0
  22. package/components/date-picker/index.ts +6 -0
  23. package/components/date-picker/index.vue +130 -0
  24. package/components/date-picker/types.ts +91 -0
  25. package/components/date-time-picker-group/index.ts +6 -0
  26. package/components/date-time-picker-group/index.vue +158 -0
  27. package/components/date-time-picker-group/types.ts +115 -0
  28. package/components/datetime-picker/index.ts +6 -0
  29. package/components/datetime-picker/index.vue +128 -0
  30. package/components/datetime-picker/types.ts +78 -0
  31. package/components/dynamic-group/index.ts +10 -0
  32. package/components/dynamic-group/index.vue +140 -0
  33. package/components/dynamic-group/types.ts +68 -0
  34. package/components/group/assist.ts +99 -0
  35. package/components/group/index.ts +7 -0
  36. package/components/group/index.vue +117 -0
  37. package/components/group/types.ts +57 -0
  38. package/components/group/virtual-group.vue +38 -0
  39. package/components/index.ts +10 -0
  40. package/components/input/index.ts +6 -0
  41. package/components/input/index.vue +83 -0
  42. package/components/input/types.ts +43 -0
  43. package/components/input-slot/index.ts +6 -0
  44. package/components/input-slot/index.vue +148 -0
  45. package/components/input-slot/types.ts +34 -0
  46. package/components/number-keyboard/index.ts +6 -0
  47. package/components/number-keyboard/index.vue +81 -0
  48. package/components/number-keyboard/types.ts +57 -0
  49. package/components/password-input/index.ts +6 -0
  50. package/components/password-input/index.vue +103 -0
  51. package/components/password-input/types.ts +64 -0
  52. package/components/picker/index.ts +6 -0
  53. package/components/picker/index.vue +136 -0
  54. package/components/picker/types.ts +94 -0
  55. package/components/radio/index.ts +6 -0
  56. package/components/radio/index.vue +68 -0
  57. package/components/radio/types.ts +58 -0
  58. package/components/radio-group/index.ts +6 -0
  59. package/components/radio-group/index.vue +74 -0
  60. package/components/radio-group/types.ts +65 -0
  61. package/components/rate/index.ts +6 -0
  62. package/components/rate/index.vue +63 -0
  63. package/components/rate/types.ts +47 -0
  64. package/components/share.ts +78 -0
  65. package/components/signature/index.ts +6 -0
  66. package/components/signature/index.vue +65 -0
  67. package/components/signature/instance.vue +161 -0
  68. package/components/signature/types.ts +79 -0
  69. package/components/slider/index.ts +6 -0
  70. package/components/slider/index.vue +63 -0
  71. package/components/slider/types.ts +53 -0
  72. package/components/stepper/index.ts +6 -0
  73. package/components/stepper/index.vue +62 -0
  74. package/components/stepper/types.ts +47 -0
  75. package/components/switch/index.ts +6 -0
  76. package/components/switch/index.vue +61 -0
  77. package/components/switch/types.ts +51 -0
  78. package/components/time-picker/index.ts +6 -0
  79. package/components/time-picker/index.vue +130 -0
  80. package/components/time-picker/types.ts +91 -0
  81. package/components/tree-select/index.ts +6 -0
  82. package/components/tree-select/index.vue +160 -0
  83. package/components/tree-select/types.ts +77 -0
  84. package/components/upload/index.ts +6 -0
  85. package/components/upload/index.vue +109 -0
  86. package/components/upload/types.ts +85 -0
  87. package/components/use.ts +45 -0
  88. package/components/utils.ts +52 -0
  89. package/components/wrapper/index.ts +6 -0
  90. package/components/wrapper/index.vue +117 -0
  91. package/components/wrapper/types.ts +94 -0
  92. package/dist/components/area/index.d.ts +5 -0
  93. package/dist/components/area/index.vue.d.ts +1843 -0
  94. package/dist/components/area/types.d.ts +1434 -0
  95. package/dist/components/cascader/index.d.ts +5 -0
  96. package/dist/components/cascader/index.vue.d.ts +2467 -0
  97. package/dist/components/cascader/types.d.ts +1419 -0
  98. package/dist/components/checkbox/index.d.ts +5 -0
  99. package/dist/components/checkbox/index.vue.d.ts +1550 -0
  100. package/dist/components/checkbox/types.d.ts +1313 -0
  101. package/dist/components/checkbox-group/index.d.ts +5 -0
  102. package/dist/components/checkbox-group/index.vue.d.ts +1643 -0
  103. package/dist/components/checkbox-group/types.d.ts +1372 -0
  104. package/dist/components/component-definition/components.d.ts +30 -0
  105. package/dist/components/component-definition/index.d.ts +4 -0
  106. package/dist/components/custom-render/index.d.ts +5 -0
  107. package/dist/components/custom-render/index.vue.d.ts +1473 -0
  108. package/dist/components/custom-render/types.d.ts +1175 -0
  109. package/dist/components/date-picker/index.d.ts +5 -0
  110. package/dist/components/date-picker/index.vue.d.ts +1888 -0
  111. package/dist/components/date-picker/types.d.ts +1458 -0
  112. package/dist/components/date-time-picker-group/index.d.ts +5 -0
  113. package/dist/components/date-time-picker-group/index.vue.d.ts +2181 -0
  114. package/dist/components/date-time-picker-group/types.d.ts +1549 -0
  115. package/dist/components/dynamic-group/index.d.ts +5 -0
  116. package/dist/components/dynamic-group/index.vue.d.ts +457 -0
  117. package/dist/components/dynamic-group/types.d.ts +403 -0
  118. package/dist/components/group/assist.d.ts +58 -0
  119. package/dist/components/group/index.d.ts +6 -0
  120. package/dist/components/group/index.vue.d.ts +139 -0
  121. package/dist/components/group/types.d.ts +189 -0
  122. package/dist/components/group/virtual-group.vue.d.ts +42 -0
  123. package/dist/components/index.d.ts +3 -0
  124. package/dist/components/input/index.d.ts +5 -0
  125. package/dist/components/input/index.vue.d.ts +2229 -0
  126. package/dist/components/input/types.d.ts +1258 -0
  127. package/dist/components/input-slot/index.d.ts +5 -0
  128. package/dist/components/input-slot/index.vue.d.ts +626 -0
  129. package/dist/components/input-slot/types.d.ts +311 -0
  130. package/dist/components/number-keyboard/index.d.ts +5 -0
  131. package/dist/components/number-keyboard/index.vue.d.ts +1643 -0
  132. package/dist/components/number-keyboard/types.d.ts +1324 -0
  133. package/dist/components/password-input/index.d.ts +5 -0
  134. package/dist/components/password-input/index.vue.d.ts +1715 -0
  135. package/dist/components/password-input/types.d.ts +1357 -0
  136. package/dist/components/picker/index.d.ts +5 -0
  137. package/dist/components/picker/index.vue.d.ts +1868 -0
  138. package/dist/components/picker/types.d.ts +1466 -0
  139. package/dist/components/radio/index.d.ts +5 -0
  140. package/dist/components/radio/index.vue.d.ts +1563 -0
  141. package/dist/components/radio/types.d.ts +1327 -0
  142. package/dist/components/radio-group/index.d.ts +5 -0
  143. package/dist/components/radio-group/index.vue.d.ts +1617 -0
  144. package/dist/components/radio-group/types.d.ts +1383 -0
  145. package/dist/components/rate/index.d.ts +5 -0
  146. package/dist/components/rate/index.vue.d.ts +1557 -0
  147. package/dist/components/rate/types.d.ts +1281 -0
  148. package/dist/components/share.d.ts +679 -0
  149. package/dist/components/signature/index.d.ts +5 -0
  150. package/dist/components/signature/index.vue.d.ts +3017 -0
  151. package/dist/components/signature/instance.vue.d.ts +1614 -0
  152. package/dist/components/signature/types.d.ts +1369 -0
  153. package/dist/components/slider/index.d.ts +5 -0
  154. package/dist/components/slider/index.vue.d.ts +1563 -0
  155. package/dist/components/slider/types.d.ts +1302 -0
  156. package/dist/components/stepper/index.d.ts +5 -0
  157. package/dist/components/stepper/index.vue.d.ts +1620 -0
  158. package/dist/components/stepper/types.d.ts +1281 -0
  159. package/dist/components/switch/index.d.ts +5 -0
  160. package/dist/components/switch/index.vue.d.ts +1529 -0
  161. package/dist/components/switch/types.d.ts +1296 -0
  162. package/dist/components/time-picker/index.d.ts +5 -0
  163. package/dist/components/time-picker/index.vue.d.ts +1936 -0
  164. package/dist/components/time-picker/types.d.ts +1458 -0
  165. package/dist/components/tree-select/index.d.ts +5 -0
  166. package/dist/components/tree-select/index.vue.d.ts +1802 -0
  167. package/dist/components/tree-select/types.d.ts +1411 -0
  168. package/dist/components/upload/index.d.ts +5 -0
  169. package/dist/components/upload/index.vue.d.ts +1697 -0
  170. package/dist/components/upload/types.d.ts +1376 -0
  171. package/dist/components/use.d.ts +53 -0
  172. package/dist/components/utils.d.ts +15 -0
  173. package/dist/components/wrapper/index.d.ts +5 -0
  174. package/dist/components/wrapper/index.vue.d.ts +1085 -0
  175. package/dist/components/wrapper/types.d.ts +541 -0
  176. package/dist/docs/.vitepress/config.d.ts +3 -0
  177. package/dist/docs/.vitepress/theme/index.d.ts +2 -0
  178. package/dist/index.cjs.js +5459 -0
  179. package/dist/index.cjs.js.map +1 -0
  180. package/dist/index.cjs.min.js +3568 -0
  181. package/dist/index.cjs.min.js.map +1 -0
  182. package/dist/index.esm.js +5264 -0
  183. package/dist/index.esm.js.map +1 -0
  184. package/dist/index.esm.min.js +3559 -0
  185. package/dist/index.esm.min.js.map +1 -0
  186. package/dist/index.umd.js +5465 -0
  187. package/dist/index.umd.js.map +1 -0
  188. package/dist/index.umd.min.js +3573 -0
  189. package/dist/index.umd.min.js.map +1 -0
  190. package/dist/src/assist.d.ts +32 -0
  191. package/dist/src/index.d.ts +5 -0
  192. package/dist/src/interface.d.ts +129 -0
  193. package/dist/src/utils.d.ts +9 -0
  194. package/dist/src/version.d.ts +2 -0
  195. package/docs/.vitepress/config.ts +99 -0
  196. package/docs/.vitepress/theme/index.ts +5 -0
  197. package/docs/README.md +20 -0
  198. package/docs/index.md +25 -0
  199. package/env.d.ts +8 -0
  200. package/package.json +71 -0
  201. package/scripts/generate-version.mjs +26 -0
  202. package/scripts/postinstall.cjs +13 -0
  203. package/scripts/utils.cjs +67 -0
  204. package/src/assist.ts +40 -0
  205. package/src/index.ts +5 -0
  206. package/src/interface.ts +293 -0
  207. package/src/utils.ts +22 -0
  208. package/src/version.ts +2 -0
  209. package/tsconfig.app.json +41 -0
  210. package/tsconfig.json +7 -0
  211. package/tsconfig.node.json +24 -0
  212. package/tsdown.config.ts +12 -0
  213. package/vite.config.ts +93 -0
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <VanField
3
+ v-if="!hide"
4
+ :name="field" :label="label"
5
+ :disabled="globalDisabled || disabled"
6
+ :readonly="globalReadonly || readonly"
7
+ v-bind="$attrs"
8
+ >
9
+ <template #input>
10
+ <VanCheckboxGroup
11
+ :name="field" :model-value="checked"
12
+ :disabled="globalDisabled || disabled || globalReadonly || readonly"
13
+ v-bind="checkboxGroupProps" v-on="checkboxGroupOn"
14
+ @update:model-value="change"
15
+ >
16
+ <template v-for="item of finalOption" :key="item[valueKey]">
17
+ <VanCheckbox :name="item[valueKey]" v-bind="checkboxProps" v-on="checkboxOn">
18
+ {{ item[labelKey] }}
19
+ <template v-for="(checkBoxItem, slotName) of checkboxSlots" :key="slotName" #[hyphenate(slotName)]="row">
20
+ <component :is="getNode(checkBoxItem)" v-bind="slotProps" :item="item" v-bind.prop="row" />
21
+ </template>
22
+ </VanCheckbox>
23
+ </template>
24
+ </VanCheckboxGroup>
25
+ </template>
26
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
27
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
28
+ </template>
29
+ </VanField>
30
+ </template>
31
+
32
+ <script lang="ts">
33
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
34
+ import { Checkbox as VanCheckbox, CheckboxGroup as VanCheckboxGroup, Field as VanField } from 'vant';
35
+ import type { SlotsType } from 'vue';
36
+ import { computed, defineComponent } from 'vue';
37
+ import { pick } from '../../src/utils';
38
+ import { useCommonSetup, useTempChecked } from '../use';
39
+ import type { CheckboxGroupSlots } from './types';
40
+ import { checkboxGroupEmitsPrivate as emits, checkboxGroupPropsPrivate as props } from './types';
41
+
42
+ /**
43
+ * @file 多选框组
44
+ */
45
+ export default defineComponent({
46
+ name: 'HCheckboxGroup',
47
+ components: { VanCheckbox, VanCheckboxGroup, VanField },
48
+ inheritAttrs: false,
49
+ props,
50
+ emits,
51
+ slots: Object as SlotsType<CheckboxGroupSlots>,
52
+ setup(props, ctx) {
53
+ const plain = usePlain(props);
54
+ const { slotProps } = useCommonSetup(props, ctx, plain);
55
+
56
+ return {
57
+ hyphenate,
58
+ getNode,
59
+ ...plain,
60
+ slotProps,
61
+ };
62
+ },
63
+ });
64
+ </script>
65
+
66
+ <style lang="scss" scoped>
67
+ </style>
@@ -0,0 +1,63 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import type { Checkbox as VanCheckbox } from 'vant';
4
+ import { CheckboxGroup as VanCheckboxGroup, Field as VanField } from 'vant';
5
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
6
+ import { camelize } from 'vue';
7
+ import type { ComponentEmit, ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
8
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
9
+ import { commonProps } from '../share';
10
+
11
+ /** 组件传参 - 私有 */
12
+ export function checkboxGroupPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
13
+ return {
14
+ ...commonProps as CommonProps<Query, OptionQuery>,
15
+ ...plainProps as PlainProps<Query, OptionQuery>,
16
+ /** 输入框左侧文本 */
17
+ label: { type: String },
18
+ /** VanCheckboxGroup 组件的属性 */
19
+ checkboxGroupProps: { type: Object as PropType<Partial<ComponentProps<typeof VanCheckboxGroup>>> },
20
+ /** VanCheckboxGroup 组件的事件 - 兼容 vue2 版本 */
21
+ checkboxGroupOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanCheckboxGroup.emits>>>>>, default: () => ({}) },
22
+ /** 显示的标签 */
23
+ labelKey: { type: String, default: 'label' },
24
+ /** 提交的值 */
25
+ valueKey: { type: String, default: 'value' },
26
+ /** VanCheckbox 组件的属性 */
27
+ checkboxProps: { type: Object as PropType<Partial<ComponentProps<typeof VanCheckbox>>> },
28
+ /** VanCheckbox 组件的事件 - 兼容 vue2 版本 */
29
+ checkboxOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanCheckbox.emits>>>>>, default: () => ({}) },
30
+ /** VanCheckbox 组件的插槽 */
31
+ checkboxSlots: { type: Object as PropType<{
32
+ /** 自定义文本 */
33
+ default?: ComponentType<{ checked: boolean; disabled: boolean; item: any } & CommonSlotsProps<any, any>>;
34
+ /** 自定义图标 */
35
+ icon?: ComponentType<{ checked: boolean; disabled: boolean; item: any } & CommonSlotsProps<any, any>>;
36
+ }> },
37
+ } as const;
38
+ }
39
+ /** 组件传参 - 私有 */
40
+ export const checkboxGroupPropsPrivate = checkboxGroupPropsGeneric();
41
+ /** 组件传参 - 外部调用 */
42
+ export const checkboxGroupProps = {
43
+ ...VanField.props as unknown as {},
44
+ ...checkboxGroupPropsPrivate,
45
+ };
46
+ export type CheckboxGroupProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof checkboxGroupPropsGeneric<Query, OptionQuery>>>;
47
+
48
+ /** 组件事件 - 私有 */
49
+ export function checkboxGroupEmitsGeneric<T>() {
50
+ return {};
51
+ }
52
+ /** 组件事件 - 私有 */
53
+ export const checkboxGroupEmitsPrivate = checkboxGroupEmitsGeneric();
54
+ /** 组件事件 - 外部调用 */
55
+ export const checkboxGroupEmits = {
56
+ ...VanField.emits,
57
+ ...checkboxGroupEmitsPrivate,
58
+ };
59
+
60
+ export type CheckboxGroupEmits<T> = ReturnType<typeof checkboxGroupEmitsGeneric<T>>;
61
+
62
+ export interface CheckboxGroupSlots extends CommonSlots<any> {
63
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 组件导出中转文件
3
+ * 从组件定义文件中导出所有组件
4
+ */
5
+ export * from '../area/index';
6
+ export * from '../cascader/index';
7
+ export * from '../checkbox-group/index';
8
+ export * from '../checkbox/index';
9
+ export * from '../custom-render/index';
10
+ export * from '../date-picker/index';
11
+ export * from '../date-time-picker-group/index';
12
+ export * from '../input/index';
13
+ export * from '../number-keyboard/index';
14
+ export * from '../password-input/index';
15
+ export * from '../picker/index';
16
+ export * from '../radio-group/index';
17
+ export * from '../radio/index';
18
+ export * from '../rate/index';
19
+ export * from '../signature/index';
20
+ export * from '../slider/index';
21
+ export * from '../stepper/index';
22
+ export * from '../switch/index';
23
+ export * from '../time-picker/index';
24
+ export * from '../tree-select/index';
25
+ export * from '../upload/index';
26
+
27
+ export const HDatetimePicker = { render: () => null };
28
+ export interface DatetimePickerProps<A, B> {}
29
+
@@ -0,0 +1,25 @@
1
+ // 组件模板文件, 为低版本做兼容
2
+ // 内部注册的且未循环引用的组件
3
+ // postinstall 脚本的参考文件
4
+ export * from '../area/index';
5
+ export * from '../cascader/index';
6
+ export * from '../checkbox-group/index';
7
+ export * from '../checkbox/index';
8
+ export * from '../custom-render/index';
9
+ export * from '../date-picker/index';
10
+ export * from '../date-time-picker-group/index';
11
+ export * from '../datetime-picker/index';
12
+ export * from '../input/index';
13
+ export * from '../number-keyboard/index';
14
+ export * from '../password-input/index';
15
+ export * from '../picker/index';
16
+ export * from '../radio-group/index';
17
+ export * from '../radio/index';
18
+ export * from '../rate/index';
19
+ export * from '../signature/index';
20
+ export * from '../slider/index';
21
+ export * from '../stepper/index';
22
+ export * from '../switch/index';
23
+ export * from '../time-picker/index';
24
+ export * from '../tree-select/index';
25
+ export * from '../upload/index';
@@ -0,0 +1,4 @@
1
+ export * from '../dynamic-group/index';
2
+ export * from '../group/index';
3
+ export * from '../input-slot/index';
4
+ export * from './components';
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
2
+ import HCustomRender from './index.vue';
3
+
4
+ export { HCustomRender };
5
+ export type HCustomRenderInstance = ComponentExposed<typeof HCustomRender>;
6
+ export * from './types';
@@ -0,0 +1,66 @@
1
+ <template>
2
+ <template v-if="renderField">
3
+ <VanField v-if="!hide" :model-value="fieldModelValue" v-bind="$attrs">
4
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
5
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
6
+ </template>
7
+ <template #input>
8
+ <component :is="customRender" v-bind="slotProps" />
9
+ </template>
10
+ </VanField>
11
+ </template>
12
+ <template v-else>
13
+ <component :is="customRender" v-bind="slotProps" />
14
+ </template>
15
+ </template>
16
+
17
+ <script lang="ts">
18
+ import { getNode, hyphenate, noop, usePlain } from '@xiaohaih/json-form-core';
19
+ import { Field as VanField } from 'vant';
20
+ import type { SlotsType } from 'vue';
21
+ import { computed, defineComponent, markRaw, ref, watch } from 'vue';
22
+ import { useCommonSetup, useTempChecked } from '../use';
23
+ import type { CustomRenderSlots } from './types';
24
+ import { customRenderEmitsPrivate as emits, customRenderPropsPrivate as props } from './types';
25
+
26
+ /**
27
+ * @file 自定义渲染
28
+ */
29
+ export default defineComponent({
30
+ name: 'HCustomRender',
31
+ components: { VanField },
32
+ inheritAttrs: false,
33
+ props,
34
+ emits,
35
+ slots: Object as SlotsType<CustomRenderSlots>,
36
+ setup(props, ctx) {
37
+ const plain = usePlain(props);
38
+ const { slotProps } = useCommonSetup(props, ctx, plain);
39
+ const fieldModelValue = computed(() => typeof plain.checked.value === 'object' ? '' : plain.checked.value);
40
+ const customRender = ref<any>();
41
+ // 由计算属性改为 watch
42
+ // 防止在 watch 中引用了响应式变量导致重渲染
43
+ watch(() => props.render, (render) => {
44
+ customRender.value = typeof render === 'function'
45
+ ? getNode(render(slotProps.value))
46
+ : render;
47
+ }, { immediate: true });
48
+ // const customRender = computed(() => {
49
+ // return typeof props.render === 'function'
50
+ // ? getNode(props.render(slotProps.value))
51
+ // : props.render;
52
+ // });
53
+
54
+ return {
55
+ hyphenate,
56
+ getNode,
57
+ ...plain,
58
+ slotProps,
59
+ fieldModelValue,
60
+ customRender,
61
+ };
62
+ },
63
+ });
64
+ </script>
65
+
66
+ <style lang="css" scoped></style>
@@ -0,0 +1,43 @@
1
+ import type { CamelCase, Obj2Props, PlainProps, usePlain } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import type { Component, ExtractPublicPropTypes, PropType, Ref } from 'vue';
4
+ import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
5
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
6
+ import { commonProps } from '../share';
7
+
8
+ /** 组件传参 - 私有 */
9
+ export function customRenderPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
10
+ return {
11
+ ...commonProps as CommonProps<Query, OptionQuery>,
12
+ ...plainProps as PlainProps<Query, OptionQuery>,
13
+ /** 是否渲染 form-item @default true */
14
+ renderField: { type: Boolean as PropType<boolean>, default: true },
15
+ /** 渲染节点 */
16
+ render: {
17
+ type: [Function, Object] as PropType<((option: CustomRenderSlotOption<Query, OptionQuery>) => () => any) | Record<string, any>>,
18
+ required: true,
19
+ },
20
+ } as const;
21
+ }
22
+ export interface CustomRenderSlotOption<Query extends Record<string, any>, OptionQuery extends Record<string, any>> extends CommonSlotsProps<Query, OptionQuery> {
23
+ }
24
+ /** 组件传参 - 私有 */
25
+ export const customRenderPropsPrivate = customRenderPropsGeneric();
26
+ /** 组件传参 - 外部调用 */
27
+
28
+ export const customRenderProps = customRenderPropsPrivate;
29
+ export type CustomRenderProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof customRenderPropsGeneric<Query, OptionQuery>>>;
30
+
31
+ /** 组件事件 - 私有 */
32
+ export function customRenderEmitsGeneric<T>() {
33
+ return {
34
+ };
35
+ }
36
+ /** 组件事件 - 私有 */
37
+ export const customRenderEmitsPrivate = customRenderEmitsGeneric();
38
+ /** 组件事件 - 外部调用 */
39
+ export const customRenderEmits = customRenderEmitsPrivate;
40
+ export type CustomRenderEmits<T> = ReturnType<typeof customRenderEmitsGeneric<T>>;
41
+
42
+ export interface CustomRenderSlots extends CommonSlots<Record<string, any>> {
43
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HDatePicker from './index.vue';
3
+
4
+ export { HDatePicker };
5
+ export type HDatePickerInstance = ComponentExposed<typeof HDatePicker>;
6
+ export * from './types';
@@ -0,0 +1,130 @@
1
+ <template>
2
+ <VanField
3
+ v-if="!hide"
4
+ :name="field"
5
+ :disabled="globalDisabled || disabled"
6
+ :readonly="true"
7
+ :is-link="isLink"
8
+ :model-value="showText"
9
+ v-bind="$attrs"
10
+ @click="clickHandle"
11
+ >
12
+ <template #extra>
13
+ <VanPopup v-model:show="popupInfo.visible" teleport="body" round position="bottom" v-bind="popupProps" v-on="popupOn" @close="popupInfo.close">
14
+ <VanDatePicker
15
+ :model-value="checkedArr"
16
+ v-bind="datePickerProps" v-on="datePickerOn"
17
+ @change="changeHandle" @confirm="confirmHandle" @cancel="cancelHandle"
18
+ >
19
+ <template v-for="(item, slotName) of datePickerSlots" :key="slotName" #[hyphenate(slotName)]="row">
20
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
21
+ </template>
22
+ </VanDatePicker>
23
+ </VanPopup>
24
+ </template>
25
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
26
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
27
+ </template>
28
+ </VanField>
29
+ </template>
30
+
31
+ <script lang="ts">
32
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
33
+ import { DatePicker as VanDatePicker, Field as VanField, Popup as VanPopup } from 'vant';
34
+ import type { SlotsType } from 'vue';
35
+ import { computed, defineComponent, nextTick, ref, watch } from 'vue';
36
+ import type { PickerOption } from '../picker/types';
37
+ import { useCommonSetup } from '../use';
38
+ import type { DatePickerSlots } from './types';
39
+ import { datePickerEmitsPrivate as emits, datePickerPropsPrivate as props } from './types';
40
+
41
+ /**
42
+ * @file 日期选择框
43
+ */
44
+ export default defineComponent({
45
+ name: 'HDatePicker',
46
+ components: { VanDatePicker, VanField, VanPopup },
47
+ inheritAttrs: false,
48
+ props,
49
+ emits,
50
+ slots: Object as SlotsType<DatePickerSlots>,
51
+ setup(props, ctx) {
52
+ const plain = usePlain(props);
53
+ const { slotProps } = useCommonSetup(props, ctx, plain);
54
+ /** 展示在页面上的值 */
55
+ const showText = ref('');
56
+ /** 给日期组件的值 */
57
+ const checkedArr = ref<string[]>([]);
58
+ let tempValue: any;
59
+ // 监听外部值的改变, 如果改变且与临时值不一致时
60
+ // 则更新当前值, 并重置临时值
61
+ watch(
62
+ plain.checked,
63
+ (val) => {
64
+ if (val === tempValue) return tempValue = null;
65
+ tempValue = null;
66
+ checkedArr.value = val ? props.valueUnformat(val, props.separator) : [];
67
+ showText.value = checkedArr.value.length ? props.format(checkedArr.value, props.separator) : '';
68
+ },
69
+ { immediate: true },
70
+ );
71
+
72
+ /** 点击事件 */
73
+ function clickHandle(ev: MouseEvent) {
74
+ if (plain.globalDisabled.value || props.disabled || plain.globalReadonly.value || props.readonly) return;
75
+ props.onRowClick ? props.onRowClick(popupInfo.value, ev) : popupInfo.value.open();
76
+ }
77
+ /**
78
+ * 日期更改事件
79
+ * @param {string} type 事件类型
80
+ * @param {string} value 日期值
81
+ */
82
+ function dateEventHandle(type: string, value: PickerOption) {
83
+ if (props.valueTrigger === type || props.datePickerProps?.showToolbar === false) {
84
+ checkedArr.value = value.selectedValues;
85
+ plain.change(props.valueFormat(value.selectedValues, props.separator));
86
+ showText.value = props.format(value.selectedValues, props.separator);
87
+ tempValue = plain.checked.value;
88
+ nextTick(() => tempValue = null);
89
+ }
90
+ switch (type) {
91
+ case 'confirm':
92
+ case 'cancel':
93
+ {
94
+ popupInfo.value.close();
95
+ break;
96
+ }
97
+ default: break;
98
+ }
99
+ }
100
+
101
+ /** 弹窗显示状态 */
102
+ const popupInfo = ref({
103
+ visible: false,
104
+ open() {
105
+ popupInfo.value.visible = true;
106
+ },
107
+ close() {
108
+ popupInfo.value.visible = false;
109
+ },
110
+ });
111
+
112
+ return {
113
+ hyphenate,
114
+ getNode,
115
+ ...plain,
116
+ slotProps,
117
+ showText,
118
+ checkedArr,
119
+ clickHandle,
120
+ changeHandle: dateEventHandle.bind(null, 'change'),
121
+ confirmHandle: dateEventHandle.bind(null, 'confirm'),
122
+ cancelHandle: dateEventHandle.bind(null, 'cancel'),
123
+ popupInfo,
124
+ };
125
+ },
126
+ });
127
+ </script>
128
+
129
+ <style lang="scss" scoped>
130
+ </style>
@@ -0,0 +1,91 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import type { Popup as VanPopup } from 'vant';
4
+ import { DatePicker as VanDatePicker, Field as VanField } from 'vant';
5
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
6
+ import type { ComponentEmit, ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
7
+ import type { PickerOption } from '../picker/types';
8
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
9
+ import { commonProps } from '../share';
10
+
11
+ /** 组件传参 - 私有 */
12
+ export function datePickerPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
13
+ return {
14
+ ...commonProps as CommonProps<Query, OptionQuery>,
15
+ ...plainProps as PlainProps<Query, OptionQuery>,
16
+ /** VanDatePicker 组件的属性 */
17
+ datePickerProps: { type: Object as PropType<Partial<ComponentProps<typeof VanDatePicker>>> },
18
+ /** VanDatePicker 组件的事件 - 兼容 vue2 版本 */
19
+ datePickerOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanDatePicker.emits>>>>>, default: () => ({}) },
20
+ /** VanDatePicker 组件的插槽 */
21
+ datePickerSlots: { type: Object as PropType<{
22
+ /** 自定义整个顶部栏的内容 */
23
+ toolbar?: ComponentType<CommonSlotsProps<any, any>>;
24
+ /** 自定义标题内容 */
25
+ title?: ComponentType<CommonSlotsProps<any, any>>;
26
+ /** 自定义确认按钮内容 */
27
+ confirm?: ComponentType<CommonSlotsProps<any, any>>;
28
+ /** 自定义取消按钮内容 */
29
+ cancel?: ComponentType<CommonSlotsProps<any, any>>;
30
+ /** 自定义选项内容 */
31
+ option?: ComponentType<{ option: PickerOption; index: number } & CommonSlotsProps<any, any>>;
32
+ /** 自定义选项上方内容 */
33
+ columnsTop?: ComponentType<CommonSlotsProps<any, any>>;
34
+ /** 自定义选项下方内容 */
35
+ columnsBottom?: ComponentType<CommonSlotsProps<any, any>>;
36
+ }> },
37
+ /** 是否展示右侧箭头并开启点击反馈 - Field 字段, 调整默认值 */
38
+ isLink: { type: Boolean, default: true },
39
+ /** 点击事件, 当传递了此事件时, 会忽略内部打开弹窗操作 */
40
+ onRowClick: { type: Function as PropType<(option: { open: () => void; close: () => void }, ev: MouseEvent) => void> },
41
+ /** 日期分隔符 @default - */
42
+ separator: { type: String, default: '-' },
43
+ /** 对值进行格式化 - 显示在页面上的值 */
44
+ format: { type: Function as PropType<(option: string[], separator: string) => any>, default: valueFormatDefault },
45
+ /** 对值进行格式化 - 提交值 */
46
+ valueFormat: { type: Function as PropType<(option: string[], separator: string) => any>, default: valueFormatDefault },
47
+ /** 取消值的格式化 - 给 VanDatePicker 的值 */
48
+ valueUnformat: { type: Function as PropType<(option: any, separator: string) => string[]>, default: valueUnformatDefault },
49
+ /** 值触发方式 @default confirm */
50
+ valueTrigger: { type: String as PropType<'change' | 'confirm' | 'cancel'>, default: 'confirm' },
51
+ /** 弹窗组件的属性 */
52
+ popupProps: { type: Object as PropType<Partial<ComponentExposed<typeof VanPopup>>> },
53
+ /** 弹窗组件的事件 - 兼容 vue2 版本 */
54
+ popupOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanPopup.emits>>>>>, default: () => ({}) },
55
+ } as const;
56
+ }
57
+ /** 组件传参 - 私有 */
58
+ export const datePickerPropsPrivate = datePickerPropsGeneric();
59
+ /** 组件传参 - 外部调用 */
60
+ export const datePickerProps = {
61
+ ...VanField.props as unknown as {},
62
+ ...datePickerPropsPrivate,
63
+ };
64
+ export type DatePickerProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof datePickerPropsGeneric<Query, OptionQuery>>>;
65
+
66
+ /** 组件事件 - 私有 */
67
+ export function datePickerEmitsGeneric<T>() {
68
+ return {};
69
+ }
70
+ /** 组件事件 - 私有 */
71
+ export const datePickerEmitsPrivate = datePickerEmitsGeneric();
72
+ /** 组件事件 - 外部调用 */
73
+ export const datePickerEmits = {
74
+ ...VanField.emits,
75
+ ...datePickerEmitsPrivate,
76
+ };
77
+
78
+ export type DatePickerEmits<T> = ReturnType<typeof datePickerEmitsGeneric<T>>;
79
+
80
+ export interface DatePickerSlots extends CommonSlots<any> {
81
+ }
82
+
83
+ /** 默认的合并函数 */
84
+ function valueFormatDefault(option: string[], separator: string) {
85
+ return option.join(separator);
86
+ }
87
+ /** 默认的取消格式化函数 */
88
+ function valueUnformatDefault(val: string, separator: string) {
89
+ if (!val) return [];
90
+ return Array.isArray(val) ? val : val.split(separator);
91
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HDateTimePickerGroup from './index.vue';
3
+
4
+ export { HDateTimePickerGroup };
5
+ export type HDateTimePickerGroupInstance = ComponentExposed<typeof HDateTimePickerGroup>;
6
+ export * from './types';