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,10 +1,6 @@
1
1
  <template>
2
- <view class="u-datetime-picker">
3
- <view
4
- v-if="hasInput"
5
- class="u-datetime-picker__has-input"
6
- @click="onShowByClickInput"
7
- >
2
+ <view :class="['hy-datetime-picker', customClass]" :style="customStyle">
3
+ <view v-if="hasInput" class="hy-datetime-picker__has-input" @click="onShowByClickInput">
8
4
  <slot name="trigger" :value="inputValue">
9
5
  <HyInput
10
6
  v-model="inputValue"
@@ -21,9 +17,7 @@
21
17
  :placeholder="input?.placeholder || '请选择时间'"
22
18
  :placeholderStyle="input?.placeholderStyle"
23
19
  :placeholderClass="input?.placeholderClass"
24
- :customStyle="
25
- Object.assign({ 'pointer-events': 'none' }, input?.customStyle)
26
- "
20
+ :customStyle="Object.assign({ 'pointer-events': 'none' }, input?.customStyle)"
27
21
  ></HyInput>
28
22
  <view class="input-cover"></view>
29
23
  </slot>
@@ -55,35 +49,177 @@
55
49
  </slot>
56
50
  </template>
57
51
  <template #toolbar-bottom>
58
- <slot name="toolbar-bottom"> </slot>
52
+ <slot name="toolbar-bottom"></slot>
59
53
  </template>
60
54
  </HyPicker>
61
55
  </view>
62
56
  </template>
63
57
 
64
58
  <script lang="ts">
59
+ /**
60
+ * 此选择器用于时间日期选择
61
+ * @displayName hy-datetime-picker
62
+ */
63
+ defineOptions({})
65
64
  export default {
66
65
  name: 'hy-datetime-picker',
67
66
  options: {
68
67
  addGlobalClass: true,
69
68
  virtualHost: true,
70
- styleIsolation: 'shared'
71
- }
69
+ styleIsolation: 'shared',
70
+ },
72
71
  }
73
72
  </script>
74
73
 
75
74
  <script setup lang="ts">
76
- import { computed, onMounted, ref, toRefs, watch } from "vue";
77
- import defaultProps from "./props";
78
- import type IProps from "./typing";
79
- import dayjs from "dayjs/esm";
80
- import { error, padZero } from "../../utils";
81
- import { DateModeEnum } from "../../typing";
75
+ import { computed, onMounted, ref, toRefs, watch } from 'vue'
76
+ import type { CSSProperties, PropType } from 'vue'
77
+ import dayjs from 'dayjs/esm'
78
+ import { error, padZero } from '../../utils'
79
+ import { DateModeEnum } from '../../typing'
80
+ import type HyInputProps from '../hy-input/typing'
81
+
82
82
  // 组件
83
- import HyInput from "../hy-input/hy-input.vue";
84
- import HyPicker from "../hy-picker/hy-picker.vue";
83
+ import HyInput from '../hy-input/hy-input.vue'
84
+ import HyPicker from '../hy-picker/hy-picker.vue'
85
+ import { IDatetimePickerEmits } from '@/package/components/hy-datetime-picker/typing'
85
86
 
