hy-app 0.4.13 → 0.5.0
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/components/hy-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,61 +1,68 @@
|
|
|
1
|
-
export interface FormRule {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface FormItemRule {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default interface HyFormSimpleProps {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
1
|
+
export interface FormRule {
|
|
2
|
+
/**
|
|
3
|
+
* 是否必填
|
|
4
|
+
*/
|
|
5
|
+
required?: boolean
|
|
6
|
+
/**
|
|
7
|
+
* 验证失败时的提示信息
|
|
8
|
+
*/
|
|
9
|
+
message?: string
|
|
10
|
+
/**
|
|
11
|
+
* 自定义验证函数
|
|
12
|
+
*/
|
|
13
|
+
validator?: (value: any) => boolean | string
|
|
14
|
+
/**
|
|
15
|
+
* 触发验证的时机
|
|
16
|
+
*/
|
|
17
|
+
trigger?: ('blur' | 'change')[]
|
|
18
|
+
/**
|
|
19
|
+
* 最小长度
|
|
20
|
+
*/
|
|
21
|
+
min?: number
|
|
22
|
+
/**
|
|
23
|
+
* 最大长度
|
|
24
|
+
*/
|
|
25
|
+
max?: number
|
|
26
|
+
/**
|
|
27
|
+
* 验证类型
|
|
28
|
+
*/
|
|
29
|
+
type?: 'phone' | 'email' | 'password'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FormItemRule {
|
|
33
|
+
[key: string]: FormRule | FormRule[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default interface HyFormSimpleProps {
|
|
37
|
+
/**
|
|
38
|
+
* 表单数据对象
|
|
39
|
+
*/
|
|
40
|
+
model?: Record<string, any>
|
|
41
|
+
/**
|
|
42
|
+
* 验证规则
|
|
43
|
+
*/
|
|
44
|
+
rules?: FormItemRule
|
|
45
|
+
/**
|
|
46
|
+
* 标签宽度
|
|
47
|
+
*/
|
|
48
|
+
labelWidth?: string | number
|
|
49
|
+
/**
|
|
50
|
+
* 标签位置
|
|
51
|
+
*/
|
|
52
|
+
labelPosition?: 'left' | 'top'
|
|
53
|
+
/**
|
|
54
|
+
* 标签对齐方式
|
|
55
|
+
*/
|
|
56
|
+
labelAlign?: 'left' | 'center' | 'right'
|
|
57
|
+
/**
|
|
58
|
+
* 表单列底部边框
|
|
59
|
+
* */
|
|
60
|
+
border: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IFormEmits {
|
|
64
|
+
/** 提交表单 */
|
|
65
|
+
(e: 'submit', data: FormRule): void
|
|
66
|
+
/** 表单校验 */
|
|
67
|
+
(e: 'validate', valid: boolean, errors: AnyObject): void
|
|
68
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import type { FormColumnsType } from
|
|
2
|
-
import type HyInputProps from
|
|
3
|
-
import type HyTextareaProps from
|
|
4
|
-
import type HySwitchProps from
|
|
5
|
-
import type HyPickerProps from
|
|
6
|
-
import type HyRadioProps from
|
|
7
|
-
import type HyCheckButtonProps from
|
|
1
|
+
import type { FormColumnsType } from '../../libs'
|
|
2
|
+
import type HyInputProps from '../hy-input/typing'
|
|
3
|
+
import type HyTextareaProps from '../hy-textarea/typing'
|
|
4
|
+
import type HySwitchProps from '../hy-switch/typing'
|
|
5
|
+
import type HyPickerProps from '../hy-picker/typing'
|
|
6
|
+
import type HyRadioProps from '../hy-radio/typing'
|
|
7
|
+
import type HyCheckButtonProps from '../hy-check-button/typing'
|
|
8
8
|
|
|
9
9
|
export default interface HyFormProps {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @description 表单域提示文字的位置
|
|
12
|
+
* left - 左侧
|
|
13
|
+
* top - 上方
|
|
14
|
+
* */
|
|
15
|
+
labelPosition?: 'left' | 'top'
|
|
16
|
+
/**
|
|
17
|
+
* @description label宽度
|
|
18
|
+
* 数字 - 固定值
|
|
19
|
+
* auto - 自适应
|
|
20
|
+
* */
|
|
21
|
+
labelWidth?: string | number
|
|
22
|
+
/**
|
|
23
|
+
* @description 是否右对齐
|
|
24
|
+
* */
|
|
25
|
+
right?: boolean
|
|
26
|
+
/**
|
|
27
|
+
* @description label字体的对齐方式
|
|
28
|
+
* left - 左对齐
|
|
29
|
+
* center - 中间对齐
|
|
30
|
+
* right - 右对齐
|
|
31
|
+
* */
|
|
32
|
+
labelAlign?: HyApp.RowCenterType
|
|
33
|
+
/**
|
|
34
|
+
* @description 显示冒号符号
|
|
35
|
+
* */
|
|
36
|
+
symbol?: boolean
|
|
37
|
+
/**
|
|
38
|
+
* @description 显示底部下划线
|
|
39
|
+
* */
|
|
40
|
+
borderBottom?: boolean
|
|
41
|
+
/**
|
|
42
|
+
* @description 当行内容高度
|
|
43
|
+
* */
|
|
44
|
+
itemHeight?: number | string
|
|
45
|
+
/**
|
|
46
|
+
* @description 输入框属性api集合
|
|
47
|
+
* */
|
|
48
|
+
input?: Partial<HyInputProps>
|
|
49
|
+
/**
|
|
50
|
+
* @description 文本域属性api集合
|
|
51
|
+
* */
|
|
52
|
+
textarea?: Partial<HyTextareaProps>
|
|
53
|
+
/**
|
|
54
|
+
* @description 选择器属性api集合
|
|
55
|
+
* */
|
|
56
|
+
picker?: Partial<HyPickerProps>
|
|
57
|
+
/**
|
|
58
|
+
* @description 开关属性api集合
|
|
59
|
+
* */
|
|
60
|
+
switchItem?: Partial<HySwitchProps>
|
|
61
|
+
/**
|
|
62
|
+
* @description 单选属性api集合
|
|
63
|
+
* */
|
|
64
|
+
radio?: Partial<HyRadioProps>
|
|
65
|
+
/**
|
|
66
|
+
* @description 选择按钮属性api集合
|
|
67
|
+
* */
|
|
68
|
+
checkButton?: Partial<HyCheckButtonProps>
|
|
69
|
+
/**
|
|
70
|
+
* @description 表单配置
|
|
71
|
+
* */
|
|
72
|
+
columns: FormColumnsType[]
|
|
73
|
+
/**
|
|
74
|
+
* @description 表单值
|
|
75
|
+
* */
|
|
76
|
+
formData: Record<string, any>
|
|
77
77
|
}
|
|
@@ -1,135 +1,106 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
<view class="hy-form-item" :class="[`hy-form-item--${labelPosition}`]">
|
|
3
|
+
<view v-if="label" class="hy-form-item__label" :style="labelStyle">
|
|
4
|
+
<text v-if="isRequired" class="hy-form-item__label--required">*</text>
|
|
5
|
+
{{ label }}
|
|
6
|
+
</view>
|
|
7
|
+
<view :class="['hy-form-item__content', formContext.border && 'hy-border__bottom']">
|
|
8
|
+
<slot></slot>
|
|
9
|
+
</view>
|
|
10
|
+
<view v-if="errorMessage" class="hy-form-item__error">
|
|
11
|
+
{{ errorMessage }}
|
|
12
|
+
</view>
|
|
6
13
|
</view>
|
|
7
|
-
<view
|
|
8
|
-
:class="[
|
|
9
|
-
'hy-form-item__content',
|
|
10
|
-
formContext.border && 'hy-border__bottom',
|
|
11
|
-
]"
|
|
12
|
-
>
|
|
13
|
-
<slot></slot>
|
|
14
|
-
</view>
|
|
15
|
-
<view v-if="errorMessage" class="hy-form-item__error">
|
|
16
|
-
{{ errorMessage }}
|
|
17
|
-
</view>
|
|
18
|
-
</view>
|
|
19
14
|
</template>
|
|
20
15
|
|
|
21
16
|
<script lang="ts">
|
|
22
17
|
export default {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
18
|
+
name: 'hy-form-item',
|
|
19
|
+
options: {
|
|
20
|
+
addGlobalClass: true,
|
|
21
|
+
virtualHost: true,
|
|
22
|
+
styleIsolation: 'shared'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
30
25
|
</script>
|
|
31
26
|
|
|
32
27
|
<script setup lang="ts">
|
|
33
|
-
import { computed, inject, onMounted, onUnmounted, provide, ref } from
|
|
34
|
-
import type {
|
|
35
|
-
import
|
|
36
|
-
import
|
|
28
|
+
import { computed, inject, onMounted, onUnmounted, provide, ref } from 'vue'
|
|
29
|
+
import type { IFormItemEmits, IFormContext } from './typing'
|
|
30
|
+
import { addUnit } from '../../libs'
|
|
31
|
+
import formItemProps from './props'
|
|
37
32
|
|
|
38
33
|
/**
|
|
39
34
|
* 表单组件子组件,需要搭配hy-form
|
|
40
35
|
* @displayName hy-form-item
|
|
41
36
|
*/
|
|
42
|
-
defineOptions({})
|
|
43
|
-
|
|
44
|
-
const props = defineProps(
|
|
45
|
-
|
|
46
|
-
* 标签文本
|
|
47
|
-
*/
|
|
48
|
-
label: String,
|
|
49
|
-
/**
|
|
50
|
-
* 表单字段名
|
|
51
|
-
*/
|
|
52
|
-
prop: String,
|
|
53
|
-
/**
|
|
54
|
-
* 是否必填
|
|
55
|
-
*/
|
|
56
|
-
required: {
|
|
57
|
-
type: Boolean,
|
|
58
|
-
default: false,
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* 验证规则
|
|
62
|
-
*/
|
|
63
|
-
rules: Object as PropType<any>,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const emit = defineEmits<{
|
|
67
|
-
change: [value: any];
|
|
68
|
-
blur: [value: any];
|
|
69
|
-
}>();
|
|
37
|
+
defineOptions({})
|
|
38
|
+
|
|
39
|
+
const props = defineProps(formItemProps)
|
|
40
|
+
const emit = defineEmits<IFormItemEmits>()
|
|
70
41
|
|
|
71
42
|
// 注入表单上下文
|
|
72
|
-
const formContext = inject<IFormContext>(
|
|
43
|
+
const formContext = inject<IFormContext>('formContext')
|
|
73
44
|
const formItem = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
45
|
+
// 处理子组件事件
|
|
46
|
+
handleChange(value: any) {
|
|
47
|
+
if (props.prop && formContext) {
|
|
48
|
+
formContext.setFieldValue(props.prop, value)
|
|
49
|
+
validate('change')
|
|
50
|
+
}
|
|
51
|
+
emit('change', value)
|
|
52
|
+
},
|
|
53
|
+
handleBlur(value: any) {
|
|
54
|
+
if (props.prop && formContext) {
|
|
55
|
+
validate('blur')
|
|
56
|
+
}
|
|
57
|
+
emit('blur', value)
|
|
85
58
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
provide("formItem", formItem);
|
|
59
|
+
}
|
|
60
|
+
provide('formItem', formItem)
|
|
90
61
|
|
|
91
62
|
// 当前组件的引用
|
|
92
|
-
const formItemRef = ref()
|
|
63
|
+
const formItemRef = ref()
|
|
93
64
|
|
|
94
65
|
// 错误信息
|
|
95
66
|
const errorMessage = computed(() => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
67
|
+
if (!formContext || !props.prop) return ''
|
|
68
|
+
return formContext.errors[props.prop] || ''
|
|
69
|
+
})
|
|
99
70
|
|
|
100
71
|
// 是否必填
|
|
101
72
|
const isRequired = computed(() => {
|
|
102
|
-
|
|
103
|
-
|
|
73
|
+
if (props.required) return true
|
|
74
|
+
if (!formContext || !props.prop) return false
|
|
104
75
|
|
|
105
|
-
|
|
106
|
-
|
|
76
|
+
const fieldRules = formContext.rules?.value?.[props.prop]
|
|
77
|
+
if (!fieldRules) return false
|
|
107
78
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
79
|
+
const rules = Array.isArray(fieldRules) ? fieldRules : [fieldRules]
|
|
80
|
+
return rules.some((rule) => rule.required)
|
|
81
|
+
})
|
|
111
82
|
|
|
112
83
|
// 标签样式
|
|
113
84
|
const labelStyle = computed(() => {
|
|
114
|
-
|
|
85
|
+
if (!formContext) return {}
|
|
115
86
|
|
|
116
|
-
|
|
87
|
+
const style: Record<string, any> = {}
|
|
117
88
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
89
|
+
if (formContext.labelWidth?.value !== 'auto') {
|
|
90
|
+
style.width = addUnit(formContext.labelWidth?.value)
|
|
91
|
+
}
|
|
121
92
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
93
|
+
if (formContext.labelAlign?.value) {
|
|
94
|
+
style.textAlign = formContext.labelAlign.value
|
|
95
|
+
}
|
|
125
96
|
|
|
126
|
-
|
|
127
|
-
})
|
|
97
|
+
return style
|
|
98
|
+
})
|
|
128
99
|
|
|
129
100
|
// 标签位置
|
|
130
101
|
const labelPosition = computed(() => {
|
|
131
|
-
|
|
132
|
-
})
|
|
102
|
+
return formContext?.labelPosition?.value || 'left'
|
|
103
|
+
})
|
|
133
104
|
|
|
134
105
|
// 监听表单数据变化
|
|
135
106
|
// watch(
|
|
@@ -144,60 +115,60 @@ const labelPosition = computed(() => {
|
|
|
144
115
|
// )
|
|
145
116
|
|
|
146
117
|
// 验证字段
|
|
147
|
-
const validate = (trigger?:
|
|
148
|
-
|
|
118
|
+
const validate = (trigger?: 'blur' | 'change') => {
|
|
119
|
+
if (!formContext || !props.prop) return true
|
|
149
120
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
121
|
+
const value = formContext.getFieldValue(props.prop)
|
|
122
|
+
return formContext.validateField(props.prop, value, trigger)
|
|
123
|
+
}
|
|
153
124
|
|
|
154
125
|
// 重置字段
|
|
155
126
|
const resetField = () => {
|
|
156
|
-
|
|
127
|
+
if (!formContext || !props.prop) return
|
|
157
128
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
129
|
+
formContext.setFieldValue(props.prop, undefined)
|
|
130
|
+
formContext.validateField(props.prop, undefined)
|
|
131
|
+
}
|
|
161
132
|
|
|
162
133
|
// 清除验证
|
|
163
134
|
const clearValidate = () => {
|
|
164
|
-
|
|
135
|
+
if (!formContext || !props.prop) return
|
|
165
136
|
|
|
166
|
-
|
|
167
|
-
}
|
|
137
|
+
delete formContext.errors[props.prop]
|
|
138
|
+
}
|
|
168
139
|
|
|
169
140
|
// 组件挂载时注册到表单
|
|
170
141
|
onMounted(() => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
})
|
|
142
|
+
if (formContext) {
|
|
143
|
+
formContext.addFormItem({
|
|
144
|
+
props: props,
|
|
145
|
+
validate,
|
|
146
|
+
resetField,
|
|
147
|
+
clearValidate
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
})
|
|
180
151
|
|
|
181
152
|
// 组件卸载时从表单中移除
|
|
182
153
|
onUnmounted(() => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
})
|
|
154
|
+
if (formContext) {
|
|
155
|
+
formContext.removeFormItem({
|
|
156
|
+
props: props,
|
|
157
|
+
validate,
|
|
158
|
+
resetField,
|
|
159
|
+
clearValidate
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
})
|
|
192
163
|
|
|
193
164
|
// 暴露方法给父组件
|
|
194
165
|
defineExpose({
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
})
|
|
166
|
+
validate,
|
|
167
|
+
resetField,
|
|
168
|
+
clearValidate
|
|
169
|
+
})
|
|
199
170
|
</script>
|
|
200
171
|
|
|
201
172
|
<style lang="scss" scoped>
|
|
202
|
-
@import
|
|
173
|
+
@import './index.scss';
|
|
203
174
|
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
const formItemProps = {
|
|
4
|
+
/**
|
|
5
|
+
* 标签文本
|
|
6
|
+
*/
|
|
7
|
+
label: String,
|
|
8
|
+
/**
|
|
9
|
+
* 表单字段名
|
|
10
|
+
*/
|
|
11
|
+
prop: String,
|
|
12
|
+
/**
|
|
13
|
+
* 是否必填
|
|
14
|
+
*/
|
|
15
|
+
required: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* 验证规则
|
|
21
|
+
*/
|
|
22
|
+
rules: Object as PropType<any>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default formItemProps
|