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,224 +1,276 @@
1
1
  <template>
2
2
  <text
3
- class="hy-count-to"
4
- :style="{
5
- fontSize: addUnit(fontSize),
6
- fontWeight: bold ? 'bold' : 'normal',
7
- color: color,
8
- }"
9
- >{{ displayValue }}</text
3
+ :class="['hy-count-to', customClass]"
4
+ :style="[
5
+ {
6
+ fontSize: addUnit(fontSize),
7
+ fontWeight: bold ? 'bold' : 'normal',
8
+ color: color,
9
+ },
10
+ customStyle,
11
+ ]"
10
12
  >
13
+ {{ displayValue }}
14
+ </text>
11
15
  </template>
12
16
 
13
17
  <script lang="ts">
18
+ /**
19
+ * 一般用于需要滚动数字到某一个值的场景,目标要求是一个递增的值。
20
+ * @displayName hy-count-to
21
+ */
22
+ defineOptions({})
14
23
  export default {
15
24
  name: 'hy-count-to',
16
25
  options: {
17
26
  addGlobalClass: true,
18
27
  virtualHost: true,
19
- styleIsolation: 'shared'
20
- }
28
+ styleIsolation: 'shared',
29
+ },
21
30
  }
22
31
  </script>
23
32
 
24
33
  <script setup lang="ts">
25
- import type IProps from "./typing";
26
- import defaultProps from "./props";
27
- import { computed, onMounted, onUnmounted, ref, toRefs, watch } from "vue";
28
- import { addUnit, isNumber } from "../../utils";
29
-
30
- const props = withDefaults(defineProps<IProps>(), defaultProps);
31
- const {
32
- startVal,
33
- duration,
34
- endVal,
35
- autoplay,
36
- separator,
37
- useEasing,
38
- decimals,
39
- decimal,
40
- } = toRefs(props);
41
- const emit = defineEmits(["end"]);
34
+ import type { ICountToEmits } from './typing'
35
+ import { computed, onMounted, ref, toRefs, watch } from 'vue'
36
+ import type { CSSProperties, PropType } from 'vue'
37
+ import { addUnit, isNumber } from '../../utils'
38
+
39
+ // const props = withDefaults(defineProps<IProps>(), defaultProps);
40
+ const props = defineProps({
41
+ /** 开始的数值,默认从0增长到某一个数 */
42
+ startVal: {
43
+ type: Number,
44
+ default: 0,
45
+ },
46
+ /** 要滚动的目标数值,必须 */
47
+ endVal: {
48
+ type: Number,
49
+ default: 0,
50
+ required: true,
51
+ },
52
+ /** 滚动到目标数值的动画持续时间,单位为毫秒(ms) */
53
+ duration: {
54
+ type: Number,
55
+ default: 2000,
56
+ },
57
+ /** 设置数值后是否自动开始滚动 */
58
+ autoplay: {
59
+ type: Boolean,
60
+ default: true,
61
+ },
62
+ /** 要显示的小数位数 */
63
+ decimals: {
64
+ type: Number,
65
+ default: 0,
66
+ },
67
+ /** 滚动结束时,是否缓动结尾 */
68
+ useEasing: {
69
+ type: Boolean,
70
+ default: true,
71
+ },
72
+ /** 十进制分割 */
73
+ decimal: {
74
+ type: String,
75
+ default: '.',
76
+ },
77
+ /** 字体颜色 */
78
+ color: String,
79
+ /** 字体大小,单位px */
80
+ fontSize: {
81
+ type: [Number, String],
82
+ default: 22,
83
+ },
84
+ /** 字体是否加粗 */
85
+ bold: {
86
+ type: Boolean,
87
+ default: false,
88
+ },
89
+ /** 千位分隔符 */
90
+ separator: String,
91
+ /** 定义需要用到的外部样式 */
92
+ customStyle: {
93
+ type: Object as PropType<CSSProperties>,
94
+ },
95
+ /** 自定义外部类名 */
96
+ customClass: String,
97
+ })
98
+ const { startVal, duration, endVal, autoplay, separator, useEasing, decimals, decimal } =
99
+ toRefs(props)
100
+ const emit = defineEmits<ICountToEmits>()
42
101
 