86
- const props = withDefaults(defineProps<IProps>(), defaultProps);
87
+ // const props = withDefaults(defineProps<IProps>(), defaultProps)
88
+ const props = defineProps({
89
+ /** 用于控制选择器的弹出和收起 */
90
+ show: {
91
+ type: Boolean,
92
+ default: false,
93
+ },
94
+ /**
95
+ * 弹出层弹出方向
96
+ * @values bottom,top
97
+ * */
98
+ popupMode: {
99
+ type: String,
100
+ default: 'bottom',
101
+ },
102
+ /** 是否显示顶部的操作栏 */
103
+ showToolbar: {
104
+ type: Boolean,
105
+ default: true,
106
+ },
107
+ /** 绑定值 */
108
+ modelValue: [String, Number, Date],
109
+ /** 顶部标题 */
110
+ title: String,
111
+ /**
112
+ * 展示格式 mode=date为日期选择,mode=time为时间选择,mode=year-month为年月选择,mode=datetime为日期时间选择
113
+ * @values date,time,year-month,datetime
114
+ * */
115
+ mode: {
116
+ type: String,
117
+ default: DateModeEnum.DATETIME,
118
+ },
119
+ /** 可选的最大时间 默认值为后10年 */
120
+ maxDate: {
121
+ type: Number,
122
+ default: new Date(new Date().getFullYear() + 10, 0, 1).getTime(),
123
+ },
124
+ /** 可选的最小时间 默认值为前10年 */
125
+ minDate: {
126
+ type: Number,
127
+ default: new Date(new Date().getFullYear() - 10, 0, 1).getTime(),
128
+ },
129
+ /** 可选的最小小时,仅mode=time有效 */
130
+ minHour: {
131
+ type: Number,
132
+ default: 0,
133
+ },
134
+ /** 可选的最大小时,仅mode=time有效 */
135
+ maxHour: {
136
+ type: Number,
137
+ default: 23,
138
+ },
139
+ /** 可选的最小分钟,仅mode=time有效 */
140
+ minMinute: {
141
+ type: Number,
142
+ default: 0,
143
+ },
144
+ /** 可选的最大分钟,仅mode=time有效 */
145
+ maxMinute: {
146
+ type: Number,
147
+ default: 59,
148
+ },
149
+ /** 选项过滤函数 */
150
+ filter: Function,
151
+ /** 选项格式化函数 */
152
+ formatter: Function,
153
+ /** 是否显示加载中状态 */
154
+ loading: {
155
+ type: Boolean,
156
+ default: false,
157
+ },
158
+ /** 各列中,单个选项的高度 */
159
+ itemHeight: {
160
+ type: Number,
161
+ default: 44,
162
+ },
163
+ /** 取消按钮的文字 */
164
+ cancelText: {
165
+ type: String,
166
+ default: '取消',
167
+ },
168
+ /** 确认按钮的文字 */
169
+ confirmText: {
170
+ type: String,
171
+ default: '确认',
172
+ },
173
+ /** 取消按钮的颜色 */
174
+ cancelColor: {
175
+ type: String,
176
+ default: '#909193',
177
+ },
178
+ /** 确认按钮的颜色 */
179
+ confirmColor: {
180
+ type: String,
181
+ default: '#3c9cff',
182
+ },
183
+ /** 每列中可见选项的数量 */
184
+ visibleItemCount: {
185
+ type: Number,
186
+ default: 5,
187
+ },
188
+ /** 是否允许点击遮罩关闭选择器 */
189
+ closeOnClickOverlay: {
190
+ type: Boolean,
191
+ default: false,
192
+ },
193
+ /** 各列的默认索引 */
194
+ defaultIndex: {
195
+ type: Array,
196
+ default() {
197
+ return []
198
+ },
199
+ },
200
+ /** 输入框是否显示边框 */
201
+ hasInput: {
202
+ type: Boolean,
203
+ default: false,
204
+ },
205
+ /** 输入框集合属性 */
206
+ input: {
207
+ type: Object as unknown as PropType<HyInputProps>,
208
+ },
209
+ /** 自定义时间格式 */
210
+ format: String,
211
+ /** 右边插槽 */
212
+ toolbarRightSlot: {
213
+ type: Boolean,
214
+ default: false,
215
+ },
216
+ /** 定义需要用到的外部样式 */
217
+ customStyle: {
218
+ type: Object as PropType<CSSProperties>,
219
+ },
220
+ /** 自定义外部类名 */
221
+ customClass: String,
222
+ })
87
223
  const {
88
224
  show,
89
225
  modelValue,
@@ -100,75 +236,69 @@ const {
100
236
  maxHour,
101
237
  minMinute,
102
238
  maxMinute,
103
- } = toRefs(props);
104
- const emit = defineEmits([
105
- "close",
106
- "cancel",
107
- "confirm",
108
- "change",
109
- "update:modelValue",
110
- ]);
239
+ } = toRefs(props)
240
+ const emit = defineEmits<IDatetimePickerEmits>()
111
241
 
112
242
  // 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
