hy-app 0.1.2 → 0.1.3

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 (221) hide show
  1. package/README.md +1 -1
  2. package/api/http.ts +8 -8
  3. package/components/dialog/index.ts +2 -2
  4. package/components/hy-address-picker/hy-address-picker.vue +3 -29
  5. package/components/hy-address-picker/index.scss +27 -0
  6. package/components/hy-avatar/hy-avatar.vue +1 -45
  7. package/components/hy-avatar/index.scss +45 -0
  8. package/components/hy-avatar/typing.d.ts +1 -1
  9. package/components/hy-back-top/hy-back-top.vue +7 -22
  10. package/components/hy-back-top/index.scss +16 -0
  11. package/components/hy-back-top/props.ts +4 -4
  12. package/components/hy-back-top/typing.d.ts +2 -3
  13. package/components/hy-badge/hy-badge.vue +1 -72
  14. package/components/hy-badge/index.scss +72 -0
  15. package/components/hy-button/hy-button.vue +12 -124
  16. package/components/hy-button/index.scss +116 -0
  17. package/components/hy-calendar/header.vue +76 -0
  18. package/components/hy-calendar/hy-calendar.vue +366 -0
  19. package/components/hy-calendar/index.scss +171 -0
  20. package/components/hy-calendar/month.vue +524 -0
  21. package/components/hy-calendar/props.ts +37 -0
  22. package/components/hy-calendar/typing.d.ts +126 -0
  23. package/components/hy-card/hy-card.vue +21 -84
  24. package/components/hy-card/index.scss +57 -0
  25. package/components/hy-card/props.ts +2 -2
  26. package/components/hy-card/typing.d.ts +1 -1
  27. package/components/hy-cell/hy-cell.vue +1 -137
  28. package/components/hy-cell/index.scss +137 -0
  29. package/components/hy-check-button/hy-check-button.vue +1 -0
  30. package/components/hy-check-button/index.scss +5 -0
  31. package/components/hy-checkbox/hy-checkbox.vue +2 -95
  32. package/components/hy-checkbox/index.scss +94 -0
  33. package/components/hy-checkbox/typing.d.ts +1 -2
  34. package/components/hy-count-down/hy-count-down.vue +150 -0
  35. package/components/hy-count-down/index.scss +6 -0
  36. package/components/hy-count-down/index.ts +52 -0
  37. package/components/hy-count-down/props.ts +10 -0
  38. package/components/hy-count-down/typing.d.ts +20 -0
  39. package/components/hy-count-to/hy-count-to.vue +213 -0
  40. package/components/hy-count-to/index.scss +6 -0
  41. package/components/hy-count-to/props.ts +17 -0
  42. package/components/hy-count-to/typing.d.ts +48 -0
  43. package/components/hy-datetime-picker/hy-datetime-picker.vue +2 -28
  44. package/components/hy-datetime-picker/index.scss +28 -0
  45. package/components/hy-divider/hy-divider.vue +24 -49
  46. package/components/hy-divider/index.scss +25 -0
  47. package/components/hy-divider/props.ts +2 -2
  48. package/components/hy-divider/typing.d.ts +1 -1
  49. package/components/hy-dropdown/hy-dropdown.vue +43 -0
  50. package/components/hy-dropdown/index.scss +17 -0
  51. package/components/hy-dropdown/props.ts +17 -0
  52. package/components/hy-dropdown/typing.d.ts +48 -0
  53. package/components/hy-dropdown-item/hy-dropdown-item.vue +194 -0
  54. package/components/hy-dropdown-item/index.scss +96 -0
  55. package/components/hy-dropdown-item/props.ts +10 -0
  56. package/components/hy-dropdown-item/typing.d.ts +31 -0
  57. package/components/hy-empty/hy-empty.vue +8 -26
  58. package/components/hy-empty/index.scss +19 -0
  59. package/components/hy-empty/props.ts +2 -2
  60. package/components/hy-empty/typing.d.ts +1 -1
  61. package/components/hy-float-button/hy-float-button.vue +201 -0
  62. package/components/hy-float-button/index.scss +69 -0
  63. package/components/hy-float-button/props.ts +25 -0
  64. package/components/hy-float-button/typing.d.ts +93 -0
  65. package/components/hy-folding-panel/hy-folding-panel.vue +9 -12
  66. package/components/hy-folding-panel/index.scss +6 -0
  67. package/components/hy-folding-panel/props.ts +2 -2
  68. package/components/hy-folding-panel/typing.d.ts +2 -2
  69. package/components/hy-form/hy-form.vue +17 -34
  70. package/components/hy-form/index.scss +30 -0
  71. package/components/hy-form/props.ts +2 -0
  72. package/components/hy-form/typing.d.ts +9 -1
  73. package/components/hy-grid/hy-grid.vue +1 -43
  74. package/components/hy-grid/index.scss +40 -0
  75. package/components/hy-icon/hy-icon.vue +1 -93
  76. package/components/hy-icon/index.scss +84 -0
  77. package/components/hy-image/hy-image.vue +212 -0
  78. package/components/hy-image/index.scss +26 -0
  79. package/components/hy-image/props.ts +24 -0
  80. package/components/hy-image/typing.d.ts +76 -0
  81. package/components/hy-input/hy-input.vue +2 -72
  82. package/components/hy-input/index.scss +65 -0
  83. package/components/hy-line/hy-line.vue +4 -8
  84. package/components/hy-line/index.scss +5 -0
  85. package/components/hy-line/props.ts +3 -3
  86. package/components/hy-line/typing.d.ts +2 -2
  87. package/components/hy-line-progress/hy-line-progress.vue +15 -44
  88. package/components/hy-line-progress/index.scss +38 -0
  89. package/components/hy-line-progress/props.ts +2 -2
  90. package/components/hy-line-progress/typing.d.ts +1 -1
  91. package/components/hy-list/hy-list.vue +11 -41
  92. package/components/hy-list/index.scss +32 -0
  93. package/components/hy-list/props.ts +2 -2
  94. package/components/hy-loading/hy-loading.vue +95 -0
  95. package/components/hy-loading/index.scss +103 -0
  96. package/components/hy-loading/props.ts +17 -0
  97. package/components/hy-loading/typing.d.ts +52 -0
  98. package/components/hy-login/TheUserLogin.vue +16 -16
  99. package/components/hy-login/hy-login.vue +9 -9
  100. package/components/hy-login/props.ts +4 -4
  101. package/components/hy-modal/hy-modal.vue +11 -89
  102. package/components/hy-modal/index.scss +77 -0
  103. package/components/hy-modal/props.ts +2 -2
  104. package/components/hy-modal/typing.d.ts +1 -1
  105. package/components/hy-navbar/hy-navbar.vue +20 -92
  106. package/components/hy-navbar/index.scss +67 -0
  107. package/components/hy-navbar/props.ts +2 -2
  108. package/components/hy-navbar/typing.d.ts +1 -1
  109. package/components/hy-notice-bar/hy-column-notice.vue +11 -39
  110. package/components/hy-notice-bar/hy-notice-bar.vue +10 -12
  111. package/components/hy-notice-bar/hy-row-notice.vue +5 -56
  112. package/components/hy-notice-bar/index.scss +93 -0
  113. package/components/hy-notice-bar/props.ts +4 -2
  114. package/components/hy-notice-bar/typing.d.ts +13 -3
  115. package/components/hy-number-step/hy-number-step.vue +1 -70
  116. package/components/hy-number-step/index.scss +71 -0
  117. package/components/hy-overlay/hy-overlay.vue +2 -14
  118. package/components/hy-overlay/index.scss +9 -0
  119. package/components/hy-picker/hy-picker.vue +1 -68
  120. package/components/hy-picker/index.scss +68 -0
  121. package/components/hy-popup/hy-popup.vue +1 -74
  122. package/components/hy-popup/index.scss +60 -0
  123. package/components/hy-price/hy-price.vue +1 -11
  124. package/components/hy-price/index.scss +11 -0
  125. package/components/hy-qrcode/hy-qrcode.vue +15 -37
  126. package/components/hy-qrcode/index.scss +23 -0
  127. package/components/hy-qrcode/props.ts +2 -2
  128. package/components/hy-qrcode/typing.d.ts +2 -2
  129. package/components/hy-radio/hy-radio.vue +2 -101
  130. package/components/hy-radio/index.scss +93 -0
  131. package/components/hy-radio/typing.d.ts +1 -2
  132. package/components/hy-rate/hy-rate.vue +1 -33
  133. package/components/hy-rate/index.scss +33 -0
  134. package/components/hy-read-more/hy-read-more.vue +7 -30
  135. package/components/hy-read-more/index.scss +25 -0
  136. package/components/hy-read-more/props.ts +3 -3
  137. package/components/hy-read-more/typing.d.ts +1 -1
  138. package/components/hy-safe-bottom/hy-safe-bottom.vue +5 -9
  139. package/components/hy-safe-bottom/index.scss +5 -0
  140. package/components/hy-scroll-list/hy-scroll-list.vue +13 -43
  141. package/components/hy-scroll-list/index.scss +34 -0
  142. package/components/hy-scroll-list/props.ts +2 -2
  143. package/components/hy-scroll-list/typing.d.ts +1 -1
  144. package/components/hy-search/hy-search.vue +1 -83
  145. package/components/hy-search/index.scss +83 -0
  146. package/components/hy-slider/hy-slider.vue +14 -92
  147. package/components/hy-slider/index.scss +77 -0
  148. package/components/hy-status-bar/hy-status-bar.vue +41 -0
  149. package/components/hy-status-bar/index.scss +6 -0
  150. package/components/hy-status-bar/props.ts +8 -0
  151. package/components/hy-status-bar/typing.d.ts +12 -0
  152. package/components/hy-steps/hy-steps.vue +36 -163
  153. package/components/hy-steps/index.scss +131 -0
  154. package/components/hy-steps/props.ts +2 -2
  155. package/components/hy-steps/typing.d.ts +2 -2
  156. package/components/hy-subsection/hy-subsection.vue +40 -132
  157. package/components/hy-subsection/index.scss +82 -0
  158. package/components/hy-subsection/props.ts +1 -0
  159. package/components/hy-subsection/typing.d.ts +13 -4
  160. package/components/hy-swipe-action/hy-swipe-action.vue +294 -0
  161. package/components/hy-swipe-action/index.scss +9 -0
  162. package/components/hy-swipe-action/index.wxs +235 -0
  163. package/components/hy-swipe-action/props.ts +16 -0
  164. package/components/hy-swipe-action/typing.d.ts +55 -0
  165. package/components/hy-swipe-action/wxs.js +15 -0
  166. package/components/hy-swiper/hy-swiper-indicator.vue +5 -35
  167. package/components/hy-swiper/hy-swiper.vue +1 -54
  168. package/components/hy-swiper/index.scss +82 -0
  169. package/components/hy-switch/hy-switch.vue +62 -72
  170. package/components/hy-switch/index.scss +46 -0
  171. package/components/hy-switch/props.ts +4 -1
  172. package/components/hy-switch/typing.d.ts +14 -1
  173. package/components/hy-tabs/hy-tabs.vue +22 -81
  174. package/components/hy-tabs/index.scss +63 -0
  175. package/components/hy-tabs/props.ts +5 -5
  176. package/components/hy-tabs/typing.d.ts +1 -1
  177. package/components/hy-tag/hy-tag.vue +1 -214
  178. package/components/hy-tag/index.scss +204 -0
  179. package/components/hy-text/hy-text.vue +238 -0
  180. package/components/hy-text/index.scss +70 -0
  181. package/components/hy-text/index.ts +0 -0
  182. package/components/hy-text/props.ts +30 -0
  183. package/components/hy-text/typing.d.ts +98 -0
  184. package/components/hy-textarea/hy-textarea.vue +1 -46
  185. package/components/hy-textarea/index.scss +40 -0
  186. package/components/hy-tooltip/hy-tooltip.vue +42 -95
  187. package/components/hy-tooltip/index.scss +64 -0
  188. package/components/hy-tooltip/props.ts +2 -2
  189. package/components/hy-tooltip/typing.d.ts +1 -1
  190. package/components/hy-transition/hy-transition.vue +4 -2
  191. package/components/hy-transition/typing.d.ts +1 -13
  192. package/components/hy-upload/hy-upload.vue +37 -182
  193. package/components/hy-upload/index.scss +147 -0
  194. package/components/hy-upload/props.ts +2 -2
  195. package/components/hy-upload/typing.d.ts +11 -11
  196. package/components/hy-warn/hy-warn.vue +15 -123
  197. package/components/hy-warn/index.scss +109 -0
  198. package/components/hy-warn/props.ts +3 -3
  199. package/components/hy-warn/typing.d.ts +4 -3
  200. package/components/hy-waterfall/index.scss +82 -0
  201. package/components/index.ts +25 -1
  202. package/components/message/index.ts +54 -54
  203. package/config/color.ts +2 -1
  204. package/global/index.ts +6 -6
  205. package/global/register-properties.ts +2 -2
  206. package/index.scss +2 -1
  207. package/libs/css/common.scss +14 -2
  208. package/package.json +2 -2
  209. package/{libs/css → public/font}/iconfont.css +4 -4
  210. package/theme.scss +6 -4
  211. package/typing/modules/common.d.ts +16 -1
  212. package/utils/calendar.js +1021 -0
  213. package/utils/colorGradient.ts +112 -0
  214. package/utils/index.ts +2 -0
  215. package/utils/inside.ts +80 -34
  216. package/utils/inspect.ts +66 -0
  217. package/utils/utils.ts +11 -12
  218. package/libs/css/download.zip +0 -0
  219. /package/{libs/css → public/font}/iconfont.ttf +0 -0
  220. /package/{libs/css → public/font}/iconfont.woff +0 -0
  221. /package/{libs/css → public/font}/iconfont.woff2 +0 -0
