app-tab-bar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="app-navigation-bar safe-area-inset-bottom" :style="{backgroundColor: bottom_background_color}" :class="{'app-tab-bar-shadow': shadow}" >
  3. <view v-for="(item, index) in tabBarNavs.navs" :key="index" class="app-tab-bar-item box-grow-1" :style="{height: botNavHei + 'rpx',backgroundColor: bottom_background_color, width: `${100/tabBarNavs.navs.length}%`}">
  4. <app-jump-button :backgroundColor="bottom_background_color"
  5. form
  6. class="app-button"
  7. :url="item.url"
  8. :open_type="item.open_type"
  9. :params="item.params"
  10. arrangement="column"
  11. >
  12. <image class="app-icon" :src=" router === item.url ? item.active_icon : item.icon"></image>
  13. <text class="app-nav-text" v-bind:style="{'color': router === item.url ? item.active_color : item.color}">
  14. {{item.text}}
  15. </text>
  16. </app-jump-button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { mapGetters, mapState } from 'vuex';
  22. export default {
  23. data() {
  24. return {
  25. router: '',
  26. }
  27. },
  28. props: {
  29. pageCount: Number,
  30. },
  31. computed: {
  32. ...mapGetters('mallConfig', {
  33. tabBarNavs: 'getNavBar'
  34. }),
  35. ...mapGetters('iPhoneX', {
  36. botNavHei: 'getNavHei',
  37. }),
  38. ...mapState('mallConfig', {
  39. bottom_background_color: state => state.navbar.bottom_background_color,
  40. shadow: state => state.navbar.shadow,
  41. }),
  42. },
  43. // #ifdef MP
  44. created() {
  45. this.router = this.$platDiff.tabBarUrl(null, this.pageCount);
  46. },
  47. // #endif
  48. watch: {
  49. // #ifdef H5
  50. '$route': {
  51. handler: function(data) {
  52. let { query, meta } = data;
  53. let str = '?';
  54. for (let key in query) {
  55. str += `${key}=${query[key]}&`
  56. }
  57. let url = '/' + meta.pagePath + str;
  58. url = url.slice(0, url.length - 1);
  59. this.router = url;
  60. },
  61. deep: true,
  62. immediate: true
  63. }
  64. // #endif
  65. }
  66. };
  67. </script>
  68. <style lang="scss" scoped>
  69. .app-navigation-bar {
  70. display: flex;
  71. flex-direction: row;
  72. width: 100%;
  73. bottom: 0;
  74. left: 0;
  75. background-color: white;
  76. z-index: 1600;
  77. position: fixed;
  78. }
  79. .app-nav-text {
  80. font-size: #{22rpx};
  81. line-height: #{22rpx};
  82. margin-top: #{75rpx};
  83. }
  84. .app-icon {
  85. width: #{50rpx};
  86. height: #{50rpx};
  87. position: absolute;
  88. top: 0;
  89. left: 50%;
  90. margin-top: #{20rpx};
  91. transform: translateX(-50%);
  92. }
  93. .app-tab-bar-item {
  94. flex-grow: 1;
  95. position: relative;
  96. }
  97. .app-tab-bar-shadow {
  98. border-top: 1rpx solid $uni-weak-color-one;
  99. }
  100. </style>