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.
Files changed (211) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/README.md +133 -0
  55. package/components/hy-coupon/hy-coupon.vue +180 -0
  56. package/components/hy-coupon/index.scss +553 -0
  57. package/components/hy-coupon/props.ts +129 -0
  58. package/components/hy-coupon/typing.d.ts +146 -0
  59. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  60. package/components/hy-datetime-picker/props.ts +142 -32
  61. package/components/hy-datetime-picker/typing.d.ts +132 -132
  62. package/components/hy-divider/hy-divider.vue +90 -169
  63. package/components/hy-divider/props.ts +78 -19
  64. package/components/hy-divider/typing.d.ts +60 -60
  65. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  66. package/components/hy-dropdown/props.ts +38 -15
  67. package/components/hy-dropdown/typing.d.ts +44 -44
  68. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  69. package/components/hy-dropdown-item/props.ts +19 -8
  70. package/components/hy-empty/hy-empty.vue +75 -129
  71. package/components/hy-empty/props.ts +57 -15
  72. package/components/hy-empty/typing.d.ts +84 -84
  73. package/components/hy-flex/hy-flex.vue +33 -88
  74. package/components/hy-flex/props.ts +58 -0
  75. package/components/hy-flex/typing.d.ts +14 -16
  76. package/components/hy-float-button/hy-float-button.vue +289 -406
  77. package/components/hy-float-button/props.ts +109 -25
  78. package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
  79. package/components/hy-folding-panel/props.ts +40 -15
  80. package/components/hy-folding-panel/typing.d.ts +52 -63
  81. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
  82. package/components/hy-folding-panel-item/index.scss +87 -0
  83. package/components/hy-folding-panel-item/props.ts +81 -0
  84. package/components/hy-folding-panel-item/typing.d.ts +23 -0
  85. package/components/hy-form/hy-form.vue +172 -212
  86. package/components/hy-form/props.ts +37 -0
  87. package/components/hy-form/typing.d.ts +68 -61
  88. package/components/hy-form-group/typing.d.ts +74 -74
  89. package/components/hy-form-item/hy-form-item.vue +100 -129
  90. package/components/hy-form-item/props.ts +25 -0
  91. package/components/hy-form-item/typing.d.ts +40 -37
  92. package/components/hy-grid/hy-grid.vue +76 -132
  93. package/components/hy-grid/props.ts +58 -16
  94. package/components/hy-grid/typing.d.ts +66 -66
  95. package/components/hy-icon/hy-icon.vue +84 -161
  96. package/components/hy-icon/props.ts +76 -22
  97. package/components/hy-icon/typing.d.ts +83 -82
  98. package/components/hy-image/hy-image.vue +142 -272
  99. package/components/hy-image/props.ts +105 -23
  100. package/components/hy-image/typing.d.ts +84 -87
  101. package/components/hy-input/hy-input.vue +230 -421
  102. package/components/hy-input/props.ts +183 -35
  103. package/components/hy-input/typing.d.ts +169 -169
  104. package/components/hy-line/hy-line.vue +34 -72
  105. package/components/hy-line/props.ts +41 -10
  106. package/components/hy-line/typing.d.ts +29 -29
  107. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  108. package/components/hy-line-progress/props.ts +31 -10
  109. package/components/hy-line-progress/typing.d.ts +29 -29
  110. package/components/hy-list/hy-list.vue +151 -220
  111. package/components/hy-list/props.ts +67 -16
  112. package/components/hy-list/typing.d.ts +52 -52
  113. package/components/hy-loading/hy-loading.vue +63 -119
  114. package/components/hy-loading/props.ts +63 -15
  115. package/components/hy-loading/typing.d.ts +49 -49
  116. package/components/hy-menu/hy-menu.vue +124 -166
  117. package/components/hy-menu/props.ts +42 -10
  118. package/components/hy-menu/typing.d.ts +60 -60
  119. package/components/hy-modal/hy-modal.vue +127 -218
  120. package/components/hy-modal/props.ts +89 -24
  121. package/components/hy-navbar/hy-navbar.vue +104 -177
  122. package/components/hy-navbar/props.ts +76 -22
  123. package/components/hy-navbar/typing.d.ts +81 -81
  124. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  125. package/components/hy-notice-bar/props.ts +80 -19
  126. package/components/hy-notice-bar/typing.d.ts +62 -62
  127. package/components/hy-notify/hy-notify.vue +128 -177
  128. package/components/hy-notify/props.ts +49 -12
  129. package/components/hy-notify/typing.d.ts +45 -41
  130. package/components/hy-number-step/hy-number-step.vue +281 -394
  131. package/components/hy-number-step/props.ts +110 -27
  132. package/components/hy-number-step/typing.d.ts +120 -120
  133. package/components/hy-overlay/hy-overlay.vue +39 -66
  134. package/components/hy-overlay/props.ts +31 -8
  135. package/components/hy-pagination/hy-pagination.vue +100 -155
  136. package/components/hy-pagination/props.ts +53 -13
  137. package/components/hy-picker/hy-picker.vue +309 -430
  138. package/components/hy-picker/index.scss +8 -12
  139. package/components/hy-picker/props.ts +110 -26
  140. package/components/hy-popover/hy-popover.vue +190 -252
  141. package/components/hy-popover/props.ts +48 -10
  142. package/components/hy-popup/hy-popup.vue +162 -248
  143. package/components/hy-popup/props.ts +82 -18
  144. package/components/hy-price/hy-price.vue +45 -104
  145. package/components/hy-price/props.ts +52 -12
  146. package/components/hy-price/typing.d.ts +41 -36
  147. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  148. package/components/hy-qrcode/props.ts +68 -18
  149. package/components/hy-qrcode/typing.d.ts +67 -66
  150. package/components/hy-radio/hy-radio.vue +161 -259
  151. package/components/hy-radio/props.ts +95 -25
  152. package/components/hy-radio/typing.d.ts +85 -84
  153. package/components/hy-rate/hy-rate.vue +185 -270
  154. package/components/hy-rate/props.ts +76 -18
  155. package/components/hy-rate/typing.d.ts +61 -60
  156. package/components/hy-read-more/hy-read-more.vue +93 -136
  157. package/components/hy-read-more/props.ts +43 -13
  158. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  159. package/components/hy-scroll-list/props.ts +22 -11
  160. package/components/hy-search/hy-search.vue +155 -284
  161. package/components/hy-search/props.ts +130 -25
  162. package/components/hy-signature/hy-signature.vue +491 -635
  163. package/components/hy-signature/props.ts +115 -26
  164. package/components/hy-signature/typing.d.ts +138 -138
  165. package/components/hy-slider/hy-slider.vue +388 -477
  166. package/components/hy-slider/props.ts +75 -19
  167. package/components/hy-steps/hy-steps.vue +212 -279
  168. package/components/hy-steps/props.ts +47 -13
  169. package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
  170. package/components/hy-submit-bar/props.ts +89 -20
  171. package/components/hy-submit-bar/typing.d.ts +86 -85
  172. package/components/hy-subsection/hy-subsection.vue +132 -185
  173. package/components/hy-subsection/props.ts +50 -17
  174. package/components/hy-subsection/typing.d.ts +52 -52
  175. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  176. package/components/hy-swipe-action/props.ts +43 -18
  177. package/components/hy-swipe-action/typing.d.ts +46 -46
  178. package/components/hy-swiper/hy-swiper.vue +159 -286
  179. package/components/hy-swiper/props.ts +126 -28
  180. package/components/hy-swiper/typing.d.ts +115 -115
  181. package/components/hy-switch/hy-switch.vue +112 -176
  182. package/components/hy-switch/props.ts +60 -15
  183. package/components/hy-switch/typing.d.ts +63 -63
  184. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  185. package/components/hy-tabs/hy-tabs.vue +277 -380
  186. package/components/hy-tabs/props.ts +75 -18
  187. package/components/hy-tag/hy-tag.vue +111 -204
  188. package/components/hy-tag/props.ts +81 -19
  189. package/components/hy-text/hy-text.vue +200 -322
  190. package/components/hy-text/props.ts +107 -28
  191. package/components/hy-textarea/hy-textarea.vue +147 -256
  192. package/components/hy-textarea/props.ts +112 -25
  193. package/components/hy-textarea/typing.d.ts +42 -42
  194. package/components/hy-toast/hy-toast.vue +135 -143
  195. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  196. package/components/hy-tooltip/props.ts +79 -15
  197. package/components/hy-transition/hy-transition.vue +111 -138
  198. package/components/hy-transition/props.ts +30 -8
  199. package/components/hy-upload/hy-upload.vue +320 -469
  200. package/components/hy-upload/props.ts +130 -27
  201. package/components/hy-warn/hy-warn.vue +80 -129
  202. package/components/hy-warn/props.ts +47 -12
  203. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  204. package/components/hy-waterfall/props.ts +19 -7
  205. package/components/hy-watermark/hy-watermark.vue +762 -870
  206. package/components/hy-watermark/props.ts +103 -22
  207. package/global.d.ts +2 -0
  208. package/libs/css/theme.scss +3 -3
  209. package/package.json +2 -2
  210. package/web-types.json +1 -1
  211. package/components/hy-folding-panel/index.scss +0 -9