@@ -0,0 +1,94 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @use "../../theme.scss" as *;
3
+
4
+ .hy-checkbox {
5
+ &-group {
6
+ &--row {
7
+ /* #ifndef APP-NVUE */
8
+ display: flex;
9
+ /* #endif */
10
+ flex-flow: row wrap;
11
+ }
12
+
13
+ &--column {
14
+ @include flex(column);
15
+ }
16
+ }
17
+
18
+ /* #ifndef APP-NVUE */
19
+ @include flex(row);
20
+ /* #endif */
21
+ overflow: hidden;
22
+ flex-direction: row;
23
+ align-items: center;
24
+ margin-bottom: 5px;
25
+ margin-top: 5px;
26
+
27
+ &-label--left {
28
+ flex-direction: row;
29
+ }
30
+
31
+ &-label--right {
32
+ flex-direction: row-reverse;
33
+ justify-content: space-between;
34
+ }
35
+
36
+ &__icon-wrap {
37
+ /* #ifndef APP-NVUE */
38
+ box-sizing: border-box;
39
+ // nvue下,border-color过渡有问题
40
+ transition-property: border-color, background-color, color;
41
+ transition-duration: 0.2s;
42
+ /* #endif */
43
+ @include flex;
44
+ align-items: center;
45
+ justify-content: center;
46
+ color: transparent;
47
+ text-align: center;
48
+ margin-right: $hy-border-margin-padding-sm;
49
+ border: $hy-border-line;
50
+
51
+ /* #ifdef MP-TOUTIAO */
52
+ // 头条小程序兼容性问题,需要设置行高为0,否则图标偏下
53
+ &__icon {
54
+ line-height: 0;
55
+ }
56
+
57
+ /* #endif */
58
+
59
+ &--circle {
60
+ border-radius: 50%;
61
+ }
62
+
63
+ &--square {
64
+ border-radius: 3px;
65
+ }
66
+
67
+ &--checked {
68
+ color: $hy-text-color-inverse;
69
+ background-color: $hy-primary;
70
+ border-color: $hy-primary;
71
+ }
72
+
73
+ &--disabled {
74
+ background-color: $hy-color-disable-bg !important;
75
+ }
76
+
77
+ &--disabled--checked {
78
+ color: $hy-color-disable-icon !important;
79
+ }
80
+ }
81
+
82
+ &__label-wrap {
83
+ /* #ifndef APP-NVUE */
84
+ word-wrap: break-word;
85
+ /* #endif */
86
+ color: $hy-text-color;
87
+ font-size: $hy-font-size-base;
88
+ margin-right: $hy-border-margin-padding-sm;
89
+
90
+ &--disabled {
91
+ color: $hy-text-color-disable;
92
+ }
93
+ }
94
+ }
@@ -1,6 +1,5 @@
1
1
  import type { CSSProperties } from "vue";
