@tplc/wot 0.0.1

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 (328) hide show
  1. package/components/common/AbortablePromise.ts +36 -0
  2. package/components/common/abstracts/_config.scss +7 -0
  3. package/components/common/abstracts/_function.scss +76 -0
  4. package/components/common/abstracts/_mixin.scss +339 -0
  5. package/components/common/abstracts/variable.scss +1346 -0
  6. package/components/common/base64.ts +30 -0
  7. package/components/common/canvasHelper.ts +49 -0
  8. package/components/common/clickoutside.ts +34 -0
  9. package/components/common/dayjs.ts +157 -0
  10. package/components/common/event.ts +8 -0
  11. package/components/common/props.ts +51 -0
  12. package/components/common/util.ts +751 -0
  13. package/components/composables/useCell.ts +13 -0
  14. package/components/composables/useChildren.ts +122 -0
  15. package/components/composables/useCountDown.ts +138 -0
  16. package/components/composables/useLockScroll.ts +39 -0
  17. package/components/composables/useParent.ts +41 -0
  18. package/components/composables/usePopover.ts +193 -0
  19. package/components/composables/useQueue.ts +52 -0
  20. package/components/composables/useRaf.ts +37 -0
  21. package/components/composables/useTouch.ts +44 -0
  22. package/components/composables/useTranslate.ts +22 -0
  23. package/components/wd-action-sheet/index.scss +204 -0
  24. package/components/wd-action-sheet/types.ts +128 -0
  25. package/components/wd-action-sheet/wd-action-sheet.vue +174 -0
  26. package/components/wd-backtop/index.scss +25 -0
  27. package/components/wd-backtop/types.ts +37 -0
  28. package/components/wd-backtop/wd-backtop.vue +48 -0
  29. package/components/wd-badge/index.scss +59 -0
  30. package/components/wd-badge/types.ts +53 -0
  31. package/components/wd-badge/wd-badge.vue +69 -0
  32. package/components/wd-button/index.scss +340 -0
  33. package/components/wd-button/types.ts +112 -0
  34. package/components/wd-button/wd-button.vue +176 -0
  35. package/components/wd-calendar/index.scss +244 -0
  36. package/components/wd-calendar/types.ts +235 -0
  37. package/components/wd-calendar/wd-calendar.vue +456 -0
  38. package/components/wd-calendar-view/index.scss +9 -0
  39. package/components/wd-calendar-view/month/index.scss +151 -0
  40. package/components/wd-calendar-view/month/month.vue +391 -0
  41. package/components/wd-calendar-view/month/types.ts +19 -0
  42. package/components/wd-calendar-view/monthPanel/index.scss +89 -0
  43. package/components/wd-calendar-view/monthPanel/month-panel.vue +388 -0
  44. package/components/wd-calendar-view/monthPanel/types.ts +48 -0
  45. package/components/wd-calendar-view/types.ts +134 -0
  46. package/components/wd-calendar-view/utils.ts +451 -0
  47. package/components/wd-calendar-view/wd-calendar-view.vue +111 -0
  48. package/components/wd-calendar-view/year/index.scss +148 -0
  49. package/components/wd-calendar-view/year/types.ts +19 -0
  50. package/components/wd-calendar-view/year/year.vue +220 -0
  51. package/components/wd-calendar-view/yearPanel/index.scss +24 -0
  52. package/components/wd-calendar-view/yearPanel/types.ts +38 -0
  53. package/components/wd-calendar-view/yearPanel/year-panel.vue +140 -0
  54. package/components/wd-card/index.scss +70 -0
  55. package/components/wd-card/types.ts +30 -0
  56. package/components/wd-card/wd-card.vue +40 -0
  57. package/components/wd-cell/index.scss +189 -0
  58. package/components/wd-cell/types.ts +96 -0
  59. package/components/wd-cell/wd-cell.vue +135 -0
  60. package/components/wd-cell-group/index.scss +55 -0
  61. package/components/wd-cell-group/types.ts +41 -0
  62. package/components/wd-cell-group/wd-cell-group.vue +45 -0
  63. package/components/wd-checkbox/index.scss +285 -0
  64. package/components/wd-checkbox/types.ts +68 -0
  65. package/components/wd-checkbox/wd-checkbox.vue +185 -0
  66. package/components/wd-checkbox-group/index.scss +20 -0
  67. package/components/wd-checkbox-group/types.ts +59 -0
  68. package/components/wd-checkbox-group/wd-checkbox-group.vue +103 -0
  69. package/components/wd-circle/index.scss +18 -0
  70. package/components/wd-circle/types.ts +54 -0
  71. package/components/wd-circle/wd-circle.vue +318 -0
  72. package/components/wd-col/index.scss +19 -0
  73. package/components/wd-col/types.ts +15 -0
  74. package/components/wd-col/wd-col.vue +91 -0
  75. package/components/wd-col-picker/index.scss +241 -0
  76. package/components/wd-col-picker/types.ts +170 -0
  77. package/components/wd-col-picker/wd-col-picker.vue +550 -0
  78. package/components/wd-collapse/index.scss +55 -0
  79. package/components/wd-collapse/types.ts +63 -0
  80. package/components/wd-collapse/wd-collapse.vue +160 -0
  81. package/components/wd-collapse-item/index.scss +79 -0
  82. package/components/wd-collapse-item/types.ts +36 -0
  83. package/components/wd-collapse-item/wd-collapse-item.vue +182 -0
  84. package/components/wd-config-provider/types.ts +1023 -0
  85. package/components/wd-config-provider/wd-config-provider.vue +82 -0
  86. package/components/wd-count-down/index.scss +14 -0
  87. package/components/wd-count-down/types.ts +41 -0
  88. package/components/wd-count-down/utils.ts +52 -0
  89. package/components/wd-count-down/wd-count-down.vue +60 -0
  90. package/components/wd-count-to/index.scss +6 -0
  91. package/components/wd-count-to/types.ts +110 -0
  92. package/components/wd-count-to/wd-count-to.vue +134 -0
  93. package/components/wd-curtain/index.scss +80 -0
  94. package/components/wd-curtain/types.ts +45 -0
  95. package/components/wd-curtain/wd-curtain.vue +174 -0
  96. package/components/wd-datetime-picker/index.scss +243 -0
  97. package/components/wd-datetime-picker/types.ts +225 -0
  98. package/components/wd-datetime-picker/wd-datetime-picker.vue +827 -0
  99. package/components/wd-datetime-picker-view/index.scss +0 -0
  100. package/components/wd-datetime-picker-view/types.ts +137 -0
  101. package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +514 -0
  102. package/components/wd-divider/index.scss +32 -0
  103. package/components/wd-divider/types.ts +12 -0
  104. package/components/wd-divider/wd-divider.vue +29 -0
  105. package/components/wd-drop-menu/index.scss +89 -0
  106. package/components/wd-drop-menu/types.ts +38 -0
  107. package/components/wd-drop-menu/wd-drop-menu.vue +128 -0
  108. package/components/wd-drop-menu-item/index.scss +66 -0
  109. package/components/wd-drop-menu-item/types.ts +78 -0
  110. package/components/wd-drop-menu-item/wd-drop-menu-item.vue +230 -0
  111. package/components/wd-fab/index.scss +115 -0
  112. package/components/wd-fab/types.ts +61 -0
  113. package/components/wd-fab/wd-fab.vue +257 -0
  114. package/components/wd-form/index.scss +10 -0
  115. package/components/wd-form/types.ts +93 -0
  116. package/components/wd-form/wd-form.vue +185 -0
  117. package/components/wd-form-item/index.scss +17 -0
  118. package/components/wd-form-item/types.ts +22 -0
  119. package/components/wd-form-item/wd-form-item.vue +65 -0
  120. package/components/wd-gap/index.scss +9 -0
  121. package/components/wd-gap/types.ts +23 -0
  122. package/components/wd-gap/wd-gap.vue +39 -0
  123. package/components/wd-grid/index.scss +9 -0
  124. package/components/wd-grid/types.ts +54 -0
  125. package/components/wd-grid/wd-grid.vue +107 -0
  126. package/components/wd-grid-item/index.scss +137 -0
  127. package/components/wd-grid-item/types.ts +74 -0
  128. package/components/wd-grid-item/wd-grid-item.vue +181 -0
  129. package/components/wd-icon/index.scss +1222 -0
  130. package/components/wd-icon/types.ts +21 -0
  131. package/components/wd-icon/wd-icon.vue +53 -0
  132. package/components/wd-icon/wd-icons.ttf +0 -0
  133. package/components/wd-img/index.scss +19 -0
  134. package/components/wd-img/types.ts +53 -0
  135. package/components/wd-img/wd-img.vue +76 -0
  136. package/components/wd-img-cropper/index.scss +227 -0
  137. package/components/wd-img-cropper/types.ts +87 -0
  138. package/components/wd-img-cropper/wd-img-cropper.vue +659 -0
  139. package/components/wd-index-anchor/index.scss +34 -0
  140. package/components/wd-index-anchor/type.ts +9 -0
  141. package/components/wd-index-anchor/wd-index-anchor.vue +57 -0
  142. package/components/wd-index-bar/index.scss +39 -0
  143. package/components/wd-index-bar/type.ts +28 -0
  144. package/components/wd-index-bar/wd-index-bar.vue +158 -0
  145. package/components/wd-input/index.scss +326 -0
  146. package/components/wd-input/types.ts +182 -0
  147. package/components/wd-input/wd-input.vue +327 -0
  148. package/components/wd-input-number/index.scss +132 -0
  149. package/components/wd-input-number/types.ts +78 -0
  150. package/components/wd-input-number/wd-input-number.vue +221 -0
  151. package/components/wd-loading/index.scss +34 -0
  152. package/components/wd-loading/types.ts +31 -0
  153. package/components/wd-loading/wd-loading.vue +90 -0
  154. package/components/wd-loadmore/index.scss +39 -0
  155. package/components/wd-loadmore/types.ts +24 -0
  156. package/components/wd-loadmore/wd-loadmore.vue +53 -0
  157. package/components/wd-message-box/index.scss +121 -0
  158. package/components/wd-message-box/index.ts +95 -0
  159. package/components/wd-message-box/types.ts +116 -0
  160. package/components/wd-message-box/wd-message-box.vue +326 -0
  161. package/components/wd-navbar/index.scss +103 -0
  162. package/components/wd-navbar/types.ts +52 -0
  163. package/components/wd-navbar/wd-navbar.vue +142 -0
  164. package/components/wd-navbar-capsule/index.scss +65 -0
  165. package/components/wd-navbar-capsule/types.ts +0 -0
  166. package/components/wd-navbar-capsule/wd-navbar-capsule.vue +31 -0
  167. package/components/wd-notice-bar/index.scss +86 -0
  168. package/components/wd-notice-bar/types.ts +56 -0
  169. package/components/wd-notice-bar/wd-notice-bar.vue +223 -0
  170. package/components/wd-notify/index.scss +34 -0
  171. package/components/wd-notify/index.ts +59 -0
  172. package/components/wd-notify/types.ts +62 -0
  173. package/components/wd-notify/wd-notify.vue +83 -0
  174. package/components/wd-number-keyboard/index.scss +78 -0
  175. package/components/wd-number-keyboard/key/index.scss +79 -0
  176. package/components/wd-number-keyboard/key/index.vue +76 -0
  177. package/components/wd-number-keyboard/key/types.ts +11 -0
  178. package/components/wd-number-keyboard/types.ts +79 -0
  179. package/components/wd-number-keyboard/wd-number-keyboard.vue +173 -0
  180. package/components/wd-overlay/index.scss +17 -0
  181. package/components/wd-overlay/types.ts +25 -0
  182. package/components/wd-overlay/wd-overlay.vue +46 -0
  183. package/components/wd-pagination/index.scss +57 -0
  184. package/components/wd-pagination/types.ts +41 -0
  185. package/components/wd-pagination/wd-pagination.vue +121 -0
  186. package/components/wd-password-input/index.scss +123 -0
  187. package/components/wd-password-input/types.ts +48 -0
  188. package/components/wd-password-input/wd-password-input.vue +58 -0
  189. package/components/wd-picker/index.scss +216 -0
  190. package/components/wd-picker/types.ts +186 -0
  191. package/components/wd-picker/wd-picker.vue +409 -0
  192. package/components/wd-picker-view/index.scss +91 -0
  193. package/components/wd-picker-view/types.ts +162 -0
  194. package/components/wd-picker-view/wd-picker-view.vue +361 -0
  195. package/components/wd-popover/index.scss +123 -0
  196. package/components/wd-popover/types.ts +69 -0
  197. package/components/wd-popover/wd-popover.vue +216 -0
  198. package/components/wd-popup/index.scss +112 -0
  199. package/components/wd-popup/types.ts +68 -0
  200. package/components/wd-popup/wd-popup.vue +227 -0
  201. package/components/wd-progress/index.scss +62 -0
  202. package/components/wd-progress/types.ts +40 -0
  203. package/components/wd-progress/wd-progress.vue +201 -0
  204. package/components/wd-radio/index.scss +300 -0
  205. package/components/wd-radio/types.ts +42 -0
  206. package/components/wd-radio/wd-radio.vue +136 -0
  207. package/components/wd-radio-group/index.scss +23 -0
  208. package/components/wd-radio-group/types.ts +36 -0
  209. package/components/wd-radio-group/wd-radio-group.vue +54 -0
  210. package/components/wd-rate/index.scss +24 -0
  211. package/components/wd-rate/types.ts +91 -0
  212. package/components/wd-rate/wd-rate.vue +131 -0
  213. package/components/wd-resize/index.scss +26 -0
  214. package/components/wd-resize/types.ts +6 -0
  215. package/components/wd-resize/wd-resize.vue +155 -0
  216. package/components/wd-row/index.scss +10 -0
  217. package/components/wd-row/types.ts +16 -0
  218. package/components/wd-row/wd-row.vue +63 -0
  219. package/components/wd-search/index.scss +148 -0
  220. package/components/wd-search/types.ts +83 -0
  221. package/components/wd-search/wd-search.vue +237 -0
  222. package/components/wd-segmented/index.scss +97 -0
  223. package/components/wd-segmented/types.ts +68 -0
  224. package/components/wd-segmented/wd-segmented.vue +143 -0
  225. package/components/wd-select-picker/index.scss +177 -0
  226. package/components/wd-select-picker/types.ts +116 -0
  227. package/components/wd-select-picker/wd-select-picker.vue +486 -0
  228. package/components/wd-sidebar/index.scss +25 -0
  229. package/components/wd-sidebar/types.ts +28 -0
  230. package/components/wd-sidebar/wd-sidebar.vue +41 -0
  231. package/components/wd-sidebar-item/index.scss +93 -0
  232. package/components/wd-sidebar-item/types.ts +31 -0
  233. package/components/wd-sidebar-item/wd-sidebar-item.vue +114 -0
  234. package/components/wd-skeleton/index.scss +101 -0
  235. package/components/wd-skeleton/index.ts +1 -0
  236. package/components/wd-skeleton/types.ts +69 -0
  237. package/components/wd-skeleton/wd-skeleton.vue +135 -0
  238. package/components/wd-slider/index.scss +91 -0
  239. package/components/wd-slider/types.ts +104 -0
  240. package/components/wd-slider/wd-slider.vue +377 -0
  241. package/components/wd-sort-button/index.scss +86 -0
  242. package/components/wd-sort-button/types.ts +43 -0
  243. package/components/wd-sort-button/wd-sort-button.vue +76 -0
  244. package/components/wd-status-tip/index.scss +37 -0
  245. package/components/wd-status-tip/types.ts +59 -0
  246. package/components/wd-status-tip/wd-status-tip.vue +94 -0
  247. package/components/wd-step/index.scss +236 -0
  248. package/components/wd-step/types.ts +33 -0
  249. package/components/wd-step/wd-step.vue +151 -0
  250. package/components/wd-steps/index.scss +10 -0
  251. package/components/wd-steps/types.ts +59 -0
  252. package/components/wd-steps/wd-steps.vue +37 -0
  253. package/components/wd-sticky/index.scss +9 -0
  254. package/components/wd-sticky/types.ts +13 -0
  255. package/components/wd-sticky/wd-sticky.vue +190 -0
  256. package/components/wd-sticky-box/index.scss +6 -0
  257. package/components/wd-sticky-box/types.ts +20 -0
  258. package/components/wd-sticky-box/wd-sticky-box.vue +154 -0
  259. package/components/wd-swipe-action/index.scss +22 -0
  260. package/components/wd-swipe-action/types.ts +43 -0
  261. package/components/wd-swipe-action/wd-swipe-action.vue +307 -0
  262. package/components/wd-swiper/index.scss +23 -0
  263. package/components/wd-swiper/types.ts +189 -0
  264. package/components/wd-swiper/wd-swiper.vue +202 -0
  265. package/components/wd-swiper-nav/index.scss +153 -0
  266. package/components/wd-swiper-nav/types.ts +42 -0
  267. package/components/wd-swiper-nav/wd-swiper-nav.vue +37 -0
  268. package/components/wd-switch/index.scss +58 -0
  269. package/components/wd-switch/types.ts +56 -0
  270. package/components/wd-switch/wd-switch.vue +83 -0
  271. package/components/wd-tab/index.scss +8 -0
  272. package/components/wd-tab/types.ts +20 -0
  273. package/components/wd-tab/wd-tab.vue +100 -0
  274. package/components/wd-tabbar/index.scss +57 -0
  275. package/components/wd-tabbar/types.ts +88 -0
  276. package/components/wd-tabbar/wd-tabbar.vue +104 -0
  277. package/components/wd-tabbar-item/index.scss +52 -0
  278. package/components/wd-tabbar-item/types.ts +51 -0
  279. package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
  280. package/components/wd-table/index.scss +132 -0
  281. package/components/wd-table/types.ts +69 -0
  282. package/components/wd-table/wd-table.vue +255 -0
  283. package/components/wd-table-col/index.scss +44 -0
  284. package/components/wd-table-col/types.ts +54 -0
  285. package/components/wd-table-col/wd-table-col.vue +149 -0
  286. package/components/wd-tabs/index.scss +280 -0
  287. package/components/wd-tabs/types.ts +71 -0
  288. package/components/wd-tabs/wd-tabs.vue +528 -0
  289. package/components/wd-tag/index.scss +115 -0
  290. package/components/wd-tag/types.ts +81 -0
  291. package/components/wd-tag/wd-tag.vue +154 -0
  292. package/components/wd-text/index.scss +34 -0
  293. package/components/wd-text/types.ts +98 -0
  294. package/components/wd-text/wd-text.vue +138 -0
  295. package/components/wd-textarea/index.scss +343 -0
  296. package/components/wd-textarea/types.ts +298 -0
  297. package/components/wd-textarea/wd-textarea.vue +303 -0
  298. package/components/wd-toast/index.scss +66 -0
  299. package/components/wd-toast/index.ts +109 -0
  300. package/components/wd-toast/types.ts +76 -0
  301. package/components/wd-toast/wd-toast.vue +212 -0
  302. package/components/wd-tooltip/index.scss +61 -0
  303. package/components/wd-tooltip/types.ts +102 -0
  304. package/components/wd-tooltip/wd-tooltip.vue +167 -0
  305. package/components/wd-transition/index.scss +91 -0
  306. package/components/wd-transition/types.ts +89 -0
  307. package/components/wd-transition/wd-transition.vue +221 -0
  308. package/components/wd-upload/index.scss +173 -0
  309. package/components/wd-upload/types.ts +378 -0
  310. package/components/wd-upload/utils.ts +152 -0
  311. package/components/wd-upload/wd-upload.vue +737 -0
  312. package/components/wd-video-preview/index.scss +34 -0
  313. package/components/wd-video-preview/types.ts +32 -0
  314. package/components/wd-video-preview/wd-video-preview.vue +76 -0
  315. package/components/wd-watermark/index.scss +18 -0
  316. package/components/wd-watermark/types.ts +82 -0
  317. package/components/wd-watermark/wd-watermark.vue +592 -0
  318. package/components/wot-design-uni/wot-design-uni.vue +14 -0
  319. package/global.d.ts +108 -0
  320. package/index.ts +30 -0
  321. package/locale/index.ts +41 -0
  322. package/locale/lang/en-US.ts +128 -0
  323. package/locale/lang/th-TH.ts +127 -0
  324. package/locale/lang/vi-VN.ts +89 -0
  325. package/locale/lang/zh-CN.ts +127 -0
  326. package/locale/lang/zh-HK.ts +84 -0
  327. package/locale/lang/zh-TW.ts +84 -0
  328. package/package.json +20 -0