113
- const inputValue = ref<string | number>(""); // 表单显示值
114
- const innerValue = ref<string | number>(""); // 表单显示值
115
- const showByClickInput = ref<boolean>(false); // 是否在hasInput模式下显示日期选择弹唱
116
- const columns = ref<any[]>([]);
117
- const innerDefaultIndex = ref<number[]>([]);
118
- let innerFormatter = (type: any, value: any) => value;
243
+ const inputValue = ref<string | number>('') // 表单显示值
244
+ const innerValue = ref<string | number>('') // 表单显示值
245
+ const showByClickInput = ref<boolean>(false) // 是否在hasInput模式下显示日期选择弹唱
246
+ const columns = ref<any[]>([])
247
+ const innerDefaultIndex = ref<number[]>([])
248
+ let innerFormatter = (type: any, value: any) => value
119
249
  const validModes = new Set([
120
250
  DateModeEnum.TIME,
121
251
  DateModeEnum.MONTH_DAY,
122
252
  DateModeEnum.HOUR_MINUTE,
123
253
  DateModeEnum.MINUTE_SECOND,
124
- ]);
254
+ ])
125
255
 
126
256
  /**
127
257
  * @description 更新各列的值
128
258
  * */
129
259
  const updateColumns = () => {
130
- const formatterFn = formatter.value || innerFormatter;
260
+ const formatterFn = formatter.value || innerFormatter
131
261
  // 获取各列的值,并且map后,对各列的具体值进行补0操作
132
262
  columns.value = getOriginColumns().map((column) =>
133
263
  column.values.map((value) => formatterFn(column.type, value)),
134
- );
135
- };
264
+ )
265
+ }
136
266
 
137
267
  /**
138
268
  * @description 更新各列的值,进行补0、格式化等操作
139
269
  * */
140
270
  const updateColumnValue = (value: string | number) => {
141
- innerValue.value = value;
142
- updateColumns();
271
+ innerValue.value = value
272
+ updateColumns()
143
273
  // 延迟执行,等待u-picker组件列数据更新完后再设置选中值索引
144
274
  setTimeout(() => {
145
- updateIndexes(value);
146
- }, 100);
147
- };
275
+ updateIndexes(value)
276
+ }, 100)
277
+ }
148
278
 
149
279
  const init = () => {
150
280
  // 获取当前值
151
- innerValue.value = correctValue(modelValue.value);
281
+ innerValue.value = correctValue(modelValue.value)
152
282
  // 更新列表
153
- updateColumnValue(innerValue.value);
283
+ updateColumnValue(innerValue.value)
154
284
 
155
285
  // 初始化hasInput展示
156
- getInputValue(innerValue.value);
157
- };
286
+ getInputValue(innerValue.value)
287
+ }
158
288
 
159
289
  watch(
160
290
  () => show.value,
161
291
  (newValue) => {
162
292
  if (newValue) {
163
- updateColumnValue(innerValue.value);
293
+ updateColumnValue(innerValue.value)
164
294
  }
165
295
  },
166
- );
296
+ )
167
297
 
168
298
  watch(
169
299
  () => modelValue.value,
170
300
  () => init(),
171
- );
301
+ )
172
302
 
173
303
  const propsChange = computed(() => {
174
304
  return [
@@ -180,66 +310,64 @@ const propsChange = computed(() => {
180
310
  minMinute.value,
181
311
  maxMinute.value,
182
312
  filter.value,
183
- ];
184
- });
313
+ ]
314
+ })
185
315
 
186
316
  watch(
187
317
  () => propsChange.value,
188
318
  () => init(),
189
- );
319
+ )
190
320
 
191
321
  onMounted(() => {
192
- init();
193
- });
322
+ init()
323
+ })
194
324
 