2
2
  import type { CheckboxColumnsVo, IFieldNames } from "../hy-check-button/typing";
3
- import { HyApp } from "@/package/typing/modules/common";
4
3
 
5
4
  export default interface IProps {
6
5
  /**
@@ -70,5 +69,5 @@ export default interface IProps {
70
69
  /**
71
70
  * @description 排列方式,row-横向,column-纵向
72
71
  * */
73
- placement?: HyApp.PermutationType;
72
+ placement?: HyApp.DirectionType;
74
73
  }
@@ -0,0 +1,150 @@
1
+ <template>
2
+ <view class="hy-count-down">
3
+ <slot :record="timeData">
4
+ <text class="hy-count-down__text">{{ formattedTime }}</text>
5
+ </slot>
6
+ </view>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import type IProps from "./typing";
11
+ import defaultProps from "./props";
12
+ import { onMounted, onUnmounted, ref, toRefs, watch } from "vue";
13
+ import { isSameSecond, parseFormat, parseTimeData } from "./index";
14
+
15
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
16
+ const { time, autoStart, millisecond, format } = toRefs(props);
17
+ const emit = defineEmits(["change", "finish"]);
18
+
19
+ let timer: any;
20
+ // 各单位(天,时,分等)剩余时间
21
+ const timeData = ref(parseTimeData(time.value));
22
+ // 格式化后的时间,如"03:23:21"
23
+ const formattedTime = ref("");
24
+ // 倒计时是否正在进行中
25
+ const runing = ref(false);
26
+ // 结束的毫秒时间戳
27
+ const endTime = ref(0);
28
+ // 剩余的毫秒时间
29
+ const remainTime = ref(0);
30
+
31
+ watch(
32
+ () => time.value,
33
+ () => reset(),
34
+ );
35
+
36
+ onMounted(() => {
37
+ reset();
38
+ });
39
+
40
+ onUnmounted(() => {
41
+ clearTimeoutFn();
42
+ });
43
+
44
+ /**
45
+ * @description 开始倒计时
46
+ */
47
+ const start = () => {
48
+ if (runing.value) return;
49
+ // 标识为进行中
50
+ runing.value = true;
51
+ // 结束时间戳 = 此刻时间戳 + 剩余的时间
52
+ endTime.value = Date.now() + remainTime.value;
53
+ toTick();
54
+ };
55
+
56
+ /**
57
+ * @description 根据是否展示毫秒,执行不同操作函数
58
+ */
59
+ const toTick = () => {
60
+ if (millisecond.value) {
61
+ microTick();
62
+ } else {
63
+ macroTick();
64
+ }
65
+ };
66
+ const macroTick = () => {
67
+ clearTimeoutFn();
68
+ // 每隔一定时间,更新一遍定时器的值
69
+ // 同时此定时器的作用也能带来毫秒级的更新
70
+ timer = setTimeout(() => {
71
+ // 获取剩余时间
72
+ const remain = getRemainTime();
73
+ // 重设剩余时间
74
+ if (!isSameSecond(remain, remainTime.value) || remain === 0) {
75
+ setRemainTime(remain);
76
+ }
77
+ // 如果剩余时间不为0,则继续检查更新倒计时
78
+ if (remainTime.value !== 0) {
79
+ macroTick();
80
+ }
81
+ }, 30);
82
+ };
83
+
84
+ const microTick = () => {
85
+ clearTimeoutFn();
86
+ timer = setTimeout(() => {
87
+ setRemainTime(getRemainTime());
88
+ if (remainTime.value !== 0) {
89
+ microTick();
90
+ }
91
+ }, 50);
92
+ };
93
+
94
+ /**
95
+ * @description 获取剩余的时间
96
+ */
97
+ const getRemainTime = () => {
98
+ // 取最大值,防止出现小于0的剩余时间值
99
+ return Math.max(endTime.value - Date.now(), 0);
100
+ };
101
+ /**
102
+ * @description 设置剩余的时间
103
+ */
104
+ const setRemainTime = (remain: number) => {
105
+ remainTime.value = remain;
106
+ // 根据剩余的毫秒时间,得出该有天,小时,分钟等的值,返回一个对象
107
+ timeData.value = parseTimeData(remain);
108
+ emit("change", timeData.value);
109
+ // 得出格式化后的时间
110
+ formattedTime.value = parseFormat(format.value, timeData.value);
111
+ // 如果时间已到,停止倒计时
112
+ if (remain <= 0) {
113
+ pause();
114
+ emit("finish");
115
+ }
116
+ };
117
+ // 重置倒计时
118
+ const reset = () => {
119
+ pause();
120
+ remainTime.value = time.value;
121
+ setRemainTime(remainTime.value);
122
+ if (autoStart.value) {
123
+ start();
124
+ }
125
+ };
126
+ /**
127
+ * @description 暂停倒计时
128
+ * */
129
+ const pause = () => {
130
+ runing.value = false;
131
+ clearTimeoutFn();
132
+ };
133
+ /**
134
+ * @description 清空定时器
135
+ * */
136
+ const clearTimeoutFn = () => {
137
+ clearTimeout(timer);
138
+ timer = null;
139
+ };
140
+
141
+ defineExpose({
142
+ reset,
143
+ start,
144
+ pause,
145
+ });
146
+ </script>
147
+
148
+ <style scoped lang="scss">
149
+ @import "./index.scss";
150
+ </style>
@@ -0,0 +1,6 @@
1
+ .hy-count-down {
2
+ &__text {
3
+ font-size: 15px;
4
+ line-height: 22px;
5
+ }
6
+ }
@@ -0,0 +1,52 @@
1
+ import { padZero } from "../../utils";
2
+
3
+ const SECOND = 1000;
4
+ const MINUTE = 60 * SECOND;
5
+ const HOUR = 60 * MINUTE;
6
+ const DAY = 24 * HOUR;
7
+ export function parseTimeData(time: number) {
8
+ const days = Math.floor(time / DAY);
9
+ const hours = Math.floor((time % DAY) / HOUR);
10
+ const minutes = Math.floor((time % HOUR) / MINUTE);
11
+ const seconds = Math.floor((time % MINUTE) / SECOND);
12
+ const milliseconds = Math.floor(time % SECOND);
13
+ return {
14
+ days,
15
+ hours,
16
+ minutes,
17
+ seconds,
18
+ milliseconds,
19
+ };
20
+ }
21
+
22
+ export function parseFormat(format: string, timeData: AnyObject) {
23
+ let { days, hours, minutes, seconds, milliseconds } = timeData;
24
+ // 如果格式化字符串中不存在DD(天),则将天的时间转为小时中去
25
+ if (format.indexOf("DD") === -1) {
26
+ hours += days * 24;
27
+ } else {
28
+ // 对天补0
29
+ format = format.replace("DD", padZero(days));
30
+ }
31
+ // 其他同理于DD的格式化处理方式
32
+ if (format.indexOf("HH") === -1) {
33
+ minutes += hours * 60;
34
+ } else {
35
+ format = format.replace("HH", padZero(hours));
36
+ }
37
+ if (format.indexOf("mm") === -1) {
38
+ seconds += minutes * 60;
39
+ } else {
40
+ format = format.replace("mm", padZero(minutes));
41
+ }
42
+ if (format.indexOf("ss") === -1) {
43
+ milliseconds += seconds * 1000;
44
+ } else {
45
+ format = format.replace("ss", padZero(seconds));
46
+ }
47
+ return format.replace("SSS", padZero(milliseconds));
48
+ }
49
+
50
+ export function isSameSecond(time1: number, time2: number) {
51
+ return Math.floor(time1 / 1000) === Math.floor(time2 / 1000);
52
+ }
@@ -0,0 +1,10 @@
1
+ import type IProps from "./typing";
2
+
3
+ const defaultProps: IProps = {
4
+ time: 0,
5
+ format: "HH:mm:ss",
6
+ autoStart: true,
7
+ millisecond: false,
8
+ };
9
+
10
+ export default defaultProps;
@@ -0,0 +1,20 @@
1
+ import type { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 倒计时时长,单位ms (默认 0 )
6
+ * */
7
+ time: number;
8
+ /**
9
+ * @description 时间格式,DD-日,HH-时,mm-分,ss-秒,SSS-毫秒 (默认 'HH:mm:ss' )
10
+ * */
11
+ format?: string;
12
+ /**
13
+ * @description 是否自动开始倒计时 (默认 true )
14
+ * */
15
+ autoStart?: boolean;
16
+ /**
17
+ * @description 是否展示毫秒倒计时 (默认 false )
18
+ * */
19
+ millisecond?: boolean;
20
+ }
@@ -0,0 +1,213 @@
1
+ <template>
2
+ <text
3
+ class="hy-count-num"
4
+ :style="{
5
+ fontSize: addUnit(fontSize),
6
+ fontWeight: bold ? 'bold' : 'normal',
7
+ color: color,
8
+ }"
9
+ >{{ displayValue }}</text
10
+ >
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ import type IProps from "./typing";
15
+ import defaultProps from "./props";
16
+ import { computed, onMounted, onUnmounted, ref, toRefs, watch } from "vue";
17
+ import { addUnit, isNumber } from "../../utils";
18
+
19
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
20
+ const {
21
+ startVal,
22
+ duration,
23
+ endVal,
24
+ autoplay,
25
+ separator,
26
+ useEasing,
27
+ decimals,
28
+ decimal,
29
+ } = toRefs(props);
30
+ const emit = defineEmits(["end"]);
31
+
32
+ const formatNumber = (num: number): string => {
33
+ let numStr = "";
34
+ // 将num转为Number类型,因为其值可能为字符串数值,调用toFixed会报错
35
+ num = Number(num);
36
+ numStr = num.toFixed(Number(decimals.value));
37
+ numStr += "";
38
+ const x = numStr.split(".");
39
+ let x1 = x[0];
40
+ const x2 = x.length > 1 ? decimal.value + x[1] : "";
41
+ const rgx = /(\d+)(\d{3})/;
42
+ if (separator.value && !isNumber(separator.value)) {
43
+ while (rgx.test(x1)) {
44
+ x1 = x1.replace(rgx, "$1" + separator.value + "$2");
45
+ }
46
+ }
47
+ return x1 + x2;
48
+ };
49
+
50
+ const localStartVal = ref(startVal.value);
51
+ let displayValue = ref(formatNumber(startVal.value));
52
+ const printVal = ref<number | null>(null);
53
+ const paused = ref(false); // 是否暂停
54
+ const localDuration = ref(Number(duration.value));
55
+ const startTime = ref<number | null>(null); // 开始的时间
56
+ const timestamp = ref<number | null>(null); // 时间戳
57
+ const remaining = ref<number | null>(null); // 停留的时间
58
+ const rAF = ref<number>(); // 停留的时间
59
+ const lastTime = ref(0); // 上一次的时间
60
+
61
+ const countDown = computed(() => {
62
+ return startVal.value > endVal.value;
63
+ });
64
+
65
+ watch(
66
+ () => startVal.value,
67
+ () => autoplay.value && start(),
68
+ );
69
+
70
+ watch(
71
+ () => endVal.value,
72
+ () => autoplay.value && start(),
73
+ );
74
+
75
+ onMounted(() => {
76
+ autoplay.value && start();
77
+ });
78
+
79
+ const easingFn = (t: number, b: number, c: number, d: number) => {
80
+ return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b;
81
+ };
82
+
83
+ const requestAnimationFrame = (callback: Function): number => {
84
+ const currTime = new Date().getTime();
85
+ // 为了使setTimteout的尽可能的接近每秒60帧的效果
86
+ const timeToCall = Math.max(0, 16 - (currTime - lastTime.value));
87
+ const id = setTimeout(() => {
88
+ callback(currTime + timeToCall);
89
+ }, timeToCall) as unknown as number;
90
+ lastTime.value = currTime + timeToCall;
91
+ return id;
92
+ };
93
+
94
+ const cancelAnimationFrame = (id?: number) => {
95
+ clearTimeout(id);
96
+ };
97
+
98
+ /**
99
+ * @description 开始滚动数字
100
+ * */
101
+ const start = () => {
102
+ localStartVal.value = startVal.value;
103
+ startTime.value = null;
104
+ localDuration.value = duration.value;
105
+ paused.value = false;
106
+ rAF.value = requestAnimationFrame(count);
107
+ };
108
+
109
+ /**
110
+ * @description 暂定状态,重新再开始滚动;或者滚动状态下,暂停
111
+ * */
112
+ const reStart = () => {
113
+ if (paused.value) {
114
+ resume();
115
+ paused.value = false;
116
+ } else {
117
+ stop();
118
+ paused.value = true;
119
+ }
120
+ };
121
+
122
+ /**
123
+ * @description 暂停
124
+ * */
125
+ const stop = () => {
126
+ cancelAnimationFrame(rAF.value);
127
+ };
128
+
129
+ /**
130
+ * @description 重新开始(暂停的情况下)
131
+ * */
132
+ const resume = () => {
133
+ if (!remaining.value) return;
134
+ startTime.value = 0;
135
+ localDuration.value = remaining.value;
136
+ if (printVal.value) {
137
+ localStartVal.value = printVal.value;
138
+ }
139
+ requestAnimationFrame(count);
140
+ };
141
+
142
+ /**
143
+ * @description 重置
144
+ * */
145
+ const reset = () => {
146
+ startTime.value = null;
147
+ cancelAnimationFrame(rAF.value);
148
+ displayValue.value = formatNumber(startVal.value);
149
+ };
150
+ const count = (time_stamp: number) => {
151
+ if (!startTime.value) startTime.value = time_stamp;
152
+ timestamp.value = time_stamp;
153
+ const progress = time_stamp - startTime.value;
154
+ remaining.value = localDuration.value - progress;
155
+ if (useEasing.value) {
156
+ if (countDown.value) {
157
+ printVal.value =
158
+ localStartVal.value -
159
+ easingFn(
160
+ progress,
161
+ 0,
162
+ localStartVal.value - endVal.value,
163
+ localDuration.value,
164
+ );
165
+ } else {
166
+ printVal.value = easingFn(
167
+ progress,
168
+ localStartVal.value,
169
+ endVal.value - localStartVal.value,
170
+ localDuration.value,
171
+ );
172
+ }
173
+ } else {
174
+ if (countDown.value) {
175
+ printVal.value =
176
+ localStartVal.value -
177
+ (localStartVal.value - endVal.value) * (progress / localDuration.value);
178
+ } else {
179
+ printVal.value =
180
+ localStartVal.value +
181
+ (endVal.value - localStartVal.value) * (progress / localDuration.value);
182
+ }
183
+ }
184
+ if (countDown.value) {
185
+ printVal.value =
186
+ printVal.value < endVal.value ? endVal.value : printVal.value;
187
+ } else {
188
+ printVal.value =
189
+ printVal.value > endVal.value ? endVal.value : printVal.value;
190
+ }
191
+ displayValue.value = formatNumber(printVal.value);
192
+ if (progress < localDuration.value) {
193
+ rAF.value = requestAnimationFrame(count);
194
+ } else {
195
+ emit("end");
196
+ }
197
+ };
198
+
199
+ const destroyed = () => {
200
+ cancelAnimationFrame(rAF.value);
201
+ };
202
+
203
+ defineExpose({
204
+ start,
205
+ stop,
206
+ reStart,
207
+ resume,
208
+ });
209
+ </script>
210
+
211
+ <style scoped lang="scss">
212
+ @import "./index.scss";
213
+ </style>
@@ -0,0 +1,6 @@
1
+ .hy-count-num {
2
+ /* #ifndef APP-NVUE */
3
+ display: inline-flex;
4
+ /* #endif */
5
+ text-align: center;
6
+ }
@@ -0,0 +1,17 @@
1
+ import type IProps from "./typing";
2
+
3
+ const defaultProps: IProps = {
4
+ startVal: 0,
5
+ endVal: 0,
6
+ duration: 2000,
7
+ autoplay: true,
8
+ decimals: 0,
9
+ useEasing: true,
10
+ decimal: ".",
11
+ color: "#606266",
12
+ fontSize: 22,
13
+ bold: false,
14
+ separator: "",
15
+ };
16
+
17
+ export default defaultProps;
@@ -0,0 +1,48 @@
1
+ import type { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 开始的数值,默认从0增长到某一个数(默认 0 )
6
+ * */
7
+ startVal?: number;
8
+ /**
9
+ * @description 要滚动的目标数值,必须 (默认 0 )
10
+ * */
11
+ endVal?: number;
12
+ /**
13
+ * @description 滚动到目标数值的动画持续时间,单位为毫秒(ms) (默认
14
+ * */
15
+ duration?: number;
16
+ /**
17
+ * @description 设置数值后是否自动开始滚动 (默认 true )
18
+ * */
19
+ autoplay?: boolean;
20
+ /**
21
+ * @description 要显示的小数位数,见官网说明(默认 0 )
22
+ * */
23
+ decimals?: number;
24
+ /**
25
+ * @description 滚动结束时,是否缓动结尾,见官网说明(默认 true )
26
+ * */
27
+ useEasing?: boolean;
28
+ /**
29
+ * @description 十进制分割 ( 默认 "." )
30
+ * */
31
+ decimal?: string;
32
+ /**
33
+ * @description 字体颜色( 默认 '#606266' )
34
+ * */
35
+ color?: string;
36
+ /**
37
+ * @description 字体大小,单位px( 默认 22 )
38
+ * */
39
+ fontSize?: number | string;
40
+ /**
41
+ * @description 字体是否加粗(默认 false )
42
+ * */
43
+ bold?: boolean;
44
+ /**
45
+ * @description 千位分隔符,见官网说明
46
+ * */
47
+ separator?: string;
48
+ }
@@ -8,7 +8,7 @@
8
8
  <slot name="trigger" :value="inputValue">
