general-basic-form 2.1.0 → 2.1.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.
package/README.md CHANGED
@@ -1,647 +1,668 @@
1
- # GeneralBasicForm
2
-
3
- ## 一个兼容 Vue2 、Vue3 和 React(未来实现) 的表单组件,支持typescript,vue2请使用@1版本,Vue3请使用@2版本
4
-
5
- | 组件\兼容性 | vue2 | vue3 | Ant Design Vue(next) | Element Plus | Element(ui) |
6
- | ------------------- | ---- | ---- | ---- | ---- | ---- |
7
- | VGeneralBasicForm | | | | | |
8
- | VSearchBox | | | | | |
9
- | VInfiniteScrollList | | √ | | √ | |
10
- | VDescriptions | √ | √ ||| √ |
11
- | VInputMobilecVerification | | √ || √ | |
12
- | VInputGraphicVerification | | √ | √ | √ | |
13
- | VTreeTransfer || √ | | | √ |
14
- | VTabs | √ | | | | √ |
15
-
16
- 安装:npm i general-basic-form<br/>
17
- install: npm i general-basic-form
18
-
19
- 示例:
20
-
21
- 因为兼容性问题,目前只能使用完整引入
22
-
23
- ```
24
- import ElementPlus from 'element-plus'
25
- import 'element-plus/dist/index.css'
26
- app.use(ElementPlus)
27
- ```
28
-
29
- ```
30
- import { VGeneralBasicForm } from 'general-basic-form'
31
- import 'general-basic-form/style'
32
- ```
33
-
34
- <VGeneralBasicForm
35
- :showSearch="showSearch"
36
- :getList="getList"
37
- :formItem="formItem"
38
- :size="size"
39
- ref="VGeneralBasicFormRef"
40
- labelWidth="90px"
41
- :noInputBlank="true"
42
- >
43
- <template v-slot:default>
44
- ...一些传入插槽的内容
45
- </template>
46
- <template v-slot:behind-the-button>
47
- <el-form-item>
48
- <div>上次同步时间:</div>
49
- </el-form-item>
50
- </template>
51
- </VGeneralBasicForm>
52
-
53
- ![image-20210903165502942](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202109031655830.png)
54
-
55
- 在单纯作为表单的时候可以这样使用:
56
-
57
- <VGeneralBasicForm
58
- formOnly
59
- :formItem="formItem"
60
- size="small"
61
- ref="VGeneralBasicFormRef"
62
- :labelWidth="formLabelWidth"
63
- :formData: {
64
- // 外部传入的表单数据,用于回填
65
- }
66
- noUrlParameters
67
- :afterReset="afterReset"
68
- v-model:loading="loading"
69
- />
70
-
71
- <style lang="scss" scoped>
72
- :deep(.el-form-item) {
73
- margin-bottom: 16px;
74
- }
75
- :deep(.el-divider--horizontal) {
76
- margin: 8px 0px;
77
- }
78
- </style>
79
-
80
- getList会传出默认的参数,首次请求时会有页数和分页大小,重置后会传出默认页数1
81
-
82
- async getList(
83
- params = {
84
- page: Number(this.$route.query.page) || 1,
85
- limit: Number(this.$route.query.limit) || 10,
86
- }
87
- ) {}
88
-
89
- 表单数据校验需要拿到内部表单的ref
90
-
91
- async getSmscode() {
92
- const VGeneralBasicFormRef = this.$refs['VGeneralBasicFormRef'] as any
93
- const state = await new Promise<boolean>((resolve, reject) => {
94
- VGeneralBasicFormRef.$refs['queryFormRef']?.validateField(
95
- 'user_phone',
96
- async (valid: boolean, props?: FormItemProp[] | undefined) => {
97
- if (valid) {
98
- const { user_phone } = VGeneralBasicFormRef['queryParams']
99
- const res: any = await SmscodeList({ user_phone })
100
- if (res) {
101
- console.log(res)
102
- resolve(true)
103
- } else {
104
- resolve(false)
105
- }
106
- } else {
107
- resolve(false)
108
- }
109
- }
110
- )
111
- })
112
- return state
113
- },
114
-
115
- setup写法:
116
- const VGeneralBasicFormRef = ref()
117
- const params = await new Promise<any>((resolve, reject) => {
118
- VGeneralBasicFormRef.value.$refs['queryFormRef']?.validate(
119
- async (valid: boolean, props?: FormItemProp[] | undefined) => {
120
- if (valid) {
121
- const params = VGeneralBasicFormRef.value['queryParams']
122
- resolve(params)
123
- } else {
124
- reject()
125
- }
126
- }
127
- )
128
- })
129
-
130
-
131
- ![image-20211014191532067](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202110141915657.png)
132
-
133
- parametersType类型介绍
134
-
135
- | parametersType形式 | 支持页面刷新 | 参数改变引起路由跳转 | 组件间共享数据 | 存储上限 | 浏览器兼容性 |
136
- | ------------------ | ------------ | -------------------- | -------------- | -------- | ------------ |
137
- | url | 是 | 是 | 是 | 中 | 高 |
138
- | data | 否 | 否 | 否 | 高 | 高 |
139
- | indexDB | 是 | 否 | 是 | 高 | 中 |
140
-
141
- 数据示例:
142
-
143
- showSearch: true, // 显示搜索条件
144
- getList(); // 请求数据的函数
145
- afterReset(); // 在重置按钮点击完后但还没重新请求时触发的的函数
146
- formOnly:true // 只展示表单不展示按钮
147
- parametersType:"url" // 见parametersType类型介绍
148
- loading:false // 加载动画
149
- formData:{} // 注意,因为可能出现的性能问题在组件watch formData的变化时没有使用deep,所以有时候深度的修改会不生效,导致表单数据不完整
150
- noInputBlank: true //校验input框不能仅输入空格
151
- //例子:formData.value.x=y ✘ | formData.value={...formData.value,x:y}
152
- currentPageKey:"page", //当前页数key
153
- pageSizeKey:"limit", //每页显示个数key
154
- defCurrentPage:1, //默认的页数
155
- defPageSize:10, //默认的每页显示个数
156
- queryWhenReady:false,//初始化完成后自动触发查找数据函数,建议用这个this.$refs["VGeneralBasicFormRef"].handleQuery({ defaultPageFirst: false })
157
- formItem: [
158
- {
159
- label: '',
160
- prop: 'bsName35',
161
- type: 'divider',
162
- setting: {
163
- },
164
- template: {
165
- default: () => {
166
- return "123123123";
167
- },
168
- },
169
- },
170
- { label: "款式名称",
171
- prop: "bsName",
172
- type: "input",
173
- setting: {
174
- placeholder: '请输入手机验证码',
175
- style: 'width: 100%'
176
- },
177
- rules: [
178
- {
179
- message: "请输入信息"
180
- },
181
- {
182
- pattern: /^\w+[\,\,\-\w' '#]+$/,
183
- message: "请输入正确的Invoice单号"
184
- }
185
- ],
186
- template: {
187
- suffix: () => {
188
- return <svg-icon icon-class="baifenbi" />;
189
- },
190
- },
191
- },
192
- {
193
- label: "二次工艺",
194
- prop: "spName",
195
- type: "select",
196
- setting:{ multiple:true, //多选},
197
- option: [
198
- { value: "3", label: "满印" },
199
- { value: "1", label: "区域印花" },
200
- { value: "2", label: "绣花" },
201
- ],
202
- },
203
- {
204
- label: "创建时间",
205
- prop: "create_time",
206
- type: "date-picker",
207
- setting: {
208
- "range-separator": "至",
209
- }
210
- },
211
- {
212
- label: "二次工艺成本价格(人民币分)",
213
- prop: "spCost",
214
- type: "input-number",
215
- "controls-position": "right",
216
- min: 0,
217
- rules: [
218
- {
219
- required: true,
220
- message: "请输入二次工艺成本价格",
221
- trigger: "blur",
222
- },
223
- ],
224
- },
225
- {
226
- label: '',
227
- prop: 'bsName2',
228
- type: 'input-graphic-verification',
229
- setting: {
230
- placeholder: '请输入图形验证码',
231
- style: 'width: 100%'
232
- },
233
- rules: [
234
- {
235
- message: '请输入图形验证码',
236
- trigger: 'blur'
237
- }
238
- ],
239
- graphicSrc, // 请求图像的URL
240
- getGraphic, // 重新请求图像的函数
241
- key:Math.random(), // 必传,图像更新后必须更新。如果URL会变化也可以用URL代替
242
- },
243
- {
244
- label: '',
245
- prop: 'bsName3',
246
- type: 'input-mobile-verification',
247
- inputSetting: {
248
- placeholder: '请输入手机验证码',
249
- style: 'width: 100%'
250
- },
251
- buttonSetting: {
252
- type: "text",
253
- style: 'text-align: end',
254
- },
255
- rules: [
256
- {
257
- message: '请输入手机验证码',
258
- trigger: 'blur'
259
- }
260
- ],
261
- getSmscode,// 获取验证码的回调函数,获取失败必须返回false,否则计时器不会重新计算
262
- },
263
- {
264
- label: '是否必填',
265
- prop: 'is_optional',
266
- type: 'radio',
267
- setting: {
268
- disabled: true
269
- },
270
- option: [
271
- { value: '是', label: 'true',border: true },
272
- { value: '否', label: 'false' }
273
- ],
274
- rules: [
275
- {
276
- required: true,
277
- message: '请输入标签项名称',
278
- trigger: 'blur'
279
- }
280
- ]
281
- },
282
- {
283
- label: '多选',
284
- prop: 'is_multi',
285
- type: 'checkbox',
286
- setting: {
287
- },
288
- option: [
289
- { value: '是', label: 'true' },
290
- { value: '', label: 'false' }
291
- ],
292
- rules: []
293
- },
294
- {
295
- label: '受访人',
296
- prop: 'contactors',
297
- type: 'form-item-slot',
298
- name: "contactors"
299
- // 插槽组件使用:
300
- // <VGeneralBasicForm ...>
301
- // <template #contactors>
302
- // <div>一些组件
303
- // 一些组件
304
- // <el-form-item prop="contactors">...</el-form-item>
305
- // </div>
306
- // </template>
307
- // </VGeneralBasicForm>
308
- },
309
- {
310
- label: "分类",
311
- prop: "分类",
312
- type: "cascader",
313
- setting:{},
314
- options: [
315
- {
316
- value: "zhinan",
317
- label: "指南",
318
- children: [
319
- {
320
- value: "shejiyuanze",
321
- label: "设计原则",
322
- children: [
323
- {
324
- value: "yizhi",
325
- label: "一致",
326
- },
327
- {
328
- value: "fankui",
329
- label: "反馈",
330
- },
331
- {
332
- value: "xiaolv",
333
- label: "效率",
334
- },
335
- {
336
- value: "kekong",
337
- label: "可控",
338
- },
339
- ],
340
- },
341
- {
342
- value: "daohang",
343
- label: "导航",
344
- children: [
345
- {
346
- value: "cexiangdaohang",
347
- label: "侧向导航",
348
- },
349
- {
350
- value: "dingbudaohang",
351
- label: "顶部导航",
352
- },
353
- ],
354
- },
355
- ],
356
- },
357
- {
358
- value: "ziyuan",
359
- label: "资源",
360
- children: [
361
- {
362
- value: "axure",
363
- label: "Axure Components",
364
- },
365
- {
366
- value: "sketch",
367
- label: "Sketch Templates",
368
- },
369
- {
370
- value: "jiaohu",
371
- label: "组件交互文档",
372
- },
373
- ],
374
- },
375
- ],
376
- },
377
- ],
378
-
379
- //rules为表单校验规则,每个组件都可以传入
380
-
381
- //input支持template,支持以下几个属性:
382
- //prefix 输入框头部内容,只对 type="text"(默认) 有效
383
- //suffix 输入框尾部内容,只对 type="text" 有效
384
- //prepend 输入框前置内容,只对 type="text" 有效
385
- //append 输入框后置内容,只对 type="text" 有效
386
-
387
- //divider支持template:
388
- //default
389
- 支持组件type:
390
-
391
- /**
392
-
393
- \* @description: 输入框
394
-
395
- */
396
-
397
- 'input' = 'input',
398
-
399
- /**
400
-
401
- \* @description: 输入框/图像验证码
402
-
403
- */
404
-
405
- 'input-graphic-verification' = 'input-graphic-verification',
406
-
407
- /**
408
-
409
- \* @description: 输入框/手机验证码
410
-
411
- */
412
-
413
- 'input-mobile-verification' = 'input-mobile-verification',
414
-
415
- /**
416
-
417
- \* @description: 分割线
418
-
419
- */
420
-
421
- 'divider' = 'divider',
422
-
423
- /**
424
-
425
- \* @description: 选择器
426
-
427
- */
428
-
429
- 'select' = 'select',
430
-
431
- /**
432
-
433
- \* @description: 级联选择器
434
-
435
- */
436
-
437
- 'cascader' = 'cascader',
438
-
439
- /**
440
-
441
- \* @description: 日期选择器
442
-
443
- */
444
-
445
- 'date-picker' = 'date-picker',
446
-
447
- /**
448
-
449
- \* @description: 数字输入框
450
-
451
- */
452
-
453
- 'input-number' = 'input-number',
454
-
455
- /**
456
-
457
- \* @description: 单选框
458
-
459
- */
460
-
461
- 'radio' = 'radio',
462
-
463
- /**
464
-
465
- \* @description: 自定义元素,插槽组件
466
-
467
- */
468
-
469
- 'form-item-slot'='form-item-slot',
470
-
471
- /**
472
-
473
- \* @description: 多选框
474
-
475
- */
476
-
477
- 'checkbox'='checkbox',
478
-
479
-
480
-
481
- # VInfiniteScrollList对虚拟滚动列表+接口的封装
482
-
483
-
484
-
485
- ![image-20231208165229296](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202312081652392.png)
486
-
487
- ```
488
- import { VInfiniteScrollList } from 'general-basic-form'
489
- import 'general-basic-form/style'
490
- <VInfiniteScrollList
491
- :search="search"
492
- id="user_id"
493
- name="name"
494
- ref="InfiniteScrollListRef"
495
- checkbox
496
- :extra="extraRender"
497
- :max="1"
498
- />
499
- ```
500
- ```
501
- 移动端配合下拉刷新使用
502
- import { getOrderItem } from "../orderItem/functional"
503
- // getOrderItem为JSX函数,返回一个VUE组件
504
-
505
- <t-pull-down-refresh v-model="refreshing" @refresh="onRefresh" class="refresh-content">
506
- <VInfiniteScrollList :search="loadData" :checkbox="false" id="cancelId" ref="InfiniteScrollListRef" checkbox
507
- :extra="getOrderItem" height="100%" infinite-scroll-distance="50"/>
508
- </t-pull-down-refresh>
509
- ```
510
- ```
511
- search:数据接口 (page: Number) => Promise<[]>
512
- id:数据key值(唯一和选择值)
513
- name:显示名字
514
- checkbox:是否有多选功能,不传的话就是单纯的虚拟滚动列表
515
- extra:同行额外显示的内容,(item: any) => VNode | String;
516
- //el-checkbox有固定高度,如果需要配置高度比较高,例如有换行的自定义extra,最好处理一下样式,例子:
517
- //:deep(.el-checkbox) {
518
- // padding: 6px 16px !important;
519
- // display: flex;
520
- // align-items: baseline;
521
- // height: auto;
522
- //}
523
- defaultSelection:包含数据key值的对象数组或者直接传入key值数组
524
- height:默认272px String
525
- ```
526
-
527
- ```
528
- defineExpose({ reset, loadList, selectInfo, list, ifbottom });
529
- InfiniteScrollListRef?.value?.reset():重置列表内容
530
- InfiniteScrollListRef?.value?.lowReset():重置列表内容,但保留已选择的选项
531
- InfiniteScrollListRef?.value?.loadList():向下滚动列表内容,受到loading和ifbottom的影响
532
- InfiniteScrollListRef?.value?.refreshList():刷新列表,滚动列表会对整个内容重新请求数据,已选择的内容会自动选择
533
- InfiniteScrollListRef?.value?.selectInfo:选择的内容
534
- InfiniteScrollListRef?.value?.list:列表的内容
535
- InfiniteScrollListRef?.value?.ifbottom:是否到底部
536
- InfiniteScrollListRef?.value?.loading:加载中
537
- ```
538
-
539
- # VDescriptions对展示描述列表的封装
540
-
541
- ![image-20231208182455415](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202312081824708.png)
542
-
543
- ```
544
- import { VDescriptions } from 'general-basic-form'
545
- <VDescriptions
546
- :formData="props.formData"
547
- :formItem="formItem"
548
- componentType="Ant Design Vue"
549
- ...其他el-descriptions的配置
550
- />
551
- ```
552
-
553
- ```
554
- formData:Object
555
- formItem:[ {
556
- label: '受访人',
557
- prop: 'contactors',
558
- render: (scope: any) => {
559
- const { $index, row = {} } = scope
560
- const { contactors = [] } = row
561
- const ele = (contactors.length > 0 ? <span>{contactors.map((item: any) => item.name).join(",")} </span> : null)
562
- return ele
563
- }
564
- },
565
- {
566
- label: '拜访详情',
567
- prop: 'detail',
568
- descriptionsItemProps:{
569
- 'label-class-name': 'label-class-name'
570
- }
571
- }]
572
- componentType:"Ant Design Vue"|"Element Plus"(默认)
573
- strict:Boolean //使用strict参数后,如果formData内的某个字段没有值,对应的描述元素将不会展示(包括标签文字),但有render的字段仍然会展示
574
- descriptionsItemProps:a-descriptions-item|el-descriptions-item的配置
575
- ```
576
-
577
- # VInputMobilecVerification,VInputGraphicVerification表单里的图形验证码、手机验证码组件,可以单独引入
578
-
579
- ```
580
- <VInputGraphicVerification :item="{同表单,可忽略label和rules字段}" :loading="loading"></VInputGraphicVerification>
581
-
582
- <VInputMobilecVerification :item="{同表单,可忽略label和rules字段}" componentType="Ant Design Vue" ref="VInputMobilecVerificationRef"></VInputMobilecVerification>
583
- ```
584
-
585
- ```
586
- componentType:"Ant Design Vue"|"Element Plus"(默认)
587
- ```
588
-
589
- ```
590
- 此用法下必须提供:
591
- provide(/* 注入名 */ "queryParams", /* 表单值对象 */ queryParams);
592
-
593
- componentType为Ant Design Vue需要提供:
594
- import { Form } from 'ant-design-vue';
595
- provide(/* 注入名 */ "Form", /* Ant Design Vue Form实例,用于表单数据更新等 */ Form);
596
-
597
- 可选:
598
- provide("size", size); // 同组件size
599
- provide("getList", getList); // 输入框回车触发
600
-
601
- 调用发送短信验证码和重置的方法
602
- VInputMobilecVerificationRef.value.VerificationButtonRef.buttonClick()
603
- VInputMobilecVerificationRef.value.VerificationButtonRef.reset()
604
- ```
605
-
606
- # VTreeTransfer 树形数据穿梭框
607
-
608
- ![image-20250425183446375](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202504251834575.png)
609
-
610
- ```
611
- <VTreeTransfer :dataSource="classmate" :treeAttributes="{
612
- 'node-key': 'user_id', props: { label: 'user_name' }, 'default-expand-all': false
613
- }" transferTitleRight="白名单(不会被选中)" transferTitleLeft="普通名单" filterable :checkedKeys="checkedKeys">
614
- </VTreeTransfer>
615
-
616
- import { VTreeTransfer } from 'general-basic-form';
617
- const VTreeTransferRef = ref([])
618
- ```
619
-
620
- ```
621
- dataSource:[
622
- {
623
- label: 'Level one 1',
624
- id:1,
625
- children: [
626
- {
627
- label: 'Level two 1-1',
628
- id:2,
629
- children: [
630
- {
631
- label: 'Level three 1-1-1',
632
- id:3,
633
- },
634
- ],
635
- },
636
- ],
637
- },] 树状结构数据
638
- treeAttributes:{} 树形控件的属性,见https://element-plus.org/zh-CN/component/tree.html
639
- transferTitleLeft:"" 左标题
640
- transferTitleRight:"" 右标题
641
- filterable:false 是否显示搜索框
642
- checkedKeys:[1,2] 选中的值
643
-
644
- 获取选中的数组详情:
645
- VTreeTransferRef.value["selectedList"].map((item) => {}))
646
- ```
647
-
1
+ <!-- @format -->
2
+
3
+ # GeneralBasicForm
4
+
5
+ ## 一个兼容 Vue2 、Vue3 React(未来实现) 的表单组件,支持 typescript,vue2 请使用@1 版本,Vue3 请使用@2 版本
6
+
7
+ | 组件\兼容性 | vue2 | vue3 | Ant Design Vue(next) | Element Plus | Element(ui) |
8
+ | ------------------------- | ---- | ---- | ---------------------- | ------------ | ------------- |
9
+ | VGeneralBasicForm | | √ | | √ ||
10
+ | VSearchBox | √ | | | | |
11
+ | VInfiniteScrollList | | √ | | √ | |
12
+ | VDescriptions | | | √ | √ | √ |
13
+ | VInputMobilecVerification | | √ | √ | √ | |
14
+ | VInputGraphicVerification | | | | | |
15
+ | VTreeTransfer | √ | √ | | √ | √ |
16
+ | VTabs | √ | | | | √ |
17
+
18
+ 安装:npm i general-basic-form<br/>
19
+ install: npm i general-basic-form
20
+
21
+ webpack4 兼容:
22
+ 加入配置:module.exports = {
23
+ transpileDependencies: ['general-basic-form'],
24
+ }
25
+
26
+ 示例:
27
+
28
+ 因为兼容性问题,目前只能使用完整引入
29
+
30
+ ```
31
+ import ElementPlus from 'element-plus'
32
+ import 'element-plus/dist/index.css'
33
+ app.use(ElementPlus)
34
+ ```
35
+
36
+ ```
37
+ import { RGeneralBasicForm } from 'general-basic-form';
38
+ ```
39
+
40
+ <RGeneralBasicForm
41
+ formItem={formItem}
42
+ getList={getList}
43
+ parametersType="data"
44
+ noInputBlank
45
+ formData={detail}
46
+ fieldGroupSetting={{ className: 'grid grid-cols-4 gap-4' }}
47
+
48
+ > </RGeneralBasicForm>
49
+
50
+ ![image-20210903165502942](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202109031655830.png)
51
+
52
+ 在单纯作为表单的时候可以这样使用:
53
+
54
+ <VGeneralBasicForm
55
+ formOnly
56
+ :formItem="formItem"
57
+ size="small"
58
+ ref="VGeneralBasicFormRef"
59
+ :labelWidth="formLabelWidth"
60
+ :formData: {
61
+ // 外部传入的表单数据,用于回填
62
+ }
63
+ noUrlParameters
64
+ :afterReset="afterReset"
65
+ v-model:loading="loading"
66
+ />
67
+
68
+ <style lang="scss" scoped>
69
+ :deep(.el-form-item) {
70
+ margin-bottom: 16px;
71
+ }
72
+ :deep(.el-divider--horizontal) {
73
+ margin: 8px 0px;
74
+ }
75
+ </style>
76
+
77
+ getList 会传出默认的参数,首次请求时会有页数和分页大小,重置后会传出默认页数 1
78
+
79
+ async getList(
80
+ params = {
81
+ page: Number(this.$route.query.page) || 1,
82
+ limit: Number(this.$route.query.limit) || 10,
83
+ }
84
+ ) {}
85
+
86
+ 表单数据校验需要拿到内部表单的 ref
87
+
88
+ async getSmscode() {
89
+ const VGeneralBasicFormRef = this.$refs['VGeneralBasicFormRef'] as any
90
+ const state = await new Promise<boolean>((resolve, reject) => {
91
+ VGeneralBasicFormRef.$refs['queryFormRef']?.validateField(
92
+ 'user_phone',
93
+ async (valid: boolean, props?: FormItemProp[] | undefined) => {
94
+ if (valid) {
95
+ const { user_phone } = VGeneralBasicFormRef['queryParams']
96
+ const res: any = await SmscodeList({ user_phone })
97
+ if (res) {
98
+ console.log(res)
99
+ resolve(true)
100
+ } else {
101
+ resolve(false)
102
+ }
103
+ } else {
104
+ resolve(false)
105
+ }
106
+ }
107
+ )
108
+ })
109
+ return state
110
+ },
111
+
112
+ setup写法:
113
+ const VGeneralBasicFormRef = ref()
114
+ const params = await new Promise<any>((resolve, reject) => {
115
+ VGeneralBasicFormRef.value.$refs['queryFormRef']?.validate(
116
+ async (valid: boolean, props?: FormItemProp[] | undefined) => {
117
+ if (valid) {
118
+ const params = VGeneralBasicFormRef.value['queryParams']
119
+ resolve(params)
120
+ } else {
121
+ reject()
122
+ }
123
+ }
124
+ )
125
+ })
126
+
127
+ ![image-20211014191532067](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202110141915657.png)
128
+
129
+ parametersType 类型介绍
130
+
131
+ | parametersType 形式 | 支持页面刷新 | 参数改变引起路由跳转 | 组件间共享数据 | 存储上限 | 浏览器兼容性 |
132
+ | ------------------- | ------------ | -------------------- | -------------- | -------- | ------------ |
133
+ | url | 是 | 是 | 是 | 中 | 高 |
134
+ | data | 否 | 否 | 否 | 高 | 高 |
135
+ | indexDB | | | | | |
136
+
137
+ 数据示例:
138
+
139
+ showSearch: true, // 显示搜索条件
140
+ getList(); // 请求数据的函数
141
+ afterReset(); // 在重置按钮点击完后但还没重新请求时触发的的函数
142
+ formOnly:true // 只展示表单不展示按钮
143
+ parametersType:"url" // 见parametersType类型介绍
144
+ loading:false // 加载动画
145
+ formData:{} // 注意,因为可能出现的性能问题在组件watch formData的变化时没有使用deep,所以有时候深度的修改会不生效,导致表单数据不完整
146
+ noInputBlank: true //校验input框不能仅输入空格
147
+ //例子:formData.value.x=y ✘ | formData.value={...formData.value,x:y}
148
+ currentPageKey:"page", //当前页数key
149
+ pageSizeKey:"limit", //每页显示个数key
150
+ defCurrentPage:1, //默认的页数
151
+ defPageSize:10, //默认的每页显示个数
152
+ queryWhenReady:false,//初始化完成后自动触发查找数据函数
153
+ formItem: [
154
+ {
155
+ label: '',
156
+ prop: 'bsName35',
157
+ type: 'divider',
158
+ setting: {
159
+ },
160
+ template: {
161
+ default: () => {
162
+ return "123123123";
163
+ },
164
+ },
165
+ },
166
+ { label: "款式名称",
167
+ prop: "bsName",
168
+ type: "input",
169
+ setting: {
170
+ placeholder: '请输入手机验证码',
171
+ style: 'width: 100%',
172
+ required: true,
173
+ },
174
+ fieldSetting: {
175
+ orientation: 'responsive',
176
+ },
177
+ rules: [
178
+ {
179
+ message: "请输入信息",
180
+ required: true,
181
+ },
182
+ {
183
+ pattern: /^\w+[\,\,\-\w' '#]+$/,
184
+ message: "请输入正确的Invoice单号"
185
+ },
186
+ {
187
+ validator: (rule, value, callback) => {
188
+ callback();
189
+ },
190
+ },
191
+ ],
192
+ //template: {
193
+ // suffix: () => {
194
+ // return <svg-icon icon-class="baifenbi" />;
195
+ // },
196
+ //},
197
+ },
198
+ {
199
+ label: '天数-价格配置',
200
+ prop: 'prices',
201
+ type: 'form-list',
202
+ setting: {
203
+ placeholder: ['请输入天数', '请输入价格'],
204
+ required: true,
205
+ type: 'number',
206
+ ndim: 2, // 多维数组
207
+ columns: ['days', 'price'],
208
+ },
209
+ fieldSetting: {
210
+ className: 'col-span-2',
211
+ },
212
+ rules: [
213
+ {
214
+ validator: (rule, value, callback) => {
215
+ console.log(value);
216
+ for (let i = 0; i < value.length; i++) {
217
+ const element = value[i];
218
+ if (!Number(element.days) || !Number(element.price)) {
219
+ callback(new Error('请输入数字'));
220
+ return;
221
+ }
222
+ }
223
+ callback();
224
+ },
225
+ },
226
+ ],
227
+ },
228
+ {
229
+ label: '护士在线增值服务内容',
230
+ prop: 'nursingCare',
231
+ type: 'form-list',
232
+ setting: {
233
+ placeholder: ['请输入服务内容'],
234
+ required: true,
235
+ ndim: 1, // 1维数组
236
+ },
237
+ fieldSetting: {
238
+ className: 'col-span-2',
239
+ },
240
+ rules: [
241
+ {
242
+ validator: (rule, value, callback) => {
243
+ console.log(value);
244
+ for (let i = 0; i < value.length; i++) {
245
+ const element = value[i];
246
+ if (!element) {
247
+ callback(new Error('请输入服务内容'));
248
+ return;
249
+ }
250
+ }
251
+ callback();
252
+ },
253
+ },
254
+ ],
255
+ },
256
+ {
257
+ label: "二次工艺",
258
+ prop: "spName",
259
+ type: "select",
260
+ setting:{ multiple:true, //多选},
261
+ option: [
262
+ { value: "3", label: "满印" },
263
+ { value: "1", label: "区域印花" },
264
+ { value: "2", label: "绣花" },
265
+ ],
266
+ },
267
+ {
268
+ label: "创建时间",
269
+ prop: "create_time",
270
+ type: "date-picker",
271
+ setting: {
272
+ "range-separator": "至",
273
+ }
274
+ },
275
+ {
276
+ label: "二次工艺成本价格(人民币分)",
277
+ prop: "spCost",
278
+ type: "input-number",
279
+ "controls-position": "right",
280
+ min: 0,
281
+ rules: [
282
+ {
283
+ required: true,
284
+ message: "请输入二次工艺成本价格",
285
+ trigger: "blur",
286
+ },
287
+ ],
288
+ },
289
+ {
290
+ label: '',
291
+ prop: 'bsName2',
292
+ type: 'input-graphic-verification',
293
+ setting: {
294
+ placeholder: '请输入图形验证码',
295
+ style: 'width: 100%'
296
+ },
297
+ rules: [
298
+ {
299
+ message: '请输入图形验证码',
300
+ trigger: 'blur'
301
+ }
302
+ ],
303
+ graphicSrc, // 请求图像的URL
304
+ getGraphic, // 重新请求图像的函数
305
+ key:Math.random(), // 必传,图像更新后必须更新。如果URL会变化也可以用URL代替
306
+ },
307
+ {
308
+ label: '',
309
+ prop: 'bsName3',
310
+ type: 'input-mobile-verification',
311
+ inputSetting: {
312
+ placeholder: '请输入手机验证码',
313
+ style: 'width: 100%'
314
+ },
315
+ buttonSetting: {
316
+ type: "text",
317
+ style: 'text-align: end',
318
+ },
319
+ rules: [
320
+ {
321
+ message: '请输入手机验证码',
322
+ trigger: 'blur'
323
+ }
324
+ ],
325
+ getSmscode,// 获取验证码的回调函数,获取失败必须返回false,否则计时器不会重新计算
326
+ },
327
+ {
328
+ label: '是否必填',
329
+ prop: 'is_optional',
330
+ type: 'radio',
331
+ setting: {
332
+ disabled: true
333
+ },
334
+ option: [
335
+ { value: '是', label: 'true',border: true },
336
+ { value: '否', label: 'false' }
337
+ ],
338
+ rules: [
339
+ {
340
+ required: true,
341
+ message: '请输入标签项名称',
342
+ trigger: 'blur'
343
+ }
344
+ ]
345
+ },
346
+ {
347
+ label: '多选',
348
+ prop: 'is_multi',
349
+ type: 'checkbox',
350
+ setting: {
351
+ },
352
+ option: [
353
+ { value: '是', label: 'true' },
354
+ { value: '否', label: 'false' }
355
+ ],
356
+ rules: []
357
+ },
358
+ {
359
+ label: '受访人',
360
+ prop: 'contactors',
361
+ type: 'form-item-slot',
362
+ name: "contactors"
363
+ // 插槽组件使用:
364
+ // <VGeneralBasicForm ...>
365
+ // <template #contactors>
366
+ // <div>一些组件
367
+ // 一些组件
368
+ // <el-form-item prop="contactors">...</el-form-item>
369
+ // </div>
370
+ // </template>
371
+ // </VGeneralBasicForm>
372
+ },
373
+ {
374
+ label: "分类",
375
+ prop: "分类",
376
+ type: "cascader",
377
+ setting:{},
378
+ options: [
379
+ {
380
+ value: "zhinan",
381
+ label: "指南",
382
+ children: [
383
+ {
384
+ value: "shejiyuanze",
385
+ label: "设计原则",
386
+ children: [
387
+ {
388
+ value: "yizhi",
389
+ label: "一致",
390
+ },
391
+ {
392
+ value: "fankui",
393
+ label: "反馈",
394
+ },
395
+ {
396
+ value: "xiaolv",
397
+ label: "效率",
398
+ },
399
+ {
400
+ value: "kekong",
401
+ label: "可控",
402
+ },
403
+ ],
404
+ },
405
+ {
406
+ value: "daohang",
407
+ label: "导航",
408
+ children: [
409
+ {
410
+ value: "cexiangdaohang",
411
+ label: "侧向导航",
412
+ },
413
+ {
414
+ value: "dingbudaohang",
415
+ label: "顶部导航",
416
+ },
417
+ ],
418
+ },
419
+ ],
420
+ },
421
+ {
422
+ value: "ziyuan",
423
+ label: "资源",
424
+ children: [
425
+ {
426
+ value: "axure",
427
+ label: "Axure Components",
428
+ },
429
+ {
430
+ value: "sketch",
431
+ label: "Sketch Templates",
432
+ },
433
+ {
434
+ value: "jiaohu",
435
+ label: "组件交互文档",
436
+ },
437
+ ],
438
+ },
439
+ ],
440
+ },
441
+ ],
442
+
443
+ //rules为表单校验规则,每个组件都可以传入
444
+
445
+ //input支持template,支持以下几个属性:
446
+ //prefix 输入框头部内容,只对 type="text"(默认) 有效
447
+ //suffix 输入框尾部内容,只对 type="text" 有效
448
+ //prepend 输入框前置内容,只对 type="text" 有效
449
+ //append 输入框后置内容,只对 type="text" 有效
450
+
451
+ //divider支持template:
452
+ //default
453
+
454
+ 支持组件 type:
455
+
456
+ /**
457
+ * @description: 输入框
458
+ * @return {*}
459
+ */
460
+ "input" = "input",
461
+ /**
462
+ * @description: 表单中的多维列表,可增减元素
463
+ * @return {*}
464
+ */
465
+ "form-list" = "form-list",
466
+ /**
467
+ * @description: 分割线
468
+ * @return {*}
469
+ */
470
+ "divider" = "divider",
471
+ /**
472
+ * @description: 选择器
473
+ * @return {*}
474
+ */
475
+ "select" = "select",
476
+ /**
477
+ * @description: 级联选择器
478
+ * @return {*}
479
+ */
480
+ "cascader" = "cascader",
481
+ /**
482
+ * @description: 日期选择器
483
+ * @return {*}
484
+ */
485
+ "date-picker" = "date-picker",
486
+ /**
487
+ * @description: 数字输入框
488
+ * @return {*}
489
+ */
490
+ "input-number" = "input-number",
491
+ /**
492
+ * @description: 单选框
493
+ * @return {*}
494
+ */
495
+ "radio" = "radio",
496
+
497
+ /**
498
+ * @description: 多选框
499
+ * @return {*}
500
+ */
501
+ "checkbox" = "checkbox",
502
+
503
+ # VInfiniteScrollList 对虚拟滚动列表+接口的封装
504
+
505
+ ![image-20231208165229296](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202312081652392.png)
506
+
507
+ ```
508
+ import { VInfiniteScrollList } from 'general-basic-form'
509
+ import 'general-basic-form/style'
510
+ <VInfiniteScrollList
511
+ :search="search"
512
+ id="user_id"
513
+ name="name"
514
+ ref="InfiniteScrollListRef"
515
+ checkbox
516
+ :extra="extraRender"
517
+ :max="1"
518
+ />
519
+ ```
520
+
521
+ ```
522
+ 移动端配合下拉刷新使用
523
+ import { getOrderItem } from "../orderItem/functional"
524
+ // getOrderItem为JSX函数,返回一个VUE组件
525
+
526
+ <t-pull-down-refresh v-model="refreshing" @refresh="onRefresh" class="refresh-content">
527
+ <VInfiniteScrollList :search="loadData" :checkbox="false" id="cancelId" ref="InfiniteScrollListRef" checkbox
528
+ :extra="getOrderItem" height="100%" infinite-scroll-distance="50"/>
529
+ </t-pull-down-refresh>
530
+ ```
531
+
532
+ ```
533
+ search:数据接口 (page: Number) => Promise<[]>
534
+ id:数据key值(唯一和选择值)
535
+ name:显示名字
536
+ checkbox:是否有多选功能,不传的话就是单纯的虚拟滚动列表
537
+ extra:同行额外显示的内容,(item: any) => VNode | String;
538
+ //el-checkbox有固定高度,如果需要配置高度比较高,例如有换行的自定义extra,最好处理一下样式,例子:
539
+ //:deep(.el-checkbox) {
540
+ // padding: 6px 16px !important;
541
+ // display: flex;
542
+ // align-items: baseline;
543
+ // height: auto;
544
+ //}
545
+ defaultSelection:包含数据key值的对象数组或者直接传入key值数组
546
+ height:默认272px String
547
+ ```
548
+
549
+ ```
550
+ defineExpose({ reset, loadList, selectInfo, list, ifbottom });
551
+ InfiniteScrollListRef?.value?.reset():重置列表内容
552
+ InfiniteScrollListRef?.value?.lowReset():重置列表内容,但保留已选择的选项
553
+ InfiniteScrollListRef?.value?.loadList():向下滚动列表内容,受到loading和ifbottom的影响
554
+ InfiniteScrollListRef?.value?.refreshList():刷新列表,滚动列表会对整个内容重新请求数据,已选择的内容会自动选择
555
+ InfiniteScrollListRef?.value?.selectInfo:选择的内容
556
+ InfiniteScrollListRef?.value?.list:列表的内容
557
+ InfiniteScrollListRef?.value?.ifbottom:是否到底部
558
+ InfiniteScrollListRef?.value?.loading:加载中
559
+ ```
560
+
561
+ # VDescriptions 对展示描述列表的封装
562
+
563
+ ![image-20231208182455415](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202312081824708.png)
564
+
565
+ ```
566
+ import { VDescriptions } from 'general-basic-form'
567
+ <VDescriptions
568
+ :formData="props.formData"
569
+ :formItem="formItem"
570
+ componentType="Ant Design Vue"
571
+ ...其他el-descriptions的配置
572
+ />
573
+ ```
574
+
575
+ ```
576
+ formData:Object
577
+ formItem:[ {
578
+ label: '受访人',
579
+ prop: 'contactors',
580
+ render: (scope: any) => {
581
+ const { $index, row = {} } = scope
582
+ const { contactors = [] } = row
583
+ const ele = (contactors.length > 0 ? <span>{contactors.map((item: any) => item.name).join(",")} </span> : null)
584
+ return ele
585
+ }
586
+ },
587
+ {
588
+ label: '拜访详情',
589
+ prop: 'detail',
590
+ descriptionsItemProps:{
591
+ 'label-class-name': 'label-class-name'
592
+ }
593
+ }]
594
+ componentType:"Ant Design Vue"|"Element Plus"(默认)
595
+ strict:Boolean //使用strict参数后,如果formData内的某个字段没有值,对应的描述元素将不会展示(包括标签文字),但有render的字段仍然会展示
596
+ descriptionsItemProps:a-descriptions-item|el-descriptions-item的配置
597
+ ```
598
+
599
+ # VInputMobilecVerification,VInputGraphicVerification 表单里的图形验证码、手机验证码组件,可以单独引入
600
+
601
+ ```
602
+ <VInputGraphicVerification :item="{同表单,可忽略label和rules字段}" :loading="loading"></VInputGraphicVerification>
603
+
604
+ <VInputMobilecVerification :item="{同表单,可忽略label和rules字段}" componentType="Ant Design Vue" ref="VInputMobilecVerificationRef"></VInputMobilecVerification>
605
+ ```
606
+
607
+ ```
608
+ componentType:"Ant Design Vue"|"Element Plus"(默认)
609
+ ```
610
+
611
+ ```
612
+ 此用法下必须提供:
613
+ provide(/* 注入名 */ "queryParams", /* 表单值对象 */ queryParams);
614
+
615
+ componentType为Ant Design Vue需要提供:
616
+ import { Form } from 'ant-design-vue';
617
+ provide(/* 注入名 */ "Form", /* Ant Design Vue Form实例,用于表单数据更新等 */ Form);
618
+
619
+ 可选:
620
+ provide("size", size); // 同组件size
621
+ provide("getList", getList); // 输入框回车触发
622
+
623
+ 调用发送短信验证码和重置的方法
624
+ VInputMobilecVerificationRef.value.VerificationButtonRef.buttonClick()
625
+ VInputMobilecVerificationRef.value.VerificationButtonRef.reset()
626
+ ```
627
+
628
+ # VTreeTransfer 树形数据穿梭框
629
+
630
+ ![image-20250425183446375](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202504251834575.png)
631
+
632
+ ```
633
+ <VTreeTransfer :dataSource="classmate" :treeAttributes="{
634
+ 'node-key': 'user_id', props: { label: 'user_name' }, 'default-expand-all': false
635
+ }" transferTitleRight="白名单(不会被选中)" transferTitleLeft="普通名单" filterable :checkedKeys="checkedKeys">
636
+ </VTreeTransfer>
637
+
638
+ import { VTreeTransfer } from 'general-basic-form';
639
+ const VTreeTransferRef = ref([])
640
+ ```
641
+
642
+ ```
643
+ dataSource:[
644
+ {
645
+ label: 'Level one 1',
646
+ id:1,
647
+ children: [
648
+ {
649
+ label: 'Level two 1-1',
650
+ id:2,
651
+ children: [
652
+ {
653
+ label: 'Level three 1-1-1',
654
+ id:3,
655
+ },
656
+ ],
657
+ },
658
+ ],
659
+ },] 树状结构数据
660
+ treeAttributes:{} 树形控件的属性,见https://element-plus.org/zh-CN/component/tree.html
661
+ transferTitleLeft:"" 左标题
662
+ transferTitleRight:"" 右标题
663
+ filterable:false 是否显示搜索框
664
+ checkedKeys:[1,2] 选中的值
665
+
666
+ 获取选中的数组详情:
667
+ VTreeTransferRef.value["selectedList"].map((item) => {}))
668
+ ```