195
325
  const getInputValue = (newValue: string | number) => {
196
- if (newValue == "" || !newValue) {
197
- inputValue.value = "";
198
- return;
326
+ if (newValue == '' || !newValue) {
327
+ inputValue.value = ''
328
+ return
199
329
  }
200
- if (mode.value === "time") {
201
- inputValue.value = newValue;
330
+ if (mode.value === 'time') {
331
+ inputValue.value = newValue
202
332
  } else {
203
333
  if (format.value) {
204
- inputValue.value = dayjs(newValue).format(format.value);
334
+ inputValue.value = dayjs(newValue).format(format.value)
205
335
  } else {
206
- let format = "";
336
+ let format = ''
207
337
  switch (mode.value) {
208
338
  case DateModeEnum.DATE:
209
- format = "YYYY-MM-DD";
210
- break;
339
+ format = 'YYYY-MM-DD'
340
+ break
211
341
  case DateModeEnum.YEAR_MONTH:
212
- format = "YYYY-MM";
213
- break;
342
+ format = 'YYYY-MM'
343
+ break
214
344
  case DateModeEnum.DATETIME:
215
- format = "YYYY-MM-DD HH:mm:ss";
216
- break;
345
+ format = 'YYYY-MM-DD HH:mm:ss'
346
+ break
217
347
  case DateModeEnum.MONTH_DAY:
218
- format = "MM-DD";
219
- break;
348
+ format = 'MM-DD'
349
+ break
220
350
  case DateModeEnum.HOUR_MINUTE:
221
- format = "HH:mm";
222
- break;
351
+ format = 'HH:mm'
352
+ break
223
353
  case DateModeEnum.MINUTE_SECOND:
224
- format = "mm:ss";
225
- break;
354
+ format = 'mm:ss'
355
+ break
226
356
  default:
227
- break;
357
+ break
228
358
  }
229
- inputValue.value = dayjs(newValue).isValid()
230
- ? dayjs(newValue).format(format)
231
- : newValue;
359
+ inputValue.value = dayjs(newValue).isValid() ? dayjs(newValue).format(format) : newValue
232
360
  }
233
361
  }
234
- };
362
+ }
235
363
  const times = (n: number, iteratee: Function) => {
236
- let index = -1;
237
- const result = Array(n < 0 ? 0 : n);
364
+ let index = -1
365
+ const result = Array(n < 0 ? 0 : n)
238
366
  while (++index < n) {
239
- result[index] = iteratee(index);
367
+ result[index] = iteratee(index)
240
368
  }
241
- return result;
242
- };
369
+ return result
370
+ }
243
371
 
244
372
  /**
245
373
  * @description 关闭选择器
@@ -247,169 +375,153 @@ const times = (n: number, iteratee: Function) => {
247
375
  const close = () => {
248
376
  if (closeOnClickOverlay.value) {
249
377
  if (hasInput.value) {
250
- showByClickInput.value = false;
378
+ showByClickInput.value = false
251
379
  }
252
- emit("close");
380
+ emit('close')
253
381
  }
254
- };
382
+ }
255
383
 
256
384
  /**
257
385
  * @description 点击工具栏的取消按钮
258
386
  * */
259
387
  const cancel = () => {
260
388
  if (hasInput.value) {
261
- showByClickInput.value = false;
389
+ showByClickInput.value = false
262
390
  }
263
- emit("cancel");
264
- };
391
+ emit('cancel')
392
+ }
265
393
 
266
394
  /**
267
395
  * @description 点击工具栏的确定按钮
268
396
  * */
269
397
  const confirm = () => {
270
- emit("update:modelValue", innerValue.value);
398
+ emit('update:modelValue', innerValue.value)
271
399
  if (hasInput.value) {
272
- getInputValue(innerValue.value);
273
- showByClickInput.value = false;
400
+ getInputValue(innerValue.value)
401
+ showByClickInput.value = false
274
402
  }
275
- emit("confirm", {
403
+ emit('confirm', {
276
404
  value: innerValue.value,
277
405
  mode: mode.value,
278
- });
279
- };
406
+ })
407
+ }
280
408
 
281
409
  /**
282
410
  * @description 用正则截取输出值,当出现多组数字时,抛出错误
283
411
  * */
284
412
  const intercept = (e: any, type?: string) => {
285
- let judge = e.match(/\d+/g);
413
+ let judge = e.match(/\d+/g)
286
414
  //判断是否掺杂数字
287
415
  if (judge.length > 1) {
288
- error("请勿在过滤或格式化函数时添加数字");
289
- return 0;
416
+ error('请勿在过滤或格式化函数时添加数字')
417
+ return 0
290
418
  } else if (type && judge[0].length == 4) {
291
419
  //判断是否是年份
292
- return judge[0];
420
+ return judge[0]
293
421
  } else if (judge[0].length > 2) {
294
- error("请勿在过滤或格式化函数时添加数字");
295
- return 0;
422
+ error('请勿在过滤或格式化函数时添加数字')
423
+ return 0
296
424
  } else {
297
- return judge[0];
425
+ return judge[0]
298
426
  }
299
- };
427
+ }
300
428
 
