tabbar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="tab-bar" :style="{'--padding-bottom':`${wagesheight}`+'rpx'}">
  3. <view class="content main-between cross-center">
  4. <view v-for="(item,index) in list" :key="index" class="tab-item dir-top-wrap cross-center main-center"
  5. :class="{active: active === index}" @click="handleSwitch(index)">
  6. <view class="icon">
  7. <image
  8. :src="active === index ? (item.selected_icon ? item.selected_icon : item.selectedIconPath) : (item.icon ? item.icon : item.iconPath)"
  9. mode="aspectFit" />
  10. </view>
  11. <text>{{ item.text }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. mapState
  19. } from 'vuex'
  20. export default {
  21. name: 'TabBar',
  22. data() {
  23. return {
  24. wagesheight: '',
  25. color: '#CBC8C7',
  26. selectedColor: '#FF6200',
  27. // types: {
  28. // 1: {
  29. // 'pagePath': '/pages/index/index',
  30. // 'iconPath': '/static/icon/home2.png',
  31. // 'selectedIconPath': '/static/icon/home1.png'
  32. // },
  33. // 2: {
  34. // 'pagePath': '/pages/map/map',
  35. // 'iconPath': '/static/icon/map02.png',
  36. // 'selectedIconPath': '/static/icon/map01.png'
  37. // },
  38. // 3: {
  39. // 'pagePath': '/pages/msg/msg',
  40. // 'iconPath': '/static/icon/msg02.png',
  41. // 'selectedIconPath': '/static/icon/msg01.png'
  42. // },
  43. // 4: {
  44. // 'pagePath': '/pages/my/my',
  45. // 'iconPath': '/static/icon/my02.png',
  46. // 'selectedIconPath': '/static/icon/my01.png'
  47. // }
  48. // },
  49. list: [{
  50. 'pagePath': '/pages/index/index',
  51. 'iconPath': '/static/icon/home02.png',
  52. 'selectedIconPath': '/static/icon/home01.png',
  53. 'text': '首页'
  54. },
  55. {
  56. 'pagePath': '/pages/map/map',
  57. 'iconPath': '/static/icon/map02.png',
  58. 'selectedIconPath': '/static/icon/map01.png',
  59. 'text': 'IHG地图'
  60. },
  61. {
  62. 'pagePath': '/pages/msg/msg',
  63. 'iconPath': '/static/icon/msg02.png',
  64. 'selectedIconPath': '/static/icon/msg01.png',
  65. 'text': '消息'
  66. },
  67. {
  68. 'pagePath': '/pages/my/my',
  69. 'iconPath': '/static/icon/my02.png',
  70. 'selectedIconPath': '/static/icon/my01.png',
  71. 'text': '我的'
  72. }
  73. ]
  74. }
  75. },
  76. computed: {
  77. ...mapState({
  78. active: seate => seate.tab.index
  79. })
  80. },
  81. created() {
  82. this.calc()
  83. uni.hideTabBar()
  84. // this.getData()
  85. },
  86. mounted() {
  87. let _this = this
  88. uni.getSystemInfo({
  89. success: function(res) {
  90. let bottom = res.safeArea.bottom
  91. let height = res.safeArea.height
  92. let cacl = bottom - height
  93. _this.wagesheight = cacl
  94. }
  95. })
  96. },
  97. methods: {
  98. handleSwitch(index) {
  99. if (index === this.active) {
  100. return
  101. }
  102. this.$store.dispatch('tab/index', index)
  103. const item = this.list[index]
  104. uni.switchTab({
  105. url: item.pagePath
  106. })
  107. },
  108. calc() {
  109. let active = 1
  110. const page = uni.$u.page().replace('//', '/')
  111. this.list.forEach((obj, index) => {
  112. if (obj.pagePath === page) {
  113. active = index
  114. }
  115. })
  116. if (active !== this.active) {
  117. this.$store.dispatch('tab/index', active)
  118. }
  119. },
  120. // getData() {
  121. // this.$api.setting.tabBar().then(res => {
  122. // const data = res.data
  123. // data.forEach(obj => {
  124. // Object.assign(obj, this.types[obj.type])
  125. // })
  126. // console.log('-->data', data)
  127. // this.list = data
  128. // })
  129. // }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .tab-bar {
  135. position: fixed;
  136. bottom: 0;
  137. left: 0;
  138. background-color: #fff;
  139. width: 100%;
  140. z-index: 999 !important;
  141. .content {
  142. background-color: #fff;
  143. box-shadow: 0px -2rpx 20rpx 0px rgba(0, 0, 0, 0.05);
  144. position: absolute;
  145. bottom: 0;
  146. width: 100%;
  147. height: 120rpx;
  148. background-size: 110% 100%;
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. // padding-bottom: var(--padding-bottom);
  153. .tab-item {
  154. flex: 1;
  155. color: #CBC8C7;
  156. transition: .3s;
  157. font-size: 24rpx;
  158. position: relative;
  159. display: flex;
  160. flex-direction: column;
  161. align-items: center;
  162. justify-content: center;
  163. &.active {
  164. color: #FF6200;
  165. }
  166. .icon {
  167. width: 42rpx;
  168. height: 42rpx;
  169. image {
  170. height: 100%;
  171. width: 100%;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. </style>