tabbar.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: '#000'
  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. // padding-top: 48rpx;
  121. // #ifndef APP-NVUE
  122. box-sizing: border-box;
  123. // #endif
  124. display: flex;
  125. flex-direction: column;
  126. background: url("@/static/home/taber-bg.png") center top / 100% auto;
  127. }
  128. .tabbar-bottom {
  129. width: 750rpx;
  130. flex: 1;
  131. // #ifndef APP-NVUE
  132. display: flex;
  133. // #endif
  134. flex-direction: row;
  135. align-items: center;
  136. justify-content: space-around;
  137. border-top-left-radius: 40rpx;
  138. border-top-right-radius: 40rpx;
  139. }
  140. .midButton {
  141. position: absolute;
  142. top: 10px;
  143. left: 330rpx;
  144. .image {
  145. height: 96rpx;
  146. width: 96rpx;
  147. }
  148. }
  149. .tabbar-bottom-item {
  150. // #ifndef APP-NVUE
  151. display: flex;
  152. // #endif
  153. align-items: center;
  154. justify-content: center;
  155. flex-direction: column;
  156. height: 120rpx;
  157. width: 100rpx;
  158. position: relative;
  159. }
  160. .tabbar-bottom-item-icon {
  161. height: 68rpx;
  162. width: 68rpx;
  163. position: relative;
  164. }
  165. .tabbar-bottom-item-text {
  166. font-size: 20rpx;
  167. color: rgb(113, 113, 113);
  168. }
  169. .tabbar-bottom-item-count {
  170. background-color: #ff4d4d;
  171. font-size: 20rpx;
  172. font-weight: bold;
  173. color: #ffffff;
  174. padding: 8rpx;
  175. position: absolute;
  176. top: 0rpx;
  177. right: 0rpx;
  178. border-radius: 100rpx;
  179. /* 半径为高度的一半 */
  180. // #ifndef APP-NVUE
  181. display: flex;
  182. // #endif
  183. justify-content: center;
  184. align-items: center;
  185. }
  186. .safe-bottom-area {
  187. width: 750rpx;
  188. background-color: #fff;
  189. }
  190. </style>