@@ -1,127 +1,127 @@
1
- import type { CSSProperties } from "vue";
1
+ import type { CSSProperties } from 'vue'
2
2
 
3
3
  export default interface HySwiperProps {
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;
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
- [key: string]: any;
104
- /** 线上地址 */
105
- url?: string;
106
- /** 标题 */
107
- title?: string;
108
- /** 海报,为视频必填 */
109
- poster?: string;
110
- /** 轮播图展示类型 */
111
- type?: "image" | "video";
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
- detail: {
116
- current: number;
117
- };
115
+ detail: {
116
+ current: number
117
+ }
118
118
  }
119
119
 
120
120
  export interface ISwiperEmits {
121
- /** 点击轮播图触发 */
122
- (e: "click", index: number): void;
123
- /** 滑动轮播图触发 */
124
- (e: "change", temp: SwiperVo["detail"]): void;
125
- /** 滑动轮播图触发 */
126
- (e: "update:current", value: string | number): void;
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
- :class="['hy-switch__node', modelValue && 'hy-switch__node--on']"
15
- :style="[nodeStyle]"
16
- ref="hy-switch__node"
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
- <hy-loading
19
- :show="loading"
20
- :size="switchSize * 0.6"
21
- mode="circle"
22
- ></hy-loading>
23
- <view class="" v-if="!loading">
24
- <slot>
25
- <HyIcon
26
- :name="modelValue ? activeIcon : inactiveIcon"
27
- :size="icon?.size || switchSize * 0.6"
28
- :color="icon?.color"
29
- :bold="icon?.bold"
30
- :customPrefix="icon?.customPrefix"
31
- :imgMode="icon?.imgMode"
32
- :width="icon?.width"
33
- :height="icon?.height"
34
- :top="icon?.top"
35
- :stop="icon?.stop"
36
- :round="icon?.round"
37
- :customStyle="icon?.customStyle"
38
- ></HyIcon>
39
- </slot>
40
- </view>
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
- name: "hy-switch",
48
- options: {
49
- addGlobalClass: true,
50
- virtualHost: true,
51
- styleIsolation: "shared",
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 "vue";
58
- import type { CSSProperties, PropType } from "vue";
59
- import { addUnit, error, isNumber } from "../../libs";
60
- import type { ISwitchEmits, SwiperValue } from "./typing";
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 "../hy-loading/hy-loading.vue";
63
- import HyIcon from "../hy-icon/hy-icon.vue";
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
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
73
- const props = defineProps({
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
- () => props.modelValue,
133
- (newValue) => {
134
- if (newValue !== props.inactiveValue && newValue !== props.activeValue) {
135
- error("v-model绑定的值必须为inactiveValue、activeValue二者之一");
136
- }
137
- },
138
- { immediate: true },
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
- return props.modelValue === props.activeValue;
146
- });
85
+ return props.modelValue === props.activeValue
86
+ })
147
87
 
