hy-app 0.2.13 → 0.2.15

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 (223) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +81 -13
  2. package/components/hy-action-sheet/typing.d.ts +1 -3
  3. package/components/hy-address-picker/hy-address-picker.vue +109 -8
  4. package/components/hy-address-picker/index.scss +2 -2
  5. package/components/hy-address-picker/typing.d.ts +39 -30
  6. package/components/hy-avatar/hy-avatar.vue +78 -4
  7. package/components/hy-avatar/typing.d.ts +21 -16
  8. package/components/hy-back-top/hy-back-top.vue +86 -28
  9. package/components/hy-back-top/typing.d.ts +17 -12
  10. package/components/hy-badge/hy-badge.vue +114 -43
  11. package/components/hy-badge/typing.d.ts +20 -15
  12. package/components/hy-button/HyButton.docgen.js +6 -0
  13. package/components/hy-button/hy-button.vue +70 -77
  14. package/components/hy-button/props.ts +40 -41
  15. package/components/hy-calendar/hy-calendar.vue +290 -143
  16. package/components/hy-calendar/typing.d.ts +38 -31
  17. package/components/hy-card/hy-card.vue +139 -36
  18. package/components/hy-card/typing.d.ts +39 -28
  19. package/components/hy-cell/hy-cell.vue +131 -67
  20. package/components/hy-cell/typing.d.ts +6 -1
  21. package/components/hy-check-button/hy-check-button.vue +101 -32
  22. package/components/hy-check-button/typing.d.ts +26 -19
  23. package/components/hy-checkbox/hy-checkbox.vue +167 -78
  24. package/components/hy-checkbox/typing.d.ts +26 -19
  25. package/components/hy-code-input/hy-code-input.vue +101 -5
  26. package/components/hy-code-input/typing.d.ts +9 -0
  27. package/components/hy-config-provider/hy-config-provider.vue +44 -24
  28. package/components/hy-config-provider/typing.d.ts +0 -4
  29. package/components/hy-count-down/hy-count-down.vue +99 -62
  30. package/components/hy-count-down/typing.d.ts +18 -5
  31. package/components/hy-count-to/hy-count-to.vue +165 -113
  32. package/components/hy-count-to/typing.d.ts +15 -11
  33. package/components/hy-datetime-picker/hy-datetime-picker.vue +338 -232
  34. package/components/hy-datetime-picker/typing.d.ts +49 -39
  35. package/components/hy-divider/hy-divider.vue +128 -64
  36. package/components/hy-divider/typing.d.ts +16 -16
  37. package/components/hy-dropdown/hy-dropdown.vue +57 -19
  38. package/components/hy-dropdown/typing.d.ts +14 -14
  39. package/components/hy-dropdown-item/hy-dropdown-item.vue +34 -5
  40. package/components/hy-dropdown-item/typing.d.ts +13 -6
  41. package/components/hy-empty/hy-empty.vue +64 -6
  42. package/components/hy-empty/typing.d.ts +5 -0
  43. package/components/hy-float-button/hy-float-button.vue +117 -5
  44. package/components/hy-float-button/typing.d.ts +7 -0
  45. package/components/hy-folding-panel/hy-folding-panel.vue +87 -25
  46. package/components/hy-folding-panel/typing.d.ts +24 -15
  47. package/components/hy-grid/hy-grid.vue +95 -35
  48. package/components/hy-grid/typing.d.ts +24 -19
  49. package/components/hy-icon/hy-icon.vue +84 -6
  50. package/components/hy-icon/typing.d.ts +5 -0
  51. package/components/hy-image/hy-image.vue +105 -6
  52. package/components/hy-image/typing.d.ts +9 -0
  53. package/components/hy-input/hy-input.vue +277 -130
  54. package/components/hy-input/props.ts +13 -14
  55. package/components/hy-input/typing.d.ts +59 -38
  56. package/components/hy-line/hy-line.vue +65 -25
  57. package/components/hy-line-progress/hy-line-progress.vue +68 -35
  58. package/components/hy-list/hy-list.vue +127 -61
  59. package/components/hy-list/typing.d.ts +19 -12
  60. package/components/hy-loading/hy-loading.vue +79 -25
  61. package/components/hy-menu/hy-menu.vue +69 -45
  62. package/components/hy-menu/typing.d.ts +22 -15
  63. package/components/hy-modal/hy-modal.vue +91 -4
  64. package/components/hy-modal/typing.d.ts +11 -0
  65. package/components/hy-navbar/hy-navbar.vue +105 -25
  66. package/components/hy-navbar/typing.d.ts +25 -20
  67. package/components/hy-notice-bar/hy-notice-bar.vue +97 -19
  68. package/components/hy-notice-bar/typing.d.ts +22 -17
  69. package/components/hy-notify/hy-notify.vue +106 -54
  70. package/components/hy-number-step/hy-number-step.vue +211 -120
  71. package/components/hy-number-step/typing.d.ts +45 -28
  72. package/components/hy-overlay/hy-overlay.vue +60 -16
  73. package/components/hy-overlay/typing.d.ts +11 -6
  74. package/components/hy-pagination/hy-pagination.vue +94 -37
  75. package/components/hy-pagination/typing.d.ts +20 -11
  76. package/components/hy-picker/hy-picker.vue +225 -160
  77. package/components/hy-picker/typing.d.ts +51 -28
  78. package/components/hy-popover/hy-popover.vue +55 -7
  79. package/components/hy-popover/typing.d.ts +21 -1
  80. package/components/hy-popup/hy-popup.vue +164 -99
  81. package/components/hy-popup/typing.d.ts +11 -0
  82. package/components/hy-price/hy-price.vue +77 -30
  83. package/components/hy-price/typing.d.ts +10 -10
  84. package/components/hy-qrcode/hy-qrcode.vue +75 -5
  85. package/components/hy-qrcode/typing.d.ts +25 -16
  86. package/components/hy-radio/hy-radio.vue +169 -88
  87. package/components/hy-radio/typing.d.ts +29 -22
  88. package/components/hy-rate/hy-rate.vue +155 -104
  89. package/components/hy-rate/typing.d.ts +23 -16
  90. package/components/hy-read-more/hy-read-more.vue +83 -56
  91. package/components/hy-read-more/typing.d.ts +18 -11
  92. package/components/hy-scroll-list/hy-scroll-list.vue +69 -58
  93. package/components/hy-scroll-list/typing.d.ts +14 -7
  94. package/components/hy-search/hy-search.vue +168 -62
  95. package/components/hy-search/typing.d.ts +47 -26
  96. package/components/hy-signature/hy-signature.vue +354 -272
  97. package/components/hy-signature/typing.d.ts +65 -52
  98. package/components/hy-slider/hy-slider.vue +208 -160
  99. package/components/hy-slider/typing.d.ts +28 -17
  100. package/components/hy-steps/hy-steps.vue +125 -99
  101. package/components/hy-steps/typing.d.ts +21 -14
  102. package/components/hy-submit-bar/hy-submit-bar.vue +129 -48
  103. package/components/hy-submit-bar/typing.d.ts +30 -23
  104. package/components/hy-subsection/hy-subsection.vue +139 -96
  105. package/components/hy-subsection/typing.d.ts +23 -16
  106. package/components/hy-swipe-action/hy-swipe-action.vue +161 -135
  107. package/components/hy-swipe-action/typing.d.ts +26 -17
  108. package/components/hy-swiper/hy-swiper.vue +178 -73
  109. package/components/hy-swiper/typing.d.ts +37 -28
  110. package/components/hy-switch/hy-switch.vue +107 -60
  111. package/components/hy-switch/typing.d.ts +25 -18
  112. package/components/hy-tabs/hy-tabs.vue +170 -160
  113. package/components/hy-tabs/typing.d.ts +36 -22
  114. package/components/hy-tag/hy-tag.vue +133 -58
  115. package/components/hy-tag/typing.d.ts +26 -18
  116. package/components/hy-text/hy-text.vue +106 -6
  117. package/components/hy-text/typing.d.ts +31 -26
  118. package/components/hy-textarea/hy-textarea.vue +183 -89
  119. package/components/hy-textarea/typing.d.ts +41 -24
  120. package/components/hy-tooltip/hy-tooltip.vue +145 -101
  121. package/components/hy-tooltip/typing.d.ts +18 -13
  122. package/components/hy-transition/hy-transition.vue +48 -13
  123. package/components/hy-transition/typing.d.ts +17 -0
  124. package/components/hy-upload/hy-upload.vue +113 -148
  125. package/components/hy-upload/typing.d.ts +71 -71
  126. package/components/hy-warn/hy-warn.vue +79 -36
  127. package/components/hy-warn/typing.d.ts +18 -11
  128. package/components/hy-waterfall/hy-waterfall.vue +90 -77
  129. package/components/hy-watermark/hy-watermark.vue +82 -5
  130. package/components/hy-watermark/typing.d.ts +20 -20
  131. package/global.d.ts +39 -59
  132. package/package.json +5 -13
  133. package/utils/inspect.ts +3 -1
  134. package/web-types.json +1 -1
  135. package/component-helper.ts +0 -177
  136. package/components.json +0 -3287
  137. package/dist/attributes.json +0 -1
  138. package/dist/docs/components/hy-action-sheet/hy-action-sheet.md +0 -41
  139. package/dist/docs/components/hy-address-picker/hy-address-picker.md +0 -25
  140. package/dist/docs/components/hy-avatar/hy-avatar.md +0 -19
  141. package/dist/docs/components/hy-back-top/hy-back-top.md +0 -19
  142. package/dist/docs/components/hy-badge/hy-badge.md +0 -13
  143. package/dist/docs/components/hy-button/hy-button.md +0 -61
  144. package/dist/docs/components/hy-calendar/header.md +0 -17
  145. package/dist/docs/components/hy-calendar/hy-calendar.md +0 -27
  146. package/dist/docs/components/hy-calendar/month.md +0 -38
  147. package/dist/docs/components/hy-card/hy-card.md +0 -24
  148. package/dist/docs/components/hy-cell/hy-cell.md +0 -26
  149. package/dist/docs/components/hy-check-button/hy-check-button.md +0 -14
  150. package/dist/docs/components/hy-checkbox/hy-checkbox.md +0 -21
  151. package/dist/docs/components/hy-code-input/hy-code-input.md +0 -15
  152. package/dist/docs/components/hy-config-provider/hy-config-provider.md +0 -13
  153. package/dist/docs/components/hy-count-down/hy-count-down.md +0 -34
  154. package/dist/docs/components/hy-count-to/hy-count-to.md +0 -31
  155. package/dist/docs/components/hy-datetime-picker/hy-datetime-picker.md +0 -25
  156. package/dist/docs/components/hy-divider/hy-divider.md +0 -13
  157. package/dist/docs/components/hy-dropdown/hy-dropdown.md +0 -13
  158. package/dist/docs/components/hy-dropdown-item/hy-dropdown-item.md +0 -20
  159. package/dist/docs/components/hy-empty/hy-empty.md +0 -20
  160. package/dist/docs/components/hy-float-button/hy-float-button.md +0 -20
  161. package/dist/docs/components/hy-folding-panel/hy-folding-panel.md +0 -24
  162. package/dist/docs/components/hy-form/hy-form.md +0 -29
  163. package/dist/docs/components/hy-grid/hy-grid.md +0 -19
  164. package/dist/docs/components/hy-icon/hy-icon.md +0 -13
  165. package/dist/docs/components/hy-image/hy-image.md +0 -22
  166. package/dist/docs/components/hy-input/hy-input.md +0 -29
  167. package/dist/docs/components/hy-line/hy-line.md +0 -7
  168. package/dist/docs/components/hy-line-progress/hy-line-progress.md +0 -13
  169. package/dist/docs/components/hy-list/hy-list.md +0 -25
  170. package/dist/docs/components/hy-loading/hy-loading.md +0 -14
  171. package/dist/docs/components/hy-login/ThePhoneLogin.md +0 -20
  172. package/dist/docs/components/hy-login/TheUserLogin.md +0 -44
  173. package/dist/docs/components/hy-login/hy-login.md +0 -14
  174. package/dist/docs/components/hy-menu/hy-menu.md +0 -21
  175. package/dist/docs/components/hy-modal/hy-modal.md +0 -23
  176. package/dist/docs/components/hy-navbar/hy-navbar.md +0 -22
  177. package/dist/docs/components/hy-notice-bar/hy-column-notice.md +0 -20
  178. package/dist/docs/components/hy-notice-bar/hy-notice-bar.md +0 -14
  179. package/dist/docs/components/hy-notice-bar/hy-row-notice.md +0 -20
  180. package/dist/docs/components/hy-notify/hy-notify.md +0 -23
  181. package/dist/docs/components/hy-number-step/hy-number-step.md +0 -27
  182. package/dist/docs/components/hy-overlay/hy-overlay.md +0 -19
  183. package/dist/docs/components/hy-pagination/hy-pagination.md +0 -14
  184. package/dist/docs/components/hy-parse/hy-parse.md +0 -46
  185. package/dist/docs/components/hy-parse/node/node.md +0 -7
  186. package/dist/docs/components/hy-picker/hy-picker.md +0 -32
  187. package/dist/docs/components/hy-popover/hy-popover.md +0 -34
  188. package/dist/docs/components/hy-popup/hy-popup.md +0 -22
  189. package/dist/docs/components/hy-price/hy-price.md +0 -13
  190. package/dist/docs/components/hy-qrcode/hy-qrcode.md +0 -15
  191. package/dist/docs/components/hy-radio/hy-radio.md +0 -21
  192. package/dist/docs/components/hy-rate/hy-rate.md +0 -14
  193. package/dist/docs/components/hy-read-more/hy-read-more.md +0 -21
  194. package/dist/docs/components/hy-scroll-list/hy-scroll-list.md +0 -21
  195. package/dist/docs/components/hy-search/hy-search.md +0 -27
  196. package/dist/docs/components/hy-signature/hy-signature.md +0 -45
  197. package/dist/docs/components/hy-slider/hy-slider.md +0 -24
  198. package/dist/docs/components/hy-status-bar/hy-status-bar.md +0 -13
  199. package/dist/docs/components/hy-steps/hy-steps.md +0 -23
  200. package/dist/docs/components/hy-submit-bar/hy-submit-bar.md +0 -21
  201. package/dist/docs/components/hy-subsection/hy-subsection.md +0 -14
  202. package/dist/docs/components/hy-swipe-action/hy-swipe-action.md +0 -29
  203. package/dist/docs/components/hy-swiper/hy-swiper-indicator.md +0 -23
  204. package/dist/docs/components/hy-swiper/hy-swiper.md +0 -22
  205. package/dist/docs/components/hy-switch/hy-switch.md +0 -20
  206. package/dist/docs/components/hy-tabBar/hy-tabBar.md +0 -13
  207. package/dist/docs/components/hy-tabs/hy-tabs.md +0 -27
  208. package/dist/docs/components/hy-tag/hy-tag.md +0 -21
  209. package/dist/docs/components/hy-text/hy-text.md +0 -13
  210. package/dist/docs/components/hy-textarea/hy-textarea.md +0 -19
  211. package/dist/docs/components/hy-toast/hy-toast.md +0 -17
  212. package/dist/docs/components/hy-tooltip/hy-tooltip.md +0 -13
  213. package/dist/docs/components/hy-transition/hy-transition.md +0 -25
  214. package/dist/docs/components/hy-upload/hy-upload.md +0 -25
  215. package/dist/docs/components/hy-warn/hy-warn.md +0 -14
  216. package/dist/docs/components/hy-waterfall/hy-waterfall.md +0 -30
  217. package/dist/docs/components/hy-watermark/hy-watermark.md +0 -7
  218. package/dist/docs/components/message/TheMessage.md +0 -17
  219. package/dist/docs/components/yk-dialog/yk-dialog.md +0 -7
  220. package/dist/tags.json +0 -1
  221. package/dist/web-types.json +0 -1
  222. package/docgen.config.js +0 -14
  223. package/web-types.config.js +0 -7
