@gmcb/uv-ui 0.2.26

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 (285) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/LICENSE +21 -0
  3. package/README.md +164 -0
  4. package/components/uv-action-sheet/props.js +50 -0
  5. package/components/uv-action-sheet/uv-action-sheet.vue +280 -0
  6. package/components/uv-album/uv-album.vue +312 -0
  7. package/components/uv-alert/props.js +45 -0
  8. package/components/uv-alert/uv-alert.vue +246 -0
  9. package/components/uv-avatar/props.js +85 -0
  10. package/components/uv-avatar/uv-avatar.vue +182 -0
  11. package/components/uv-avatar-group/props.js +53 -0
  12. package/components/uv-avatar-group/uv-avatar-group.vue +106 -0
  13. package/components/uv-back-top/props.js +58 -0
  14. package/components/uv-back-top/uv-back-top.vue +116 -0
  15. package/components/uv-badge/props.js +73 -0
  16. package/components/uv-badge/uv-badge.vue +176 -0
  17. package/components/uv-button/nvue.scss +46 -0
  18. package/components/uv-button/props.js +163 -0
  19. package/components/uv-button/uv-button.vue +529 -0
  20. package/components/uv-button/vue.scss +93 -0
  21. package/components/uv-calendar/calendar.js +546 -0
  22. package/components/uv-calendar/header.vue +104 -0
  23. package/components/uv-calendar/month.vue +616 -0
  24. package/components/uv-calendar/props.js +145 -0
  25. package/components/uv-calendar/uv-calendar.vue +390 -0
  26. package/components/uv-calendars/calendar-body.vue +376 -0
  27. package/components/uv-calendars/calendar-item.vue +248 -0
  28. package/components/uv-calendars/calendar.js +546 -0
  29. package/components/uv-calendars/i18n/en.json +12 -0
  30. package/components/uv-calendars/i18n/index.js +8 -0
  31. package/components/uv-calendars/i18n/zh-Hans.json +12 -0
  32. package/components/uv-calendars/i18n/zh-Hant.json +12 -0
  33. package/components/uv-calendars/util.js +435 -0
  34. package/components/uv-calendars/uv-calendars.vue +452 -0
  35. package/components/uv-cell/props.js +116 -0
  36. package/components/uv-cell/uv-cell.vue +209 -0
  37. package/components/uv-cell-group/props.js +15 -0
  38. package/components/uv-cell-group/uv-cell-group.vue +63 -0
  39. package/components/uv-checkbox/props.js +70 -0
  40. package/components/uv-checkbox/uv-checkbox.vue +371 -0
  41. package/components/uv-checkbox-group/props.js +84 -0
  42. package/components/uv-checkbox-group/uv-checkbox-group.vue +119 -0
  43. package/components/uv-code/props.js +35 -0
  44. package/components/uv-code/uv-code.vue +136 -0
  45. package/components/uv-code-input/props.js +83 -0
  46. package/components/uv-code-input/uv-code-input.vue +272 -0
  47. package/components/uv-col/props.js +30 -0
  48. package/components/uv-col/uv-col.vue +165 -0
  49. package/components/uv-collapse/props.js +20 -0
  50. package/components/uv-collapse/uv-collapse.vue +86 -0
  51. package/components/uv-collapse-item/props.js +60 -0
  52. package/components/uv-collapse-item/uv-collapse-item.vue +228 -0
  53. package/components/uv-column-notice/props.js +61 -0
  54. package/components/uv-column-notice/uv-column-notice.vue +176 -0
  55. package/components/uv-count-down/props.js +25 -0
  56. package/components/uv-count-down/utils.js +62 -0
  57. package/components/uv-count-down/uv-count-down.vue +169 -0
  58. package/components/uv-count-to/props.js +60 -0
  59. package/components/uv-count-to/uv-count-to.vue +187 -0
  60. package/components/uv-datetime-picker/props.js +130 -0
  61. package/components/uv-datetime-picker/uv-datetime-picker.vue +355 -0
  62. package/components/uv-divider/props.js +45 -0
  63. package/components/uv-divider/uv-divider.vue +113 -0
  64. package/components/uv-drop-down/uv-drop-down.vue +135 -0
  65. package/components/uv-drop-down-item/uv-drop-down-item.vue +169 -0
  66. package/components/uv-drop-down-popup/uv-drop-down-popup.vue +242 -0
  67. package/components/uv-empty/props.js +60 -0
  68. package/components/uv-empty/uv-empty.vue +126 -0
  69. package/components/uv-form/props.js +46 -0
  70. package/components/uv-form/uv-form.vue +209 -0
  71. package/components/uv-form/valid.js +1343 -0
  72. package/components/uv-form-item/props.js +49 -0
  73. package/components/uv-form-item/uv-form-item.vue +226 -0
  74. package/components/uv-gap/props.js +25 -0
  75. package/components/uv-gap/uv-gap.vue +36 -0
  76. package/components/uv-grid/props.js +20 -0
  77. package/components/uv-grid/uv-grid.vue +100 -0
  78. package/components/uv-grid-item/props.js +15 -0
  79. package/components/uv-grid-item/uv-grid-item.vue +223 -0
  80. package/components/uv-icon/icons.js +160 -0
  81. package/components/uv-icon/props.js +90 -0
  82. package/components/uv-icon/uv-icon.vue +226 -0
  83. package/components/uv-icon/uvicons.ttf +0 -0
  84. package/components/uv-image/props.js +100 -0
  85. package/components/uv-image/uv-image.vue +296 -0
  86. package/components/uv-index-anchor/props.js +30 -0
  87. package/components/uv-index-anchor/uv-index-anchor.vue +98 -0
  88. package/components/uv-index-item/uv-index-item.vue +87 -0
  89. package/components/uv-index-list/props.js +30 -0
  90. package/components/uv-index-list/uv-index-list.vue +461 -0
  91. package/components/uv-input/props.js +175 -0
  92. package/components/uv-input/uv-input.vue +348 -0
  93. package/components/uv-keyboard/props.js +95 -0
  94. package/components/uv-keyboard/uv-keyboard.vue +180 -0
  95. package/components/uv-keyboard-car/props.js +24 -0
  96. package/components/uv-keyboard-car/uv-keyboard-car.vue +347 -0
  97. package/components/uv-keyboard-number/props.js +19 -0
  98. package/components/uv-keyboard-number/uv-keyboard-number.vue +201 -0
  99. package/components/uv-line/props.js +34 -0
  100. package/components/uv-line/uv-line.vue +60 -0
  101. package/components/uv-line-progress/props.js +29 -0
  102. package/components/uv-line-progress/uv-line-progress.vue +146 -0
  103. package/components/uv-link/props.js +40 -0
  104. package/components/uv-link/uv-link.vue +83 -0
  105. package/components/uv-list/uv-list.vue +147 -0
  106. package/components/uv-list-item/uv-list-item.vue +535 -0
  107. package/components/uv-load-more/props.js +95 -0
  108. package/components/uv-load-more/uv-load-more.vue +152 -0
  109. package/components/uv-loading-icon/props.js +67 -0
  110. package/components/uv-loading-icon/uv-loading-icon.vue +347 -0
  111. package/components/uv-loading-page/props.js +55 -0
  112. package/components/uv-loading-page/uv-loading-page.vue +96 -0
  113. package/components/uv-modal/props.js +90 -0
  114. package/components/uv-modal/uv-modal.vue +245 -0
  115. package/components/uv-navbar/props.js +89 -0
  116. package/components/uv-navbar/uv-navbar.vue +245 -0
  117. package/components/uv-no-network/props.js +20 -0
  118. package/components/uv-no-network/uv-no-network.vue +222 -0
  119. package/components/uv-notice-bar/props.js +76 -0
  120. package/components/uv-notice-bar/uv-notice-bar.vue +110 -0
  121. package/components/uv-notify/props.js +45 -0
  122. package/components/uv-notify/uv-notify.vue +220 -0
  123. package/components/uv-number-box/props.js +118 -0
  124. package/components/uv-number-box/uv-number-box.vue +397 -0
  125. package/components/uv-overlay/props.js +25 -0
  126. package/components/uv-overlay/uv-overlay.vue +85 -0
  127. package/components/uv-parse/node/node.vue +576 -0
  128. package/components/uv-parse/parser.js +1335 -0
  129. package/components/uv-parse/uv-parse.vue +498 -0
  130. package/components/uv-pick-color/colors.js +217 -0
  131. package/components/uv-pick-color/props.js +47 -0
  132. package/components/uv-pick-color/uv-pick-color.vue +551 -0
  133. package/components/uv-picker/props.js +95 -0
  134. package/components/uv-picker/uv-picker.vue +329 -0
  135. package/components/uv-popup/keypress.js +45 -0
  136. package/components/uv-popup/uv-popup.vue +537 -0
  137. package/components/uv-preview-video/uv-preview-video.vue +52 -0
  138. package/components/uv-qrcode/cache.js +1 -0
  139. package/components/uv-qrcode/gcanvas/bridge/bridge-weex.js +241 -0
  140. package/components/uv-qrcode/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
  141. package/components/uv-qrcode/gcanvas/context-2d/FillStylePattern.js +8 -0
  142. package/components/uv-qrcode/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
  143. package/components/uv-qrcode/gcanvas/context-2d/RenderingContext.js +666 -0
  144. package/components/uv-qrcode/gcanvas/context-webgl/ActiveInfo.js +11 -0
  145. package/components/uv-qrcode/gcanvas/context-webgl/Buffer.js +21 -0
  146. package/components/uv-qrcode/gcanvas/context-webgl/Framebuffer.js +21 -0
  147. package/components/uv-qrcode/gcanvas/context-webgl/GLenum.js +298 -0
  148. package/components/uv-qrcode/gcanvas/context-webgl/GLmethod.js +142 -0
  149. package/components/uv-qrcode/gcanvas/context-webgl/GLtype.js +23 -0
  150. package/components/uv-qrcode/gcanvas/context-webgl/Program.js +21 -0
  151. package/components/uv-qrcode/gcanvas/context-webgl/Renderbuffer.js +21 -0
  152. package/components/uv-qrcode/gcanvas/context-webgl/RenderingContext.js +1191 -0
  153. package/components/uv-qrcode/gcanvas/context-webgl/Shader.js +22 -0
  154. package/components/uv-qrcode/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
  155. package/components/uv-qrcode/gcanvas/context-webgl/Texture.js +22 -0
  156. package/components/uv-qrcode/gcanvas/context-webgl/UniformLocation.js +22 -0
  157. package/components/uv-qrcode/gcanvas/context-webgl/classUtils.js +3 -0
  158. package/components/uv-qrcode/gcanvas/env/canvas.js +74 -0
  159. package/components/uv-qrcode/gcanvas/env/image.js +96 -0
  160. package/components/uv-qrcode/gcanvas/env/tool.js +24 -0
  161. package/components/uv-qrcode/gcanvas/index.js +39 -0
  162. package/components/uv-qrcode/props.js +85 -0
  163. package/components/uv-qrcode/qrcode.js +34 -0
  164. package/components/uv-qrcode/queue.js +41 -0
  165. package/components/uv-qrcode/uv-qrcode.vue +1038 -0
  166. package/components/uv-radio/props.js +65 -0
  167. package/components/uv-radio/uv-radio.vue +349 -0
  168. package/components/uv-radio-group/props.js +89 -0
  169. package/components/uv-radio-group/uv-radio-group.vue +115 -0
  170. package/components/uv-rate/props.js +73 -0
  171. package/components/uv-rate/uv-rate.vue +274 -0
  172. package/components/uv-read-more/props.js +62 -0
  173. package/components/uv-read-more/uv-read-more.vue +162 -0
  174. package/components/uv-row/props.js +20 -0
  175. package/components/uv-row/uv-row.vue +95 -0
  176. package/components/uv-row-notice/props.js +40 -0
  177. package/components/uv-row-notice/uv-row-notice.vue +341 -0
  178. package/components/uv-safe-bottom/uv-safe-bottom.vue +67 -0
  179. package/components/uv-scroll-list/nvue.js +29 -0
  180. package/components/uv-scroll-list/props.js +35 -0
  181. package/components/uv-scroll-list/scrollWxs.wxs +51 -0
  182. package/components/uv-scroll-list/uv-scroll-list.vue +218 -0
  183. package/components/uv-search/props.js +127 -0
  184. package/components/uv-search/uv-search.vue +311 -0
  185. package/components/uv-skeleton/props.js +65 -0
  186. package/components/uv-skeleton/uv-skeleton.vue +250 -0
  187. package/components/uv-skeletons/uv-skeletons.vue +247 -0
  188. package/components/uv-slider/props.js +58 -0
  189. package/components/uv-slider/uv-slider.vue +58 -0
  190. package/components/uv-status-bar/props.js +8 -0
  191. package/components/uv-status-bar/uv-status-bar.vue +54 -0
  192. package/components/uv-steps/props.js +40 -0
  193. package/components/uv-steps/uv-steps.vue +83 -0
  194. package/components/uv-steps-item/props.js +25 -0
  195. package/components/uv-steps-item/uv-steps-item.vue +347 -0
  196. package/components/uv-sticky/props.js +41 -0
  197. package/components/uv-sticky/uv-sticky.vue +223 -0
  198. package/components/uv-subsection/props.js +54 -0
  199. package/components/uv-subsection/uv-subsection.vue +269 -0
  200. package/components/uv-swipe-action/props.js +10 -0
  201. package/components/uv-swipe-action/uv-swipe-action.vue +65 -0
  202. package/components/uv-swipe-action-item/index - backup.wxs +256 -0
  203. package/components/uv-swipe-action-item/index.wxs +225 -0
  204. package/components/uv-swipe-action-item/nvue - backup.js +264 -0
  205. package/components/uv-swipe-action-item/nvue.js +182 -0
  206. package/components/uv-swipe-action-item/props.js +40 -0
  207. package/components/uv-swipe-action-item/uv-swipe-action-item.vue +200 -0
  208. package/components/uv-swipe-action-item/wxs.js +15 -0
  209. package/components/uv-swiper/props.js +136 -0
  210. package/components/uv-swiper/uv-swiper.vue +263 -0
  211. package/components/uv-swiper-indicator/props.js +30 -0
  212. package/components/uv-swiper-indicator/uv-swiper-indicator.vue +112 -0
  213. package/components/uv-switch/props.js +58 -0
  214. package/components/uv-switch/uv-switch.vue +182 -0
  215. package/components/uv-tabbar/props.js +50 -0
  216. package/components/uv-tabbar/uv-tabbar.vue +146 -0
  217. package/components/uv-tabbar-item/props.js +40 -0
  218. package/components/uv-tabbar-item/uv-tabbar-item.vue +146 -0
  219. package/components/uv-tabs/props.js +71 -0
  220. package/components/uv-tabs/uv-tabs.vue +391 -0
  221. package/components/uv-tags/props.js +104 -0
  222. package/components/uv-tags/uv-tags.vue +379 -0
  223. package/components/uv-text/props.js +113 -0
  224. package/components/uv-text/uv-text.vue +218 -0
  225. package/components/uv-text/value.js +87 -0
  226. package/components/uv-textarea/props.js +138 -0
  227. package/components/uv-textarea/uv-textarea.vue +238 -0
  228. package/components/uv-toast/uv-toast.vue +292 -0
  229. package/components/uv-toolbar/props.js +40 -0
  230. package/components/uv-toolbar/uv-toolbar.vue +109 -0
  231. package/components/uv-tooltip/props.js +60 -0
  232. package/components/uv-tooltip/uv-tooltip.vue +372 -0
  233. package/components/uv-transition/createAnimation.js +131 -0
  234. package/components/uv-transition/props.js +31 -0
  235. package/components/uv-transition/uv-transition.vue +320 -0
  236. package/components/uv-upload/mixin.js +22 -0
  237. package/components/uv-upload/props.js +130 -0
  238. package/components/uv-upload/utils.js +151 -0
  239. package/components/uv-upload/uv-upload.vue +488 -0
  240. package/components/uv-vtabs/props.js +79 -0
  241. package/components/uv-vtabs/uv-vtabs.vue +438 -0
  242. package/components/uv-vtabs-item/uv-vtabs-item.vue +68 -0
  243. package/components/uv-waterfall/props.js +69 -0
  244. package/components/uv-waterfall/uv-waterfall.vue +265 -0
  245. package/index.js +82 -0
  246. package/index.scss +7 -0
  247. package/libs/config/config.js +34 -0
  248. package/libs/css/color.scss +32 -0
  249. package/libs/css/common.scss +100 -0
  250. package/libs/css/components.scss +23 -0
  251. package/libs/css/variable.scss +111 -0
  252. package/libs/css/vue.scss +40 -0
  253. package/libs/function/colorGradient.js +134 -0
  254. package/libs/function/compress.js +27 -0
  255. package/libs/function/debounce.js +29 -0
  256. package/libs/function/digit.js +167 -0
  257. package/libs/function/index.js +734 -0
  258. package/libs/function/platform.js +75 -0
  259. package/libs/function/test.js +287 -0
  260. package/libs/function/throttle.js +30 -0
  261. package/libs/luch-request/adapters/index.js +132 -0
  262. package/libs/luch-request/core/InterceptorManager.js +51 -0
  263. package/libs/luch-request/core/Request.js +201 -0
  264. package/libs/luch-request/core/buildFullPath.js +20 -0
  265. package/libs/luch-request/core/defaults.js +33 -0
  266. package/libs/luch-request/core/dispatchRequest.js +6 -0
  267. package/libs/luch-request/core/mergeConfig.js +126 -0
  268. package/libs/luch-request/core/settle.js +16 -0
  269. package/libs/luch-request/helpers/buildURL.js +64 -0
  270. package/libs/luch-request/helpers/combineURLs.js +14 -0
  271. package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
  272. package/libs/luch-request/index.d.ts +197 -0
  273. package/libs/luch-request/index.js +2 -0
  274. package/libs/luch-request/utils/clone.js +264 -0
  275. package/libs/luch-request/utils.js +135 -0
  276. package/libs/mixin/button.js +13 -0
  277. package/libs/mixin/mixin.js +172 -0
  278. package/libs/mixin/mpMixin.js +8 -0
  279. package/libs/mixin/mpShare.js +13 -0
  280. package/libs/mixin/openType.js +47 -0
  281. package/libs/mixin/touch.js +59 -0
  282. package/libs/util/dayjs.js +216 -0
  283. package/libs/util/route.js +126 -0
  284. package/package.json +28 -0
  285. package/theme.scss +43 -0
