@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,182 @@
1
+ <template>
2
+ <view
3
+ class="uv-switch"
4
+ :class="[disabled && 'uv-switch--disabled']"
5
+ :style="[switchStyle, $uv.addStyle(customStyle)]"
6
+ @tap="clickHandler"
7
+ >
8
+ <view
9
+ class="uv-switch__bg"
10
+ :style="[bgStyle]"
11
+ >
12
+ </view>
13
+ <view
14
+ class="uv-switch__node"
15
+ :class="[innerValue && 'uv-switch__node--on']"
16
+ :style="[nodeStyle]"
17
+ ref="uv-switch__node"
18
+ >
19
+ <uv-loading-icon
20
+ :show="loading"
21
+ mode="circle"
22
+ timingFunction='linear'
23
+ :color="innerValue ? activeColor : '#AAABAD'"
24
+ :size="size * 0.6"
25
+ />
26
+ </view>
27
+ </view>
28
+ </template>
29
+ <script>
30
+ import mpMixin from '../../libs/mixin/mpMixin.js'
31
+ import mixin from '../../libs/mixin/mixin.js'
32
+ import props from './props.js';
33
+ /**
34
+ * switch 开关选择器
35
+ * @description 选择开关一般用于只有两个选择,且只能选其一的场景。
36
+ * @tutorial https://www.uvui.cn/components/switch.html
37
+ * @property {Boolean} loading 是否处于加载中(默认 false )
38
+ * @property {Boolean} disabled 是否禁用(默认 false )
39
+ * @property {String | Number} size 开关尺寸,单位px (默认 25 )
40
+ * @property {String} activeColor 打开时的背景色 (默认 '#2979ff' )
41
+ * @property {String} inactiveColor 关闭时的背景色 (默认 '#ffffff' )
42
+ * @property {Boolean | String | Number} value 通过v-model双向绑定的值 (默认 false )
43
+ * @property {Boolean | String | Number} activeValue 打开选择器时通过change事件发出的值 (默认 true )
44
+ * @property {Boolean | String | Number} inactiveValue 关闭选择器时通过change事件发出的值 (默认 false )
45
+ * @property {Boolean} asyncChange 是否开启异步变更,开启后需要手动控制输入值 (默认 false )
46
+ * @property {String | Number} space 圆点与外边框的距离 (默认 0 )
47
+ * @property {Object} customStyle 定义需要用到的外部样式
48
+ *
49
+ * @event {Function} change 在switch打开或关闭时触发
50
+ * @example <uv-switch v-model="checked" active-color="red" inactive-color="#eee"></uv-switch>
51
+ */
52
+ export default {
53
+ name: "uv-switch",
54
+ mixins: [mpMixin, mixin, props],
55
+ data() {
56
+ return {
57
+ bgColor: '#ffffff',
58
+ innerValue: false
59
+ }
60
+ },
61
+ watch: {
62
+ value(newVal) {
63
+ if (newVal !== this.inactiveValue && newVal !== this.activeValue) {
64
+ return this.$uv.error('v-model绑定的值必须为inactiveValue、activeValue二者之一')
65
+ }
66
+ this.innerValue = newVal;
67
+ },
68
+ modelValue(newVal) {
69
+ if (newVal !== this.inactiveValue && newVal !== this.activeValue) {
70
+ return this.$uv.error('v-model绑定的值必须为inactiveValue、activeValue二者之一')
71
+ }
72
+ this.innerValue = newVal;
73
+ }
74
+ },
75
+ created() {
76
+ this.innerValue = this.value || this.modelValue;
77
+ },
78
+ computed: {
79
+ isActive() {
80
+ return this.innerValue === this.activeValue;
81
+ },
82
+ switchStyle() {
83
+ let style = {}
84
+ // 这里需要加2,是为了腾出边框的距离,否则圆点node会和外边框紧贴在一起
85
+ style.width = this.$uv.addUnit(this.$uv.getPx(this.size) * 2 + 2)
86
+ style.height = this.$uv.addUnit(this.$uv.getPx(this.size) + 2)
87
+ // 如果自定义了“非激活”演示,name边框颜色设置为透明(跟非激活颜色一致)
88
+ // 这里不能简单的设置为非激活的颜色,否则打开状态时,会有边框,所以需要透明
89
+ if (this.customInactiveColor) {
90
+ style.borderColor = 'rgba(0, 0, 0, 0)'
91
+ }
92
+ style.backgroundColor = this.isActive ? this.activeColor : this.inactiveColor
93
+ return style;
94
+ },
95
+ nodeStyle() {
96
+ let style = {}
97
+ // 如果自定义非激活颜色,将node圆点的尺寸减少两个像素,让其与外边框距离更大一点
98
+ style.width = this.$uv.addUnit(this.$uv.getPx(this.size) - this.space)
99
+ style.height = this.$uv.addUnit(this.$uv.getPx(this.size) - this.space)
100
+ const translateX = this.isActive ? this.$uv.addUnit(this.space) : this.$uv.addUnit(this.$uv.getPx(this.size));
101
+ style.transform = `translateX(-${translateX})`
102
+ return style
103
+ },
104
+ bgStyle() {
105
+ let style = {}
106
+ // 这里配置一个多余的元素在HTML中,是为了让switch切换时,有更良好的背景色扩充体验(见实际效果)
107
+ style.width = this.$uv.addUnit(this.$uv.getPx(this.size) * 2 - this.$uv.getPx(this.size) / 2)
108
+ style.height = this.$uv.addUnit(this.$uv.getPx(this.size))
109
+ style.backgroundColor = this.inactiveColor
110
+ // 打开时,让此元素收缩,否则反之
111
+ style.transform = `scale(${this.isActive ? 0 : 1})`
112
+ return style
113
+ },
114
+ customInactiveColor() {
115
+ // 之所以需要判断是否自定义了“非激活”颜色,是为了让node圆点离外边框更宽一点的距离
116
+ return this.inactiveColor !== '#fff' && this.inactiveColor !== '#ffffff'
117
+ }
118
+ },
119
+ methods: {
120
+ clickHandler() {
121
+ if (!this.disabled && !this.loading) {
122
+ const oldValue = this.isActive ? this.inactiveValue : this.activeValue
123
+ if (!this.asyncChange) {
124
+ this.$emit('input', oldValue)
125
+ this.$emit('update:modelValue', oldValue)
126
+ }
127
+ // 放到下一个生命周期,因为双向绑定的value修改父组件状态需要时间,且是异步的
128
+ this.$nextTick(() => {
129
+ this.$emit('change', oldValue)
130
+ })
131
+ }
132
+ }
133
+ }
134
+ };
135
+ </script>
136
+
137
+ <style lang="scss" scoped>
138
+ @import '../../libs/css/components.scss';
139
+ .uv-switch {
140
+ @include flex(row);
141
+ /* #ifndef APP-NVUE */
142
+ box-sizing: border-box;
143
+ /* #endif */
144
+ position: relative;
145
+ background-color: #fff;
146
+ border-width: 1px;
147
+ border-radius: 100px;
148
+ transition: background-color 0.4s;
149
+ border-color: rgba(0, 0, 0, 0.12);
150
+ border-style: solid;
151
+ justify-content: flex-end;
152
+ align-items: center;
153
+ // 由于weex为阿里逗着玩的KPI项目,导致bug奇多,这必须要写这一行,
154
+ // 否则在iOS上,点击页面任意地方,都会触发switch的点击事件
155
+ overflow: hidden;
156
+ &__node {
157
+ @include flex(row);
158
+ align-items: center;
159
+ justify-content: center;
160
+ border-radius: 100px;
161
+ background-color: #fff;
162
+ border-radius: 100px;
163
+ box-shadow: 1px 1px 1px 0 rgba(0, 0, 0, 0.25);
164
+ transition-property: transform;
165
+ transition-duration: 0.4s;
166
+ transition-timing-function: cubic-bezier(0.3, 1.05, 0.4, 1.05);
167
+ }
168
+ &__bg {
169
+ position: absolute;
170
+ border-radius: 100px;
171
+ background-color: #FFFFFF;
172
+ transition-property: transform;
173
+ transition-duration: 0.4s;
174
+ border-top-left-radius: 0;
175
+ border-bottom-left-radius: 0;
176
+ transition-timing-function: ease;
177
+ }
178
+ &--disabled {
179
+ opacity: 0.6;
180
+ }
181
+ }
182
+ </style>
@@ -0,0 +1,50 @@
1
+ export default {
2
+ props: {
3
+ // 当前匹配项的name
4
+ value: {
5
+ type: [String, Number, null],
6
+ default: null
7
+ },
8
+ // 是否为iPhoneX留出底部安全距离
9
+ safeAreaInsetBottom: {
10
+ type: Boolean,
11
+ default: true
12
+ },
13
+ // 是否显示上方边框
14
+ border: {
15
+ type: Boolean,
16
+ default: true
17
+ },
18
+ // 元素层级z-index
19
+ zIndex: {
20
+ type: [String, Number],
21
+ default: 9
22
+ },
23
+ // 选中标签的颜色
24
+ activeColor: {
25
+ type: String,
26
+ default: '#1989fa'
27
+ },
28
+ // 未选中标签的颜色
29
+ inactiveColor: {
30
+ type: String,
31
+ default: '#7d7e80'
32
+ },
33
+ // 是否固定在底部
34
+ fixed: {
35
+ type: Boolean,
36
+ default: true
37
+ },
38
+ // fixed定位固定在底部时,是否生成一个等高元素防止塌陷
39
+ placeholder: {
40
+ type: Boolean,
41
+ default: true
42
+ },
43
+ // 图标大小
44
+ iconSize: {
45
+ type: [String, Number],
46
+ default: 20
47
+ },
48
+ ...uni.$uv?.props?.tabbar
49
+ }
50
+ }
@@ -0,0 +1,146 @@
1
+ <template>
2
+ <view class="uv-tabbar">
3
+ <view
4
+ class="uv-tabbar__content"
5
+ ref="uv-tabbar__content"
6
+ @touchmove.stop.prevent="noop"
7
+ :class="[border && 'uv-border-top', fixed && 'uv-tabbar--fixed']"
8
+ :style="[tabbarStyle]"
9
+ >
10
+ <view class="uv-tabbar__content__item-wrapper">
11
+ <slot />
12
+ </view>
13
+ <uv-safe-bottom v-if="safeAreaInsetBottom"></uv-safe-bottom>
14
+ </view>
15
+ <view
16
+ class="uv-tabbar__placeholder"
17
+ v-if="placeholder"
18
+ :style="{
19
+ height: placeholderHeight + 'px',
20
+ }"
21
+ ></view>
22
+ </view>
23
+ </template>
24
+
25
+ <script>
26
+ import mpMixin from '../../libs/mixin/mpMixin.js'
27
+ import mixin from '../../libs/mixin/mixin.js'
28
+ import props from './props.js';
29
+ // #ifdef APP-NVUE
30
+ const dom = uni.requireNativePlugin('dom')
31
+ // #endif
32
+ /**
33
+ * Tabbar 底部导航栏
34
+ * @description 此组件提供了自定义tabbar的能力。
35
+ * @tutorial https://www.uvui.cn/components/tabbar.html
36
+ * @property {String | Number} value 当前匹配项的name
37
+ * @property {Boolean} safeAreaInsetBottom 是否为iPhoneX留出底部安全距离(默认 true )
38
+ * @property {Boolean} border 是否显示上方边框(默认 true )
39
+ * @property {String | Number} zIndex 元素层级z-index(默认 1 )
40
+ * @property {String} activeColor 选中标签的颜色(默认 '#1989fa' )
41
+ * @property {String} inactiveColor 未选中标签的颜色(默认 '#7d7e80' )
42
+ * @property {Boolean} fixed 是否固定在底部(默认 true )
43
+ * @property {Boolean} placeholder fixed定位固定在底部时,是否生成一个等高元素防止塌陷(默认 true )
44
+ * @property {Object} customStyle 定义需要用到的外部样式
45
+ *
46
+ * @example <uv-tabbar :value="value2" :placeholder="false" @change="name => value2 = name" :fixed="false" :safeAreaInsetBottom="false"><uv-tabbar-item text="首页" icon="home" dot ></uv-tabbar-item></uv-tabbar>
47
+ */
48
+ export default {
49
+ name: 'uv-tabbar',
50
+ mixins: [mpMixin, mixin, props],
51
+ data() {
52
+ return {
53
+ placeholderHeight: 0
54
+ }
55
+ },
56
+ computed: {
57
+ tabbarStyle() {
58
+ const style = {
59
+ zIndex: this.zIndex
60
+ }
61
+ // 合并来自父组件的customStyle样式
62
+ return this.$uv.deepMerge(style, this.$uv.addStyle(this.customStyle))
63
+ },
64
+ // 监听多个参数的变化,通过在computed执行对应的操作
65
+ updateChild() {
66
+ return [this.value, this.activeColor, this.inactiveColor]
67
+ },
68
+ updatePlaceholder() {
69
+ return [this.fixed, this.placeholder]
70
+ }
71
+ },
72
+ watch: {
73
+ updateChild() {
74
+ // 如果updateChildren中的元素发生了变化,则执行子元素初始化操作
75
+ this.updateChildren()
76
+ },
77
+ updatePlaceholder() {
78
+ // 如果fixed,placeholder等参数发生变化,重新计算占位元素的高度
79
+ this.setPlaceholderHeight()
80
+ }
81
+ },
82
+ created() {
83
+ this.children = []
84
+ },
85
+ mounted() {
86
+ this.setPlaceholderHeight()
87
+ },
88
+ methods: {
89
+ updateChildren() {
90
+ // 如果存在子元素,则执行子元素的updateFromParent进行更新数据
91
+ this.children.length && this.children.map(child => child.updateFromParent())
92
+ },
93
+ // 设置用于防止塌陷元素的高度
94
+ async setPlaceholderHeight() {
95
+ if (!this.fixed || !this.placeholder) return
96
+ // 延时一定时间
97
+ await this.$uv.sleep(20)
98
+ // #ifndef APP-NVUE
99
+ this.$uvGetRect('.uv-tabbar__content').then(({height = 50}) => {
100
+ // 修复IOS safearea bottom 未填充高度
101
+ this.placeholderHeight = height
102
+ })
103
+ // #endif
104
+
105
+ // #ifdef APP-NVUE
106
+ dom.getComponentRect(this.$refs['uv-tabbar__content'], (res) => {
107
+ const {
108
+ size
109
+ } = res
110
+ this.placeholderHeight = size.height
111
+ })
112
+ // #endif
113
+ }
114
+ }
115
+ }
116
+ </script>
117
+
118
+ <style lang="scss" scoped>
119
+ $show-border: 1;
120
+ $show-border-top: 1;
121
+ @import '../../libs/css/variable.scss';
122
+ @import '../../libs/css/components.scss';
123
+ @import '../../libs/css/color.scss';
124
+ .uv-tabbar {
125
+ @include flex(column);
126
+ flex: 1;
127
+ justify-content: center;
128
+
129
+ &__content {
130
+ @include flex(column);
131
+ background-color: #fff;
132
+
133
+ &__item-wrapper {
134
+ height: 50px;
135
+ @include flex(row);
136
+ }
137
+ }
138
+
139
+ &--fixed {
140
+ position: fixed;
141
+ bottom: 0;
142
+ left: 0;
143
+ right: 0;
144
+ }
145
+ }
146
+ </style>
@@ -0,0 +1,40 @@
1
+ export default {
2
+ props: {
3
+ // item标签的名称,作为与uv-tabbar的value参数匹配的标识符
4
+ name: {
5
+ type: [String, Number, null],
6
+ default: null
7
+ },
8
+ // uv-ui内置图标或者绝对路径的图片
9
+ icon: {
10
+ icon: String,
11
+ default: ''
12
+ },
13
+ // 图标大小,默认uv-tabbar的iconSize=20
14
+ iconSize: {
15
+ type: [String, Number],
16
+ default: ''
17
+ },
18
+ // 右上角的角标提示信息
19
+ badge: {
20
+ type: [String, Number, null],
21
+ default: null
22
+ },
23
+ // 是否显示圆点,将会覆盖badge参数
24
+ dot: {
25
+ type: Boolean,
26
+ default: false
27
+ },
28
+ // 描述文本
29
+ text: {
30
+ type: String,
31
+ default: ''
32
+ },
33
+ // 控制徽标的位置,对象或者字符串形式,可以设置top和right属性
34
+ badgeStyle: {
35
+ type: [Object, String],
36
+ default: 'top: 6px;right:2px;'
37
+ },
38
+ ...uni.$uv?.props?.tabbarItem
39
+ }
40
+ }
@@ -0,0 +1,146 @@
1
+ <template>
2
+ <view
3
+ class="uv-tabbar-item"
4
+ :style="[$uv.addStyle(customStyle)]"
5
+ @tap="clickHandler"
6
+ >
7
+ <view class="uv-tabbar-item__icon">
8
+ <uv-icon
9
+ v-if="icon"
10
+ :name="icon"
11
+ :color="isActive? parentData.activeColor : parentData.inactiveColor"
12
+ :size="iconSize? iconSize: parentData.iconSize"
13
+ ></uv-icon>
14
+ <template v-else>
15
+ <slot
16
+ v-if="isActive"
17
+ name="active-icon"
18
+ />
19
+ <slot
20
+ v-else
21
+ name="inactive-icon"
22
+ />
23
+ </template>
24
+ <uv-badge
25
+ absolute
26
+ :offset="[0, dot ? '34rpx' : badge > 9 ? '14rpx' : '20rpx']"
27
+ :customStyle="badgeStyle"
28
+ :isDot="dot"
29
+ :value="badge || (dot ? 1 : null)"
30
+ :show="dot || badge > 0"
31
+ ></uv-badge>
32
+ </view>
33
+
34
+ <slot name="text">
35
+ <text
36
+ class="uv-tabbar-item__text"
37
+ :style="{
38
+ color: isActive? parentData.activeColor : parentData.inactiveColor
39
+ }"
40
+ >{{ text }}</text>
41
+ </slot>
42
+ </view>
43
+ </template>
44
+
45
+ <script>
46
+ import mpMixin from '../../libs/mixin/mpMixin.js'
47
+ import mixin from '../../libs/mixin/mixin.js'
48
+ import props from './props.js';
49
+ /**
50
+ * TabbarItem 底部导航栏子组件
51
+ * @description 此组件提供了自定义tabbar的能力。
52
+ * @tutorial https://www.uvui.cn/components/tabbar.html
53
+ * @property {String | Number} name item标签的名称,作为与uv-tabbar的value参数匹配的标识符
54
+ * @property {String} icon uvui内置图标或者绝对路径的图片
55
+ * @property {String | Number} badge 右上角的角标提示信息
56
+ * @property {Boolean} dot 是否显示圆点,将会覆盖badge参数(默认 false )
57
+ * @property {String} text 描述文本
58
+ * @property {Object | String} badgeStyle 控制徽标的位置,对象或者字符串形式,可以设置top和right属性(默认 'top: 6px;right:2px;' )
59
+ * @property {Object} customStyle 定义需要用到的外部样式
60
+ *
61
+ * @example <uv-tabbar :value="value2" :placeholder="false" @change="name => value2 = name" :fixed="false" :safeAreaInsetBottom="false"><uv-tabbar-item text="首页" icon="home" dot ></uv-tabbar-item></uv-tabbar>
62
+ */
63
+ export default {
64
+ name: 'uv-tabbar-item',
65
+ mixins: [mpMixin, mixin, props],
66
+ emits: ['click','change'],
67
+ data() {
68
+ return {
69
+ isActive: false, // 是否处于激活状态
70
+ parentData: {
71
+ value: null,
72
+ activeColor: '',
73
+ inactiveColor: '',
74
+ iconSize: 20
75
+ }
76
+ }
77
+ },
78
+ created() {
79
+ this.init()
80
+ },
81
+ methods: {
82
+ init() {
83
+ // 支付宝小程序不支持provide/inject,所以使用这个方法获取整个父组件,在created定义,避免循环引用
84
+ this.updateParentData()
85
+ if (!this.parent) {
86
+ this.$uv.error('uv-tabbar-item必须搭配uv-tabbar组件使用')
87
+ }
88
+ // 本子组件在uv-tabbar的children数组中的索引
89
+ const index = this.parent.children.indexOf(this)
90
+ // 判断本组件的name(如果没有定义name,就用index索引)是否等于父组件的value参数
91
+ this.isActive = (this.name || index) === this.parentData.value
92
+ },
93
+ updateParentData() {
94
+ // 此方法在mixin中
95
+ this.getParentData('uv-tabbar')
96
+ },
97
+ // 此方法将会被父组件uv-tabbar调用
98
+ updateFromParent() {
99
+ // 重新初始化
100
+ this.init()
101
+ },
102
+ clickHandler() {
103
+ this.$nextTick(() => {
104
+ const index = this.parent.children.indexOf(this)
105
+ const name = this.name || index
106
+ // 点击的item为非激活的item才发出change事件
107
+ if (name !== this.parent.value) {
108
+ this.parent.$emit('change', name)
109
+ }
110
+ this.$emit('click', name)
111
+ })
112
+ }
113
+ },
114
+ }
115
+ </script>
116
+
117
+ <style lang="scss" scoped>
118
+ @import '../../libs/css/components.scss';
119
+ @import '../../libs/css/color.scss';
120
+ .uv-tabbar-item {
121
+ @include flex(column);
122
+ align-items: center;
123
+ justify-content: center;
124
+ flex: 1;
125
+
126
+ &__icon {
127
+ @include flex;
128
+ position: relative;
129
+ width: 150rpx;
130
+ justify-content: center;
131
+ }
132
+
133
+ &__text {
134
+ margin-top: 2px;
135
+ font-size: 12px;
136
+ color: $uv-content-color;
137
+ }
138
+ }
139
+
140
+ /* #ifdef MP */
141
+ // 由于小程序都使用shadow DOM形式实现,需要给影子宿主设置flex: 1才能让其撑开
142
+ :host {
143
+ flex: 1
144
+ }
145
+ /* #endif */
146
+ </style>
@@ -0,0 +1,71 @@
1
+ export default {
2
+ props: {
3
+ // 滑块的移动过渡时间,单位ms
4
+ duration: {
5
+ type: Number,
6
+ default: 300
7
+ },
8
+ // tabs标签数组
9
+ list: {
10
+ type: Array,
11
+ default: () => []
12
+ },
13
+ // 滑块颜色
14
+ lineColor: {
15
+ type: String,
16
+ default: '#3c9cff'
17
+ },
18
+ // 菜单选择中时的样式
19
+ activeStyle: {
20
+ type: [String, Object],
21
+ default: () => ({
22
+ color: '#303133'
23
+ })
24
+ },
25
+ // 菜单非选中时的样式
26
+ inactiveStyle: {
27
+ type: [String, Object],
28
+ default: () => ({
29
+ color: '#606266'
30
+ })
31
+ },
32
+ // 滑块长度
33
+ lineWidth: {
34
+ type: [String, Number],
35
+ default: 20
36
+ },
37
+ // 滑块高度
38
+ lineHeight: {
39
+ type: [String, Number],
40
+ default: 3
41
+ },
42
+ // 滑块背景显示大小,当滑块背景设置为图片时使用
43
+ lineBgSize: {
44
+ type: String,
45
+ default: 'cover'
46
+ },
47
+ // 菜单item的样式
48
+ itemStyle: {
49
+ type: [String, Object],
50
+ default: () => ({
51
+ height: '44px'
52
+ })
53
+ },
54
+ // 菜单是否可滚动
55
+ scrollable: {
56
+ type: Boolean,
57
+ default: true
58
+ },
59
+ // 当前选中标签的索引
60
+ current: {
61
+ type: [Number, String],
62
+ default: 0
63
+ },
64
+ // 默认读取的键名
65
+ keyName: {
66
+ type: String,
67
+ default: 'name'
68
+ },
69
+ ...uni.$uv?.props?.tabs
70
+ }
71
+ }