@@ -1,44 +1,51 @@
1
- import type { CSSProperties } from "vue";
1
+ import type { CSSProperties } from 'vue'
2
2
 
3
3
  export default interface HyReadMoreProps {
4
4
  /**
5
5
  * @description 内容超出此高度才会显示展开全文按钮,单位px(默认 400 )
6
6
  * */
7
- showHeight?: number;
7
+ showHeight?: number
8
8
  /**
9
9
  * @description 展开后是否显示收起按钮(默认 false )
10
10
  * */
11
- toggle?: boolean;
11
+ toggle?: boolean
12
12
  /**
13
13
  * @description 关闭时的提示文字(默认 '展开阅读全文' )
14
14
  * */
15
- closeText?: string;
15
+ closeText?: string
16
16
  /**
17
17
  * @description 展开时的提示文字(默认 '收起' )
18
18
  * */
19
- openText?: string;
19
+ openText?: string
20
20
  /**
21
21
  * @description 提示文字的颜色(默认 '#2979ff' )
22
22
  * */
23
- color?: string;
23
+ color?: string
24
24
  /**
25
25
  * @description 提示文字的大小,单位px (默认 14 )
26
26
  * */
27
- fontSize?: number;
27
+ fontSize?: number
28
28
  /**
29
29
  * @description 段落首行缩进的字符个数 (默认 '2em' )
30
30
  * */
31
- textIndent?: string;
31
+ textIndent?: string
32
32
  /**
33
33
  * @description 用于在 open 和 close 事件中当作回调参数返回
34
34
  * */
35
- name?: string;
35
+ name?: string
36
36
  /**
37
37
  * @description 显示阴影的样式
38
38
  * */
39
- shadowStyle?: CSSProperties;
39
+ shadowStyle?: CSSProperties
40
40
  /**
41
41
  * @description 定义需要用到的外部样式
42
42
  * */
43
- customStyle?: CSSProperties;
43
+ customStyle?: CSSProperties
44
+ }
45
+
46
+ export interface IReadMoreEmits {
47
+ /** 打开触发 */
48
+ (e: 'open', name: string): void
49
+ /** 关闭触发 */
50
+ (e: 'close', name: string): void
44
51
  }
