tab.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="tab">
  3. <view class="content main-between cross-center">
  4. <view
  5. v-for="(item,index) in list"
  6. :key="index"
  7. class="tab-item dir-top-wrap cross-center main-center"
  8. :class="{active: active === index, center: item.center}"
  9. @click="handleSwitch(index)"
  10. >
  11. <view class="icon">
  12. <image :src="active === index ? item.selectedIconPath : item.iconPath" mode="aspectFit" />
  13. </view>
  14. <text>{{ item.text }}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { mapState } from 'vuex'
  21. export default {
  22. name: 'Tab',
  23. data() {
  24. return {
  25. color: '#898E92',
  26. selectedColor: '#652907',
  27. list: [
  28. {
  29. pagePath: '/pages/groupon/index',
  30. iconPath: '/static/image/tab/groupon.png',
  31. selectedIconPath: '/static/image/tab/groupon-HL.png',
  32. center: false,
  33. text: '抢爆品'
  34. },
  35. {
  36. pagePath: '/pages/index/index',
  37. iconPath: '/static/image/tab/member.png',
  38. selectedIconPath: '/static/image/tab/member-HL.png',
  39. center: true,
  40. text: '会员卡'
  41. },
  42. {
  43. pagePath: '/pages/store/index',
  44. iconPath: '/static/image/tab/store.png',
  45. selectedIconPath: '/static/image/tab/store-HL.png',
  46. center: false,
  47. text: '会员店'
  48. }
  49. ]
  50. }
  51. },
  52. computed: {
  53. ...mapState({
  54. active: seate => seate.tab.index
  55. })
  56. },
  57. created() {
  58. this.calc()
  59. },
  60. methods: {
  61. handleSwitch(index) {
  62. if (index === this.active) {
  63. return
  64. }
  65. this.$store.dispatch('tab/index', index)
  66. const item = this.list[index]
  67. uni.switchTab({
  68. url: item.pagePath
  69. })
  70. },
  71. calc() {
  72. let active = 1
  73. const page = uni.$u.page()
  74. this.list.forEach((obj, index) => {
  75. if (obj.pagePath === page) {
  76. active = index
  77. }
  78. })
  79. if (active !== this.active) {
  80. this.$store.dispatch('tab/index', active)
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .tab{
  88. position: fixed;
  89. bottom: 0;
  90. height: 170rpx;
  91. width: 100%;
  92. .content{
  93. background: url("@/static/image/tab/tab-bg.png") no-repeat bottom;
  94. height: 160rpx;
  95. position: absolute;
  96. bottom: 0;
  97. width: 100%;
  98. background-size: 110% 100%;
  99. .tab-item{
  100. flex: 1;
  101. color: #898E92;
  102. transition: .3s;
  103. font-size: 24rpx;
  104. position: relative;
  105. top: 20rpx;
  106. &.active{
  107. color: #652907;
  108. }
  109. .icon{
  110. width: 42rpx;
  111. height: 42rpx;
  112. image{
  113. height: 100%;
  114. width: 100%;
  115. }
  116. }
  117. &.center{
  118. position: relative;
  119. top: 0;
  120. color: #fff;
  121. .icon{
  122. width: 120rpx;
  123. height: 120rpx;
  124. image{
  125. height: 100%;
  126. width: 100%;
  127. }
  128. }
  129. text{
  130. position: absolute;
  131. top: 50%;
  132. transform: translateY(-67%);
  133. }
  134. &:before{
  135. content: "";
  136. background: #fff;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. </style>