@ebfe/vantkit-doc 0.0.1 → 0.0.2

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.
@@ -0,0 +1,369 @@
1
+ # DateRangePicker
2
+
3
+ ### 介绍
4
+
5
+ 主要基于 vant 的 popup、picker-group、date-picker 组件进行二次封装,方便处理时间选择的需求场景。
6
+
7
+ - 支持传入所有 [date-picker props](https://vant-ui.github.io/vant/#/zh-CN/date-picker#props)
8
+ - 支持传入所有 [picker-group props](https://vant-ui.github.io/vant/#/zh-CN/picker-group#props)
9
+ - 支持暴露所有 [picker-group slots](https://vant-ui.github.io/vant/#/zh-CN/picker-group#slots)
10
+
11
+ **主要功能描述**
12
+
13
+ - 支持自定义触发器
14
+ - 支持自定义展示值
15
+ - 支持更改 picker 打开时默认选中的值(modelValue 有值,则以 modelValue 为准)
16
+ - 支持根据选择的时间大小自动矫正 values 的顺序
17
+ - 支持确认前的自定义拦截处理逻辑
18
+
19
+ **对开发者的解脱**
20
+
21
+ - 符合 ui 设计
22
+ - 默认处理选项的 formatter
23
+ - 默认 title、tabs、nextStepText 配置
24
+ - 无脑的双向绑定 values,自动矫正时间顺序
25
+ - 打开收起逻辑的编写
26
+ - 对所选项 `真实值`、`展示值` 的隔离和处理
27
+
28
+ ## 代码演示
29
+
30
+ ### 基础用法
31
+
32
+ ```html
33
+ <template>
34
+ <DateRangePicker v-model="modelValue" :picker-group-props="{ title: '基础用法' }">
35
+ <template #trigger="{ triggerPopupShow, showValue }">
36
+ <div class="trigger-box">
37
+ <p>value: {{ modelValue }}</p>
38
+ <p>showValue: {{ showValue }}</p>
39
+ <van-button @click="triggerPopupShow"> trigger </van-button>
40
+ </div>
41
+ </template>
42
+ </DateRangePicker>
43
+ </template>
44
+
45
+ <script setup lang="ts">
46
+ import { useWrapperRef } from '@ebfe/vhooks';
47
+ import { DateRangePicker } from '@ebfe/vant-kit';
48
+ import { Button as VanButton } from 'vant';
49
+
50
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
51
+ </script>
52
+
53
+ <style scoped lang="less">
54
+ .trigger-box {
55
+ display: flex;
56
+ flex-direction: column;
57
+ justify-content: center;
58
+ align-items: center;
59
+ }
60
+ </style>
61
+ ```
62
+
63
+ ### 格式化展示值
64
+
65
+ props:`showValueFormatter?: (p: { startDate?: Date; endDate?: Date }) => string`
66
+
67
+ ```html
68
+ <template>
69
+ <DateRangePicker
70
+ v-model="modelValue"
71
+ :show-value-formatter="
72
+ ({ startDate, endDate }) => {
73
+ if (startDate && endDate) {
74
+ return (
75
+ dayjs(startDate).format('YY年MM月DD日') +
76
+ ' / ' +
77
+ dayjs(endDate).format('YY年MM月DD日')
78
+ );
79
+ }
80
+ }
81
+ "
82
+ :picker-group-props="{ title: '格式化展示值' }"
83
+ @confirm="
84
+ (p) => {
85
+ showToast(`dayjs(date).format('YY年MM月DD日'))`);
86
+ console.log(p);
87
+ }
88
+ "
89
+ >
90
+ <template #trigger="{ triggerPopupShow, showValue }">
91
+ <div class="trigger-box">
92
+ <p>value: {{ modelValue }}</p>
93
+ <p>showValue: {{ showValue }}</p>
94
+ <van-button type="primary" @click="triggerPopupShow"> trigger </van-button>
95
+ </div>
96
+ </template>
97
+ </DateRangePicker>
98
+ </template>
99
+
100
+ <script setup lang="ts">
101
+ import { useWrapperRef } from '@ebfe/vhooks';
102
+ import { DateRangePicker } from '@ebfe/vant-kit';
103
+ import { Button as VanButton, showToast } from 'vant';
104
+ import dayjs from 'dayjs';
105
+
106
+ const [modelValue] = useWrapperRef<[string, string]>(['2020-03-04', '2030-05-06']);
107
+ </script>
108
+
109
+ <style scoped lang="less">
110
+ .trigger-box {
111
+ display: flex;
112
+ flex-direction: column;
113
+ justify-content: center;
114
+ align-items: center;
115
+ }
116
+ </style>
117
+ ```
118
+
119
+ ### 自定义 picker 打开时默认选中的值
120
+
121
+ modelValue 有值,则以 modelValue 为准
122
+
123
+ ```html
124
+ <template>
125
+ <DateRangePicker
126
+ ref="DateRangePickerRef"
127
+ v-model="modelValue"
128
+ :picker-group-props="{ title: '设置 picker 默认选中项' }"
129
+ >
130
+ <template #trigger="{ triggerPopupShow, pickerRealtimeOptions, showValue }">
131
+ <div class="trigger-box">
132
+ <p>value:{{ modelValue }}</p>
133
+ <p>showValue:{{ showValue }}</p>
134
+ <p>picker 实时选中值👇</p>
135
+ <p>{{ pickerRealtimeOptions }}</p>
136
+ <p>(modelValue 有值,则以 modelValue 为准)</p>
137
+ <van-space>
138
+ <van-button type="primary" @click="triggerPopupShow"> trigger </van-button>
139
+ <van-button
140
+ type="warning"
141
+ @click="
142
+ () =>
143
+ DateRangePickerRef?.setPickerRealtimeDate({
144
+ start: '2022-02-02',
145
+ end: '2033-03-03',
146
+ })
147
+ "
148
+ >
149
+ 2022-02-02 ~ 2033-03-03
150
+ </van-button>
151
+ </van-space>
152
+ </div>
153
+ </template>
154
+ </DateRangePicker>
155
+ </template>
156
+
157
+ <script setup lang="ts">
158
+ import { useWrapperRef } from '@ebfe/vhooks';
159
+ import { DateRangePicker } from '@ebfe/vant-kit';
160
+ import { ref } from 'vue';
161
+ import { Button as VanButton, Space as VanSpace } from 'vant';
162
+
163
+ const DateRangePickerRef = ref<InstanceType<typeof DateRangePicker>>();
164
+
165
+ const [modelValue] = useWrapperRef<[string, string]>(['2020-03-04', '2030-05-06']);
166
+ </script>
167
+
168
+ <style scoped lang="less">
169
+ .trigger-box {
170
+ display: flex;
171
+ flex-direction: column;
172
+ justify-content: center;
173
+ align-items: center;
174
+ }
175
+ </style>
176
+ ```
177
+
178
+ ### 确认前的自定义拦截处理逻辑
179
+
180
+ props:`beforeConfirm?: (newValues: string[]) => boolean;`
181
+
182
+ - 返回 true,values 正常更新,弹窗关闭
183
+ - 返回 false,则什么都不做
184
+
185
+ ```html
186
+ <template>
187
+ <DateRangePicker
188
+ v-model="modelValue"
189
+ :picker-group-props="{ title: 'beforeConfirm' }"
190
+ :before-confirm="
191
+ (values) => {
192
+ const [start, end] = values;
193
+ if (start == dayjs().format('YYYY-MM-DD') && start === end) {
194
+ return true;
195
+ }
196
+ showFailToast('请选择当前日期');
197
+ return false;
198
+ }
199
+ "
200
+ >
201
+ <template #trigger="{ triggerPopupShow, showValue }">
202
+ <div class="trigger-box">
203
+ <p>value: {{ modelValue }}</p>
204
+ <p>showValue: {{ showValue }}</p>
205
+ <van-button @click="triggerPopupShow"> trigger </van-button>
206
+ </div>
207
+ </template>
208
+ </DateRangePicker>
209
+ </template>
210
+
211
+ <script setup lang="ts">
212
+ import { useWrapperRef } from '@ebfe/vhooks';
213
+ import { DateRangePicker } from '@ebfe/vant-kit';
214
+ import { showFailToast, Button as VanButton } from 'vant';
215
+ import dayjs from 'dayjs';
216
+
217
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
218
+ </script>
219
+
220
+ <style scoped lang="less">
221
+ .trigger-box {
222
+ display: flex;
223
+ flex-direction: column;
224
+ justify-content: center;
225
+ align-items: center;
226
+ }
227
+ </style>
228
+ ```
229
+
230
+ ### 支持所有 date-picker props
231
+
232
+ 例如设置 columnsType 为: 月日
233
+
234
+ ```html
235
+ <template>
236
+ <DateRangePicker
237
+ v-model="modelValue"
238
+ :picker-group-props="{ title: '设置 columnsType' }"
239
+ :picker-props="{ columnsType: ['month', 'day'] }"
240
+ >
241
+ <template #trigger="{ triggerPopupShow, showValue }">
242
+ <div class="trigger-box">
243
+ <p>value: {{ modelValue }}</p>
244
+ <p>showValue: {{ showValue }}</p>
245
+ <van-button @click="triggerPopupShow"> trigger </van-button>
246
+ </div>
247
+ </template>
248
+ </DateRangePicker>
249
+ </template>
250
+
251
+ <script setup lang="ts">
252
+ import { useWrapperRef } from '@ebfe/vhooks';
253
+ import { DateRangePicker } from '@ebfe/vant-kit';
254
+ import { Button as VanButton } from 'vant';
255
+
256
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
257
+ </script>
258
+
259
+ <style scoped lang="less">
260
+ .trigger-box {
261
+ display: flex;
262
+ flex-direction: column;
263
+ justify-content: center;
264
+ align-items: center;
265
+ }
266
+ </style>
267
+ ```
268
+
269
+ ### 支持所有 picker-group props
270
+
271
+ 例如设置 confirmButtonText
272
+
273
+ ```html
274
+ <template>
275
+ <DateRangePicker
276
+ v-model="modelValue"
277
+ :picker-group-props="{
278
+ title: '设置 confirmButtonText',
279
+ confirmButtonText: '👉✅👈',
280
+ }"
281
+ >
282
+ <template #trigger="{ triggerPopupShow }">
283
+ <div class="trigger-box">
284
+ <van-button @click="triggerPopupShow"> trigger </van-button>
285
+ </div>
286
+ </template>
287
+ </DateRangePicker>
288
+ </template>
289
+
290
+ <script setup lang="ts">
291
+ import { useWrapperRef } from '@ebfe/vhooks';
292
+ import { DateRangePicker } from '@ebfe/vant-kit';
293
+ import { Button as VanButton } from 'vant';
294
+
295
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
296
+ </script>
297
+
298
+ <style scoped lang="less">
299
+ .trigger-box {
300
+ display: flex;
301
+ flex-direction: column;
302
+ justify-content: center;
303
+ align-items: center;
304
+ }
305
+ </style>
306
+ ```
307
+
308
+ ### 支持所有 picker-group slots
309
+
310
+ 例如设置 toolbar
311
+
312
+ ```html
313
+ <template>
314
+ <DateRangePicker v-model="modelValue" :picker-group-props="{ title: '设置 toolbar' }">
315
+ <template #trigger="{ triggerPopupShow }">
316
+ <div class="trigger-box">
317
+ <van-button @click="triggerPopupShow"> trigger </van-button>
318
+ </div>
319
+ </template>
320
+
321
+ <template #toolbar> 👉自定义工具栏👈 </template>
322
+ </DateRangePicker>
323
+ </template>
324
+
325
+ <script setup lang="ts">
326
+ import { useWrapperRef } from '@ebfe/vhooks';
327
+ import { DateRangePicker } from '@ebfe/vant-kit';
328
+ import { Button as VanButton } from 'vant';
329
+
330
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
331
+ </script>
332
+
333
+ <style scoped lang="less">
334
+ .trigger-box {
335
+ display: flex;
336
+ flex-direction: column;
337
+ justify-content: center;
338
+ align-items: center;
339
+ }
340
+ </style>
341
+ ```
342
+
343
+ ## API
344
+
345
+ ### Props
346
+
347
+ TDatePickerProps
348
+
349
+ | 参数 | 说明 | 类型 | 默认值 |
350
+ | ------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------ |
351
+ | modelValue | 值 | `string[]` | - |
352
+ | pickerProps | [date-picker props](https://vant-ui.github.io/vant/#/zh-CN/date-picker#props) | `Partial<DatePickerProps>` | - |
353
+ | pickerGroupProps | [picker-group props](https://vant-ui.github.io/vant/#/zh-CN/picker-group#props) | `Partial<PickerGroupProps>` | - |
354
+ | showValueFormatter | 自定义展示值 | `showValueFormatter?: (p: { startDate?: Date; endDate?: Date }) => string` | - |
355
+ | beforeConfirm | 确认前的自定义拦截处理逻辑 | `beforeConfirm?: (newValues: TDateRangePickerProps['modelValue']) => boolean` | - |
356
+
357
+ ### Slots
358
+
359
+ 支持暴露所有 [picker-group slots](https://vant-ui.github.io/vant/#/zh-CN/picker-group#slots)
360
+
361
+ | 插槽名 | 说明 | 参数 |
362
+ | ------- | ------ | ------------------------------------------------------- |
363
+ | trigger | 触发器 | `{ showValue, triggerPopupShow, pickerRealtimeOptions}` |
364
+
365
+ ### 方法
366
+
367
+ | 方法名 | 说明 | 类型 |
368
+ | :-------------------- | :--------------------------------------------------------------------- | :-------------------------------------------- |
369
+ | setPickerRealtimeDate | 设置 picker 打开时默认选中的值(modelValue 有值,则以modelValue 为准) | `(p: { start: string; end: string }) => void` |
@@ -0,0 +1,101 @@
1
+ # FieldDatePicker
2
+
3
+ ### 介绍
4
+
5
+ 基于 DatePicker 以及 vant 的 field 组件进行二次封装,方便处理表单中的时间选择需求场景。
6
+
7
+ - 支持传入所有 DatePicker props(类型 TDatePickerProps)
8
+ - 支持传入所有的 [vant field props](https://vant-ui.github.io/vant/#/zh-CN/field#props)
9
+
10
+ **主要功能描述**
11
+
12
+ - 集成 DatePicker 所有功能
13
+
14
+ **对开发者的解脱**
15
+
16
+ - 符合 ui 设计
17
+ - 默认场景下 van-field 绑定值就是展示值,FieldDatePicker 内部将绑定值与展示值表单真正需要收集的值分隔开。
18
+
19
+ ## 代码演示
20
+
21
+ ### 基础用法
22
+
23
+ ```html
24
+ <template>
25
+ <van-form ref="FormRef" :validate-trigger="['onBlur', 'onChange', 'onSubmit']">
26
+ <p>modelValue:{{ modelValue }}</p>
27
+ <FieldDatePicker
28
+ ref="FieldDatePickerRef"
29
+ v-model="modelValue"
30
+ :field-props="{
31
+ name: 'dateField',
32
+ label: 'FieldDatePicker',
33
+ labelWidth: '12.5rem',
34
+ readonly: false,
35
+ required: true,
36
+ rules: [{ required: true, message: '请选择' }],
37
+ }"
38
+ :show-value-formatter="(date) => date?.toLocaleDateString()"
39
+ :picker-props="{ title: '选择' }"
40
+ >
41
+ <template #columns-top>Ashutefannao</template>
42
+ </FieldDatePicker>
43
+
44
+ <van-field
45
+ v-model="testFieldModelValue"
46
+ name="testField"
47
+ label="testField"
48
+ :rules="[{ required: true, message: '请选择' }]"
49
+ ></van-field>
50
+ </van-form>
51
+ <van-button
52
+ type="primary"
53
+ @click="
54
+ () => {
55
+ FormRef?.validate?.().finally(() => {
56
+ console.log(FormRef?.getValues?.());
57
+ });
58
+ }
59
+ "
60
+ >
61
+ 验证
62
+ </van-button>
63
+ </template>
64
+
65
+ <script lang="ts" setup>
66
+ import { useWrapperRef } from '@ebfe/vhooks';
67
+ import { ref } from 'vue';
68
+ import { FieldDatePicker } from '@ebfe/vant-kit';
69
+ import { Form as VanForm, Field as VanField, Button as VanButton, FormInstance } from 'vant';
70
+
71
+ const FormRef = ref<FormInstance>();
72
+
73
+ const [modelValue] = useWrapperRef('');
74
+ const FieldDatePickerRef = ref<InstanceType<typeof FieldDatePicker>>();
75
+
76
+ const [testFieldModelValue] = useWrapperRef('');
77
+ </script>
78
+
79
+ <style scoped lang="less">
80
+ .trigger-box {
81
+ display: flex;
82
+ flex-direction: column;
83
+ justify-content: center;
84
+ align-items: center;
85
+ }
86
+ </style>
87
+ ```
88
+
89
+ ## API
90
+
91
+ ### Props
92
+
93
+ TDatePickerProps & [FieldProps](https://vant-ui.github.io/vant/#/zh-CN/field#props)
94
+
95
+ ### Slots
96
+
97
+ 支持暴露所有 DatePicker Slots
98
+
99
+ ### 方法
100
+
101
+ 支持暴露所有 DatePicker 方法
@@ -0,0 +1,134 @@
1
+ # FieldDatePicker
2
+
3
+ ### 介绍
4
+
5
+ 基于 DateRangePicker 以及 vant 的 field 组件进行二次封装,方便处理表单中的时间范围选择需求场景。
6
+
7
+ - 支持传入所有 DateRangePicker props(类型 TDateRangePickerProps)
8
+ - 支持传入所有的 [vant field props](https://vant-ui.github.io/vant/#/zh-CN/field#props)
9
+
10
+ **主要功能描述**
11
+
12
+ - 集成 DateRangePicker 所有功能
13
+
14
+ **对开发者的解脱**
15
+
16
+ - 符合 ui 设计
17
+ - 重复逻辑抽离
18
+
19
+ > 与普通二开表单组件不同,value 涉及多值,而 vant field value 只能是字符串,因此这里帮给表单的值就是 showValue
20
+
21
+ ## 代码演示
22
+
23
+ ### 基础用法
24
+
25
+ ```html
26
+ <template>
27
+ <van-form ref="FormRef">
28
+ <p>modelValue:{{ modelValue }}</p>
29
+ <FieldDateRangePicker
30
+ ref="FieldDateRangePickerRef"
31
+ v-model="modelValue"
32
+ :field-props="{
33
+ name: 'dateField',
34
+ label: 'FieldDateRangePicker',
35
+ labelWidth: '9.5rem',
36
+ readonly: false,
37
+ required: true,
38
+ rules: [{ required: true, message: '请选择' }],
39
+ }"
40
+ :show-value-formatter="
41
+ ({ startDate, endDate }) =>
42
+ startDate &&
43
+ endDate &&
44
+ `${startDate?.toLocaleDateString()} 〰 ${endDate?.toLocaleDateString()}`
45
+ "
46
+ :before-confirm="
47
+ (values) => {
48
+ const [start, end] = values;
49
+ if (start == dayjs().format('YYYY-MM-DD') && start === end) {
50
+ return true;
51
+ }
52
+ showFailToast('请选择当前日期');
53
+ return false;
54
+ }
55
+ "
56
+ >
57
+ <template #confirm> ➡ </template>
58
+ </FieldDateRangePicker>
59
+
60
+ <van-field
61
+ v-model="testFieldModelValue"
62
+ name="testField"
63
+ label="testField"
64
+ :rules="[{ required: true, message: '请选择' }]"
65
+ ></van-field>
66
+ </van-form>
67
+ <van-space>
68
+ <van-button
69
+ type="primary"
70
+ @click="
71
+ () => {
72
+ FormRef?.validate?.().finally(() => {
73
+ console.log(FormRef?.getValues?.());
74
+ });
75
+ }
76
+ "
77
+ >
78
+ 验证表单
79
+ </van-button>
80
+ <van-button type="primary" @click="setPickerRealtimeDate"> 切换默认选中时间为当前日期 </van-button>
81
+ </van-space>
82
+ </template>
83
+
84
+ <script lang="ts" setup>
85
+ import { useWrapperRef } from '@ebfe/vhooks';
86
+ import { ref } from 'vue';
87
+ import { FieldDateRangePicker } from '@ebfe/vant-kit';
88
+ import {
89
+ Form as VanForm,
90
+ Field as VanField,
91
+ Button as VanButton,
92
+ Space as VanSpace,
93
+ FormInstance,
94
+ showFailToast,
95
+ } from 'vant';
96
+ import dayjs from 'dayjs';
97
+ const FormRef = ref<FormInstance>();
98
+
99
+ const [modelValue] = useWrapperRef<[string, string]>(['', '']);
100
+ const FieldDateRangePickerRef = ref<InstanceType<typeof FieldDateRangePicker>>();
101
+
102
+ const setPickerRealtimeDate = () => {
103
+ FieldDateRangePickerRef.value?.setPickerRealtimeDate?.({
104
+ start: dayjs().format('YYYY-MM-DD'),
105
+ end: dayjs().format('YYYY-MM-DD'),
106
+ });
107
+ };
108
+
109
+ const [testFieldModelValue] = useWrapperRef('');
110
+ </script>
111
+
112
+ <style scoped lang="less">
113
+ .trigger-box {
114
+ display: flex;
115
+ flex-direction: column;
116
+ justify-content: center;
117
+ align-items: center;
118
+ }
119
+ </style>
120
+ ```
121
+
122
+ ## API
123
+
124
+ ### Props
125
+
126
+ TDateRangePickerProps & [FieldProps](https://vant-ui.github.io/vant/#/zh-CN/field#props)
127
+
128
+ ### Slots
129
+
130
+ 支持暴露所有 DateRangePicker Slots
131
+
132
+ ### 方法
133
+
134
+ 支持暴露所有 DateRangePicker 方法