@@ -25,114 +25,125 @@
25
25
  class="hy-scroll-list__indicator__line__bar"
26
26
  :style="barStyle"
27
27
  ref="hy-scroll-list__indicator__line__bar"
28
- >
29
- </view>
28
+ ></view>
30
29
  </view>
31
30
  </view>
32
31
  </view>
33
32
  </template>
34
33
 
35
34
  <script lang="ts">
35
+ /**
36
+ * 该组件一般用于同时展示多个商品、分类的场景,也可以完成左右滑动的列表。
37
+ * @displayName hy-scroll-list
38
+ */
39
+ defineOptions({})
36
40
  export default {
37
41
  name: 'hy-scroll-list',
38
42
  options: {
39
43
  addGlobalClass: true,
40
44
  virtualHost: true,
41
- styleIsolation: 'shared'
42
- }
45
+ styleIsolation: 'shared',
46
+ },
43
47
  }
44
48
  </script>
45
49
 
46
50
  <script setup lang="ts">
47
- import {
48
- computed,
49
- type CSSProperties,
50
- toRefs,
51
- ref,
52
- onMounted,
53
- getCurrentInstance,
54
- } from "vue";
55
- import defaultProps from "./props";
56
- import type IProps from "./typing";
57
- import { addUnit, colorGradient, getRect, sleep } from "../../utils";
51
+ import { computed, type CSSProperties, toRefs, ref, onMounted, getCurrentInstance } from 'vue'
52
+ import type { IScrollListEmits } from './typing'
53
+ import { addUnit, colorGradient, getRect, sleep } from '../../utils'
58
54
 