301
429
  /**
302
430
  * @description 列发生变化时触发
303
431
  * */
304
432
  const change = (e: any) => {
305
- const { indexs, values } = e;
306
- let selectValue: string | number = "";
433
+ const { indexs, values } = e
434
+ let selectValue: string | number = ''
307
435
  if (validModes.has(mode.value) && mode.value !== DateModeEnum.MONTH_DAY) {
308
436
  // 根据value各列索引,从各列数组中,取出当前时间的选中值
309
- selectValue = `${intercept(values[0][indexs[0]])}:${intercept(
310
- values[1][indexs[1]],
311
- )}`;
437
+ selectValue = `${intercept(values[0][indexs[0]])}:${intercept(values[1][indexs[1]])}`
312
438
  } else if (mode.value === DateModeEnum.MONTH_DAY) {
313
439
  // 根据value各列索引,从各列数组中,取出当前时间的选中值
314
- selectValue = `${intercept(values[0][indexs[0]])}-${intercept(
315
- values[1][indexs[1]],
316
- )}`;
440
+ selectValue = `${intercept(values[0][indexs[0]])}-${intercept(values[1][indexs[1]])}`
317
441
  } else {
318
442
  // 将选择的值转为数值,比如'03'转为数值的3,'2019'转为数值的2019
319
- const year = parseInt(intercept(values[0][indexs[0]], "year"));
320
- const month = parseInt(intercept(values[1][indexs[1]]));
321
- let date = parseInt(values[2] ? intercept(values[2][indexs[2]]) : 1);
443
+ const year = parseInt(intercept(values[0][indexs[0]], 'year'))
444
+ const month = parseInt(intercept(values[1][indexs[1]]))
445
+ let date = parseInt(values[2] ? intercept(values[2][indexs[2]]) : 1)
322
446
  let hour = 0,
323
447
  minute = 0,
324
- second = 0;
448
+ second = 0
325
449
  // 此月份的最大天数
326
- const maxDate = dayjs(`${year}-${month}`).daysInMonth();
450
+ const maxDate = dayjs(`${year}-${month}`).daysInMonth()
327
451
  // 不允许超过maxDate值
328
- date = Math.min(maxDate, date);
452
+ date = Math.min(maxDate, date)
329
453
  if (mode.value === DateModeEnum.DATETIME) {
330
- hour = parseInt(intercept(values[3][indexs[3]]));
331
- minute = parseInt(intercept(values[4][indexs[4]]));
332
- second = parseInt(intercept(values[5][indexs[5]]));
454
+ hour = parseInt(intercept(values[3][indexs[3]]))
455
+ minute = parseInt(intercept(values[4][indexs[4]]))
456
+ second = parseInt(intercept(values[5][indexs[5]]))
333
457
  }
334
458
  // 转为时间模式
335
- selectValue = Number(new Date(year, month - 1, date, hour, minute, second));
459
+ selectValue = Number(new Date(year, month - 1, date, hour, minute, second))
336
460
  }
337
461
  // 取出准确的合法值,防止超越边界的情况
338
- selectValue = correctValue(selectValue);
339
- innerValue.value = selectValue;
340
- updateColumnValue(selectValue);
462
+ selectValue = correctValue(selectValue)
463
+ innerValue.value = selectValue
464
+ updateColumnValue(selectValue)
341
465
  // 发出change时间,value为当前选中的时间戳
342
- emit("change", {
466
+ emit('change', {
343
467
  value: selectValue,
344
468
  // #ifndef MP-WEIXIN
345
469
  // 微信小程序不能传递this实例,会因为循环引用而报错
346
470
  // picker: this.$refs.picker,
347
471
  // #endif
348
472
  mode: mode.value,
349
- });
350
- };
473
+ })
474
+ }
351
475
 
