tab-bar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <van-tabbar class="u-tabbar" :active="tabbarActive" @change="onChange" :placeholder="true" active-color="#E57519"
  3. inactive-color="#7D7D7D">
  4. <template v-for="(item, index) in list">
  5. <van-tabbar-item v-if="index !== 2" :name="item.name" :key="index" :icon="item.icon" icon-prefix="tabbar-icon">
  6. {{ item.text }}
  7. </van-tabbar-item>
  8. <template v-else>
  9. <view class="tabbar-center-item" :class="{ 'active': tabbarActive === item.name } " hover-class="active"
  10. @click="onClickCenter">
  11. <view class="tabbar-center-round">
  12. <view>
  13. <van-icon :name="item.icon" class-prefix="tabbar-icon" />
  14. </view>
  15. </view>
  16. <view class="tabbar-center-text">
  17. {{ item.text }}
  18. </view>
  19. </view>
  20. </template>
  21. </template>
  22. </van-tabbar>
  23. </template>
  24. <script>
  25. import VanTabbar from '@/wxcomponents/vant/tabbar/index'
  26. import VanTabbarItem from '@/wxcomponents/vant/tabbar-item/index'
  27. export default {
  28. options: {
  29. styleIsolation: 'shared'
  30. },
  31. components: {
  32. VanTabbar,
  33. VanTabbarItem
  34. },
  35. props: {
  36. active: String
  37. },
  38. watch: {
  39. active(val) {
  40. this.tabbarActive = val
  41. }
  42. },
  43. data() {
  44. return {
  45. tabbarActive: 'home',
  46. list: [{
  47. name: 'home',
  48. icon: 'home',
  49. text: '首页',
  50. url: '/pages/index'
  51. }, {
  52. name: 'exhibitor',
  53. icon: 'exhibitor',
  54. text: '展商',
  55. url: '/pages/signup/signup'
  56. },
  57. {
  58. name: 'registration',
  59. icon: 'registration',
  60. text: '观众预登记',
  61. url: '/pages/test'
  62. },
  63. {
  64. name: 'activity',
  65. icon: 'activity',
  66. text: '同期活动',
  67. url: '/pages/test'
  68. },
  69. {
  70. name: 'user',
  71. icon: 'user',
  72. text: '个人中心',
  73. url: '/pages/test'
  74. }
  75. ]
  76. }
  77. },
  78. created() {
  79. this.tabbarActive = this.active
  80. },
  81. methods: {
  82. onChange(active) {
  83. this.tabbarActive = active
  84. if (this.tabbarActive === 'home') {
  85. uni.setNavigationBarTitle({
  86. title: '慕尼黑上海电子生产设备展'
  87. });
  88. } else if (this.tabbarActive === 'exhibitor') {
  89. uni.setNavigationBarTitle({
  90. title: '展商'
  91. });
  92. } else if (this.tabbarActive === 'activity') {
  93. uni.setNavigationBarTitle({
  94. title: '同期活动'
  95. });
  96. } else if (this.tabbarActive === 'user') {
  97. uni.setNavigationBarTitle({
  98. title: '个人中心'
  99. });
  100. }
  101. this.$emit('update:active', active)
  102. this.$emit('change', active)
  103. },
  104. onClickCenter() {
  105. this.showAlertDialog('功能未开通')
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss">
  111. .u-tabbar{
  112. .van-tabbar{
  113. height: 118rpx;
  114. }
  115. .van-tabbar-item{
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: space-between;
  119. padding-top: 16rpx;
  120. padding-bottom: 16rpx;
  121. }
  122. .van-tabbar-item__icon{
  123. margin-bottom: 0;
  124. }
  125. .van-tabbar-item__text {
  126. font-size: $fontSize3;
  127. color: #7D7D7D;
  128. }
  129. .van-tabbar-item--active {
  130. .van-tabbar-item__text {
  131. color: $textActionColor;
  132. }
  133. }
  134. .tabbar-center-item {
  135. position: relative;
  136. top: -50rpx;
  137. z-index: 1;
  138. flex: 1;
  139. &.active {
  140. .tabbar-center-text {
  141. color: $textActionColor;
  142. }
  143. }
  144. }
  145. .tabbar-center-text {
  146. font-size: $fontSize3;
  147. color: #7D7D7D;
  148. margin-top: 18rpx;
  149. text-align: center;
  150. }
  151. .tabbar-center-round {
  152. @include display-flex-center;
  153. width: 100rpx;
  154. height: 100rpx;
  155. border-radius: 50%;
  156. background-color: $buttonPrimaryColor;
  157. margin: auto;
  158. &>view {
  159. @include display-flex-center;
  160. width: 96rpx;
  161. height: 96rpx;
  162. border-radius: 50%;
  163. border: 1rpx solid #FFFFFF;
  164. color: #FFFFFF;
  165. background-color: $buttonPrimaryColor;
  166. .tabbar-icon {
  167. font-size: 60rpx;
  168. }
  169. }
  170. }
  171. .tabbar-icon-activity {
  172. font-size: 40rpx;
  173. }
  174. .tabbar-icon-user {
  175. font-size: 46rpx;
  176. }
  177. }
  178. </style>