59
- const props = withDefaults(defineProps<IProps>(), defaultProps);
60
- const {
61
- indicatorWidth,
62
- indicatorColor,
63
- indicatorBarWidth,
64
- indicatorActiveColor,
65
- } = toRefs(props);
66
- const emit = defineEmits(["click", "left", "right"]);
55
+ // const props = withDefaults(defineProps<IProps>(), defaultProps)
56
+ const props = defineProps({
57
+ /** 指示器的整体宽度 */
58
+ indicatorWidth: {
59
+ type: Number,
60
+ default: 50,
61
+ },
62
+ /** 滑块的宽度 */
63
+ indicatorBarWidth: {
64
+ type: Number,
65
+ default: 20,
66
+ },
67
+ /** 是否显示面板指示器 */
68
+ indicator: {
69
+ type: Boolean,
70
+ default: true,
71
+ },
72
+ /** 指示器非激活颜色 */
73
+ indicatorColor: String,
74
+ /** 指示器的激活颜色 */
75
+ indicatorActiveColor: String,
76
+ })
77
+ const { indicatorWidth, indicatorColor, indicatorBarWidth, indicatorActiveColor } = toRefs(props)
78
+ const emit = defineEmits<IScrollListEmits>()
67
79
 
68
- const instance = getCurrentInstance();
80
+ const instance = getCurrentInstance()
69
81
  const scrollInfo = ref({
70
82
  scrollLeft: 0,
71
83
  scrollWidth: 0,
72
- });
73
- const scrollWidth = ref(0);
74
- const barLeft = ref(0);
84
+ })
85
+ const scrollWidth = ref(0)
86
+ const barLeft = ref(0)
75
87
 