352
476
  /**
353
477
  * @description 更新索引
354
478
  * */
355
479
  const updateIndexes = (value: number | string) => {
356
- let values: string[] = [];
357
- let timeArr: string[] = [];
358
- const formatterFn = formatter.value || innerFormatter;
480
+ let values: string[] = []
481
+ let timeArr: string[] = []
482
+ const formatterFn = formatter.value || innerFormatter
359
483
 
360
484
  switch (mode.value) {
361
485
  case DateModeEnum.TIME:
362
- timeArr = value.toString().split(":");
486
+ timeArr = value.toString().split(':')
363
487
  // 使用formatter格式化方法进行管道处理
364
- values = [
365
- formatterFn("hour", timeArr[0]),
366
- formatterFn("minute", timeArr[1]),
367
- ];
368
- break;
488
+ values = [formatterFn('hour', timeArr[0]), formatterFn('minute', timeArr[1])]
489
+ break
369
490
  case DateModeEnum.MONTH_DAY:
370
- timeArr = value.toString().split("-");
491
+ timeArr = value.toString().split('-')
371
492
  // 使用formatter格式化方法进行管道处理
372
- values = [
373
- formatterFn("month", timeArr[0]),
374
- formatterFn("day", timeArr[1]),
375
- ];
376
- break;
493
+ values = [formatterFn('month', timeArr[0]), formatterFn('day', timeArr[1])]
494
+ break
377
495
  case DateModeEnum.HOUR_MINUTE:
378
- timeArr = value.toString().split(":");
496
+ timeArr = value.toString().split(':')
379
497
  // 使用formatter格式化方法进行管道处理
380
- values = [
381
- formatterFn("hour", timeArr[0]),
382
- formatterFn("minute", timeArr[1]),
383
- ];
384
- break;
498
+ values = [formatterFn('hour', timeArr[0]), formatterFn('minute', timeArr[1])]
499
+ break
385
500
  case DateModeEnum.MINUTE_SECOND:
386
- timeArr = value.toString().split(":");
501
+ timeArr = value.toString().split(':')
387
502
  // 使用formatter格式化方法进行管道处理
388
- values = [
389
- formatterFn("minute", timeArr[0]),
390
- formatterFn("second", timeArr[1]),
391
- ];
392
- break;
503
+ values = [formatterFn('minute', timeArr[0]), formatterFn('second', timeArr[1])]
504
+ break
393
505
  default:
394
506
  values = [
395
- formatterFn("year", `${dayjs(value).year()}`),
507
+ formatterFn('year', `${dayjs(value).year()}`),
396
508
  // 月份补0
397
- formatterFn("month", padZero(dayjs(value).month() + 1)),
398
- ];
509
+ formatterFn('month', padZero(dayjs(value).month() + 1)),
510
+ ]
399
511
  if (mode.value === DateModeEnum.DATE) {
400
512
  // date模式,需要添加天列
401
- values.push(formatterFn("day", padZero(dayjs(value).date())));
513
+ values.push(formatterFn('day', padZero(dayjs(value).date())))
402
514
  }
403
515
  if (mode.value === DateModeEnum.DATETIME) {
404
516
  // 数组的push方法,可以写入多个参数
405
517
  values.push(
406
- formatterFn("day", padZero(dayjs(value).date())),
407
- formatterFn("hour", padZero(dayjs(value).hour())),
408
- formatterFn("minute", padZero(dayjs(value).minute())),
409
- formatterFn("second", padZero(dayjs(value).second())),
410
- );
518
+ formatterFn('day', padZero(dayjs(value).date())),
519
+ formatterFn('hour', padZero(dayjs(value).hour())),
520
+ formatterFn('minute', padZero(dayjs(value).minute())),
521
+ formatterFn('second', padZero(dayjs(value).second())),
522
+ )
411
523
  }
412
- break;
524
+ break
413
525
  }
414
526
  // 根据当前各列的所有值,从各列默认值中找到默认值在各列中的索引
415
527
  innerDefaultIndex.value = columns.value.map((column, index) => {
@@ -417,9 +529,9 @@ const updateIndexes = (value: number | string) => {
417
529
  return Math.max(
418
530
  0,
419
531
  column.findIndex((item: string) => item === values[index]),
420
- );
421
- });
422
- };
532
+ )
533
+ })
534
+ }
423
535
 