43
102
  const formatNumber = (num: number): string => {
44
- let numStr = "";
103
+ let numStr = ''
45
104
  // 将num转为Number类型,因为其值可能为字符串数值,调用toFixed会报错
46
- num = Number(num);
47
- numStr = num.toFixed(Number(decimals.value));
48
- numStr += "";
49
- const x = numStr.split(".");
50
- let x1 = x[0];
51
- const x2 = x.length > 1 ? decimal.value + x[1] : "";
52
- const rgx = /(\d+)(\d{3})/;
105
+ num = Number(num)
106
+ numStr = num.toFixed(Number(decimals.value))
107
+ numStr += ''
108
+ const x = numStr.split('.')
109
+ let x1 = x[0]
110
+ const x2 = x.length > 1 ? decimal.value + x[1] : ''
111
+ const rgx = /(\d+)(\d{3})/
53
112
  if (separator.value && !isNumber(separator.value)) {
54
113
  while (rgx.test(x1)) {
55
- x1 = x1.replace(rgx, "$1" + separator.value + "$2");
114
+ x1 = x1.replace(rgx, '$1' + separator.value + '$2')
56
115
  }
57
116
  }
58
- return x1 + x2;
59
- };
60
-
61
- const localStartVal = ref(startVal.value);
62
- let displayValue = ref(formatNumber(startVal.value));
63
- const printVal = ref<number | null>(null);
64
- const paused = ref(false); // 是否暂停
65
- const localDuration = ref(Number(duration.value));
66
- const startTime = ref<number | null>(null); // 开始的时间
67
- const timestamp = ref<number | null>(null); // 时间戳
68
- const remaining = ref<number | null>(null); // 停留的时间
69
- const rAF = ref<number>(); // 停留的时间
70
- const lastTime = ref(0); // 上一次的时间
117
+ return x1 + x2
118
+ }
119
+
120
+ const localStartVal = ref(startVal.value)
121
+ let displayValue = ref(formatNumber(startVal.value))
122
+ const printVal = ref<number | null>(null)
123
+ const paused = ref(false) // 是否暂停
124
+ const localDuration = ref(Number(duration.value))
125
+ const startTime = ref<number | null>(null) // 开始的时间
126
+ const timestamp = ref<number | null>(null) // 时间戳
127
+ const remaining = ref<number | null>(null) // 停留的时间
128
+ const rAF = ref<number>() // 停留的时间
129
+ const lastTime = ref(0) // 上一次的时间
71
130
 
72
131
  const countDown = computed(() => {
73
- return startVal.value > endVal.value;
74
- });
132
+ return startVal.value > endVal.value
133
+ })
75
134
 
76
135
  watch(
77
136
  () => startVal.value,
78
137
  () => autoplay.value && start(),
79
- );
138
+ )
80
139
 
81
140
  watch(
82
141
  () => endVal.value,
83
142
  () => autoplay.value && start(),
84
- );
143
+ )
85
144
 
86
145
  onMounted(() => {
87
- autoplay.value && start();
88
- });
146
+ autoplay.value && start()
147
+ })
89
148
 
90
149
  const easingFn = (t: number, b: number, c: number, d: number) => {
91
- return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b;
92
- };
150
+ return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b
151
+ }
93
152
 
94
153
  const requestAnimationFrame = (callback: Function): number => {
95
- const currTime = new Date().getTime();
154
+ const currTime = new Date().getTime()
96
155
  // 为了使setTimteout的尽可能的接近每秒60帧的效果
97
- const timeToCall = Math.max(0, 16 - (currTime - lastTime.value));
156
+ const timeToCall = Math.max(0, 16 - (currTime - lastTime.value))
98
157
  const id = setTimeout(() => {
99
- callback(currTime + timeToCall);
100
- }, timeToCall) as unknown as number;
101
- lastTime.value = currTime + timeToCall;
102
- return id;
103
- };
158
+ callback(currTime + timeToCall)
159
+ }, timeToCall) as unknown as number
160
+ lastTime.value = currTime + timeToCall
161
+ return id
162
+ }
104
163
 