76
88
  /**
77
89
  * @description 线条样式
78
90
  * */
79
91
  const barStyle = computed<CSSProperties>(() => {
80
- const style: CSSProperties = {};
81
- style.transform = `translateX(${barLeft.value}px)`;
92
+ const style: CSSProperties = {}
93
+ style.transform = `translateX(${barLeft.value}px)`
82
94
  // 设置滑块的宽度和背景色,是每个平台都需要的
83
- style.width = addUnit(indicatorBarWidth.value);
84
- style.backgroundColor = indicatorActiveColor.value;
85
- return style;
86
- });
95
+ style.width = addUnit(indicatorBarWidth.value)
96
+ style.backgroundColor = indicatorActiveColor.value
97
+ return style
98
+ })
87
99
  /**
88
100
  * @description 轨道样式
89
101
  * */
90
102
  const lineStyle = computed<CSSProperties>(() => {
91
- const style: CSSProperties = {};
103
+ const style: CSSProperties = {}
92
104
  // 指示器整体的样式,需要设置其宽度和背景色
93
- style.width = addUnit(indicatorWidth.value);
105
+ style.width = addUnit(indicatorWidth.value)
94
106
  style.backgroundColor =
95
107
  indicatorColor.value ||
96
- (indicatorActiveColor.value &&
97
- colorGradient(indicatorActiveColor.value)[90]);
98
- return style;
99
- });
108
+ (indicatorActiveColor.value && colorGradient(indicatorActiveColor.value)[90])
109
+ return style
110
+ })
100
111
 
101
112
  onMounted(() => {
102
- initWidth();
103
- });
113
+ initWidth()
114
+ })
104
115
 
105
116
  /**
106
117
  * @description 初始化宽度
107
118
  * */