424
536
  /**
425
537
  * @description 获取每列数据
@@ -428,41 +540,41 @@ const getOriginColumns = () => {
428
540
  // 生成各列的值
429
541
  return getRanges().map(({ type, range }) => {
430
542
  let values = times(range[1] - range[0] + 1, (index: number) => {
431
- let value: string | number = range[0] + index;
432
- value = type === "year" ? `${value}` : padZero(value);
433
- return value;
434
- });
543
+ let value: string | number = range[0] + index
544
+ value = type === 'year' ? `${value}` : padZero(value)
545
+ return value
546
+ })
435
547
  // 进行过滤
436
548
  if (filter.value) {
437
- values = filter.value(type, values);
549
+ values = filter.value(type, values)
438
550
  if (!values || (values && values.length == 0)) {
439
- error("日期filter结果不能为空");
551
+ error('日期filter结果不能为空')
440
552
  }
441
553
  }
442
- return { type, values };
443
- });
444
- };
554
+ return { type, values }
555
+ })
556
+ }
445
557
 
446
558
  /**
447
559
  * @description 得出合法的时间
448
560
  * */
449
561
  const correctValue = (value: number | string | Date): string | number => {
450
- const isDateMode = mode.value !== DateModeEnum.TIME;
562
+ const isDateMode = mode.value !== DateModeEnum.TIME
451
563
  // if (isDateMode && !test.date(value)) {
452
564
  if (!isDateMode && !value) {
453
565
  // 如果是时间类型,而又没有默认值的话,就用最小时间
454
- value = `${padZero(minHour.value)}:${padZero(minMinute.value)}`;
566
+ value = `${padZero(minHour.value)}:${padZero(minMinute.value)}`
455
567
  }
456
568
  // 时间类型
457
569
  if (validModes.has(mode.value)) {
458
- return value as string;
570
+ return value as string
459
571
  } else {
460
572
  // 如果是日期格式,控制在最小日期和最大日期之间
461
- value = dayjs(value).isBefore(dayjs(minDate.value)) ? minDate.value : value;
462
- value = dayjs(value).isAfter(dayjs(maxDate.value)) ? maxDate.value : value;
463
- return value as string | number;
573
+ value = dayjs(value).isBefore(dayjs(minDate.value)) ? minDate.value : value
574
+ value = dayjs(value).isAfter(dayjs(maxDate.value)) ? maxDate.value : value
575
+ return value as string | number
464
576
  }
465
- };
577
+ }
466
578
  /**
467
579
  * @description 获取每列的最大和最小值
468
580
  * */
@@ -470,85 +582,79 @@ const getRanges = () => {
470
582
  if (mode.value === DateModeEnum.TIME) {
471
583
  return [
472
584
  {
473
- type: "hour",
585
+ type: 'hour',
474
586
  range: [props.minHour, props.maxHour],
475
587
  },
476
588
  {
477
- type: "minute",
589
+ type: 'minute',
478
590
  range: [props.minMinute, props.maxMinute],
479
591
  },
480
- ];
592
+ ]
481
593
  }
482
- const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary(
483
- "max",
484
- innerValue.value,
485
- );
486
- const { minYear, minDate, minMonth, minHour, minMinute } = getBoundary(
487
- "min",
488
- innerValue.value,
489
- );
594
+ const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary('max', innerValue.value)
595
+ const { minYear, minDate, minMonth, minHour, minMinute } = getBoundary('min', innerValue.value)
490
596
  const result = [
491
597
  {
492
- type: "year",
598
+ type: 'year',
493
599
  range: [minYear, maxYear],
494
600
  },
495
601
  {
496
- type: "month",
602
+ type: 'month',
497
603
  range: [minMonth, maxMonth],
498
604
  },
499
605
  {
500
- type: "day",
606
+ type: 'day',
501
607
  range: [minDate, maxDate],
502
608
  },
503
609
  {
504
- type: "hour",
610
+ type: 'hour',
505
611
  range: [minHour, maxHour],
506
612
  },
507
613
  {
508
- type: "minute",
614
+ type: 'minute',
509
615
  range: [minMinute, maxMinute],
510
616
  },
511
617
  {
512
- type: "second",
618
+ type: 'second',
513
619
  range: [minMinute, maxMinute],
514
620
  },
515
- ];
516
- let arr = result;
621
+ ]
622
+ let arr = result
517
623
  // 截取对应的列数