File without changes
@@ -0,0 +1,137 @@
1
+ import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
2
+ import {
3
+ baseProps,
4
+ makeBooleanProp,
5
+ makeNumberProp,
6
+ makeRequiredProp,
7
+ makeStringProp,
8
+ } from '../common/props'
9
+
10
+ export type DateTimeType = 'date' | 'year-month' | 'time' | 'datetime' | 'year'
11
+
12
+ /**
13
+ * @description 根据传入的值和类型,获取当前的选项数组,便于传入 pickerView
14
+ * @param value
15
+ * @param type picker类型
16
+ * @return {Array} pickerValue
17
+ */
18
+ export function getPickerValue(value: string | number, type: DateTimeType) {
19
+ const values: number[] = []
20
+ const date = new Date(value)
21
+ if (type === 'time') {
22
+ const pair = String(value).split(':')
23
+ values.push(parseInt(pair[0]), parseInt(pair[1]))
24
+ } else {
25
+ values.push(date.getFullYear(), date.getMonth() + 1)
26
+ if (type === 'date') {
27
+ values.push(date.getDate())
28
+ } else if (type === 'datetime') {
29
+ values.push(date.getDate(), date.getHours(), date.getMinutes())
30
+ }
31
+ }
32
+ return values
33
+ }
34
+
35
+ export const datetimePickerViewProps = {
36
+ ...baseProps,
37
+ /**
38
+ * 选中项,当 type 为 time 时,类型为字符串,否则为 时间戳
39
+ */
40
+ modelValue: makeRequiredProp([String, Number, Date]),
41
+ /**
42
+ * 加载中
43
+ */
44
+ loading: makeBooleanProp(false),
45
+ /**
46
+ * 加载的颜色,只能使用十六进制的色值写法,且不能使用缩写
47
+ */
48
+ loadingColor: makeStringProp('#4D80F0'),
49
+ /**
50
+ * picker内部滚筒高
51
+ */
52
+ columnsHeight: makeNumberProp(217),
53
+ valueKey: makeStringProp('value'),
54
+ labelKey: makeStringProp('label'),
55
+ /**
56
+ * 选择器类型,可选值:date / year-month / time
57
+ */
58
+ type: makeStringProp<DateTimeType>('datetime'),
59
+ /**
60
+ * 自定义过滤选项的函数,返回列的选项数组
61
+ */
62
+ filter: Function as PropType<DatetimePickerViewFilter>,
63
+ /**
64
+ * 自定义弹出层选项文案的格式化函数,返回一个字符串
65
+ */
66
+ formatter: Function as PropType<DatetimePickerViewFormatter>,
67
+ /**
68
+ * 自定义列的格式化函数
69
+ */
70
+ columnFormatter: Function as PropType<DatetimePickerViewColumnFormatter>,
71
+ /**
72
+ * 最小日期
73
+ */
74
+ minDate: makeNumberProp(new Date(new Date().getFullYear() - 10, 0, 1).getTime()),
75
+ /**
76
+ * 最大日期
77
+ */
78
+ maxDate: makeNumberProp(new Date(new Date().getFullYear() + 10, 11, 31).getTime()),
79
+ /**
80
+ * 最小小时,time类型时生效
81
+ */
82
+ minHour: makeNumberProp(0),
83
+ /**
84
+ * 最大小时,time类型时生效
85
+ */
86
+ maxHour: makeNumberProp(23),
87
+ /**
88
+ * 最小分钟,time类型时生效
89
+ */
90
+ minMinute: makeNumberProp(0),
91
+ /**
92
+ * 最大分钟,time类型时生效
93
+ */
94
+ maxMinute: makeNumberProp(59),
95
+ /**
96
+ * 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
97
+ */
98
+ immediateChange: makeBooleanProp(false),
99
+ startSymbol: makeBooleanProp(false),
100
+ }
101
+
102
+ export type DatetimePickerViewColumnType = 'year' | 'month' | 'date' | 'hour' | 'minute'
103
+
104
+ export type DatetimePickerViewOption = {
105
+ label: string
106
+ value: number
107
+ }
108
+
109
+ export type DatetimePickerViewFilter = (
110
+ type: DatetimePickerViewColumnType,
111
+ values: number[],
112
+ ) => number[]
113
+
114
+ export type DatetimePickerViewFormatter = (type: string, value: string) => string
115
+
116
+ export type DatetimePickerViewColumnFormatter = (
117
+ picker: DatetimePickerViewInstance,
118
+ ) => DatetimePickerViewOption[][]
119
+
120
+ export type DatetimePickerViewProps = ExtractPropTypes<typeof datetimePickerViewProps>
121
+
122
+ export type DatetimePickerViewExpose = {
123
+ updateColumns: () => DatetimePickerViewOption[][]
124
+ setColumns: (columnList: DatetimePickerViewOption[][]) => void
125
+ getSelects: () => Record<string, any> | Record<string, any>[] | undefined
126
+ correctValue: (value: string | number) => string | number
127
+ getPickerValue: (value: string | number, type: DateTimeType) => number[]
128
+ getOriginColumns: () => {
129
+ type: DatetimePickerViewColumnType
130
+ values: number[]
131
+ }[]
132
+ }
133
+
134
+ export type DatetimePickerViewInstance = ComponentPublicInstance<
135
+ DatetimePickerViewProps,
136
+ DatetimePickerViewExpose
137
+ >
@@ -0,0 +1,514 @@
1
+ <template>
2
+ <view>
3
+ <wd-picker-view
4
+ ref="datePickerview"
5
+ :custom-class="customClass"
6
+ :custom-style="customStyle"
7
+ :immediate-change="immediateChange"
8
+ v-model="pickerValue"
9
+ :columns="columns"
10
+ :columns-height="columnsHeight"
11
+ :columnChange="columnChange"
12
+ :loading="loading"
13
+ :loading-color="loadingColor"
14
+ @change="onChange"
15
+ @pickstart="onPickStart"
16
+ @pickend="onPickEnd"
17
+ ></wd-picker-view>
18
+ </view>
19
+ </template>
20
+ <script lang="ts">
21
+ export default {
22
+ name: 'wd-datetime-picker-view',
23
+ virtualHost: true,
24
+ addGlobalClass: true,
25
+ styleIsolation: 'shared',
26
+ }
27
+ </script>
28
+
29
+ <script lang="ts" setup>
30
+ import { getCurrentInstance, onBeforeMount, ref, watch } from 'vue'
31
+ import { debounce, isFunction, isDef, padZero, range, isArray } from '../common/util'
32
+ import {
33
+ getPickerValue,
34
+ datetimePickerViewProps,
35
+ type DatetimePickerViewColumnType,
36
+ type DatetimePickerViewOption,
37
+ type DatetimePickerViewExpose,
38
+ } from './types'
39
+ import type { PickerViewInstance } from '../wd-picker-view/types'
40
+
41
+ // 本地时间戳
42
+ /** @description 判断时间戳是否合法 */
43
+ const isValidDate = (date: string | number | Date) => isDef(date) && !Number.isNaN(date)
44
+ /**
45
+ * @description 生成n个元素,并使用iterator接口进行填充
46
+ * @param n
47
+ * @param iteratee
48
+ * @return {any[]}
49
+ */
50
+ const times = (n: number, iteratee: (index: number) => number) => {
51
+ let index: number = -1
52
+ const length = n < 0 ? 0 : n
53
+ const result: number[] = Array(length)
54
+ while (++index < n) {
55
+ result[index] = iteratee(index)
56
+ }
57
+ return result
58
+ }
59
+ /**
60
+ * @description 获取某年某月有多少天
61
+ * @param {Number} year
62
+ * @param {Number} month
63
+ * @return {Number} day
64
+ */
65
+ const getMonthEndDay = (year: number, month: number) => {
66
+ return 32 - new Date(year, month - 1, 32).getDate()
67
+ }
68
+
69
+ const props = defineProps(datetimePickerViewProps)
70
+ const emit = defineEmits(['change', 'pickstart', 'pickend', 'update:modelValue'])
71
+
72
+ // pickerview
73
+ const datePickerview = ref<PickerViewInstance>()
74
+ // 内部保持时间戳的
75
+ const innerValue = ref<null | string | number>(null)
76
+ // 传递给pickerView的columns的数据
77
+ const columns = ref<DatetimePickerViewOption[][]>([])
78
+ // 传递给pickerView的value的数据
79
+ const pickerValue = ref<string | number | boolean | string[] | number[] | boolean[]>([])
80
+ // 自定义组件是否已经调用created hook
81
+ const created = ref<boolean>(false)
82
+
83
+ const { proxy } = getCurrentInstance() as any
84
+
85
+ defineExpose<DatetimePickerViewExpose>({
86
+ updateColumns,
87
+ setColumns,
88
+ getSelects,
89
+ correctValue,
90
+ getPickerValue,
91
+ getOriginColumns,
92
+ ...props,
93
+ })
94
+ /**
95
+ * @description updateValue 防抖函数的占位符
96
+ */
97
+ const updateValue = debounce(() => {
98
+ // 只有等created hook初始化数据之后,observer才能执行此操作
99
+ if (!created.value) return
100
+ const val = correctValue(props.modelValue)
101
+ const isEqual = val === innerValue.value
102
+ if (!isEqual) {
103
+ updateColumnValue(val)
104
+ } else {
105
+ columns.value = updateColumns()
106
+ }
107
+ }, 50)
108
+
109
+ watch(
110
+ () => props.modelValue,
111
+ (val, oldVal) => {
112
+ if (val === oldVal) return
113
+ // 外部传入值更改时 更新picker数据
114
+ const value = correctValue(val)
115
+ updateColumnValue(value)
116
+ },
117
+ { deep: true, immediate: true },
118
+ )
119
+
120
+ watch(
121
+ () => props.type,
122
+ (target) => {
123
+ const type = ['date', 'year-month', 'time', 'datetime', 'year']
124
+ if (type.indexOf(target) === -1) {
125
+ console.error(`type must be one of ${type}`)
126
+ }
127
+ // 每次type更新时都需要刷新整个列表
128
+ updateValue()
129
+ },
130
+ { deep: true, immediate: true },
131
+ )
132
+
133
+ watch(
134
+ () => props.filter,
135
+ (fn) => {
136
+ if (fn && !isFunction(fn)) {
137
+ console.error('The type of filter must be Function')
138
+ }
139
+ updateValue()
140
+ },
141
+ { deep: true, immediate: true },
142
+ )
143
+
144
+ watch(
145
+ () => props.formatter,
146
+ (fn) => {
147
+ if (fn && !isFunction(fn)) {
148
+ console.error('The type of formatter must be Function')
149
+ }
150
+ updateValue()
151
+ },
152
+ { deep: true, immediate: true },
153
+ )
154
+
155
+ watch(
156
+ () => props.columnFormatter,
157
+ (fn) => {
158
+ if (fn && !isFunction(fn)) {
159
+ console.error('The type of columnFormatter must be Function')
160
+ }
161
+ updateValue()
162
+ },
163
+ { deep: true, immediate: true },
164
+ )
165
+
166
+ watch(
167
+ [
168
+ () => props.minDate,
169
+ () => props.maxDate,
170
+ () => props.minHour,
171
+ () => props.maxHour,
172
+ () => props.minMinute,
173
+ () => props.minMinute,
174
+ () => props.maxMinute,
175
+ ],
176
+ () => {
177
+ updateValue()
178
+ },
179
+ {
180
+ deep: true,
181
+ immediate: true,
182
+ },
183
+ )
184
+
185
+ onBeforeMount(() => {
186
+ // 初始化完毕,打开observer触发render的开关
187
+ created.value = true
188
+ const innerValue = correctValue(props.modelValue)
189
+ updateColumnValue(innerValue)
190
+ })
191
+
192
+ /** pickerView触发change事件,同步修改pickerValue */
193
+ function onChange({ value }: { value: string | string[] }) {
194
+ // 更新pickerView的value
195
+ pickerValue.value = value
196
+ // pickerValue => innerValue
197
+ const result = updateInnerValue()
198
+ emit('update:modelValue', result)
199
+ // 这个地方的value返回的是picker数组,实际上在此处我们应该返回 change 的是 value date类型的值
200
+ emit('change', {
201
+ value: result,
202
+ picker: proxy.$.exposed,
203
+ })
204
+ }
205
+
206
+ /**
207
+ * @description 使用formatter格式化getOriginColumns的结果
208
+ * @return {Array<Array<Number>>} 用于传入picker的columns
209
+ */
210
+ function updateColumns(): DatetimePickerViewOption[][] {
211
+ const { formatter, columnFormatter } = props
212
+ if (columnFormatter) {
213
+ return columnFormatter(proxy.$.exposed)
214
+ } else {
215
+ return getOriginColumns().map((column) => {
216
+ return column.values.map((value) => {
217
+ return {
218
+ label: formatter ? formatter(column.type, padZero(value)) : padZero(value),
219
+ value,
220
+ }
221
+ })
222
+ })
223
+ }
224
+ }
225
+
226
+ /**
227
+ * 设置数据列
228
+ * @param columnList 数据列
229
+ */
230
+ function setColumns(columnList: DatetimePickerViewOption[][]) {
231
+ columns.value = columnList
232
+ }
233
+
234
+ /**
235
+ * @description 根据getRanges得到的范围计算所有的列的数据
236
+ * @return {{values: any[], type: String}[]} 年
237
+ */
238
+ function getOriginColumns() {
239
+ const { filter } = props
240
+ return getRanges().map(({ type, range }) => {
241
+ let values = times(range[1] - range[0] + 1, (index: number) => {
242
+ return range[0] + index
243
+ })
244
+
245
+ if (filter) {
246
+ values = filter(type, values)
247
+ }
248
+
249
+ return {
250
+ type,
251
+ values,
252
+ }
253
+ })
254
+ }
255
+
256
+ /**
257
+ * @description 根据时间戳生成年月日时分的边界范围
258
+ * @return {Array<{type:String,range:Array<Number>}>}
259
+ */
260
+ function getRanges(): Array<{ type: DatetimePickerViewColumnType; range: number[] }> {
261
+ if (props.type === 'time') {
262
+ return [
263
+ {
264
+ type: 'hour',
265
+ range: [props.minHour, props.maxHour],
266
+ },
267
+ {
268
+ type: 'minute',
269
+ range: [props.minMinute, props.maxMinute],
270
+ },
271
+ ]
272
+ }
273
+
274
+ const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary(
275
+ 'max',
276
+ innerValue.value as number,
277
+ )
278
+ const { minYear, minDate, minMonth, minHour, minMinute } = getBoundary(
279
+ 'min',
280
+ innerValue.value as number,
281
+ )
282
+
283
+ const result: Array<{ type: DatetimePickerViewColumnType; range: number[] }> = [
284
+ {
285
+ type: 'year',
286
+ range: [minYear, maxYear],
287
+ },
288
+ {
289
+ type: 'month',
290
+ range: [minMonth, maxMonth],
291
+ },
292
+ {
293
+ type: 'date',
294
+ range: [minDate, maxDate],
295
+ },
296
+ {
297
+ type: 'hour',
298
+ range: [minHour, maxHour],
299
+ },
300
+ {
301
+ type: 'minute',
302
+ range: [minMinute, maxMinute],
303
+ },
304
+ ]
305
+
306
+ if (props.type === 'date') result.splice(3, 2)
307
+ if (props.type === 'year-month') result.splice(2, 3)
308
+ if (props.type === 'year') result.splice(1, 4)
309
+ return result
310
+ }
311
+
312
+ /**
313
+ * @description 修正时间入参,判定是否为规范时间类型
314
+ * @param {String | Number} value
315
+ * @return {String | Number} innerValue
316
+ */
317
+ function correctValue(value: string | number | Date): string | number {
318
+ const isDateType = props.type !== 'time'
319
+ if (isDateType && !isValidDate(value)) {
320
+ // 是Date类型,但入参不可用,使用最小时间戳代替
321
+ value = props.minDate
322
+ } else if (!isDateType && !value) {
323
+ // 非Date类型,无入参,使用最小小时代替
324
+ value = `${padZero(props.minHour)}:00`
325
+ }
326
+
327
+ // 当type为time时
328
+ if (!isDateType) {
329
+ // 非Date类型,直接走此逻辑
330
+ let [hour, minute] = (value as string).split(':')
331
+ hour = padZero(range(Number(hour), props.minHour, props.maxHour))
332
+ minute = padZero(range(Number(minute), props.minMinute, props.maxMinute))
333
+ return `${hour}:${minute}`
334
+ }
335
+
336
+ // date type
337
+ value = Math.min(Math.max(Number(value), props.minDate), props.maxDate)
338
+
339
+ return value
340
+ }
341
+
342
+ /**
343
+ * @description 根据时间戳,计算所有选项的范围
344
+ * @param {'min'|'max'} type 类型
345
+ * @param {Number} innerValue 时间戳
346
+ */
347
+ function getBoundary(type: 'min' | 'max', innerValue: number) {
348
+ const value = new Date(innerValue)
349
+ const boundary = new Date(props[`${type}Date`])
350
+ const year = boundary.getFullYear()
351
+ let month: number = 1
352
+ let date: number = 1
353
+ let hour: number = 0
354
+ let minute: number = 0
355
+
356
+ if (type === 'max') {
357
+ month = 12
358
+ date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1)
359
+ hour = 23
360
+ minute = 59
361
+ }
362
+
363
+ if (value.getFullYear() === year) {
364
+ month = boundary.getMonth() + 1
365
+ if (value.getMonth() + 1 === month) {
366
+ date = boundary.getDate()
367
+ if (value.getDate() === date) {
368
+ hour = boundary.getHours()
369
+ if (value.getHours() === hour) {
370
+ minute = boundary.getMinutes()
371
+ }
372
+ }
373
+ }
374
+ }
375
+ return {
376
+ [`${type}Year`]: year,
377
+ [`${type}Month`]: month,
378
+ [`${type}Date`]: date,
379
+ [`${type}Hour`]: hour,
380
+ [`${type}Minute`]: minute,
381
+ }
382
+ }
383
+
384
+ /**
385
+ * @description 根据传入的value以及type,初始化innerValue,期间会使用format格式化数据
386
+ * @param value
387
+ * @return {Array}
388
+ */
389
+ function updateColumnValue(value: string | number) {
390
+ const values = getPickerValue(value, props.type)
391
+ // 更新pickerView的value,columns
392
+ if (props.modelValue !== value) {
393
+ emit('update:modelValue', value)
394
+ emit('change', {
395
+ value,
396
+ picker: proxy.$.exposed,
397
+ })
398
+ }
399
+ innerValue.value = value
400
+ columns.value = updateColumns()
401
+ pickerValue.value = values
402
+ }
403
+
404
+ /**
405
+ * @description 根据当前的选中项 处理innerValue
406
+ * @return {date} innerValue
407
+ */
408
+ function updateInnerValue() {
409
+ const { type } = props
410
+ let innerValue: string | number = ''
411
+ const pickerVal = datePickerview.value?.getValues() || []
412
+ const values = isArray(pickerVal) ? pickerVal : [pickerVal]
413
+
414
+ if (type === 'time') {
415
+ innerValue = `${padZero(values[0])}:${padZero(values[1])}`
416
+ return innerValue
417
+ }
418
+
419
+ // 处理年份 索引位0
420
+ const year = values[0] && parseInt(values[0])
421
+
422
+ // 处理月 索引位1
423
+ const month = type === 'year' ? 1 : values[1] && parseInt(values[1])
424
+
425
+ const maxDate = getMonthEndDay(Number(year), Number(month))
426
+
427
+ // 处理 date 日期 索引位2
428
+ let date: string | number = 1
429
+ if (type !== 'year-month' && type !== 'year') {
430
+ date =
431
+ (Number(values[2]) && parseInt(String(values[2]))) > maxDate
432
+ ? maxDate
433
+ : values[2] && parseInt(String(values[2]))
434
+ }
435
+
436
+ // 处理 时分 索引位3,4
437
+ let hour = 0
438
+ let minute = 0
439
+
440
+ if (type === 'datetime') {
441
+ hour = Number(values[3]) && parseInt(values[3])
442
+ minute = Number(values[4]) && parseInt(values[4])
443
+ }
444
+ const value = new Date(Number(year), Number(month) - 1, Number(date), hour, minute).getTime()
445
+
446
+ innerValue = correctValue(value)
447
+ return innerValue
448
+ }
449
+
450
+ /**
451
+ * @description 选中项改变,多级联动
452
+ */
453
+ function columnChange(picker: PickerViewInstance) {
454
+ // time year-mouth year 无需联动
455
+ if (props.type === 'time' || props.type === 'year-month' || props.type === 'year') {
456
+ return
457
+ }
458
+ /** 重新计算年月日时分秒,修正时间。 */
459
+ const values = picker.getValues() as string[]
460
+ const year = Number(values[0])
461
+ const month = Number(values[1])
462
+ const maxDate = getMonthEndDay(year, month)
463
+ let date = Number(values[2])
464
+ date = date > maxDate ? maxDate : date
465
+ let hour: number = 0
466
+ let minute: number = 0
467
+ if (props.type === 'datetime') {
468
+ hour = Number(values[3])
469
+ minute = Number(values[4])
470
+ }
471
+ const value = new Date(year, month - 1, date, hour, minute).getTime()
472
+ /** 根据计算选中项的时间戳,重新计算所有的选项列表 */
473
+ // 更新选中时间戳
474
+ innerValue.value = correctValue(value)
475
+ // 根据innerValue获取最新的时间表,重新生成对应的数据源
476
+
477
+ const newColumns = updateColumns()
478
+ // 深拷贝联动之前的选中项
479
+ const selectedIndex = picker.getSelectedIndex().slice(0)
480
+ /**
481
+ * 选中年会修改对应的年份的月数,和月份对应的日期。
482
+ * 选中月,会修改月份对应的日数
483
+ */
484
+ newColumns.forEach((_columns, index) => {
485
+ const nextColumnIndex = index + 1
486
+ const nextColumnData = newColumns[nextColumnIndex]
487
+ if (nextColumnIndex > newColumns.length - 1) return
488
+ picker.setColumnData(
489
+ nextColumnIndex,
490
+ nextColumnData,
491
+ selectedIndex[nextColumnIndex] <= nextColumnData.length - 1
492
+ ? selectedIndex[nextColumnIndex]
493
+ : 0,
494
+ )
495
+ })
496
+ }
497
+ function onPickStart() {
498
+ emit('pickstart')
499
+ }
500
+ function onPickEnd() {
501
+ emit('pickend')
502
+ }
503
+
504
+ function getSelects() {
505
+ const pickerVal = datePickerview.value?.getSelects()
506
+ if (pickerVal == null) return undefined
507
+ if (isArray(pickerVal)) return pickerVal
508
+ return [pickerVal]
509
+ }
510
+ </script>
511
+
512
+ <style lang="scss" scoped>
513
+ @import './index';
514
+ </style>
@@ -0,0 +1,32 @@
1
+ @import '../common/abstracts/variable';
2
+ @import '../common/abstracts/mixin';
3
+
4
+ .wot-theme-dark {
5
+ @include b(divider) {
6
+ color: $-dark-color3;
7
+
8
+ @include e(line) {
9
+ background: $-dark-color-gray;
10
+ }
11
+ }
12
+ }
13
+
14
+ @include b(divider) {
15
+ position: relative;
16
+ display: flex;
17
+ align-items: center;
18
+ padding: $-divider-padding;
19
+ font-size: $-divider-fs;
20
+ color: $-divider-color;
21
+
22
+ @include e(line) {
23
+ display: block;
24
+ flex: 1;
25
+ height: 1px;
26
+ background: $-divider-line-color;
27
+ transform: scaleY(0.5);
28
+ }
29
+ @include e(content) {
30
+ padding: 0 12px;
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import type { ExtractPropTypes } from 'vue'
2
+ import { baseProps, makeStringProp } from '../common/props'
3
+
4
+ export const dividerProps = {
5
+ ...baseProps,
6
+ /**
7
+ * 自定义颜色,所有颜色的写法
8
+ */
9
+ color: makeStringProp(''),
10
+ }
11
+
12
+ export type DividerProps = ExtractPropTypes<typeof dividerProps>