108
119
  const initWidth = async () => {
109
120
  // 延时一定时间,以获取dom尺寸
110
- await sleep(30);
121
+ await sleep(30)
111
122
  // #ifndef APP-NVUE
112
- getRect(".hy-scroll-list", false, instance).then((size) => {
113
- scrollWidth.value = (size as UniApp.NodeInfo).width!;
114
- });
123
+ getRect('.hy-scroll-list', false, instance).then((size) => {
124
+ scrollWidth.value = (size as UniApp.NodeInfo).width!
125
+ })
115
126
  // #endif
116
- };
127
+ }
117
128
 
118
129
  const onScroll = (event: any) => {
119
- const { scrollLeft, scrollWidth: totalWidth } = event.detail;
120
- const targetWidth = totalWidth - scrollWidth.value;
121
- const targetBarWidth = indicatorWidth.value - indicatorBarWidth.value;
122
- barLeft.value = (scrollLeft / targetWidth) * targetBarWidth;
123
- };
130
+ const { scrollLeft, scrollWidth: totalWidth } = event.detail
131
+ const targetWidth = totalWidth - scrollWidth.value
132
+ const targetBarWidth = indicatorWidth.value - indicatorBarWidth.value
133
+ barLeft.value = (scrollLeft / targetWidth) * targetBarWidth
134
+ }
124
135
 
125
136
  const onScrollToLower = () => {
126
- barLeft.value = indicatorWidth.value - indicatorBarWidth.value;
127
- emit("right");
128
- };
137
+ barLeft.value = indicatorWidth.value - indicatorBarWidth.value
138
+ emit('scrollRight')
139
+ }
129
140
 
130
141
  const onScrollToUpper = () => {
131
- barLeft.value = 0;
132
- emit("left");
133
- };
142
+ barLeft.value = 0
143
+ emit('scrollLeft')
144
+ }
134
145
  </script>
135
146
 
136
147
  <style lang="scss" scoped>
137
- @import "./index.scss";
148
+ @import './index.scss';
138
149
  </style>
@@ -1,28 +1,35 @@
1
- import type { CSSProperties } from "vue";
1
+ import type { CSSProperties } from 'vue'
2
2
 
3
3
  export default interface HyScrollListProps {
4
4
  /**
5
5
  * @description 指示器的整体宽度 (默认 50 )
6
6
  * */
7
- indicatorWidth?: number;
7
+ indicatorWidth?: number
8
8
  /**
9
9
  * @description 滑块的宽度 (默认 20 )
10
10
  * */
11
- indicatorBarWidth?: number;
11
+ indicatorBarWidth?: number
12
12
  /**
13
13
  * @description 是否显示面板指示器 (默认 true )
14
14
  * */
15
- indicator?: boolean;
15
+ indicator?: boolean
16
16
  /**
17
17
  * @description 指示器非激活颜色 (默认 '#f2f2f2' )
18
18
  * */
19
- indicatorColor?: string;
19
+ indicatorColor?: string
20
20
  /**
21
21
  * @description 指示器的激活颜色 (默认 '#3c9cff' )
22
22
  * */
23
- indicatorActiveColor?: string;
23
+ indicatorActiveColor?: string
24
24
  /**
25
25
  * @description 指示器样式,可通过bottom,left,right进行定位
26
26
  * */
27
- indicatorStyle?: CSSProperties;
27
+ indicatorStyle?: CSSProperties
28
+ }
29
+
30
+ export interface IScrollListEmits {
31
+ /** 滑动到左边时触发 */
32
+ (e: 'scrollLeft'): void
33
+ /** 滑动到右边时触发 */
34
+ (e: 'scrollRight'): void
28
35
  }
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <view
3
- class="hy-search"
3
+ :class="['hy-search', customStyle]"
4
4
  @tap="clickHandler"
5
5
  :style="[
6
6
  {
@@ -87,146 +87,252 @@
87
87
  class="hy-search__action"
88
88
  :class="[(showActionBtn || show) && 'hy-search__action--active']"
89
89
  @tap.stop.prevent="confirm"
90
- >{{ actionText }}</text
91
90
  >
91
+ {{ actionText }}
92
+ </text>
92
93
  </view>
93
94
  </template>
94
95
 
95
96
  <script lang="ts">
97
+ /**
98
+ * 搜索组件,集成了常见搜索框所需功能,用户可以一键引入,开箱即用。
99
+ * @displayName hy-search
100
+ */
101
+ defineOptions({})
96
102
  export default {
97
103
  name: 'hy-search',
98
104
  options: {
99
105
  addGlobalClass: true,
100
106
  virtualHost: true,
101
- styleIsolation: 'shared'
102
- }
107
+ styleIsolation: 'shared',
108
+ },
103
109
  }
104
110
  </script>
105
111
 
106
112
  <script setup lang="ts">
