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,127 +1,127 @@
|
|
|
1
|
-
import type { CSSProperties } from
|
|
1
|
+
import type { CSSProperties } from 'vue'
|
|
2
2
|
|
|
3
3
|
export default interface HySwiperProps {
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @description 轮播图数据
|
|
6
|
+
* */
|
|
7
|
+
list: (string | Record<string, unknown>)[]
|
|
8
|
+
/**
|
|
9
|
+
* @description list数组中指定对象的目标属性名(默认 'url' )
|
|
10
|
+
* */
|
|
11
|
+
keyName?: string
|
|
12
|
+
/**
|
|
13
|
+
* @description 是否显示面板指示器(默认 false )
|
|
14
|
+
* */
|
|
15
|
+
indicator?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* @description 指示器非激活颜色(默认 '#FFFFFF' )
|
|
18
|
+
* */
|
|
19
|
+
indicatorActiveColor?: string
|
|
20
|
+
/**
|
|
21
|
+
* @description 指示器的激活颜色(默认 'rgba(255, 255, 255, 0.35)' )
|
|
22
|
+
* */
|
|
23
|
+
indicatorInactiveColor?: string
|
|
24
|
+
/**
|
|
25
|
+
* @description 指示器样式,可通过bottom,left,right进行定位
|
|
26
|
+
* */
|
|
27
|
+
indicatorStyle?: CSSProperties
|
|
28
|
+
/**
|
|
29
|
+
* @description 指示器模式(默认 'line' )
|
|
30
|
+
* */
|
|
31
|
+
indicatorMode?: HyApp.SwiperIndicatorModeType
|
|
32
|
+
/**
|
|
33
|
+
* @description 是否自动切换(默认 true )
|
|
34
|
+
* */
|
|
35
|
+
autoplay?: boolean
|
|
36
|
+
/**
|
|
37
|
+
* @description 当前所在滑块的 index(默认 0 )
|
|
38
|
+
* */
|
|
39
|
+
current?: number | string
|
|
40
|
+
/**
|
|
41
|
+
* @description 当前所在滑块的 item-id ,不能与 current 被同时指定
|
|
42
|
+
* */
|
|
43
|
+
currentItemId?: string
|
|
44
|
+
/**
|
|
45
|
+
* @description 滑块自动切换时间间隔(ms)(默认 3000 )
|
|
46
|
+
* */
|
|
47
|
+
interval?: number
|
|
48
|
+
/**
|
|
49
|
+
* @description 滑块切换过程所需时间(ms)(默认 300 )
|
|
50
|
+
* */
|
|
51
|
+
duration?: number
|
|
52
|
+
/**
|
|
53
|
+
* @description 播放到末尾后是否重新回到开头(默认 false )
|
|
54
|
+
* */
|
|
55
|
+
circular?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* @description 前边距,可用于露出前一项的一小部分,nvue和支付宝不支持(默认 0 )
|
|
58
|
+
* */
|
|
59
|
+
previousMargin?: number | string
|
|
60
|
+
/**
|
|
61
|
+
* @description 后边距,可用于露出后一项的一小部分,nvue和支付宝不支持(默认 0 )
|
|
62
|
+
* */
|
|
63
|
+
nextMargin?: number | string
|
|
64
|
+
/**
|
|
65
|
+
* @description 当开启时,会根据滑动速度,连续滑动多屏,支付宝不支持(默认 false )
|
|
66
|
+
* */
|
|
67
|
+
acceleration?: boolean
|
|
68
|
+
/**
|
|
69
|
+
* @description 同时显示的滑块数量,nvue、支付宝小程序不支持(默认 1 )
|
|
70
|
+
* */
|
|
71
|
+
displayMultipleItems?: number
|
|
72
|
+
/**
|
|
73
|
+
* @description 指定swiper切换缓动动画类型, 只对微信小程序有效(默认 'default' )
|
|
74
|
+
* */
|
|
75
|
+
easingFunction?: string
|
|
76
|
+
/**
|
|
77
|
+
* @description 图片的裁剪模式(默认 'aspectFill' )
|
|
78
|
+
* */
|
|
79
|
+
imgMode?: HyApp.ImageModeVo
|
|
80
|
+
/**
|
|
81
|
+
* @description 组件高度(默认 130 )
|
|
82
|
+
* */
|
|
83
|
+
height?: number
|
|
84
|
+
/**
|
|
85
|
+
* @description 背景颜色(默认 '#f3f4f6' )
|
|
86
|
+
* */
|
|
87
|
+
bgColor?: string
|
|
88
|
+
/**
|
|
89
|
+
* @description 组件圆角,数值或带单位的字符串(默认 4 )
|
|
90
|
+
* */
|
|
91
|
+
radius?: number | string
|
|
92
|
+
/**
|
|
93
|
+
* @description 是否加载中(默认 false )
|
|
94
|
+
* */
|
|
95
|
+
loading?: boolean
|
|
96
|
+
/**
|
|
97
|
+
* @description 是否显示标题,要求数组对象中有title属性(默认 false )
|
|
98
|
+
* */
|
|
99
|
+
showTitle?: boolean
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export interface SwiperList {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
[key: string]: any
|
|
104
|
+
/** 线上地址 */
|
|
105
|
+
url?: string
|
|
106
|
+
/** 标题 */
|
|
107
|
+
title?: string
|
|
108
|
+
/** 海报,为视频必填 */
|
|
109
|
+
poster?: string
|
|
110
|
+
/** 轮播图展示类型 */
|
|
111
|
+
type?: 'image' | 'video'
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
export interface SwiperVo {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
detail: {
|
|
116
|
+
current: number
|
|
117
|
+
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export interface ISwiperEmits {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
/** 点击轮播图触发 */
|
|
122
|
+
(e: 'click', index: number): void
|
|
123
|
+
/** 滑动轮播图触发 */
|
|
124
|
+
(e: 'change', temp: SwiperVo['detail']): void
|
|
125
|
+
/** 滑动轮播图触发 */
|
|
126
|
+
(e: 'update:current', value: string | number): void
|
|
127
127
|
}
|
|
@@ -1,237 +1,173 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view
|
|
3
|
-
:class="[
|
|
4
|
-
'hy-switch cursor-pointer',
|
|
5
|
-
disabled && 'hy-switch__disabled',
|
|
6
|
-
isActive ? 'hy-switch__active' : 'hy-switch__container',
|
|
7
|
-
customClass,
|
|
8
|
-
]"
|
|
9
|
-
:style="[switchStyle, customStyle]"
|
|
10
|
-
@tap="clickHandler"
|
|
11
|
-
>
|
|
12
|
-
<view class="hy-switch__bg" :style="[bgStyle]"></view>
|
|
13
2
|
<view
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
:class="[
|
|
4
|
+
'hy-switch cursor-pointer',
|
|
5
|
+
disabled && 'hy-switch__disabled',
|
|
6
|
+
isActive ? 'hy-switch__active' : 'hy-switch__container',
|
|
7
|
+
customClass
|
|
8
|
+
]"
|
|
9
|
+
:style="[switchStyle, customStyle]"
|
|
10
|
+
@tap="clickHandler"
|
|
17
11
|
>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
<view class="hy-switch__bg" :style="[bgStyle]"></view>
|
|
13
|
+
<view
|
|
14
|
+
:class="['hy-switch__node', modelValue && 'hy-switch__node--on']"
|
|
15
|
+
:style="[nodeStyle]"
|
|
16
|
+
ref="hy-switch__node"
|
|
17
|
+
>
|
|
18
|
+
<hy-loading :show="loading" :size="switchSize * 0.6" mode="circle"></hy-loading>
|
|
19
|
+
<view class="" v-if="!loading">
|
|
20
|
+
<slot>
|
|
21
|
+
<hy-icon
|
|
22
|
+
:name="modelValue ? activeIcon : inactiveIcon"
|
|
23
|
+
:size="icon?.size || switchSize * 0.6"
|
|
24
|
+
:color="icon?.color"
|
|
25
|
+
:bold="icon?.bold"
|
|
26
|
+
:customPrefix="icon?.customPrefix"
|
|
27
|
+
:imgMode="icon?.imgMode"
|
|
28
|
+
:width="icon?.width"
|
|
29
|
+
:height="icon?.height"
|
|
30
|
+
:top="icon?.top"
|
|
31
|
+
:stop="icon?.stop"
|
|
32
|
+
:round="icon?.round"
|
|
33
|
+
:customStyle="icon?.customStyle"
|
|
34
|
+
></hy-icon>
|
|
35
|
+
</slot>
|
|
36
|
+
</view>
|
|
37
|
+
</view>
|
|
41
38
|
</view>
|
|
42
|
-
</view>
|
|
43
39
|
</template>
|
|
44
40
|
|
|
45
41
|
<script lang="ts">
|
|
46
42
|
export default {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
43
|
+
name: 'hy-switch',
|
|
44
|
+
options: {
|
|
45
|
+
addGlobalClass: true,
|
|
46
|
+
virtualHost: true,
|
|
47
|
+
styleIsolation: 'shared'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
54
50
|
</script>
|
|
55
51
|
|
|
56
52
|
<script setup lang="ts">
|
|
57
|
-
import { watch, nextTick, computed } from
|
|
58
|
-
import type { CSSProperties
|
|
59
|
-
import { addUnit, error, isNumber } from
|
|
60
|
-
import type { ISwitchEmits
|
|
53
|
+
import { watch, nextTick, computed } from 'vue'
|
|
54
|
+
import type { CSSProperties } from 'vue'
|
|
55
|
+
import { addUnit, error, isNumber } from '../../libs'
|
|
56
|
+
import type { ISwitchEmits } from './typing'
|
|
57
|
+
import switchProps from './props'
|
|
61
58
|
// 组件
|
|
62
|
-
import HyLoading from
|
|
63
|
-
import HyIcon from
|
|
64
|
-
import type HyIconProps from "../hy-icon/typing";
|
|
59
|
+
import HyLoading from '../hy-loading/hy-loading.vue'
|
|
60
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* 选择开关用于在打开和关闭状态之间进行切换。
|
|
68
64
|
* @displayName hy-switch
|
|
69
65
|
*/
|
|
70
|
-
defineOptions({})
|
|
66
|
+
defineOptions({})
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
/** 通过v-model双向绑定的值 */
|
|
75
|
-
modelValue: {
|
|
76
|
-
type: [String, Number, Boolean] as PropType<SwiperValue>,
|
|
77
|
-
default: false,
|
|
78
|
-
},
|
|
79
|
-
/** 是否处于加载中 */
|
|
80
|
-
loading: {
|
|
81
|
-
type: Boolean,
|
|
82
|
-
default: false,
|
|
83
|
-
},
|
|
84
|
-
/** 是否禁用 */
|
|
85
|
-
disabled: {
|
|
86
|
-
type: Boolean,
|
|
87
|
-
default: false,
|
|
88
|
-
},
|
|
89
|
-
/** 开关尺寸,单位px */
|
|
90
|
-
size: {
|
|
91
|
-
type: [String, Number] as PropType<string | number>,
|
|
92
|
-
default: "medium",
|
|
93
|
-
},
|
|
94
|
-
/** 打开时的背景色 */
|
|
95
|
-
activeColor: String,
|
|
96
|
-
/** 关闭时的背景色 */
|
|
97
|
-
inactiveColor: String,
|
|
98
|
-
/** 打开选择器时通过change事件发出的值 */
|
|
99
|
-
activeValue: {
|
|
100
|
-
type: [String, Number, Boolean] as PropType<SwiperValue>,
|
|
101
|
-
default: true,
|
|
102
|
-
},
|
|
103
|
-
/** 关闭选择器时通过change事件发出的值 */
|
|
104
|
-
inactiveValue: {
|
|
105
|
-
type: [String, Number, Boolean] as PropType<SwiperValue>,
|
|
106
|
-
default: false,
|
|
107
|
-
},
|
|
108
|
-
/** 打开选择器时图标 */
|
|
109
|
-
activeIcon: String,
|
|
110
|
-
/** 关闭选择器时图标 */
|
|
111
|
-
inactiveIcon: String,
|
|
112
|
-
/** 图标 */
|
|
113
|
-
icon: Object as unknown as PropType<HyIconProps>,
|
|
114
|
-
/** 是否开启异步变更,开启后需要手动控制输入值 */
|
|
115
|
-
asyncChange: {
|
|
116
|
-
type: Boolean,
|
|
117
|
-
default: false,
|
|
118
|
-
},
|
|
119
|
-
/** 圆点与外边框的距离 */
|
|
120
|
-
space: {
|
|
121
|
-
type: Number,
|
|
122
|
-
default: 0,
|
|
123
|
-
},
|
|
124
|
-
/** 定义需要用到的外部样式 */
|
|
125
|
-
customStyle: Object as PropType<CSSProperties>,
|
|
126
|
-
/** 自定义外部类名 */
|
|
127
|
-
customClass: String,
|
|
128
|
-
});
|
|
129
|
-
const emit = defineEmits<ISwitchEmits>();
|
|
68
|
+
const props = defineProps(switchProps)
|
|
69
|
+
const emit = defineEmits<ISwitchEmits>()
|
|
130
70
|
|
|
131
71
|
watch(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
)
|
|
72
|
+
() => props.modelValue,
|
|
73
|
+
(newValue) => {
|
|
74
|
+
if (newValue !== props.inactiveValue && newValue !== props.activeValue) {
|
|
75
|
+
error('v-model绑定的值必须为inactiveValue、activeValue二者之一')
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{ immediate: true }
|
|
79
|
+
)
|
|
140
80
|
|
|
141
81
|
/**
|
|
142
82
|
* @description 是否打开
|
|
143
83
|
* */
|
|
144
84
|
const isActive = computed(() => {
|
|
145
|
-
|
|
146
|
-
})
|
|
85
|
+
return props.modelValue === props.activeValue
|
|
86
|
+
})
|
|
147
87
|
|
|
148
88
|
/**
|
|
149
89
|
* @description 设置开关大小
|
|
150
90
|
* */
|
|
151
91
|
const switchSize = computed((): number => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
92
|
+
const sz: AnyObject = {
|
|
93
|
+
small: 20,
|
|
94
|
+
medium: 25,
|
|
95
|
+
large: 30
|
|
96
|
+
}
|
|
157
97
|
|
|
158
|
-
|
|
159
|
-
})
|
|
98
|
+
return isNumber(props.size) ? props.size : sz[props.size]
|
|
99
|
+
})
|
|
160
100
|
|
|
161
101
|
/**
|
|
162
102
|
* @description 开关样式
|
|
163
103
|
* */
|
|
164
104
|
const switchStyle = computed<CSSProperties>(() => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return style;
|
|
179
|
-
});
|
|
105
|
+
let style: CSSProperties = {}
|
|
106
|
+
// 这里需要加2,是为了腾出边框的距离,否则圆点node会和外边框紧贴在一起
|
|
107
|
+
style.width = addUnit(switchSize.value * 2 + 2)
|
|
108
|
+
style.height = addUnit(switchSize.value + 2)
|
|
109
|
+
// style.borderColor = this.value ? 'rgba(0, 0, 0, 0)' : 'rgba(0, 0, 0, 0.12)'
|
|
110
|
+
// 如果自定义了“非激活”演示,name边框颜色设置为透明(跟非激活颜色一致)
|
|
111
|
+
// 这里不能简单的设置为非激活的颜色,否则打开状态时,会有边框,所以需要透明
|
|
112
|
+
if (customInactiveColor.value) {
|
|
113
|
+
style.borderColor = 'rgba(0, 0, 0, 0)'
|
|
114
|
+
}
|
|
115
|
+
style.backgroundColor = isActive.value ? props.activeColor : props.inactiveColor
|
|
116
|
+
return style
|
|
117
|
+
})
|
|
180
118
|
|
|
181
119
|
/**
|
|
182
120
|
* @description 圆圈样式
|
|
183
121
|
* */
|
|
184
122
|
const nodeStyle = computed<CSSProperties>(() => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return style;
|
|
194
|
-
});
|
|
123
|
+
let style: CSSProperties = {}
|
|
124
|
+
// 如果自定义非激活颜色,将node圆点的尺寸减少两个像素,让其与外边框距离更大一点
|
|
125
|
+
style.width = addUnit(switchSize.value - props.space)
|
|
126
|
+
style.height = addUnit(switchSize.value - props.space)
|
|
127
|
+
const translateX = isActive.value ? addUnit(props.space) : addUnit(switchSize.value)
|
|
128
|
+
style.transform = `translateX(-${translateX})`
|
|
129
|
+
return style
|
|
130
|
+
})
|
|
195
131
|
|
|
196
132
|
/**
|
|
197
133
|
* @description 背景样式
|
|
198
134
|
* */
|
|
199
135
|
const bgStyle = computed<CSSProperties>(() => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
})
|
|
136
|
+
let style: CSSProperties = {}
|
|
137
|
+
// 这里配置一个多余的元素在HTML中,是为了让switch切换时,有更良好的背景色扩充体验(见实际效果)
|
|
138
|
+
style.width = addUnit(switchSize.value * 2 - switchSize.value / 2)
|
|
139
|
+
style.height = addUnit(switchSize.value)
|
|
140
|
+
style.backgroundColor = props.inactiveColor
|
|
141
|
+
// 打开时,让此元素收缩,否则反之
|
|
142
|
+
style.transform = `scale(${isActive.value ? 0 : 1})`
|
|
143
|
+
return style
|
|
144
|
+
})
|
|
209
145
|
|
|
210
146
|
/**
|
|
211
147
|
* @description 自定义颜色
|
|
212
148
|
* */
|
|
213
149
|
const customInactiveColor = computed(() => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})
|
|
150
|
+
// 之所以需要判断是否自定义了“非激活”颜色,是为了让node圆点离外边框更宽一点的距离
|
|
151
|
+
return props.inactiveColor !== '#fff' && props.inactiveColor !== '#ffffff'
|
|
152
|
+
})
|
|
217
153
|
|
|
218
154
|
/**
|
|
219
155
|
* @description 点击事件
|
|
220
156
|
* */
|
|
221
157
|
const clickHandler = () => {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
158
|
+
if (!props.disabled && !props.loading) {
|
|
159
|
+
const oldValue = isActive.value ? props.inactiveValue : props.activeValue
|
|
160
|
+
if (!props.asyncChange) {
|
|
161
|
+
emit('update:modelValue', oldValue)
|
|
162
|
+
}
|
|
163
|
+
// 放到下一个生命周期,因为双向绑定的value修改父组件状态需要时间,且是异步的
|
|
164
|
+
nextTick(() => {
|
|
165
|
+
emit('change', oldValue)
|
|
166
|
+
})
|
|
226
167
|
}
|
|
227
|
-
|
|
228
|
-
nextTick(() => {
|
|
229
|
-
emit("change", oldValue);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
};
|
|
168
|
+
}
|
|
233
169
|
</script>
|
|
234
170
|
|
|
235
171
|
<style lang="scss" scoped>
|
|
236
|
-
@import
|
|
172
|
+
@import './index.scss';
|
|
237
173
|
</style>
|