@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
@@ -0,0 +1,40 @@
1
+ /*
2
+ * @Author: weisheng
3
+ * @Date: 2024-03-15 20:40:34
4
+ * @LastEditTime: 2024-03-18 15:32:11
5
+ * @LastEditors: weisheng
6
+ * @Description:
7
+ * @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-progress\types.ts
8
+ * 记得注释
9
+ */
10
+ import type { PropType } from 'vue'
11
+ import { baseProps, makeBooleanProp, makeNumberProp } from '../common/props'
12
+
13
+ export type ProgressStatus = 'success' | 'danger' // 状态类型
14
+
15
+ export const progressProps = {
16
+ ...baseProps,
17
+ /**
18
+ * 进度数值,最大值100
19
+ */
20
+ percentage: makeNumberProp(0),
21
+ /**
22
+ * 是否隐藏进度条上的文字,默认值为false
23
+ */
24
+ hideText: makeBooleanProp(false),
25
+ /**
26
+ * 进度条颜色
27
+ */
28
+ color: {
29
+ type: [String, Array, Object] as PropType<string | string[] | Record<string, any>[]>,
30
+ default: 'linear-gradient(315deg, rgba(81,124,240,1) 0%,rgba(118,158,245,1) 100%)',
31
+ },
32
+ /**
33
+ * 进度增加1%所需毫秒数
34
+ */
35
+ duration: makeNumberProp(30),
36
+ /**
37
+ * 进度条状态
38
+ */
39
+ status: String as PropType<ProgressStatus>,
40
+ }
@@ -0,0 +1,201 @@
1
+ <template>
2
+ <view :class="`wd-progress ${customClass}`" :style="customStyle">
3
+ <!--进度条-->
4
+ <view class="wd-progress__outer">
5
+ <view :class="`wd-progress__inner ${progressClass}`" :style="rootStyle"></view>
6
+ </view>
7
+ <!--文案、图标-->
8
+ <view v-if="!hideText" class="wd-progress__label">{{ percentage }}%</view>
9
+ <wd-icon
10
+ v-else-if="status"
11
+ :custom-class="`wd-progress__label wd-progress__icon ${progressClass}`"
12
+ :name="status == 'danger' ? 'close-outline' : 'check-outline'"
13
+ :color="typeof color === 'string' ? color : ''"
14
+ ></wd-icon>
15
+ </view>
16
+ </template>
17
+
18
+ <script lang="ts">
19
+ export default {
20
+ name: 'wd-progress',
21
+ options: {
22
+ virtualHost: true,
23
+ addGlobalClass: true,
24
+ styleIsolation: 'shared',
25
+ },
26
+ }
27
+ </script>
28
+
29
+ <script lang="ts" setup>
30
+ import { computed, ref, watch } from 'vue'
31
+ import { checkNumRange, isArray, objToStyle } from '../common/util'
32
+ import { progressProps } from './types'
33
+
34
+ const props = defineProps(progressProps)
35
+ // 进度条展示的颜色
36
+ const showColor = ref<string>('')
37
+ // 进度条展示的进度
38
+ const showPercent = ref<number>(0)
39
+ // newPercent - oldPercent 的绝对值
40
+ const changeCount = ref<number>(0)
41
+ const progressClass = ref<string>('')
42
+
43
+ let timer: NodeJS.Timeout | null = null // 定时器
44
+
45
+ const rootStyle = computed(() => {
46
+ const style: Record<string, string | number> = {
47
+ background: showColor.value,
48
+ width: showPercent.value + '%',
49
+ 'transition-duration': changeCount.value * props.duration * 0.001 + 's',
50
+ }
51
+ return objToStyle(style)
52
+ })
53
+
54
+ watch(
55
+ () => props.percentage,
56
+ (newValue) => {
57
+ // 校验类型
58
+ if (Number.isNaN(newValue) || newValue < 0 || newValue > 100) {
59
+ console.error('The value of percentage must be between 0 and 100')
60
+ }
61
+ controlProgress()
62
+ },
63
+ )
64
+
65
+ watch(
66
+ () => props.color,
67
+ () => {
68
+ controlProgress()
69
+ },
70
+ {
71
+ deep: true,
72
+ immediate: true,
73
+ },
74
+ )
75
+
76
+ watch(
77
+ () => props.status,
78
+ () => {
79
+ computeProgressClass()
80
+ },
81
+ {
82
+ deep: true,
83
+ immediate: true,
84
+ },
85
+ )
86
+
87
+ watch(
88
+ () => props.duration,
89
+ (newValue) => {
90
+ checkNumRange(newValue)
91
+ },
92
+ {
93
+ deep: true,
94
+ immediate: true,
95
+ },
96
+ )
97
+
98
+ function computeProgressClass() {
99
+ const { status } = props
100
+ const progressClasses: string[] = []
101
+ status && progressClasses.push(`is-${status}`)
102
+ progressClass.value = progressClasses.join(' ')
103
+ }
104
+
105
+ /**
106
+ * @description
107
+ * @param {Number} targetPercent 目标值
108
+ * @param {String} color 目标颜色
109
+ */
110
+ function update(targetPercent: number, color: string) {
111
+ // 需要等上一个定时器跑完
112
+ if (timer) return
113
+ const { duration } = props
114
+ // transition-duration的优先更高
115
+ changeCount.value = Math.abs(targetPercent - showPercent.value)
116
+ setTimeout(() => {
117
+ showPercent.value = targetPercent
118
+ showColor.value = color
119
+ timer = setTimeout(() => {
120
+ clearTimeout(timer as any)
121
+ timer = null
122
+ controlProgress()
123
+ }, changeCount.value * duration)
124
+ }, 50)
125
+ }
126
+
127
+ /**
128
+ * @description 控制进度条的进度和每段的颜色
129
+ */
130
+ function controlProgress() {
131
+ const {
132
+ // 目标百分比
133
+ percentage,
134
+ // 传入的color数组
135
+ color,
136
+ } = props
137
+ // 锁
138
+ if (showPercent.value === percentage || !percentage) return
139
+ /**
140
+ * 数组边界安全判断
141
+ */
142
+ const colorArray: string[] | Record<string, any>[] = (isArray(color) ? color : [color]) as
143
+ | string[]
144
+ | Record<string, any>[]
145
+ if (colorArray.length === 0) throw Error('The colorArray is empty')
146
+ const isStrArray = (colorArray as any).every((item: any) => typeof item === 'string')
147
+ // eslint-disable-next-line no-prototype-builtins
148
+ const isObjArray = (colorArray as any).every(
149
+ (color: any) =>
150
+ Object.prototype.hasOwnProperty.call(color, 'color') &&
151
+ Object.prototype.hasOwnProperty.call(color, 'percentage'),
152
+ )
153
+ if (!isStrArray && !isObjArray) {
154
+ throw Error('Color must be String or Object with color and percentage')
155
+ }
156
+ if (
157
+ isObjArray &&
158
+ (colorArray as any).some(({ percentage }: any) => Number.isNaN(parseInt(percentage)))
159
+ ) {
160
+ throw Error('All the percentage must can be formatted to Number')
161
+ }
162
+ /**
163
+ * 根据colorArray平均分布每段color值,或使用用户自定义的值
164
+ */
165
+ const partNum = parseInt(`${100 / colorArray.length}`)
166
+ const partList = isObjArray
167
+ ? colorArray.sort((a: any, b: any) => a.percentage - b.percentage)
168
+ : colorArray.map((item, index) => {
169
+ return {
170
+ color: item,
171
+ percentage: (index + 1) * partNum,
172
+ }
173
+ })
174
+ /**
175
+ * 找到当前目标
176
+ */
177
+ showPercent.value > percentage
178
+ ? // 减小不加动画,找到第一个比target大的锚点,取锚点颜色并设置target值
179
+ partList.some((part: any) => {
180
+ if (percentage <= part.percentage) {
181
+ update(percentage, part.color)
182
+ return true
183
+ }
184
+ return false
185
+ })
186
+ : // 增加使用分段动画
187
+ partList.some((part: any, index: number) => {
188
+ if (showPercent.value < part.percentage && part.percentage <= percentage) {
189
+ // 找到第一个比now大的点,如果这个点比target小或等,就把这个点设置为下一个即将展示的点
190
+ update(part.percentage, part.color)
191
+ return true
192
+ } else if (index === partList.length - 1) {
193
+ update(percentage, part.color)
194
+ }
195
+ return false
196
+ })
197
+ }
198
+ </script>
199
+ <style lang="scss" scoped>
200
+ @import './index';
201
+ </style>
@@ -0,0 +1,300 @@
1
+ @import './../common/abstracts/_mixin';
2
+ @import './../common/abstracts/variable';
3
+
4
+ .wot-theme-dark {
5
+ @include b(radio) {
6
+ @include e(shape) {
7
+ background: transparent;
8
+ }
9
+ @include e(label) {
10
+ color: $-dark-color;
11
+ }
12
+ @include when(button) {
13
+ .wd-radio__label {
14
+ background-color: $-dark-background;
15
+ }
16
+ @include when(checked) {
17
+ .wd-radio__label {
18
+ background-color: $-dark-background2;
19
+ }
20
+ }
21
+ }
22
+
23
+ @include when(dot) {
24
+ .wd-radio__shape {
25
+ &::before {
26
+ background-color: $-radio-dot-checked-bg;
27
+ }
28
+ }
29
+ @include when(checked) {
30
+ .wd-radio__shape {
31
+ background-color: transparent;
32
+ }
33
+ }
34
+ }
35
+
36
+ @include when(disabled) {
37
+ .wd-radio__label {
38
+ color: $-dark-color-gray;
39
+ }
40
+ @include when(checked) {
41
+ .wd-radio__label {
42
+ color: $-dark-color-gray;
43
+ }
44
+ }
45
+
46
+ @include when(button) {
47
+ .wd-radio__label {
48
+ color: $-dark-color-gray;
49
+ background: #3a3a3c;
50
+ border-color: #c8c9cc;
51
+ }
52
+ @include when(checked) {
53
+ .wd-radio__label {
54
+ color: #c8c9cc;
55
+ background: #3a3a3c;
56
+ border-color: #c8c9cc;
57
+ }
58
+ }
59
+ }
60
+
61
+ @include when(dot) {
62
+ .wd-radio__shape {
63
+ background: #3a3a3c;
64
+ border-color: #c8c9cc;
65
+ &::before {
66
+ background-color: #c8c9cc;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ @include b(radio) {
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: space-between;
78
+ margin-top: $-radio-margin;
79
+ line-height: 1.2;
80
+ text-align: center;
81
+
82
+ @include when(first) {
83
+ margin-top: 0;
84
+ }
85
+ @include e(shape) {
86
+ position: relative;
87
+ display: inline-block;
88
+ display: none;
89
+ width: $-radio-size;
90
+ height: $-radio-size;
91
+ font-size: $-radio-size;
92
+ color: transparent;
93
+ vertical-align: middle;
94
+ background: $-radio-bg;
95
+ transition: background 0.2s;
96
+ }
97
+ @include e(input) {
98
+ position: absolute;
99
+ width: 0;
100
+ height: 0;
101
+ margin: 0;
102
+ opacity: 0;
103
+ }
104
+ @include e(label) {
105
+ display: inline-block;
106
+ font-size: $-radio-label-fs;
107
+ line-height: 20px;
108
+ color: $-radio-label-color;
109
+ vertical-align: top;
110
+ }
111
+ @include when(checked) {
112
+ .wd-radio__shape {
113
+ display: inline-block;
114
+ color: $-radio-checked-color;
115
+ border-color: currentColor;
116
+ }
117
+ .wd-radio__check {
118
+ color: $-radio-checked-color;
119
+ opacity: 1;
120
+ }
121
+ }
122
+
123
+ @include when(dot) {
124
+ .wd-radio__shape {
125
+ position: relative;
126
+ box-sizing: border-box;
127
+ display: inline-block;
128
+ border: 2px solid $-radio-dot-border-color;
129
+ border-radius: 50%;
130
+ transition: none;
131
+
132
+ &::before {
133
+ position: absolute;
134
+ top: calc(50% - #{$-radio-dot-size / 2});
135
+ left: calc(50% - #{$-radio-dot-size / 2});
136
+ width: $-radio-dot-size;
137
+ height: $-radio-dot-size;
138
+ content: '';
139
+ background-color: #fff;
140
+ border-radius: 50%;
141
+ transition: transform 0.2s ease-in;
142
+ transform: scale(0);
143
+ }
144
+ }
145
+ @include when(checked) {
146
+ .wd-radio__shape {
147
+ background-color: $-radio-dot-checked-bg;
148
+ border-color: $-radio-dot-checked-border-color;
149
+ &::before {
150
+ transform: scale(1);
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ @include when(button) {
157
+ display: inline-block;
158
+ margin-top: 0;
159
+ margin-right: 10px;
160
+
161
+ .wd-radio__shape {
162
+ display: none;
163
+ }
164
+ .wd-radio__label {
165
+ box-sizing: border-box;
166
+ min-width: $-radio-button-min-width;
167
+ max-width: $-radio-button-max-width;
168
+ height: $-radio-button-height;
169
+ padding: 5px 15px;
170
+ margin-right: 0;
171
+ font-size: $-radio-button-fs;
172
+ background-color: $-radio-button-bg;
173
+ border: 1px solid $-radio-button-border;
174
+ border-radius: $-radio-button-radius;
175
+ transition: all 0.2s;
176
+ @include lineEllipsis;
177
+ }
178
+ @include when(checked) {
179
+ .wd-radio__label {
180
+ color: $-radio-checked-color;
181
+ background-color: $-radio-bg;
182
+ border-color: currentColor;
183
+ }
184
+ }
185
+ }
186
+
187
+ @include when(inline) {
188
+ display: inline-block;
189
+ margin-top: 0;
190
+ margin-right: $-radio-margin;
191
+
192
+ @include when(first) {
193
+ margin-left: 0;
194
+ }
195
+ .wd-radio__shape {
196
+ display: block;
197
+ float: left;
198
+ margin-right: 4px;
199
+ &::after {
200
+ display: table;
201
+ clear: both;
202
+ content: '';
203
+ }
204
+ }
205
+
206
+ @include when(dot) {
207
+ .wd-radio__shape {
208
+ margin-top: 2px;
209
+ }
210
+ @include when(large) {
211
+ .wd-radio__shape {
212
+ margin-top: 0;
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ @include when(disabled) {
219
+ .wd-radio__label {
220
+ color: $-radio-disabled-label-color;
221
+ }
222
+ @include when(checked) {
223
+ .wd-radio__shape {
224
+ color: $-radio-disabled-label-color;
225
+ }
226
+ .wd-radio__check {
227
+ color: $-radio-disabled-label-color;
228
+ }
229
+ .wd-radio__label {
230
+ color: $-radio-disabled-label-color;
231
+ }
232
+ }
233
+
234
+ @include when(button) {
235
+ .wd-radio__label {
236
+ color: $-radio-disabled-label-color;
237
+ background: $-radio-disabled-color;
238
+ border-color: $-radio-disabled-color;
239
+ border-color: $-radio-button-border;
240
+ }
241
+ @include when(checked) {
242
+ .wd-radio__label {
243
+ background: $-radio-disabled-color;
244
+ border-color: $-radio-button-disabled-border;
245
+ }
246
+ }
247
+ }
248
+
249
+ @include when(dot) {
250
+ .wd-radio__shape {
251
+ background: $-radio-dot-disabled-bg;
252
+ border-color: $-radio-dot-disabled-border;
253
+ }
254
+ }
255
+ }
256
+
257
+ // 以下内容用于解决父子组件样式隔离的问题 —— START
258
+ @include when(cell-radio) {
259
+ padding: 13px 15px;
260
+ margin: 0;
261
+
262
+ @include when(large) {
263
+ padding: 14px 15px;
264
+ }
265
+ }
266
+
267
+ @include when(button-radio) {
268
+ box-sizing: border-box;
269
+ display: inline-flex;
270
+ width: 33.3333%;
271
+ padding: 12px 12px 0px 0px;
272
+
273
+ .wd-radio__label {
274
+ width: 100%;
275
+ max-width: inherit;
276
+ }
277
+ }
278
+ @include when(large) {
279
+ .wd-radio__shape {
280
+ width: $-radio-large-size;
281
+ height: $-radio-large-size;
282
+ font-size: $-radio-large-size;
283
+ }
284
+ .wd-radio__label {
285
+ font-size: $-radio-large-label-fs;
286
+ }
287
+
288
+ @include when(dot) {
289
+ .wd-radio__shape {
290
+ &::before {
291
+ top: calc(50% - #{$-radio-dot-large-size / 2});
292
+ left: calc(50% - #{$-radio-dot-large-size / 2});
293
+ width: $-radio-dot-large-size;
294
+ height: $-radio-dot-large-size;
295
+ }
296
+ }
297
+ }
298
+ }
299
+ // 以下内容用于解决父子组件样式隔离的问题 —— END
300
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * @Author: weisheng
3
+ * @Date: 2024-03-15 20:40:34
4
+ * @LastEditTime: 2024-03-18 16:01:19
5
+ * @LastEditors: weisheng
6
+ * @Description:
7
+ * @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-radio\types.ts
8
+ * 记得注释
9
+ */
10
+ import type { PropType } from 'vue'
11
+ import { baseProps, makeRequiredProp } from '../common/props'
12
+
13
+ export type RadioShape = 'dot' | 'button' | 'check'
14
+
15
+ export const radioProps = {
16
+ ...baseProps,
17
+ /** 选中时的值 */
18
+ value: makeRequiredProp([String, Number, Boolean]),
19
+ /** 单选框的形状 */
20
+ shape: String as PropType<RadioShape>,
21
+ /** 选中的颜色 */
22
+ checkedColor: String,
23
+ /** 禁用 */
24
+ disabled: {
25
+ type: [Boolean, null] as PropType<boolean | null>,
26
+ default: null,
27
+ },
28
+ /** 单元格 */
29
+ cell: {
30
+ type: [Boolean, null] as PropType<boolean | null>,
31
+ default: null,
32
+ },
33
+ /** 大小 */
34
+ size: String,
35
+ /** 内联 */
36
+ inline: {
37
+ type: [Boolean, null] as PropType<boolean | null>,
38
+ default: null,
39
+ },
40
+ /** 最大宽度 */
41
+ maxWidth: String,
42
+ }
@@ -0,0 +1,136 @@
1
+ <template>
2
+ <view
3
+ :class="`wd-radio ${innerCell ? 'is-cell-radio' : ''} ${innerCell && innerShape == 'button' ? 'is-button-radio' : ''} ${
4
+ innerSize ? 'is-' + innerSize : ''
5
+ } ${innerInline ? 'is-inline' : ''} ${isChecked ? 'is-checked' : ''} ${innerShape !== 'check' ? 'is-' + innerShape : ''} ${
6
+ innerDisabled ? 'is-disabled' : ''
7
+ } ${customClass}`"
8
+ :style="customStyle"
9
+ @click="handleClick"
10
+ >
11
+ <view
12
+ class="wd-radio__label"
13
+ :style="`${maxWidth ? 'max-width:' + maxWidth : ''}; ${
14
+ isChecked && innerShape === 'button' && !innerDisabled ? 'color :' + innerCheckedColor : ''
15
+ }`"
16
+ >
17
+ <slot></slot>
18
+ </view>
19
+ <view
20
+ class="wd-radio__shape"
21
+ :style="isChecked && !disabled ? 'color: ' + innerCheckedColor : ''"
22
+ >
23
+ <wd-icon
24
+ v-if="innerShape === 'check'"
25
+ :style="isChecked && !disabled ? 'color: ' + innerCheckedColor : ''"
26
+ name="check"
27
+ ></wd-icon>
28
+ </view>
29
+ </view>
30
+ </template>
31
+ <script lang="ts">
32
+ export default {
33
+ name: 'wd-radio',
34
+ options: {
35
+ virtualHost: true,
36
+ addGlobalClass: true,
37
+ styleIsolation: 'shared',
38
+ },
39
+ }
40
+ </script>
41
+ <script lang="ts" setup>
42
+ import { computed, watch } from 'vue'
43
+ import { useParent } from '../composables/useParent'
44
+ import { RADIO_GROUP_KEY } from '../wd-radio-group/types'
45
+ import { radioProps } from './types'
46
+
47
+ const props = defineProps(radioProps)
48
+
49
+ const { parent: radioGroup } = useParent(RADIO_GROUP_KEY)
50
+
51
+ const isChecked = computed(() => {
52
+ if (radioGroup) {
53
+ return props.value === radioGroup.props.modelValue
54
+ } else {
55
+ return false
56
+ }
57
+ })
58
+
59
+ const innerShape = computed(() => {
60
+ if (!props.shape && radioGroup && radioGroup.props.shape) {
61
+ return radioGroup.props.shape
62
+ } else {
63
+ return props.shape
64
+ }
65
+ })
66
+
67
+ const innerCheckedColor = computed(() => {
68
+ if (!props.checkedColor && radioGroup && radioGroup.props.checkedColor) {
69
+ return radioGroup.props.checkedColor
70
+ } else {
71
+ return props.checkedColor
72
+ }
73
+ })
74
+
75
+ const innerDisabled = computed(() => {
76
+ if (
77
+ (props.disabled === null || props.disabled === undefined) &&
78
+ radioGroup &&
79
+ radioGroup.props.disabled
80
+ ) {
81
+ return radioGroup.props.disabled
82
+ } else {
83
+ return props.disabled
84
+ }
85
+ })
86
+
87
+ const innerInline = computed(() => {
88
+ if (
89
+ (props.inline === null || props.inline === undefined) &&
90
+ radioGroup &&
91
+ radioGroup.props.inline
92
+ ) {
93
+ return radioGroup.props.inline
94
+ } else {
95
+ return props.inline
96
+ }
97
+ })
98
+
99
+ const innerSize = computed(() => {
100
+ if (!props.size && radioGroup && radioGroup.props.size) {
101
+ return radioGroup.props.size
102
+ } else {
103
+ return props.size
104
+ }
105
+ })
106
+
107
+ const innerCell = computed(() => {
108
+ if ((props.cell === null || props.cell === undefined) && radioGroup && radioGroup.props.cell) {
109
+ return radioGroup.props.cell
110
+ } else {
111
+ return props.cell
112
+ }
113
+ })
114
+
115
+ watch(
116
+ () => props.shape,
117
+ (newValue) => {
118
+ const type = ['check', 'dot', 'button']
119
+ if (!newValue || type.indexOf(newValue) === -1)
120
+ console.error(`shape must be one of ${type.toString()}`)
121
+ },
122
+ )
123
+
124
+ /**
125
+ * 点击子元素,通知父元素触发change事件
126
+ */
127
+ function handleClick() {
128
+ const { value } = props
129
+ if (!innerDisabled.value && radioGroup && value !== null && value !== undefined) {
130
+ radioGroup.updateValue(value)
131
+ }
132
+ }
133
+ </script>
134
+ <style lang="scss" scoped>
135
+ @import './index';
136
+ </style>