107
- import { computed, nextTick, toRefs, ref, watch } from "vue";
108
- import defaultProps from "./props";
109
- import type IProps from "./typing";
110
- import { sleep, addUnit } from "../../utils";
111
- import { IconConfig } from "../../config";
112
- import HyIcon from "../hy-icon/hy-icon.vue";
113
+ import { computed, nextTick, toRefs, ref, watch, PropType, type CSSProperties } from 'vue'
114
+ import type { ISearchEmits } from './typing'
115
+ import { sleep, addUnit } from '../../utils'
116
+ import { IconConfig } from '../../config'
117
+ import HyIcon from '../hy-icon/hy-icon.vue'
118
+ import type HyIconProps from '../hy-icon/typing'
113
119
 
114
- const props = withDefaults(defineProps<IProps>(), defaultProps);
115
- const { focus, modelValue, showAction, animation, disabled } = toRefs(props);
116
- const emit = defineEmits([
117
- "click",
118
- "change",
119
- "update:modelValue",
120
- "clickIcon",
121
- "search",
122
- "clear",
123
- "confirm",
124
- "change",
125
- "focus",
126
- "blur",
127
- ]);
120
+ // const props = withDefaults(defineProps<IProps>(), defaultProps)
121
+ const props = defineProps({
122
+ /** 输入框初始值 */
123
+ modelValue: String,
124
+ /**
125
+ * 搜索框形状
126
+ * @values circle,square
127
+ * */
128
+ shape: {
129
+ type: String,
130
+ default: 'circle',
131
+ },
132
+ /** 搜索框背景颜色 */
133
+ bgColor: String,
134
+ /** 占位文字内容 */
135
+ placeholder: {
136
+ type: String,
137
+ default: '请输入关键字',
138
+ },
139
+ /** 是否启用清除控件 */
140
+ clear: {
141
+ type: Boolean,
142
+ default: true,
143
+ },
144
+ /** 是否自动获得焦点 */
145
+ focus: {
146
+ type: Boolean,
147
+ default: false,
148
+ },
149
+ /** 是否显示右侧控件 */
150
+ showAction: {
151
+ type: Boolean,
152
+ default: true,
153
+ },
154
+ /** 右侧控件文字 */
155
+ actionText: {
156
+ type: String,
157
+ default: '搜索',
158
+ },
159
+ /** 右侧控件的样式,对象形式 */
160
+ actionStyle: {
161
+ type: Object as PropType<CSSProperties>,
162
+ default: {},
163
+ },
164
+ /** 输入框内容水平对齐方式 */
165
+ inputAlign: {
166
+ type: String,
167
+ default: 'left',
168
+ },
169
+ /** 自定义输入框样式,对象形式 */
170
+ inputStyle: {
171
+ type: Object as PropType<CSSProperties>,
172
+ default: {},
173
+ },
174
+ /** 是否启用输入框 */
175
+ disabled: {
176
+ type: Boolean,
177
+ default: false,
178
+ },
179
+ /** 边框颜色,配置了颜色,才会有边框 */
180
+ borderColor: {
181
+ type: String,
182
+ default: 'transparent',
183
+ },
184
+ /** 输入框字体颜色 */
185
+ color: String,
186
+ /** placeholder的颜色 */
187
+ placeholderColor: {
188
+ type: String,
189
+ default: '#909399',
190
+ },
191
+ /** 输入框左边的图标属性集合,可以为图标名称或图片路径 */
192
+ searchIcon: Object as PropType<HyIconProps>,
193
+ /** 组件与其他上下左右之间的距离,带单位的字符串形式,如"30px" */
194
+ margin: {
195
+ type: [String, Number],
196
+ default: 0,
197
+ },
198
+ /** 是否开启动画,见上方说明 */
199
+ animation: {
200
+ type: Boolean,
201
+ default: false,
202
+ },
203
+ /** 输入框最大能输入的长度,-1为不限制长度 */
204
+ maxlength: {
205
+ type: Number,
206
+ default: -1,
207
+ },
208
+ /** 输入框高度,单位px */
209
+ height: {
210
+ type: Number,
211
+ default: 30,
212
+ },
213
+ /** 搜索框左边显示内容 */
214
+ label: String,
215
+ /** 键盘弹起时,是否自动上推页面 */
216
+ adjustPosition: {
217
+ type: Boolean,
218
+ default: true,
219
+ },
220
+ /** 键盘收起时,是否自动失去焦点 */
221
+ autoBlur: {
222
+ type: Boolean,
223
+ default: true,
224
+ },
225
+ /** 定义需要用到的外部样式 */
226
+ customStyle: {
227
+ type: Object as PropType<CSSProperties>,
228
+ },
229
+ /** 自定义外部类名 */
230
+ customClass: String,
231
+ })
232
+ const { focus, modelValue, showAction, animation, disabled } = toRefs(props)
233
+ const emit = defineEmits<ISearchEmits>()
128
234
 
