diy-bottom-nav.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view>
  3. <view class="u-tabbar-inner">
  4. <view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="redirectTo(item.link)">
  5. <image :src="index == linkIndex ? item.selectedIconPath : item.iconPath" mode="scaleToFill"></image>
  6. <text class="item-desc" :class="{ 'color-base-text': index == linkIndex }">{{ item.text }}</text>
  7. </view>
  8. </view>
  9. <!-- 解决fixed定位后导航栏塌陷的问题 -->
  10. <view class="un-tabbar-flex"></view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'diy-bottom-nav',
  16. props:{
  17. linkIndex: { // 当前tab的下标
  18. type: Number,
  19. default () {
  20. return 0
  21. }
  22. }
  23. },
  24. data() {
  25. return {
  26. currentRoute: '', //当前页面路径
  27. jumpFlag: true,
  28. list: [
  29. {
  30. link: '/pages/order/list',
  31. selectedIconPath: '/static/images/tabbar/order_selected.png',
  32. iconPath: '/static/images/tabbar/order.png',
  33. text: '订单'
  34. },
  35. {
  36. link: '/pages/goods/list',
  37. selectedIconPath: '/static/images/tabbar/goods_selected.png',
  38. iconPath: '/static/images/tabbar/goods.png',
  39. text: '商品'
  40. },
  41. {
  42. link: '/pages/index/index',
  43. selectedIconPath: '/static/images/tabbar/shop_selected.png',
  44. iconPath: '/static/images/tabbar/shop.png',
  45. text: '店铺'
  46. },
  47. {
  48. link: '/pages/member/list',
  49. selectedIconPath: '/static/images/tabbar/member_selected.png',
  50. iconPath: '/static/images/tabbar/member.png',
  51. text: '会员'
  52. },
  53. {
  54. link: '/pages/my/index',
  55. selectedIconPath: '/static/images/tabbar/my_selected.png',
  56. iconPath: '/static/images/tabbar/my.png',
  57. text: '我的'
  58. }
  59. ]
  60. };
  61. },
  62. methods: {
  63. redirectTo(link) {
  64. if (!this.jumpFlag) return;
  65. this.jumpFlag = false;
  66. setTimeout(() => {
  67. this.jumpFlag = true;
  68. }, 300);
  69. this.$util.redirectTo(link);
  70. }
  71. }
  72. };
  73. </script>
  74. <style lang="scss">
  75. .u-tabbar-inner {
  76. position: fixed;
  77. left: 0;
  78. bottom: 0;
  79. width: 100%;
  80. min-height: 50px;
  81. z-index: 998;
  82. display: flex;
  83. background-color: #fff;
  84. box-sizing: border-box;
  85. padding-bottom: constant(safe-area-inset-bottom);
  86. padding-bottom: env(safe-area-inset-bottom);
  87. .tabbar-item {
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. width: 150rpx;
  92. image {
  93. margin-top: 7px;
  94. width: 24px;
  95. height: 24px;
  96. }
  97. .item-desc {
  98. font-size: 10px;
  99. color: #333;
  100. }
  101. }
  102. .un-tabbar-flex {
  103. height: 50px;
  104. background-color: transparent;
  105. padding-bottom: 0;
  106. padding-bottom: constant(safe-area-inset-bottom);
  107. padding-bottom: env(safe-area-inset-bottom);
  108. }
  109. }
  110. .un-tabbar-flex {
  111. width: 100%;
  112. height: 50px;
  113. background-color: transparent;
  114. padding-bottom: 0;
  115. padding-bottom: constant(safe-area-inset-bottom);
  116. padding-bottom: env(safe-area-inset-bottom);
  117. }
  118. </style>