tabbar.vue 4.1 KB

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