148
88
  /**
149
89
  * @description 设置开关大小
150
90
  * */
151
91
  const switchSize = computed((): number => {
152
- const sz: AnyObject = {
153
- small: 20,
154
- medium: 25,
155
- large: 30,
156
- };
92
+ const sz: AnyObject = {
93
+ small: 20,
94
+ medium: 25,
95
+ large: 30
96
+ }
157
97
 
158
- return isNumber(props.size) ? props.size : sz[props.size];
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
- let style: CSSProperties = {};
166
- // 这里需要加2,是为了腾出边框的距离,否则圆点node会和外边框紧贴在一起
167
- style.width = addUnit(switchSize.value * 2 + 2);
168
- style.height = addUnit(switchSize.value + 2);
169
- // style.borderColor = this.value ? 'rgba(0, 0, 0, 0)' : 'rgba(0, 0, 0, 0.12)'
170
- // 如果自定义了“非激活”演示,name边框颜色设置为透明(跟非激活颜色一致)
171
- // 这里不能简单的设置为非激活的颜色,否则打开状态时,会有边框,所以需要透明
172
- if (customInactiveColor.value) {
173
- style.borderColor = "rgba(0, 0, 0, 0)";
174
- }
175
- style.backgroundColor = isActive.value
176
- ? props.activeColor
177
- : props.inactiveColor;
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
- let style: CSSProperties = {};
186
- // 如果自定义非激活颜色,将node圆点的尺寸减少两个像素,让其与外边框距离更大一点
187
- style.width = addUnit(switchSize.value - props.space);
188
- style.height = addUnit(switchSize.value - props.space);
189
- const translateX = isActive.value
190
- ? addUnit(props.space)
191
- : addUnit(switchSize.value);
192
- style.transform = `translateX(-${translateX})`;
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
- let style: CSSProperties = {};
201
- // 这里配置一个多余的元素在HTML中,是为了让switch切换时,有更良好的背景色扩充体验(见实际效果)
202
- style.width = addUnit(switchSize.value * 2 - switchSize.value / 2);
203
- style.height = addUnit(switchSize.value);
204
- style.backgroundColor = props.inactiveColor;
205
- // 打开时,让此元素收缩,否则反之
206
- style.transform = `scale(${isActive.value ? 0 : 1})`;
207
- return style;
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
- // 之所以需要判断是否自定义了“非激活”颜色,是为了让node圆点离外边框更宽一点的距离
215
- return props.inactiveColor !== "#fff" && props.inactiveColor !== "#ffffff";
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
- if (!props.disabled && !props.loading) {
223
- const oldValue = isActive.value ? props.inactiveValue : props.activeValue;
224
- if (!props.asyncChange) {
225
- emit("update:modelValue", oldValue);
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
- // 放到下一个生命周期,因为双向绑定的value修改父组件状态需要时间,且是异步的
228
- nextTick(() => {
229
- emit("change", oldValue);
230
- });
231
- }
232
- };
168
+ }
233
169
  </script>
234
170
 
235
171
  <style lang="scss" scoped>
236
- @import "./index.scss";
172
+ @import './index.scss';
237
173
  </style>