tabbar.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 v-if="item.type!='midButton'" :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" v-if="item.count">{{ item.count >= 99 ? '99+' : item.count
  11. }}</text>
  12. </view>
  13. </view>
  14. <view class="midButton" @click="midButtonGo()">
  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. if (item.pagePath == '/pages/message/mailMessage') {
  68. uni.$emit('check_login', () => {
  69. uni.switchTab({
  70. url: item.pagePath,
  71. });
  72. })
  73. return;
  74. }
  75. uni.switchTab({
  76. url: item.pagePath,
  77. });
  78. // this.payAnimation()
  79. },
  80. midButtonGo(item, index) {
  81. if (!item.pagePath) return;
  82. console.log();
  83. // uni.switchTab({
  84. // url: item.pagePath,
  85. // });
  86. // this.payAnimation()
  87. },
  88. async payAnimation() {
  89. const active = [{
  90. dom: this.$refs.tabbarItem[this.currentIndex],
  91. styles: {
  92. transform: `scale(1.2)`
  93. },
  94. transformOrigin: 'center center',
  95. timingFunction: 'ease-in-out',
  96. duration: 100,
  97. },
  98. {
  99. dom: this.$refs.tabbarItem[this.currentIndex],
  100. styles: {
  101. transform: `scale(1)`
  102. },
  103. transformOrigin: 'center center',
  104. timingFunction: 'ease-in-out',
  105. duration: 100,
  106. }
  107. ]
  108. for (var i = 0; i < active.length; i++) {
  109. await this.animationActive(active[i])
  110. }
  111. },
  112. animationActive(active) {
  113. return new Promise((resolve, reject) => {
  114. animationModule.transition(active.dom, {
  115. styles: active.styles || {},
  116. duration: active.duration,
  117. timingFunction: active.timingFunction,
  118. delay: active.delay || 0,
  119. transformOrigin: active.transformOrigin,
  120. }, () => {
  121. resolve()
  122. })
  123. })
  124. },
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .tabbar-area {
  130. position: fixed;
  131. bottom: 0rpx;
  132. width: 750rpx;
  133. height: 145rpx;
  134. background-color: transparent;
  135. padding-top: 25rpx;
  136. // padding-top: 48rpx;
  137. // #ifndef APP-NVUE
  138. box-sizing: border-box;
  139. // #endif
  140. display: flex;
  141. flex-direction: column;
  142. background: url("@/static/home/taber-bg.png") center top / 100% auto;
  143. }
  144. .tabbar-bottom {
  145. width: 750rpx;
  146. flex: 1;
  147. // #ifndef APP-NVUE
  148. display: flex;
  149. // #endif
  150. flex-direction: row;
  151. align-items: center;
  152. justify-content: space-around;
  153. border-top-left-radius: 40rpx;
  154. border-top-right-radius: 40rpx;
  155. }
  156. .midButton {
  157. position: absolute;
  158. top: 10px;
  159. left: 330rpx;
  160. .image {
  161. height: 96rpx;
  162. width: 96rpx;
  163. }
  164. }
  165. .tabbar-bottom-item {
  166. // #ifndef APP-NVUE
  167. display: flex;
  168. // #endif
  169. align-items: center;
  170. justify-content: center;
  171. flex-direction: column;
  172. height: 120rpx;
  173. width: 100rpx;
  174. position: relative;
  175. }
  176. .tabbar-bottom-item-icon {
  177. height: 68rpx;
  178. width: 68rpx;
  179. position: relative;
  180. }
  181. .tabbar-bottom-item-text {
  182. font-size: 20rpx;
  183. color: rgb(113, 113, 113);
  184. }
  185. .tabbar-bottom-item-count {
  186. background-color: #ff4d4d;
  187. font-size: 20rpx;
  188. font-weight: bold;
  189. color: #ffffff;
  190. padding: 8rpx;
  191. position: absolute;
  192. top: 0rpx;
  193. right: 0rpx;
  194. border-radius: 100rpx;
  195. /* 半径为高度的一半 */
  196. // #ifndef APP-NVUE
  197. display: flex;
  198. // #endif
  199. justify-content: center;
  200. align-items: center;
  201. }
  202. .safe-bottom-area {
  203. width: 750rpx;
  204. background-color: #fff;
  205. }
  206. </style>