tabbar.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="tabbar-area">
  3. <view class="tabbar-bottom" :style="{ backgroundColor: backgroundColor, height: tabbarHeight + 'px' }">
  4. <view class="tabbar-bottom-item" ref="tabbarItem" v-for="(item, index) in tabbars" :key="index"
  5. @click="switchTab(item,index)">
  6. <image :src="currentIndex == index ? item.selectedIconPath : item.iconPath"
  7. :class="['tabbar-bottom-item-icon']"></image>
  8. <text class="tabbar-bottom-item-text"
  9. :style="{ color: currentIndex == index ? textActiveColor : textColor }">{{ item.text }}</text>
  10. <text class="tabbar-bottom-item-count"
  11. v-if="item.count">{{ item.count >= 99 ? '99+' : item.count }}</text>
  12. </view>
  13. </view>
  14. <view class="midButton">
  15. <image class="image" src="../../static/tabbar-icon/center.png" mode=""></image>
  16. </view>
  17. <uv-safe-bottom></uv-safe-bottom>
  18. </view>
  19. </template>
  20. <script>
  21. let animationModule = null;
  22. // #ifdef APP-NVUE
  23. animationModule = weex.requireModule('animation')
  24. // #endif
  25. export default {
  26. props: {
  27. currentIndex: {
  28. type: Number,
  29. default: 0
  30. },
  31. backgroundColor: {
  32. type: String,
  33. default: '#fff'
  34. },
  35. textColor: {
  36. type: String,
  37. default: '#717171'
  38. },
  39. textActiveColor: {
  40. type: String,
  41. default: '#1ABC9C'
  42. },
  43. tabbarHeight: {
  44. type: Number,
  45. default: 60
  46. },
  47. tabbars: {
  48. type: Array,
  49. default: () => ([])
  50. },
  51. midButton: {
  52. type: Boolean,
  53. default: true,
  54. }
  55. },
  56. data() {
  57. return {}
  58. },
  59. mounted() {
  60. uni.hideTabBar()
  61. },
  62. methods: {
  63. switchTab(item, index) {
  64. if (!item.pagePath) return;
  65. uni.switchTab({
  66. url: item.pagePath,
  67. });
  68. // this.payAnimation()
  69. },
  70. async payAnimation() {
  71. const active = [{
  72. dom: this.$refs.tabbarItem[this.currentIndex],
  73. styles: {
  74. transform: `scale(1.2)`
  75. },
  76. transformOrigin: 'center center',
  77. timingFunction: 'ease-in-out',
  78. duration: 100,
  79. },
  80. {
  81. dom: this.$refs.tabbarItem[this.currentIndex],
  82. styles: {
  83. transform: `scale(1)`
  84. },
  85. transformOrigin: 'center center',
  86. timingFunction: 'ease-in-out',
  87. duration: 100,
  88. }
  89. ]
  90. for (var i = 0; i < active.length; i++) {
  91. await this.animationActive(active[i])
  92. }
  93. },
  94. animationActive(active) {
  95. return new Promise((resolve, reject) => {
  96. animationModule.transition(active.dom, {
  97. styles: active.styles || {},
  98. duration: active.duration,
  99. timingFunction: active.timingFunction,
  100. delay: active.delay || 0,
  101. transformOrigin: active.transformOrigin,
  102. }, () => {
  103. resolve()
  104. })
  105. })
  106. },
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .tabbar-area {
  112. position: fixed;
  113. bottom: 0rpx;
  114. width: 750rpx;
  115. height: 145rpx;
  116. background-color: transparent;
  117. padding-top: 25rpx;
  118. // #ifndef APP-NVUE
  119. box-sizing: border-box;
  120. // #endif
  121. }
  122. .tabbar-bottom {
  123. width: 750rpx;
  124. height: 120rpx;
  125. // #ifndef APP-NVUE
  126. display: flex;
  127. // #endif
  128. flex-direction: row;
  129. align-items: center;
  130. justify-content: space-around;
  131. border-top-left-radius: 40rpx;
  132. border-top-right-radius: 40rpx;
  133. }
  134. .midButton {
  135. position: absolute;
  136. top: 0px;
  137. left: 305rpx;
  138. .image {
  139. height: 145rpx;
  140. width: 145rpx;
  141. }
  142. }
  143. .tabbar-bottom-item {
  144. // #ifndef APP-NVUE
  145. display: flex;
  146. // #endif
  147. align-items: center;
  148. justify-content: center;
  149. flex-direction: column;
  150. height: 120rpx;
  151. width: 100rpx;
  152. position: relative;
  153. }
  154. .tabbar-bottom-item-icon {
  155. height: 80rpx;
  156. width: 54rpx;
  157. position: relative;
  158. }
  159. .tabbar-bottom-item-text {
  160. font-size: 20rpx;
  161. color: rgb(113, 113, 113);
  162. }
  163. .tabbar-bottom-item-count {
  164. background-color: #ff4d4d;
  165. font-size: 20rpx;
  166. font-weight: bold;
  167. color: #ffffff;
  168. padding: 8rpx;
  169. position: absolute;
  170. top: 0rpx;
  171. right: 0rpx;
  172. border-radius: 100rpx;
  173. /* 半径为高度的一半 */
  174. // #ifndef APP-NVUE
  175. display: flex;
  176. // #endif
  177. justify-content: center;
  178. align-items: center;
  179. }
  180. </style>