@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,161 @@
1
+ <template>
2
+ <VanSignature
3
+ v-if="!(globalDisabled || disabled || globalReadonly || readonly)"
4
+ ref="signatureRef"
5
+ v-bind="signatureProps" v-on="signatureOn"
6
+ @end="end" @submit="change" @clear="clear"
7
+ >
8
+ <template v-for="(item, slotName) of signatureSlots" :key="slotName" #[hyphenate(slotName)]="row">
9
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
10
+ </template>
11
+ </VanSignature>
12
+ <img v-else-if="imgSrc" :src="imgSrc" style="padding: var(--van-signature-padding);">
13
+ <i v-else />
14
+ </template>
15
+
16
+ <script lang="ts">
17
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
18
+ import type { SignatureInstance } from 'vant';
19
+ import { Field as VanField, Signature as VanSignature } from 'vant';
20
+ import type { SlotsType } from 'vue';
21
+ import { computed, defineComponent, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue';
22
+ import { useCommonSetup } from '../use';
23
+ import type { SignatureSlots, SubmitOption } from './types';
24
+ import { signatureEmitsPrivate as emits, signaturePropsPrivate as props } from './types';
25
+
26
+ const ratio = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
27
+ function getSize(canvas: HTMLCanvasElement) {
28
+ return { width: canvas.offsetWidth * ratio, height: canvas.offsetHeight * ratio };
29
+ }
30
+ /**
31
+ * 绘制图片到 canvas 上
32
+ * @param {object} opt - 绘制选项
33
+ * @param {HTMLCanvasElement} opt.canvas - 待渲染的画布
34
+ * @param {string} opt.src - 图片来源
35
+ * @param {CanvasRenderingContext2D} [opt.ctx] - 画布上下文,若未提供则使用 canvas.getContext('2d') 获取
36
+ * @param {() => boolean} [opt.allowPaint] - 是否允许绘制, 默认为 true
37
+ */
38
+ function drawImage(opt: {
39
+ /** 待渲染的画布 */
40
+ canvas: HTMLCanvasElement | undefined;
41
+ src: string | undefined;
42
+ ctx?: CanvasRenderingContext2D | null;
43
+ allowPaint?: () => boolean;
44
+ }) {
45
+ const canvas = opt.canvas;
46
+ if (!(canvas && opt.src)) return;
47
+ const ctx = opt.ctx || canvas.getContext('2d');
48
+ if (!ctx) return;
49
+ const img = new Image();
50
+ img.onload = () => {
51
+ if (opt.allowPaint?.() === false) return;
52
+ const { width, height } = getSize(canvas);
53
+ ctx.clearRect(0, 0, width, height);
54
+ ctx.drawImage(img, 0, 0, width / ratio, height / ratio);
55
+ };
56
+ img.src = opt.src;
57
+ }
58
+ /** 释放 blob */
59
+ function revokeBlob(value: any) {
60
+ typeof value === 'string' && value.slice(0, 5) === 'blob:' && URL.revokeObjectURL(value);
61
+ }
62
+
63
+ /**
64
+ * @file 纯签名组件
65
+ */
66
+ export default defineComponent({
67
+ name: 'HSignaturePure',
68
+ components: { VanField, VanSignature },
69
+ inheritAttrs: false,
70
+ props,
71
+ emits,
72
+ slots: Object as SlotsType<SignatureSlots>,
73
+ setup(props, ctx) {
74
+ const signatureRef = useTemplateRef<SignatureInstance>('signatureRef');
75
+ const plain = usePlain(props);
76
+ plain.on('reset', () => reset);
77
+ /** 将当前值转为图片地址 */
78
+ const imgSrc = computed(() => props.format(plain.checked.value));
79
+ watch(imgSrc, (value, oldValue) => oldValue && revokeBlob(oldValue));
80
+ onBeforeUnmount(() => imgSrc.value && revokeBlob(imgSrc.value));
81
+ /** 是否由用户触发 */
82
+ const isUserChange = ref(false);
83
+ /** 覆盖值更改事件 */
84
+ function change(value: SubmitOption) {
85
+ isUserChange.value = true;
86
+ plain.change(props.valueFormat(value));
87
+ nextTick(() => isUserChange.value = false);
88
+ }
89
+ onMounted(() => updateCanvasContent(imgSrc.value));
90
+ watch(imgSrc, updateCanvasContent);
91
+ /** 更新画布内容 */
92
+ function updateCanvasContent(val: string | undefined) {
93
+ if (isUserChange.value) return;
94
+ // 当图片地址变化且非用户触发时, 说明外部值发生了变化, 此时需要重新绘制图片
95
+ drawImage({
96
+ ...getCanvas(),
97
+ src: val,
98
+ allowPaint: () => val === imgSrc.value,
99
+ });
100
+ }
101
+ const { slotProps } = useCommonSetup(props, ctx, plain);
102
+ const isResetting = ref(false);
103
+ /** 清空事件 */
104
+ function clear() {
105
+ if (isResetting.value) return;
106
+ plain.change(undefined);
107
+ }
108
+ /** 重置事件 */
109
+ function reset() {
110
+ if (!signatureRef.value) return;
111
+ let _src = imgSrc.value;
112
+ if (signatureRef.value.clear) {
113
+ isResetting.value = true;
114
+ nextTick(() => isResetting.value = false);
115
+ signatureRef.value.clear();
116
+ }
117
+ // 兼容低版本的 VanSignature 组件,低版本没有 clear 方法
118
+ else {
119
+ const { canvas, ctx } = getCanvas();
120
+ if (!(canvas && ctx)) return;
121
+ const { width, height } = getSize(canvas);
122
+ ctx.clearRect(0, 0, width, height);
123
+ ctx.closePath();
124
+ const bgColor = props.signatureProps?.backgroundColor;
125
+ if (bgColor) {
126
+ ctx.fillStyle = bgColor;
127
+ ctx.fillRect(0, 0, width, height);
128
+ }
129
+ }
130
+ // 重置后, 如果图片值未改变则无法触发 watch 回调, 需要主动重新绘制
131
+ nextTick(() => _src === imgSrc.value && updateCanvasContent(_src));
132
+ }
133
+ /** 获取画布 */
134
+ function getCanvas() {
135
+ const canvas = signatureRef.value?.$el?.getElementsByTagName('canvas')[0] as HTMLCanvasElement | undefined;
136
+ const ctx = canvas?.getContext('2d');
137
+ return { canvas, ctx };
138
+ }
139
+ /** 签名结束事件 */
140
+ function end() {
141
+ props.submitAtEnd && signatureRef.value?.submit?.();
142
+ }
143
+ ctx.emit('load', plain);
144
+
145
+ return {
146
+ hyphenate,
147
+ getNode,
148
+ ...plain,
149
+ change,
150
+ slotProps,
151
+ signatureRef,
152
+ imgSrc,
153
+ clear,
154
+ end,
155
+ };
156
+ },
157
+ });
158
+ </script>
159
+
160
+ <style lang="scss" scoped>
161
+ </style>
@@ -0,0 +1,79 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import { Field as VanField, Signature as VanSignature } from 'vant';
4
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
7
+ import { commonProps } from '../share';
8
+
9
+ /** 组件传参 - 私有 */
10
+ export function signaturePropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
11
+ return {
12
+ ...commonProps as CommonProps<Query, OptionQuery>,
13
+ ...plainProps as PlainProps<Query, OptionQuery>,
14
+ /** 是否渲染 VanField 组件 */
15
+ renderField: { type: Boolean as PropType<boolean>, default: true },
16
+ /** VanSignature 组件的属性 */
17
+ signatureProps: { type: Object as PropType<Partial<ComponentProps<typeof VanSignature>>> },
18
+ /** VanSignature 组件的事件 - 兼容 vue2 版本 */
19
+ signatureOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanSignature.emits>>>>>, default: () => ({}) },
20
+ /** VanSignature 组件的插槽 */
21
+ signatureSlots: { type: Object as PropType<{
22
+ /** 自定义提示文案 */
23
+ tips?: ComponentType<CommonSlotsProps<any, any>>;
24
+ }> },
25
+ /**
26
+ * 是否在结束签名时触发一次提交事件
27
+ * @tips 该属性需要 vant 版本大等于 4.8.6 才支持
28
+ */
29
+ submitAtEnd: { type: Boolean, default: true },
30
+ /** 对提交的数据进行处理 - 与 format 配合使用 */
31
+ valueFormat: { type: Function as PropType<(option: SubmitOption) => any | Promise<any>>, default: (v: SubmitOption) => v },
32
+ /** 当需要作为图片回显时的处理函数 - 与 format 配合使用 */
33
+ format: { type: Function as PropType<(option: unknown) => string>, default: signatureFormat },
34
+ } as const;
35
+ }
36
+ /** 组件传参 - 私有 */
37
+ export const signaturePropsPrivate = signaturePropsGeneric();
38
+ /** 组件传参 - 外部调用 */
39
+ export const signatureProps = {
40
+ ...VanField.props as unknown as {},
41
+ ...signaturePropsPrivate,
42
+ };
43
+ export type SignatureProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof signaturePropsGeneric<Query, OptionQuery>>>;
44
+
45
+ /** 组件事件 - 私有 */
46
+ export function signatureEmitsGeneric<T>() {
47
+ return {
48
+ /** 组件加载后触发 - 供可选渲染 VanField 使用 */
49
+ load: (params: any) => true,
50
+ };
51
+ }
52
+ /** 组件事件 - 私有 */
53
+ export const signatureEmitsPrivate = signatureEmitsGeneric();
54
+ /** 组件事件 - 外部调用 */
55
+ export const signatureEmits = {
56
+ ...VanField.emits,
57
+ ...signatureEmitsPrivate,
58
+ };
59
+
60
+ export type SignatureEmits<T> = ReturnType<typeof signatureEmitsGeneric<T>>;
61
+
62
+ export interface SignatureSlots extends CommonSlots<any> {
63
+ }
64
+
65
+ /** 提交时的参数 */
66
+ export interface SubmitOption {
67
+ /** base64 */
68
+ image: string;
69
+ /** */
70
+ canvas: string;
71
+ }
72
+
73
+ /** 格式化回显图片时的参数 */
74
+ export function signatureFormat(option: SubmitOption | string | Blob) {
75
+ if (!option) return '';
76
+ if (typeof option === 'string') return option;
77
+ if (option instanceof Blob) return URL.createObjectURL(option);
78
+ return option.image;
79
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HSlider from './index.vue';
3
+
4
+ export { HSlider };
5
+ export type HSliderInstance = ComponentExposed<typeof HSlider>;
6
+ export * from './types';
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <VanField
3
+ v-if="!hide"
4
+ :name="field"
5
+ :model-value="(checked as number)"
6
+ :disabled="globalDisabled || disabled"
7
+ :readonly="globalReadonly || readonly"
8
+ v-bind="$attrs"
9
+ >
10
+ <template #input>
11
+ <VanSlider
12
+ :disabled="globalDisabled || disabled"
13
+ :readonly="globalReadonly || readonly"
14
+ :model-value="(checked as number)"
15
+ v-bind="sliderProps" v-on="sliderOn"
16
+ @update:model-value="change"
17
+ >
18
+ <template v-for="(item, slotName) of sliderSlots" :key="slotName" #[hyphenate(slotName)]="row">
19
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
20
+ </template>
21
+ </VanSlider>
22
+ </template>
23
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
24
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
25
+ </template>
26
+ </VanField>
27
+ </template>
28
+
29
+ <script lang="ts">
30
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
31
+ import { Field as VanField, Slider as VanSlider } from 'vant';
32
+ import type { SlotsType } from 'vue';
33
+ import { defineComponent } from 'vue';
34
+ import { useCommonSetup } from '../use';
35
+ import type { SliderSlots } from './types';
36
+ import { sliderEmitsPrivate as emits, sliderPropsPrivate as props } from './types';
37
+
38
+ /**
39
+ * @file 滑块
40
+ */
41
+ export default defineComponent({
42
+ name: 'HSlider',
43
+ components: { VanField, VanSlider },
44
+ inheritAttrs: false,
45
+ props,
46
+ emits,
47
+ slots: Object as SlotsType<SliderSlots>,
48
+ setup(props, ctx) {
49
+ const plain = usePlain(props);
50
+ const { slotProps } = useCommonSetup(props, ctx, plain);
51
+
52
+ return {
53
+ hyphenate,
54
+ getNode,
55
+ ...plain,
56
+ slotProps,
57
+ };
58
+ },
59
+ });
60
+ </script>
61
+
62
+ <style lang="scss" scoped>
63
+ </style>
@@ -0,0 +1,53 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import { Field as VanField, Slider as VanSlider } from 'vant';
4
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
7
+ import { commonProps } from '../share';
8
+
9
+ /** 组件传参 - 私有 */
10
+ export function sliderPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
11
+ return {
12
+ ...commonProps as CommonProps<Query, OptionQuery>,
13
+ ...plainProps as PlainProps<Query, OptionQuery>,
14
+ /** VanSlider 组件的属性 */
15
+ sliderProps: { type: Object as PropType<Partial<ComponentProps<typeof VanSlider>>> },
16
+ /** VanSlider 组件的事件 - 兼容 vue2 版本 */
17
+ sliderOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanSlider.emits>>>>>, default: () => ({}) },
18
+ /** VanSlider 组件的插槽 */
19
+ sliderSlots: { type: Object as PropType<{
20
+ /** 自定义滑块按钮 */
21
+ button?: ComponentType<CommonSlotsProps<any, any>>;
22
+ /** 自定义左侧滑块按钮(双滑块模式下) */
23
+ leftButton?: ComponentType<CommonSlotsProps<any, any>>;
24
+ /** 自定义右侧滑块按钮(双滑块模式下) */
25
+ rightButton?: ComponentType<CommonSlotsProps<any, any>>;
26
+ }> },
27
+ } as const;
28
+ }
29
+ /** 组件传参 - 私有 */
30
+ export const sliderPropsPrivate = sliderPropsGeneric();
31
+ /** 组件传参 - 外部调用 */
32
+ export const sliderProps = {
33
+ ...VanField.props as unknown as {},
34
+ ...sliderPropsPrivate,
35
+ };
36
+ export type SliderProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof sliderPropsGeneric<Query, OptionQuery>>>;
37
+
38
+ /** 组件事件 - 私有 */
39
+ export function sliderEmitsGeneric<T>() {
40
+ return {};
41
+ }
42
+ /** 组件事件 - 私有 */
43
+ export const sliderEmitsPrivate = sliderEmitsGeneric();
44
+ /** 组件事件 - 外部调用 */
45
+ export const sliderEmits = {
46
+ ...VanField.emits,
47
+ ...sliderEmitsPrivate,
48
+ };
49
+
50
+ export type SliderEmits<T> = ReturnType<typeof sliderEmitsGeneric<T>>;
51
+
52
+ export interface SliderSlots extends CommonSlots<any> {
53
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HStepper from './index.vue';
3
+
4
+ export { HStepper };
5
+ export type HStepperInstance = ComponentExposed<typeof HStepper>;
6
+ export * from './types';
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <VanField
3
+ v-if="!hide"
4
+ :name="field"
5
+ :model-value="checked"
6
+ :disabled="globalDisabled || disabled"
7
+ :readonly="globalReadonly || readonly"
8
+ v-bind="$attrs"
9
+ >
10
+ <template #input>
11
+ <VanStepper
12
+ :disabled="globalDisabled || disabled || globalReadonly || readonly"
13
+ :model-value="(checked as number)"
14
+ v-bind="stepperProps" v-on="stepperOn"
15
+ @update:model-value="change"
16
+ >
17
+ <template v-for="(item, slotName) of stepperSlots" :key="slotName" #[hyphenate(slotName)]="row">
18
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
19
+ </template>
20
+ </VanStepper>
21
+ </template>
22
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
23
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
24
+ </template>
25
+ </VanField>
26
+ </template>
27
+
28
+ <script lang="ts">
29
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
30
+ import { Field as VanField, Stepper as VanStepper } from 'vant';
31
+ import type { SlotsType } from 'vue';
32
+ import { defineComponent } from 'vue';
33
+ import { useCommonSetup } from '../use';
34
+ import type { StepperSlots } from './types';
35
+ import { stepperEmitsPrivate as emits, stepperPropsPrivate as props } from './types';
36
+
37
+ /**
38
+ * @file 步进器
39
+ */
40
+ export default defineComponent({
41
+ name: 'HStepper',
42
+ components: { VanField, VanStepper },
43
+ inheritAttrs: false,
44
+ props,
45
+ emits,
46
+ slots: Object as SlotsType<StepperSlots>,
47
+ setup(props, ctx) {
48
+ const plain = usePlain(props);
49
+ const { slotProps } = useCommonSetup(props, ctx, plain);
50
+
51
+ return {
52
+ hyphenate,
53
+ getNode,
54
+ ...plain,
55
+ slotProps,
56
+ };
57
+ },
58
+ });
59
+ </script>
60
+
61
+ <style lang="scss" scoped>
62
+ </style>
@@ -0,0 +1,47 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import { Field as VanField, Stepper as VanStepper } from 'vant';
4
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
7
+ import { commonProps } from '../share';
8
+
9
+ /** 组件传参 - 私有 */
10
+ export function stepperPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
11
+ return {
12
+ ...commonProps as CommonProps<Query, OptionQuery>,
13
+ ...plainProps as PlainProps<Query, OptionQuery>,
14
+ /** VanStepper 组件的属性 */
15
+ stepperProps: { type: Object as PropType<Partial<ComponentProps<typeof VanStepper>>> },
16
+ /** VanStepper 组件的事件 - 兼容 vue2 版本 */
17
+ stepperOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanStepper.emits>>>>>, default: () => ({}) },
18
+ /** VanStepper 组件的插槽 */
19
+ stepperSlots: { type: Object as PropType<{
20
+ }> },
21
+ } as const;
22
+ }
23
+ /** 组件传参 - 私有 */
24
+ export const stepperPropsPrivate = stepperPropsGeneric();
25
+ /** 组件传参 - 外部调用 */
26
+ export const stepperProps = {
27
+ ...VanField.props as unknown as {},
28
+ ...stepperPropsPrivate,
29
+ };
30
+ export type StepperProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof stepperPropsGeneric<Query, OptionQuery>>>;
31
+
32
+ /** 组件事件 - 私有 */
33
+ export function stepperEmitsGeneric<T>() {
34
+ return {};
35
+ }
36
+ /** 组件事件 - 私有 */
37
+ export const stepperEmitsPrivate = stepperEmitsGeneric();
38
+ /** 组件事件 - 外部调用 */
39
+ export const stepperEmits = {
40
+ ...VanField.emits,
41
+ ...stepperEmitsPrivate,
42
+ };
43
+
44
+ export type StepperEmits<T> = ReturnType<typeof stepperEmitsGeneric<T>>;
45
+
46
+ export interface StepperSlots extends CommonSlots<any> {
47
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HSwitch from './index.vue';
3
+
4
+ export { HSwitch };
5
+ export type HSwitchInstance = ComponentExposed<typeof HSwitch>;
6
+ export * from './types';
@@ -0,0 +1,61 @@
1
+ <template>
2
+ <VanField
3
+ v-if="!hide"
4
+ :name="field"
5
+ :disabled="globalDisabled || disabled"
6
+ :readonly="globalReadonly || readonly"
7
+ v-bind="$attrs"
8
+ >
9
+ <template #input>
10
+ <VanSwitch
11
+ :disabled="globalDisabled || disabled || globalReadonly || readonly"
12
+ :model-value="checked"
13
+ v-bind="switchProps" v-on="switchOn"
14
+ @update:model-value="change"
15
+ >
16
+ <template v-for="(item, slotName) of switchSlots" :key="slotName" #[hyphenate(slotName)]="row">
17
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
18
+ </template>
19
+ </VanSwitch>
20
+ </template>
21
+ <template v-for="(item, slotName) of slots" :key="slotName" #[hyphenate(slotName)]="row">
22
+ <component :is="getNode(item)" v-bind="slotProps" v-bind.prop="row" />
23
+ </template>
24
+ </VanField>
25
+ </template>
26
+
27
+ <script lang="ts">
28
+ import { getNode, hyphenate, usePlain } from '@xiaohaih/json-form-core';
29
+ import { Field as VanField, Switch as VanSwitch } from 'vant';
30
+ import type { SlotsType } from 'vue';
31
+ import { defineComponent } from 'vue';
32
+ import { useCommonSetup } from '../use';
33
+ import type { SwitchSlots } from './types';
34
+ import { switchEmitsPrivate as emits, switchPropsPrivate as props } from './types';
35
+
36
+ /**
37
+ * @file 开关
38
+ */
39
+ export default defineComponent({
40
+ name: 'HSwitch',
41
+ components: { VanField, VanSwitch },
42
+ inheritAttrs: false,
43
+ props,
44
+ emits,
45
+ slots: Object as SlotsType<SwitchSlots>,
46
+ setup(props, ctx) {
47
+ const plain = usePlain(props);
48
+ const { slotProps } = useCommonSetup(props, ctx, plain);
49
+
50
+ return {
51
+ hyphenate,
52
+ getNode,
53
+ ...plain,
54
+ slotProps,
55
+ };
56
+ },
57
+ });
58
+ </script>
59
+
60
+ <style lang="scss" scoped>
61
+ </style>
@@ -0,0 +1,51 @@
1
+ import type { emits2obj, PlainProps } from '@xiaohaih/json-form-core';
2
+ import { emits2props, plainProps } from '@xiaohaih/json-form-core';
3
+ import { Field as VanField, Switch as VanSwitch } from 'vant';
4
+ import type { ExtractPublicPropTypes, PropType } from 'vue';
5
+ import type { ComponentProps } from 'vue-component-type-helpers';
6
+ import type { CommonProps, CommonSlots, CommonSlotsProps, ComponentType } from '../share';
7
+ import { commonProps } from '../share';
8
+
9
+ /** 组件传参 - 私有 */
10
+ export function switchPropsGeneric<Query extends Record<string, any>, OptionQuery extends Record<string, any>>() {
11
+ return {
12
+ ...commonProps as CommonProps<Query, OptionQuery>,
13
+ ...plainProps as PlainProps<Query, OptionQuery>,
14
+ /** VanSwitch 组件的属性 */
15
+ switchProps: { type: Object as PropType<Partial<ComponentProps<typeof VanSwitch>>> },
16
+ /** VanSwitch 组件的事件 - 兼容 vue2 版本 */
17
+ switchOn: { type: Object as PropType<Partial<ReturnType<typeof emits2obj<NonNullable<typeof VanSwitch.emits>>>>>, default: () => ({}) },
18
+ /** VanSwitch 组件的插槽 */
19
+ switchSlots: { type: Object as PropType<{
20
+ /** 自定义按钮的内容 */
21
+ node?: ComponentType<CommonSlotsProps<any, any>>;
22
+ /** 自定义开关的背景内容 */
23
+ background?: ComponentType<CommonSlotsProps<any, any>>;
24
+ }> },
25
+ } as const;
26
+ }
27
+ /** 组件传参 - 私有 */
28
+ export const switchPropsPrivate = switchPropsGeneric();
29
+ /** 组件传参 - 外部调用 */
30
+ export const switchProps = {
31
+ ...VanField.props as unknown as {},
32
+ ...switchPropsPrivate,
33
+ };
34
+ export type SwitchProps<Query extends Record<string, any>, OptionQuery extends Record<string, any>> = ExtractPublicPropTypes<ReturnType<typeof switchPropsGeneric<Query, OptionQuery>>>;
35
+
36
+ /** 组件事件 - 私有 */
37
+ export function switchEmitsGeneric<T>() {
38
+ return {};
39
+ }
40
+ /** 组件事件 - 私有 */
41
+ export const switchEmitsPrivate = switchEmitsGeneric();
42
+ /** 组件事件 - 外部调用 */
43
+ export const switchEmits = {
44
+ ...VanField.emits,
45
+ ...switchEmitsPrivate,
46
+ };
47
+
48
+ export type SwitchEmits<T> = ReturnType<typeof switchEmitsGeneric<T>>;
49
+
50
+ export interface SwitchSlots extends CommonSlots<any> {
51
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentExposed } from 'vue-component-type-helpers';
2
+ import HTimePicker from './index.vue';
3
+
4
+ export { HTimePicker };
5
+ export type HTimePickerInstance = ComponentExposed<typeof HTimePicker>;
6
+ export * from './types';