518
- if (mode.value === DateModeEnum.DATE) arr = result.splice(0, 3);
519
- if (mode.value === DateModeEnum.YEAR_MONTH) arr = result.splice(0, 2);
520
- if (mode.value === DateModeEnum.MONTH_DAY) arr = result.splice(1, 2);
521
- if (mode.value === DateModeEnum.HOUR_MINUTE) arr = result.splice(3, 2);
522
- if (mode.value === DateModeEnum.MINUTE_SECOND) arr = result.splice(4, 2);
523
- return arr;
524
- };
624
+ if (mode.value === DateModeEnum.DATE) arr = result.splice(0, 3)
625
+ if (mode.value === DateModeEnum.YEAR_MONTH) arr = result.splice(0, 2)
626
+ if (mode.value === DateModeEnum.MONTH_DAY) arr = result.splice(1, 2)
627
+ if (mode.value === DateModeEnum.HOUR_MINUTE) arr = result.splice(3, 2)
628
+ if (mode.value === DateModeEnum.MINUTE_SECOND) arr = result.splice(4, 2)
629
+ return arr
630
+ }
525
631
  /**
526
632
  * @description 根据minDate、maxDate、minHour、maxHour等边界值,判断各列的开始和结束边界值
527
633
  * */
528
634
  const getBoundary = (type: string, innerVal: string | number) => {
529
- const value = new Date(innerVal);
530
- const boundary = new Date((props as any)[`${type}Date`]);
531
- const year = dayjs(boundary).year();
532
- let month = 1;
533
- let date = 1;
534
- let hour = 0;
535
- let minute = 0;
536
- if (type === "max") {
537
- month = 12;
635
+ const value = new Date(innerVal)
636
+ const boundary = new Date((props as any)[`${type}Date`])
637
+ const year = dayjs(boundary).year()
638
+ let month = 1
639
+ let date = 1
640
+ let hour = 0
641
+ let minute = 0
642
+ if (type === 'max') {
643
+ month = 12
538
644
  // 月份的天数
539
- date = dayjs(value).daysInMonth() || 31;
540
- hour = 23;
541
- minute = 59;
645
+ date = dayjs(value).daysInMonth() || 31
646
+ hour = 23
647
+ minute = 59
542
648
  }
543
649
  // 获取边界值,逻辑是:当年达到了边界值(最大或最小年),就检查月允许的最大和最小值,以此类推
544
650
  if (dayjs(value).year() === year) {
545
- month = dayjs(boundary).month() + 1;
651
+ month = dayjs(boundary).month() + 1
546
652
  if (dayjs(value).month() + 1 === month) {
547
- date = dayjs(boundary).date();
653
+ date = dayjs(boundary).date()
548
654
  if (dayjs(value).date() === date) {
549
- hour = dayjs(boundary).hour();
655
+ hour = dayjs(boundary).hour()
550
656
  if (dayjs(value).hour() === hour) {
551
- minute = dayjs(boundary).minute();
657
+ minute = dayjs(boundary).minute()
552
658
  }
553
659
  }
554
660
  }
@@ -559,15 +665,15 @@ const getBoundary = (type: string, innerVal: string | number) => {
559
665
  [`${type}Date`]: date,
560
666
  [`${type}Hour`]: hour,
561
667
  [`${type}Minute`]: minute,
562
- };
563
- };
668
+ }
669
+ }
564
670
  const onShowByClickInput = () => {
565
671
  if (!input.value.disabled) {
566
- showByClickInput.value = !showByClickInput.value;
672
+ showByClickInput.value = !showByClickInput.value
567
673
  }
568
- };
674
+ }
569
675
  </script>
570
676
 
571
677
  <style lang="scss" scoped>
572
- @import "./index.scss";
678
+ @import './index.scss';
573
679
  </style>