@@ -0,0 +1,391 @@
1
+ <template>
2
+ <view class="uv-tabs" :style="[$uv.addStyle(customStyle)]">
3
+ <view class="uv-tabs__wrapper">
4
+ <slot name="left" />
5
+ <view class="uv-tabs__wrapper__scroll-view-wrapper">
6
+ <scroll-view
7
+ :scroll-x="scrollable"
8
+ :scroll-left="scrollLeft"
9
+ scroll-with-animation
10
+ class="uv-tabs__wrapper__scroll-view"
11
+ :show-scrollbar="false"
12
+ ref="uv-tabs__wrapper__scroll-view"
13
+ >
14
+ <view
15
+ class="uv-tabs__wrapper__nav"
16
+ ref="uv-tabs__wrapper__nav"
17
+ :style="{
18
+ flex: scrollable ? '' : 1
19
+ }"
20
+ >
21
+ <view
22
+ class="uv-tabs__wrapper__nav__item"
23
+ v-for="(item, index) in list"
24
+ :key="index"
25
+ @tap="clickHandler(item, index)"
26
+ :ref="`uv-tabs__wrapper__nav__item-${index}`"
27
+ :style="[{flex: scrollable ? '' : 1},$uv.addStyle(itemStyle)]"
28
+ :class="[`uv-tabs__wrapper__nav__item-${index}`, item.disabled && 'uv-tabs__wrapper__nav__item--disabled']"
29
+ >
30
+ <text
31
+ :class="[item.disabled && 'uv-tabs__wrapper__nav__item__text--disabled']"
32
+ class="uv-tabs__wrapper__nav__item__text"
33
+ :style="[textStyle(index)]"
34
+ >{{ item[keyName] }}</text>
35
+ <uv-badge
36
+ :show="!!(item.badge && (item.badge.show || item.badge.isDot || item.badge.value))"
37
+ :isDot="item.badge && item.badge.isDot || propsBadge.isDot"
38
+ :value="item.badge && item.badge.value || propsBadge.value"
39
+ :max="item.badge && item.badge.max || propsBadge.max"
40
+ :type="item.badge && item.badge.type || propsBadge.type"
41
+ :showZero="item.badge && item.badge.showZero || propsBadge.showZero"
42
+ :bgColor="item.badge && item.badge.bgColor || propsBadge.bgColor"
43
+ :color="item.badge && item.badge.color || propsBadge.color"
44
+ :shape="item.badge && item.badge.shape || propsBadge.shape"
45
+ :numberType="item.badge && item.badge.numberType || propsBadge.numberType"
46
+ :inverted="item.badge && item.badge.inverted || propsBadge.inverted"
47
+ customStyle="margin-left: 4px;"
48
+ ></uv-badge>
49
+ </view>
50
+ <!-- #ifdef APP-NVUE -->
51
+ <view
52
+ v-if="lineHeight > 0 && lineWidth > 0"
53
+ class="uv-tabs__wrapper__nav__line"
54
+ ref="uv-tabs__wrapper__nav__line"
55
+ :style="[{
56
+ width: $uv.addUnit(lineWidth),
57
+ height: firstTime?0:$uv.addUnit(lineHeight),
58
+ background: lineColor,
59
+ backgroundSize: lineBgSize,
60
+ }]"
61
+ >
62
+ <!-- #endif -->
63
+ <!-- #ifndef APP-NVUE -->
64
+ <view
65
+ v-if="lineHeight > 0 && lineWidth > 0"
66
+ class="uv-tabs__wrapper__nav__line"
67
+ ref="uv-tabs__wrapper__nav__line"
68
+ :style="[{
69
+ width: $uv.addUnit(lineWidth),
70
+ transform: `translate(${lineOffsetLeft}px)`,
71
+ transitionDuration: `${firstTime ? 0 : duration}ms`,
72
+ height: firstTime?0:$uv.addUnit(lineHeight),
73
+ background: lineColor,
74
+ backgroundSize: lineBgSize,
75
+ }]"
76
+ >
77
+ <!-- #endif -->
78
+ </view>
79
+ </view>
80
+ </scroll-view>
81
+ </view>
82
+ <slot name="right" />
83
+ </view>
84
+ </view>
85
+ </template>
86
+
87
+ <script>
88
+ import mpMixin from '../../libs/mixin/mpMixin.js'
89
+ import mixin from '../../libs/mixin/mixin.js'
90
+ import uvBadgeProps from '../uv-badge/props.js'
91
+ // #ifdef APP-NVUE
92
+ const animation = uni.requireNativePlugin('animation')
93
+ const dom = uni.requireNativePlugin('dom')
94
+ // #endif
95
+ import props from './props.js';
96
+ /**
97
+ * Tabs 标签
98
+ * @description tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
99
+ * @tutorial https://www.uvui.cn/components/tabs.html
100
+ * @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
101
+ * @property {String | Number} duration 滑块移动一次所需的时间,单位秒(默认 200 )
102
+ * @property {String | Object} activeStyle 菜单选择中时的样式(默认{ color: '#303133' })
103
+ * @property {String | Object} inactiveStyle 菜单非选择中时的样式(默认{ color: '#606266' })
104
+ * @property {String | Number} lineWidth 滑块长度(默认 20)
105
+ * @property {String | Number} lineHeight 滑块高度(默认 3)
106
+ * @property {String} lineColor 滑块颜色(默认:'#3c9cff')
107
+ * @property {String} lineBgSize 滑块背景显示大小,当滑块背景设置为图片时使用(默认 cover)
108
+ * @property {String | Number} itemStyle 菜单item的样式(默认 { height: '44px' })
109
+ * @property {String} scrollable 菜单是否可滚动,选项很少的时候设置为false整个tabs自动居中显示(默认:true)
110
+ * @property {String | Number} current 当前选中标签的索引(默认 0 )
111
+ * @property {String} keyName 从list元素对象中读取的键名(默认 'name' )
112
+ * @property {String | Number} swierWidth swiper的宽度(默认 '750rpx' )
113
+ * @property {String | Object} customStyle 自定义外部样式
114
+ *
115
+ * @event {Function(index)} change 标签改变时触发 index: 点击了第几个tab,索引从0开始
116
+ * @event {Function(index)} click 点击标签时触发 index: 点击了第几个tab,索引从0开始
117
+ * @example <uv-tabs :list="list" :is-scroll="false" :current="current" @change="change"></uv-tabs>
118
+ */
119
+ export default {
120
+ name: 'uv-tabs',
121
+ emits: ['click','change'],
122
+ mixins: [mpMixin, mixin, props],
123
+ data() {
124
+ return {
125
+ firstTime: true,
126
+ scrollLeft: 0,
127
+ scrollViewWidth: 0,
128
+ lineOffsetLeft: 0,
129
+ tabsRect: {
130
+ left: 0
131
+ },
132
+ innerCurrent: 0,
133
+ moving: false,
134
+ }
135
+ },
136
+ watch: {
137
+ current: {
138
+ immediate: true,
139
+ handler (newValue, oldValue) {
140
+ // 内外部值不相等时,才尝试移动滑块
141
+ if (newValue !== this.innerCurrent) {
142
+ this.innerCurrent = newValue
143
+ this.$nextTick(() => {
144
+ this.resize()
145
+ })
146
+ }
147
+ }
148
+ },
149
+ // list变化时,重新渲染list各项信息
150
+ list() {
151
+ this.$nextTick(() => {
152
+ this.resize()
153
+ })
154
+ }
155
+ },
156
+ computed: {
157
+ textStyle() {
158
+ return index => {
159
+ const style = {}
160
+ // 取当期是否激活的样式
161
+ const customeStyle = index == this.innerCurrent ? this.$uv.addStyle(this.activeStyle) : this.$uv
162
+ .addStyle(
163
+ this.inactiveStyle)
164
+ // 如果当前菜单被禁用,则加上对应颜色,需要在此做处理,是因为nvue下,无法在style样式中通过!import覆盖标签的内联样式
165
+ if (this.list[index].disabled) {
166
+ style.color = '#c8c9cc'
167
+ }
168
+ return this.$uv.deepMerge(customeStyle, style)
169
+ }
170
+ },
171
+ propsBadge() {
172
+ return uvBadgeProps
173
+ }
174
+ },
175
+ async mounted() {
176
+ this.init()
177
+ },
178
+ methods: {
179
+ setLineLeft() {
180
+ const tabItem = this.list[this.innerCurrent];
181
+ if (!tabItem) {
182
+ return;
183
+ }
184
+ // 获取滑块该移动的位置
185
+ let lineOffsetLeft = this.list
186
+ .slice(0, this.innerCurrent)
187
+ .reduce((total, curr) => total + curr.rect.width, 0);
188
+ // 获取下划线的数值px表示法
189
+ let lineWidth = this.$uv.getPx(this.lineWidth);
190
+ if (this.$uv.test.number(this.lineWidth) && this.$uv.unit) {
191
+ lineWidth = this.$uv.getPx(`${this.lineWidth}${this.$uv.unit}`);
192
+ }
193
+ this.lineOffsetLeft = lineOffsetLeft + (tabItem.rect.width - lineWidth) / 2
194
+ // #ifdef APP-NVUE
195
+ // 第一次移动滑块,无需过渡时间
196
+ this.animation(this.lineOffsetLeft, this.firstTime ? 0 : parseInt(this.duration))
197
+ // #endif
198
+
199
+ // 如果是第一次执行此方法,让滑块在初始化时,瞬间滑动到第一个tab item的中间
200
+ // 这里需要一个定时器,因为在非nvue下,是直接通过style绑定过渡时间,需要等其过渡完成后,再设置为false(非第一次移动滑块)
201
+ if (this.firstTime) {
202
+ setTimeout(() => {
203
+ this.firstTime = false
204
+ }, 20);
205
+ }
206
+ },
207
+ // nvue下设置滑块的位置
208
+ animation(x, duration = 0) {
209
+ // #ifdef APP-NVUE
210
+ const ref = this.$refs['uv-tabs__wrapper__nav__line']
211
+ animation.transition(ref, {
212
+ styles: {
213
+ transform: `translateX(${x}px)`
214
+ },
215
+ duration
216
+ })
217
+ // #endif
218
+ },
219
+ // 点击某一个标签
220
+ clickHandler(item, index) {
221
+ // 因为标签可能为disabled状态,所以click是一定会发出的,但是change事件是需要可用的状态才发出
222
+ this.$emit('click', {
223
+ ...item,
224
+ index
225
+ })
226
+ // 如果disabled状态,返回
227
+ if (item.disabled) return
228
+ if(this.innerCurrent != index) {
229
+ this.$emit('change', {
230
+ ...item,
231
+ index
232
+ })
233
+ }
234
+ this.innerCurrent = index
235
+ // #ifndef APP-NVUE
236
+ this.$nextTick(()=>{
237
+ this.resize()
238
+ })
239
+ // #endif
240
+ // #ifdef APP-NVUE
241
+ this.$nextTick(()=>{
242
+ // nvue模式下再给点延时,确保万无一失
243
+ this.$uv.sleep(30).then(res=>{
244
+ this.resize()
245
+ });
246
+ })
247
+ // #endif
248
+ },
249
+ init() {
250
+ this.$uv.sleep().then(() => {
251
+ this.resize()
252
+ })
253
+ },
254
+ setScrollLeft() {
255
+ // 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
256
+ const tabRect = this.list[this.innerCurrent]
257
+ // 累加得到当前item到左边的距离
258
+ const offsetLeft = this.list
259
+ .slice(0, this.innerCurrent)
260
+ .reduce((total, curr) => {
261
+ return total + curr.rect.width
262
+ }, 0)
263
+ // 此处为屏幕宽度
264
+ const windowWidth = this.$uv.sys().windowWidth
265
+ // 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
266
+ let scrollLeft = offsetLeft - (this.tabsRect.width - tabRect.rect.width) / 2 - (windowWidth - this.tabsRect
267
+ .right) / 2 + this.tabsRect.left / 2
268
+ // 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度
269
+ scrollLeft = Math.min(scrollLeft, this.scrollViewWidth - this.tabsRect.width)
270
+ this.scrollLeft = Math.max(0, scrollLeft)
271
+ },
272
+ // 获取所有标签的尺寸
273
+ resize() {
274
+ // 如果不存在list,则不处理
275
+ if(this.list.length === 0) {
276
+ return
277
+ }
278
+ Promise.all([this.getTabsRect(), this.getAllItemRect()]).then(([tabsRect, itemRect = []]) => {
279
+ this.tabsRect = tabsRect
280
+ this.scrollViewWidth = 0
281
+ itemRect.map((item, index) => {
282
+ // 计算scroll-view的宽度,这里
283
+ this.scrollViewWidth += item.width
284
+ // 另外计算每一个item的中心点X轴坐标
285
+ this.list[index].rect = item
286
+ })
287
+ // 获取了tabs的尺寸之后,设置滑块的位置
288
+ this.setLineLeft()
289
+ this.setScrollLeft()
290
+ })
291
+ },
292
+ // 获取导航菜单的尺寸
293
+ getTabsRect() {
294
+ return new Promise(resolve => {
295
+ this.queryRect('uv-tabs__wrapper__scroll-view').then(size => resolve(size))
296
+ })
297
+ },
298
+ // 获取所有标签的尺寸
299
+ getAllItemRect() {
300
+ return new Promise(resolve => {
301
+ const promiseAllArr = this.list.map((item, index) => this.queryRect(
302
+ `uv-tabs__wrapper__nav__item-${index}`, true))
303
+ Promise.all(promiseAllArr).then(sizes => resolve(sizes))
304
+ })
305
+ },
306
+ // 获取各个标签的尺寸
307
+ queryRect(el, item) {
308
+ // #ifndef APP-NVUE
309
+ // $uvGetRect为uni-ui自带的节点查询简化方法,详见文档介绍:https://www.uvui.cn/js/getRect.html
310
+ // 组件内部一般用this.$uvGetRect,对外的为getRect,二者功能一致,名称不同
311
+ return new Promise(resolve => {
312
+ this.$uvGetRect(`.${el}`).then(size => {
313
+ resolve(size)
314
+ })
315
+ })
316
+ // #endif
317
+
318
+ // #ifdef APP-NVUE
319
+ // nvue下,使用dom模块查询元素高度
320
+ // 返回一个promise,让调用此方法的主体能使用then回调
321
+ return new Promise(resolve => {
322
+ dom.getComponentRect(item ? this.$refs[el][0] : this.$refs[el], res => {
323
+ resolve(res.size)
324
+ })
325
+ })
326
+ // #endif
327
+ },
328
+ },
329
+ }
330
+ </script>
331
+ <style lang="scss" scoped>
332
+ @import '../../libs/css/components.scss';
333
+ @import '../../libs/css/color.scss';
334
+ .uv-tabs {
335
+
336
+ &__wrapper {
337
+ @include flex;
338
+ align-items: center;
339
+
340
+ &__scroll-view-wrapper {
341
+ flex: 1;
342
+ /* #ifndef APP-NVUE */
343
+ overflow: auto hidden;
344
+ /* #endif */
345
+ }
346
+
347
+ &__scroll-view {
348
+ @include flex;
349
+ flex: 1;
350
+ }
351
+
352
+ &__nav {
353
+ @include flex;
354
+ position: relative;
355
+
356
+ &__item {
357
+ padding: 0 11px;
358
+ @include flex;
359
+ align-items: center;
360
+ justify-content: center;
361
+
362
+ &--disabled {
363
+ /* #ifndef APP-NVUE */
364
+ cursor: not-allowed;
365
+ /* #endif */
366
+ }
367
+
368
+ &__text {
369
+ font-size: 15px;
370
+ color: $uv-content-color;
371
+
372
+ &--disabled {
373
+ color: $uv-disabled-color !important;
374
+ }
375
+ }
376
+ }
377
+
378
+ &__line {
379
+ height: 3px;
380
+ background: $uv-primary;
381
+ width: 30px;
382
+ position: absolute;
383
+ bottom: 2px;
384
+ border-radius: 100px;
385
+ transition-property: transform;
386
+ transition-duration: 300ms;
387
+ }
388
+ }
389
+ }
390
+ }
391
+ </style>
@@ -0,0 +1,104 @@
1
+ export default {
2
+ props: {
3
+ // 标签类型info、primary、success、warning、error
4
+ type: {
5
+ type: String,
6
+ default: 'primary'
7
+ },
8
+ // 不可用
9
+ disabled: {
10
+ type: [Boolean, String],
11
+ default: false
12
+ },
13
+ // 标签的大小,large,medium,mini
14
+ size: {
15
+ type: String,
16
+ default: 'medium'
17
+ },
18
+ // tag的形状,circle(两边半圆形), square(方形,带圆角)
19
+ shape: {
20
+ type: String,
21
+ default: 'square'
22
+ },
23
+ // 标签文字
24
+ text: {
25
+ type: [String, Number],
26
+ default: ''
27
+ },
28
+ // 背景颜色,默认为空字符串,即不处理
29
+ bgColor: {
30
+ type: String,
31
+ default: ''
32
+ },
33
+ // 标签字体颜色,默认为空字符串,即不处理
34
+ color: {
35
+ type: String,
36
+ default: ''
37
+ },
38
+ // 标签的边框颜色
39
+ borderColor: {
40
+ type: String,
41
+ default: ''
42
+ },
43
+ // 点击时返回的索引值,用于区分例遍的数组哪个元素被点击了
44
+ name: {
45
+ type: [String, Number],
46
+ default: ''
47
+ },
48
+ // 镂空时是否填充背景色
49
+ plainFill: {
50
+ type: Boolean,
51
+ default: false
52
+ },
53
+ // 是否镂空
54
+ plain: {
55
+ type: Boolean,
56
+ default: false
57
+ },
58
+ // 是否可关闭
59
+ closable: {
60
+ type: Boolean,
61
+ default: false
62
+ },
63
+ // 关闭按钮图标的颜色
64
+ closeColor: {
65
+ type: String,
66
+ default: '#C6C7CB'
67
+ },
68
+ // 关闭按钮图标的位置 right(右边)right-top(右上) 默认right-top
69
+ closePlace: {
70
+ type: String,
71
+ default: 'right-top'
72
+ },
73
+ // 是否显示
74
+ show: {
75
+ type: Boolean,
76
+ default: true
77
+ },
78
+ // 内置图标,或绝对路径的图片
79
+ icon: {
80
+ type: String,
81
+ default: ''
82
+ },
83
+ // 图标颜色
84
+ iconColor: {
85
+ type: String,
86
+ default: ''
87
+ },
88
+ // nvue模式下 是否直接显示,在uv-list等cell下面使用就需要设置
89
+ cellChild: {
90
+ type: Boolean,
91
+ default: false
92
+ },
93
+ // 文字样式
94
+ textStyle: {
95
+ type: Object,
96
+ default: () => ({}),
97
+ },
98
+ customStyle: {
99
+ type: Object,
100
+ default: () => ({}),
101
+ },
102
+ ...uni.$uv?.props?.tags
103
+ }
104
+ }