105
164
  const cancelAnimationFrame = (id?: number) => {
106
- clearTimeout(id);
107
- };
165
+ clearTimeout(id)
166
+ }
108
167
 
109
168
  /**
110
169
  * @description 开始滚动数字
111
170
  * */
112
171
  const start = () => {
113
- localStartVal.value = startVal.value;
114
- startTime.value = null;
115
- localDuration.value = duration.value;
116
- paused.value = false;
117
- rAF.value = requestAnimationFrame(count);
118
- };
172
+ localStartVal.value = startVal.value
173
+ startTime.value = null
174
+ localDuration.value = duration.value
175
+ paused.value = false
176
+ rAF.value = requestAnimationFrame(count)
177
+ }
119
178
 
120
179
  /**
121
180
  * @description 暂定状态,重新再开始滚动;或者滚动状态下,暂停
122
181
  * */
123
182
  const reStart = () => {
124
183
  if (paused.value) {
125
- resume();
126
- paused.value = false;
184
+ resume()
185
+ paused.value = false
127
186
  } else {
128
- stop();
129
- paused.value = true;
187
+ stop()
188
+ paused.value = true
130
189
  }
131
- };
190
+ }
132
191
 
133
192
  /**
134
193
  * @description 暂停
135
194
  * */
136
195
  const stop = () => {
137
- cancelAnimationFrame(rAF.value);
138
- };
196
+ cancelAnimationFrame(rAF.value)
197
+ }
139
198
 
140
199
  /**
141
200
  * @description 重新开始(暂停的情况下)
142
201
  * */
143
202
  const resume = () => {
144
- if (!remaining.value) return;
145
- startTime.value = 0;
146
- localDuration.value = remaining.value;
203
+ if (!remaining.value) return
204
+ startTime.value = 0
205
+ localDuration.value = remaining.value
147
206
  if (printVal.value) {
148
- localStartVal.value = printVal.value;
207
+ localStartVal.value = printVal.value
149
208
  }
150
- requestAnimationFrame(count);
151
- };
209
+ requestAnimationFrame(count)
210
+ }
152
211
 
153
212
  /**
154
213
  * @description 重置
155
214
  * */
156
215
  const reset = () => {
157
- startTime.value = null;
158
- cancelAnimationFrame(rAF.value);
159
- displayValue.value = formatNumber(startVal.value);
160
- };
216
+ startTime.value = null
217
+ cancelAnimationFrame(rAF.value)
218
+ displayValue.value = formatNumber(startVal.value)
219
+ }
161
220
  const count = (time_stamp: number) => {
162
- if (!startTime.value) startTime.value = time_stamp;
163
- timestamp.value = time_stamp;
164
- const progress = time_stamp - startTime.value;
165
- remaining.value = localDuration.value - progress;
221
+ if (!startTime.value) startTime.value = time_stamp
222
+ timestamp.value = time_stamp
223
+ const progress = time_stamp - startTime.value
224
+ remaining.value = localDuration.value - progress
166
225
  if (useEasing.value) {
167
226
  if (countDown.value) {
168
227
  printVal.value =
169
228
  localStartVal.value -
170
- easingFn(
171
- progress,
172
- 0,
173
- localStartVal.value - endVal.value,
174
- localDuration.value,
175
- );
229
+ easingFn(progress, 0, localStartVal.value - endVal.value, localDuration.value)
176
230
  } else {
177
231
  printVal.value = easingFn(
178
232
  progress,
179
233
  localStartVal.value,
180
234
  endVal.value - localStartVal.value,
181
235
  localDuration.value,
182
- );
236
+ )
183
237
  }
184
238
  } else {
185
239
  if (countDown.value) {
186
240
  printVal.value =
187
241
  localStartVal.value -
188
- (localStartVal.value - endVal.value) * (progress / localDuration.value);
242
+ (localStartVal.value - endVal.value) * (progress / localDuration.value)
189
243
  } else {
190
244
  printVal.value =
191
245
  localStartVal.value +
192
- (endVal.value - localStartVal.value) * (progress / localDuration.value);
246
+ (endVal.value - localStartVal.value) * (progress / localDuration.value)
193
247
  }
194
248
  }