129
- const keyword = ref<string>("");
235
+ const keyword = ref<string>('')
130
236
  // 是否显示右边的清除图标
131
- const showClear = ref<boolean>(false);
132
- const show = ref<boolean>(false);
237
+ const showClear = ref<boolean>(false)
238
+ const show = ref<boolean>(false)
133
239
  // 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件
134
- const focused = ref(focus.value);
240
+ const focused = ref(focus.value)
135
241
 
136
242
  watch(
137
243
  () => keyword.value,
138
244
  (newValue: string) => {
139
- emit("update:modelValue", newValue);
140
- emit("change", newValue);
245
+ emit('update:modelValue', newValue)
246
+ emit('change', newValue)
141
247
  },
142
- );
248
+ )
143
249
 
144
250
  watch(
145
251
  () => modelValue.value,
146
252
  (newValue: string) => {
147
- keyword.value = newValue;
253
+ keyword.value = newValue
148
254
  },
149
255
  { immediate: true },
150
- );
256
+ )
151
257
 
152
258
  const showActionBtn = computed<boolean>(() => {
153
- return !animation.value && showAction.value;
154
- });
259
+ return !animation.value && showAction.value
260
+ })
155
261
 
156
262
  /**
157
263
  * @description
158
264
  * */
159
265
  const inputChange = (e: Event) => {
160
- keyword.value = e.detail.value;
161
- };
266
+ keyword.value = e.detail.value
267
+ }
162
268
  /**
163
269
  * @description 清空输入
164
270
  * */
165
271
  const clear = () => {
166
- keyword.value = "";
272
+ keyword.value = ''
167
273
  // 延后发出事件,避免在父组件监听clear事件时,value为更新前的值(不为空)
168
274
  nextTick(() => {
169
- emit("clear");
170
- });
171
- };
275
+ emit('clear')
276
+ })
277
+ }
172
278
  /**
173
279
  * @description 确定搜索
174
280
  * */
175
281
  const search = (e: InputEvent) => {
176
- emit("search", e.detail.value);
282
+ emit('search', e.detail.value)
177
283
  try {
178
284
  // 收起键盘
179
- uni.hideKeyboard();
285
+ uni.hideKeyboard()
180
286
  } catch (e) {}
181
- };
287
+ }
182
288
  /**
183
289
  * @description 点击右边自定义按钮的事件
184
290
  */
185
291
  const confirm = () => {
186
- emit("confirm", keyword.value);
292
+ emit('confirm', keyword.value)
187
293
  try {
188
294
  // 收起键盘
189
- uni.hideKeyboard();
295
+ uni.hideKeyboard()
190
296
  } catch (e) {}
191
- };
297
+ }
192
298
  /**
193
299
  * @description 获取焦点
194
300
  * */
195
301
  const getFocus = () => {
196
- focused.value = true;
302
+ focused.value = true
197
303
  // 开启右侧搜索按钮展开的动画效果
198
- if (animation.value && showAction.value) show.value = true;
199
- emit("focus", keyword.value);
200
- };
304
+ if (animation.value && showAction.value) show.value = true
305
+ emit('focus', keyword.value)
306
+ }
201
307
  /**
202
308
  * @description 失去焦点
203
309
  */
204
310
  const blur = async () => {
205
311
  // 最开始使用的是监听图标@touchstart事件,自从hx2.8.4后,此方法在微信小程序出错
206
312
  // 这里改为监听点击事件,手点击清除图标时,同时也发生了@blur事件,导致图标消失而无法点击,这里做一个延时
207
- show.value = false;
208
- emit("blur", keyword.value);
209
- await sleep(100);
210
- focused.value = false;
211
- };
313
+ show.value = false
314
+ emit('blur', keyword.value)
315
+ await sleep(100)
316
+ focused.value = false
317
+ }
212
318
  /**
213
319
  * @description 点击搜索框,只有disabled=true时才发出事件,因为禁止了输入,意味着是想跳转真正的搜索页
214
320
  * */
215
321
  const clickHandler = () => {
216
- if (disabled.value) emit("click");
217
- };
322
+ if (disabled.value) emit('click')
323
+ }
218
324
  /**
219
325
  * @description 点击左边图标
220
326
  * */
221
327
  const clickIcon = () => {
222
- emit("clickIcon", keyword.value);
328
+ emit('clickIcon', keyword.value)
223
329
  try {
224
330
  // 收起键盘
225
- uni.hideKeyboard();
331
+ uni.hideKeyboard()
226
332
  } catch (e) {}
227
- };
333
+ }
228
334
  </script>
229
335
 
230
336
  <style lang="scss" scoped>
231
- @import "./index.scss";
337
+ @import './index.scss';
232
338
  </style>