@ebfe/vantkit-doc 0.0.2 → 0.0.4

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.
@@ -1,101 +0,0 @@
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 方法
@@ -1,134 +0,0 @@
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 方法
@@ -1,281 +0,0 @@
1
- # FieldMaskTxt
2
-
3
- ### 介绍
4
-
5
- 将脱敏逻辑嵌入表单组件中,将开发者从脱敏相关的具体实现逻辑中解脱出来。
6
-
7
- - 包含数据回显、编辑、兜底处理
8
- - 如果存在上下步表单,基于后端的数据源(加密且脱敏)进行编辑后,再最后一步进行预览时,数据已经变成用户最新输入的(加密未脱敏)数据,此时组件会自行进行脱敏。点击小眼睛也可正常转化未脱敏状态。
9
- - 这种情况其实已经被‘兜底处理’包含了,只要数据源不符合约定的(加密且脱敏)逻辑,前端尽力兜底
10
-
11
- **主要功能描述**
12
-
13
- - 脱敏逻辑嵌入表单组件
14
- - 自动处理数据源(加密数据)的解密逻辑
15
- - 表单展示值与真正需要收集的值自动分隔开
16
- - 针对不同项目、业务场景,支持自定义:
17
- - 加解密方法
18
- - 脱敏占位符号
19
- - 脱敏展示的策略
20
- - 内部已经支持部分策略(身份证、手机号、邮箱、银行卡号),可自由配置。
21
- - 也支持完全自定义
22
- - 支持根据脱敏状态,定制不同的表单验证规则
23
- - 支持对真实收集值的 field 组件定制 props
24
-
25
- ## 代码演示
26
-
27
- ### 基础用法
28
-
29
- ```html
30
- <template>
31
- <demo-block title="基础用法">
32
- <van-form ref="FormRef" :validate-trigger="['onBlur', 'onChange']">
33
- <section>
34
- <span class="desc">设置初始值: 加密且脱敏</span>
35
- <van-field label="明文" placeholder="请输入" v-model="dataSourcePlainTxt" />
36
- <van-field disabled label="密文" v-model="dataSourceCipherTxt" placeholder="输入明文, 制造密文" />
37
- <p>modelValue:</p>
38
- {{ filedValue }}
39
- <FieldMaskTxt
40
- :preset="commonPreset"
41
- mask-id="maskId"
42
- v-model="filedValue"
43
- :field-props="{
44
- name: 'testField',
45
- label: '测试字段',
46
- required: true,
47
- rules: [{ required: true, message: '请输入' }],
48
- }"
49
- />
50
- </section>
51
- <van-button round block type="primary" @click="handleSubmit"> 提交 </van-button>
52
- </van-form>
53
- </demo-block>
54
- </template>
55
-
56
- <script setup lang="ts">
57
- import { FieldMaskTxt, TMaskTxtProps } from '@ebfe/vant-kit';
58
- import { useWrapperRef } from '@ebfe/vhooks';
59
- import { Form as VanForm, Field as VanField, Button as VanButton, FormInstance } from 'vant';
60
- import { getAesCryptoTool } from '@ebfe/utils';
61
- import { computed, ref, watch } from 'vue';
62
-
63
- const { AES_Encrypt, AES_Dencrypt } = getAesCryptoTool({
64
- key: '12345678',
65
- });
66
-
67
- /**
68
- * 制造数据源
69
- */
70
- const [dataSourcePlainTxt] = useWrapperRef('12345678');
71
- const dataSourceCipherTxt = computed(() => commonPreset.encrypt?.(dataSourcePlainTxt.value) as string);
72
- const commonPreset: TMaskTxtProps['preset'] = {
73
- decrypt: AES_Dencrypt,
74
- encrypt: AES_Encrypt,
75
- fetchPlaintext: async (_maskId) => {
76
- return new Promise<string>((resolve) => {
77
- setTimeout(() => {
78
- // eslint-disable-next-line no-console
79
- console.log('模拟接口调用');
80
- resolve(dataSourceCipherTxt.value!);
81
- }, 1000);
82
- });
83
- },
84
- };
85
-
86
- /**
87
- * 表单逻辑
88
- */
89
- const [filedValue, setFiledValue] = useWrapperRef(dataSourceCipherTxt.value);
90
- watch(dataSourceCipherTxt, setFiledValue);
91
-
92
- const FormRef = ref<FormInstance>();
93
- const handleSubmit = () => {
94
- FormRef.value?.validate().then(() => {
95
- // eslint-disable-next-line no-console
96
- console.log('getValues', FormRef.value?.getValues?.());
97
- });
98
- };
99
- </script>
100
-
101
- <style scoped lang="less">
102
- section {
103
- padding: 0px 16px;
104
- display: flex;
105
- flex-direction: column;
106
- justify-content: center;
107
- align-items: center;
108
- gap: 12px;
109
-
110
- .desc {
111
- font-size: 12px;
112
- align-self: flex-start;
113
- color: #aaa;
114
- }
115
- }
116
- </style>
117
- ```
118
-
119
- ### 根据脱敏状态定制 rules
120
-
121
- props.genFieldRules
122
-
123
- > 初始状态(脱敏)
124
- >
125
- > - 数据被脱敏,不知道数据源真正是什么样子的,因此不需要验证
126
- >
127
- > 编辑状态(未脱敏)
128
- >
129
- > - genFieldRules 生成的 rules,默认会分别传入用于展示、用于收集数据的 filed 组件中。
130
- > - 用于收集数据的 filed 组件,值是加密后的,不能通过校验,因此可以配置 real-field-props 控制真实收集数据的 filed 组件 props
131
-
132
- ```html
133
- <template>
134
- <demo-block title="根据脱敏状态定制 rules">
135
- <van-form ref="FormRef" :validate-trigger="['onBlur', 'onChange']">
136
- <section>
137
- <span class="desc">设置初始值: 加密且脱敏</span>
138
- <van-field label="明文" placeholder="请输入" v-model="dataSourcePlainTxt" />
139
- <van-field disabled label="密文" v-model="dataSourceCipherTxt" placeholder="输入明文, 制造密文" />
140
- <p>modelValue:</p>
141
- {{ filedValue }}
142
- <FieldMaskTxt
143
- :preset="commonPreset"
144
- mask-id="maskId"
145
- v-model="filedValue"
146
- :field-props="{
147
- name: 'testField',
148
- label: '测试字段',
149
- required: true,
150
- rules: [{ required: true }],
151
- }"
152
- :gen-field-rules="genFieldRules"
153
- :real-field-props="{
154
- rules: [],
155
- }"
156
- />
157
- </section>
158
- <van-button round block type="primary" @click="handleSubmit"> 提交 </van-button>
159
- </van-form>
160
- </demo-block>
161
- </template>
162
-
163
- <script setup lang="ts">
164
- import { FieldMaskTxt, TMaskTxtProps } from '@ebfe/vant-kit';
165
- import { useWrapperRef } from '@ebfe/vhooks';
166
- import { Form as VanForm, Field as VanField, Button as VanButton, FormInstance } from 'vant';
167
- import { getAesCryptoTool, IdRule } from '@ebfe/utils';
168
- import { computed, ref, watch } from 'vue';
169
-
170
- const { AES_Encrypt, AES_Dencrypt } = getAesCryptoTool({
171
- key: '12345678',
172
- });
173
-
174
- /**
175
- * 制造数据源
176
- */
177
- const [dataSourcePlainTxt] = useWrapperRef('130999199909099999');
178
- const dataSourceCipherTxt = computed(() => commonPreset.encrypt?.(dataSourcePlainTxt.value) as string);
179
- const commonPreset: TMaskTxtProps['preset'] = {
180
- decrypt: AES_Dencrypt,
181
- encrypt: AES_Encrypt,
182
- maskType: 'id',
183
- fetchPlaintext: async (_maskId) => {
184
- return new Promise<string>((resolve) => {
185
- setTimeout(() => {
186
- // eslint-disable-next-line no-console
187
- console.log('模拟接口调用');
188
- resolve(dataSourceCipherTxt.value!);
189
- }, 1000);
190
- });
191
- },
192
- };
193
-
194
- /**
195
- * 表单逻辑
196
- */
197
- const [filedValue, setFiledValue] = useWrapperRef(dataSourceCipherTxt.value);
198
- watch(dataSourceCipherTxt, setFiledValue);
199
-
200
- const genFieldRules = ({ isPlaintextVisible }) => {
201
- return [
202
- {
203
- required: true,
204
- message: isPlaintextVisible && IdRule?.message,
205
- validator:
206
- isPlaintextVisible &&
207
- ((value) => {
208
- return IdRule.pattern.test(value);
209
- }),
210
- },
211
- ];
212
- };
213
-
214
- const FormRef = ref<FormInstance>();
215
- const handleSubmit = () => {
216
- FormRef.value?.validate().then(() => {
217
- // eslint-disable-next-line no-console
218
- console.log('getValues', FormRef.value?.getValues?.());
219
- });
220
- };
221
- </script>
222
-
223
- <style scoped lang="less">
224
- section {
225
- padding: 0px 16px;
226
- display: flex;
227
- flex-direction: column;
228
- justify-content: center;
229
- align-items: center;
230
- gap: 12px;
231
-
232
- .desc {
233
- font-size: 12px;
234
- align-self: flex-start;
235
- color: #aaa;
236
- }
237
- }
238
- </style>
239
- ```
240
-
241
- ## API
242
-
243
- ### Props
244
-
245
- ```
246
- TFieldMaskTxtProps
247
- ```
248
-
249
- | 参数 | 说明 | 类型 | 默认值 |
250
- | :------------- | :--------------------------------------- | :------------------------------------------------------------ | :----- |
251
- | preset | 一些预设 | `Omit<IUseMaskedFieldOptions, 'maskId'` | - |
252
- | maskId | 数据标识,来源于后端,也需传递给后端 | string | - |
253
- | modelValue | 表单真实收集的值 | string | - |
254
- | fieldProps | 用于展示、真实收集值的表单组件公用 props | `Partial<Omit<FieldProps, 'modelValue'>>` | - |
255
- | genFieldRules | 根据脱敏状态生成表单验证规则 | `(p: { isPlaintextVisible: boolean }) => FieldProps['rules']` | - |
256
- | realFieldProps | 用于真实收集值的表单组件 props | `Partial<Omit<FieldProps, 'modelValue'>>` | |
257
- | loading | 用于只读、回显数据场景下的异步 loading | boolean | false |
258
-
259
- ```ts
260
- interface IUseMaskedFieldOptions {
261
- modelValue: ComputedRef<string>;
262
- maskId: ComputedRef<string>;
263
- fetchPlaintext: (maskId: string) => Promise<string>;
264
- decrypt: (cipher: string) => string;
265
- encrypt?: (plain: string) => string;
266
- placeholder?: string;
267
- /**
268
- * 自定义脱敏函数(最高优先级)
269
- * 若提供,则忽略 maskType 和 placeholder
270
- */
271
- maskStrategy?: (str: string) => string;
272
- /**
273
- * 使用内置脱敏策略(中优先级)
274
- * 若未提供 maskStrategy,则使用此策略
275
- */
276
- maskType?: TMaskType;
277
- onValueUpdate?: (value: string) => void;
278
- }
279
-
280
- type TMaskType = 'id' | 'phone' | 'bankCard' | 'email';
281
- ```
@@ -1,115 +0,0 @@
1
- # FieldMultiPicker
2
-
3
- ### 介绍
4
-
5
- 基于 MultiPicker 以及 vant 的 field 组件进行二次封装,方便处理表单中的单项选择需求场景。
6
-
7
- - 支持传入所有 MultiPicker props(类型 TMultiPickerProps)
8
- - 支持传入所有的 [vant field props](https://vant-ui.github.io/vant/#/zh-CN/field#props)
9
-
10
- **主要功能描述**
11
-
12
- - 集成 MultiPicker 所有功能
13
-
14
- **对开发者的解脱**
15
-
16
- - 符合 ui 设计
17
- - 默认场景下 van-field 绑定值就是展示值,FieldMultiPicker 内部将绑定值与展示值表单真正需要收集的值分隔开。
18
-
19
- ## 代码演示
20
-
21
- ### 基础用法
22
-
23
- ```html
24
- <template>
25
- <van-form ref="FormRef">
26
- <span @click="getIdMapData">modelValue: {{ pickerValue }}</span>
27
- <FieldMultiPicker
28
- ref="FieldMultiPickerRef"
29
- v-model="pickerValue"
30
- :options="options"
31
- :field-names="fieldNames"
32
- title="基础用法"
33
- tip-txt="这就是基础组件 - MultiPicke"
34
- :field-props="{
35
- name: 'multiPicker',
36
- label: '多选',
37
- placeholder: '请选择',
38
- required: true,
39
- rules: [{ required: true, message: '请选择' }],
40
- }"
41
- />
42
- <van-button round block type="primary" @click="handleSubmit"> 提交 </van-button>
43
- </van-form>
44
- </template>
45
-
46
- <script setup lang="ts">
47
- import { useWrapperRef } from '@ebfe/vhooks';
48
- import { FieldMultiPicker } from '@ebfe/vant-kit';
49
- import { ref } from 'vue';
50
- import { Form as VanForm, Button as VanButton, FormInstance } from 'vant';
51
-
52
- const FormRef = ref<FormInstance>();
53
- const handleSubmit = () => {
54
- FormRef.value?.validate().then(() => {
55
- // eslint-disable-next-line no-console
56
- console.log('getValues', FormRef.value?.getValues?.());
57
- // eslint-disable-next-line no-console
58
- console.log('真实值', { multiPicker: pickerValue.value });
59
- });
60
- };
61
-
62
- const options = [
63
- { name: '选项1', value: '1' },
64
- { name: '选项2', value: '2', disabled: true },
65
- { name: '选项3', value: '3' },
66
- ];
67
- const fieldNames = {
68
- label: 'name',
69
- value: 'value',
70
- };
71
- const [pickerValue, _setPickerValue] = useWrapperRef<string[]>([]);
72
-
73
- const FieldMultiPickerRef = ref<InstanceType<typeof FieldMultiPicker>>();
74
- const getIdMapData = () => {
75
- FieldMultiPickerRef.value?.getOptionsIdMapData?.();
76
- // console.log(
77
- // 'getIdMapData',
78
- // FieldMultiPickerRef.value?.getOptionsIdMapData?.(),
79
- // );
80
- };
81
- </script>
82
-
83
- <style scoped lang="less">
84
- .desc {
85
- font-size: 12px;
86
- text-align: center;
87
- }
88
- </style>
89
- ```
90
-
91
- ## API
92
-
93
- ### Props
94
-
95
- 继承 TMultiPickerProps 的同时
96
-
97
- | 参数 | 说明 | 类型 | 默认值 |
98
- | ---------- | ------------------ | ---------------- | ------ |
99
- | fieldProps | 当前选中项对应的值 | vant field props | - |
100
-
101
- ### Events
102
-
103
- 继承 MultiPicker
104
-
105
- | 事件名 | 说明 | 回调参数 |
106
- | :----- | :--- | :------- |
107
- | - | - | - |
108
-
109
- ### Slots
110
-
111
- 继承 MultiPicker
112
-
113
- | 名称 | 说明 | 参数 |
114
- | :--- | :--- | :--- |
115
- | - | - | - |