index-tabbar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="index-tabbar">
  3. <view class="item" v-for="(item, index) in list" :key="index" @tap="switchTabbar(index)" @longpress="longpress(index)" @touchend="touchend(index)">
  4. <view class="hover" :class="index === activeIndex ? 'active' : ''"></view>
  5. <image v-if="tabbarIndex === index" :src="item.icon_act"></image>
  6. <image v-else :src="item.icon"></image>
  7. <text :class="tabbarIndex === index ? 'active' : ''">{{ item.name }}</text>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. activeIndex: -1,
  16. list: [
  17. {
  18. name: '首页',
  19. icon: '../../static/index/tabbar/index.png',
  20. icon_act: '../../static/index/tabbar/index-act.png'
  21. },
  22. {
  23. name: '数据',
  24. icon: '../../static/index/tabbar/data.png',
  25. icon_act: '../../static/index/tabbar/data-act.png'
  26. },
  27. {
  28. name: '社区',
  29. icon: '../../static/index/tabbar/community.png',
  30. icon_act: '../../static/index/tabbar/community-act.png'
  31. },
  32. {
  33. name: '我的',
  34. icon: '../../static/index/tabbar/my.png',
  35. icon_act: '../../static/index/tabbar/my-act.png'
  36. },
  37. ]
  38. }
  39. },
  40. computed: {
  41. tabbarIndex() { return this.$store.state.app.index_tabbar_index }
  42. },
  43. methods: {
  44. switchTabbar(index) {
  45. this.$store.commit('app/SWITCHINDEXTAABARINDEX', index)
  46. this.activeIndex = index
  47. setTimeout(() => {
  48. this.activeIndex = -1
  49. }, 400)
  50. },
  51. longpress(index) {
  52. this.activeIndex = index
  53. },
  54. touchend(index) {
  55. this.activeIndex = -1
  56. this.$store.commit('app/SWITCHINDEXTAABARINDEX', index)
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .index-tabbar {
  63. left: 0;
  64. bottom: 0;
  65. width: 100%;
  66. display: flex;
  67. position: fixed;
  68. background: #FFFFFF;
  69. align-items: center;
  70. box-sizing: border-box;
  71. border-top: 1rpx solid #B2B2B2;
  72. height: $app-tabbar-height;
  73. justify-content: space-around;
  74. .item {
  75. flex: 1;
  76. height: 100%;
  77. display: flex;
  78. overflow: hidden;
  79. position: relative;
  80. align-items: center;
  81. flex-direction: column;
  82. .hover {
  83. top: 50%;
  84. width: 0;
  85. height: 0;
  86. left: 50%;
  87. z-index: 1;
  88. position: absolute;
  89. border-radius: 60rpx;
  90. background: rgba(1, 1, 1, .1);
  91. transform: translate(-50%, -50%);
  92. &.active {
  93. animation: tap-in .3s;
  94. animation-fill-mode: forwards;
  95. }
  96. }
  97. text {
  98. color: #666666;
  99. font-size: 22rpx;
  100. &.active {
  101. color: $app-base-color;
  102. }
  103. }
  104. image {
  105. width: 38rpx;
  106. height: 38rpx;
  107. margin: 16rpx 0 8rpx;
  108. }
  109. }
  110. }
  111. @keyframes tap-in {
  112. 0% {
  113. width: 0;
  114. height: 0;
  115. }
  116. 100% {
  117. width: 120%;
  118. height: 120%;
  119. }
  120. }
  121. </style>