195
249
  if (countDown.value) {
196
- printVal.value =
197
- printVal.value < endVal.value ? endVal.value : printVal.value;
250
+ printVal.value = printVal.value < endVal.value ? endVal.value : printVal.value
198
251
  } else {
199
- printVal.value =
200
- printVal.value > endVal.value ? endVal.value : printVal.value;
252
+ printVal.value = printVal.value > endVal.value ? endVal.value : printVal.value
201
253
  }
202
- displayValue.value = formatNumber(printVal.value);
254
+ displayValue.value = formatNumber(printVal.value)
203
255
  if (progress < localDuration.value) {
204
- rAF.value = requestAnimationFrame(count);
256
+ rAF.value = requestAnimationFrame(count)
205
257
  } else {
206
- emit("end");
258
+ emit('end')
207
259
  }
208
- };
260
+ }
209
261
 
210
262
  const destroyed = () => {
211
- cancelAnimationFrame(rAF.value);
212
- };
263
+ cancelAnimationFrame(rAF.value)
264
+ }
213
265
 
214
266
  defineExpose({
215
267
  start,
216
268
  stop,
217
269
  reStart,
218
270
  resume,
219
- });
271
+ })
220
272
  </script>
221
273
 
222
274
  <style scoped lang="scss">
223
- @import "./index.scss";
275
+ @import './index.scss';
224
276
  </style>
@@ -2,45 +2,49 @@ export default interface HyCountToProps {
2
2
  /**
3
3
  * @description 开始的数值,默认从0增长到某一个数(默认 0 )
4
4
  * */
5
- startVal?: number;
5
+ startVal?: number
6
6
  /**
7
7
  * @description 要滚动的目标数值,必须 (默认 0 )
8
8
  * */
9
- endVal?: number;
9
+ endVal: number
10
10
  /**
11
11
  * @description 滚动到目标数值的动画持续时间,单位为毫秒(ms) (默认
12
12
  * */
13
- duration?: number;
13
+ duration?: number
14
14
  /**
15
15
  * @description 设置数值后是否自动开始滚动 (默认 true )
16
16
  * */
17
- autoplay?: boolean;
17
+ autoplay?: boolean
18
18
  /**
19
19
  * @description 要显示的小数位数,见官网说明(默认 0 )
20
20
  * */
21
- decimals?: number;
21
+ decimals?: number
22
22
  /**
23
23
  * @description 滚动结束时,是否缓动结尾,见官网说明(默认 true )
24
24
  * */
25
- useEasing?: boolean;
25
+ useEasing?: boolean
26
26
  /**
27
27
  * @description 十进制分割 ( 默认 "." )
28
28
  * */
29
- decimal?: string;
29
+ decimal?: string
30
30
  /**
31
31
  * @description 字体颜色( 默认 '#606266' )
32
32
  * */
33
- color?: string;
33
+ color?: string
34
34
  /**
35
35
  * @description 字体大小,单位px( 默认 22 )
36
36
  * */
37
- fontSize?: number | string;
37
+ fontSize?: number | string
38
38
  /**
39
39
  * @description 字体是否加粗(默认 false )
40
40
  * */
41
- bold?: boolean;
41
+ bold?: boolean
42
42
  /**
43
43
  * @description 千位分隔符,见官网说明
44
44
  * */
45
- separator?: string;
45
+ separator?: string
46
+ }
47
+
48
+ export interface ICountToEmits {
49
+ (e: 'end'): void
46
50
  }