9
9
  <HyInput
10
10
  :placeholder="placeholder"
11
- :readonly="!!showByClickInput"
11
+ :readonly="true"
12
12
  v-model="inputValue"
13
13
  :disabled="disabled"
14
14
  :disabledColor="disabledColor"
@@ -554,31 +554,5 @@ const onShowByClickInput = () => {
554
554
  </script>
555
555
 
556
556
  <style lang="scss" scoped>
557
- @import "../../libs/css/mixin.scss";
558
- .hy-datetime-picker {
559
- flex: 1;
560
- &__has-input {
561
- position: relative;
562
- display: flex;
563
- flex-direction: column;
564
- justify-content: center;
565
- /* #ifndef APP-NVUE */
566
- width: 100%;
567
- /* #endif */
568
- .input-cover {
569
- opacity: 0;
570
- position: absolute;
571
- top: 0;
572
- bottom: 0;
573
- left: 0;
574
- right: 0;
575
- display: flex;
576
- flex-direction: column;
577
- justify-content: center;
578
- border-radius: 4px;
579
- border: 1px solid #eee;
580
- padding: 0 10px;
581
- }
582
- }
583
- }
557
+ @import "./index.scss";
584
558
  </style>
@@ -0,0 +1,28 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+
3
+ .hy-datetime-picker {
4
+ flex: 1;
5
+ &__has-input {
6
+ position: relative;
7
+ display: flex;
8
+ flex-direction: column;
9
+ justify-content: center;
10
+ /* #ifndef APP-NVUE */
11
+ width: 100%;
12
+ /* #endif */
13
+ .input-cover {
14
+ opacity: 0;
15
+ position: absolute;
16
+ top: 0;
17
+ bottom: 0;
18
+ left: 0;
19
+ right: 0;
20
+ display: flex;
21
+ flex-direction: column;
22
+ justify-content: center;
23
+ border-radius: 4px;
24
+ border: 1px solid #eee;
25
+ padding: 0 10px;
26
+ }
27
+ }
28
+ }