tab-bar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="footer">
  3. <view class="index" @click="swithTab(1)">
  4. <view><image :src="currentPage === 1?'../../static/tabbar/menu-1.png':'../../static/tabbar/menu-1-active.png'"></image></view>
  5. <view :class="[currentPage === 1?'current':'']">首页</view>
  6. </view>
  7. <view class="scan" @click="swithTab(2)">
  8. <view><image src="../../static/tabbar/menu-2.png"></image></view>
  9. <view class="hover">扫码换电</view>
  10. </view>
  11. <view class="index" @click="swithTab(3)">
  12. <view><image :src="currentPage === 3?'../../static/tabbar/menu-3-active.png':'../../static/tabbar/menu-3.png'"></image></view>
  13. <view :class="[currentPage === 3?'current':'']">我的</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name:"tab-bar",
  20. data() {
  21. return {
  22. currentPage:0,
  23. stationCode:null,
  24. };
  25. },
  26. mounted() {
  27. this.getRoute()
  28. },
  29. methods:{
  30. swithTab(num){
  31. if(num === 1){
  32. uni.switchTab({
  33. url: '/pages/index/index',
  34. });
  35. }else if(num === 2){
  36. if(this.$storage.getJson("token")){
  37. let stationCode='st001'
  38. this.$http.getStationExchange({stationCode:stationCode}).then(res=>{
  39. if(res.code === 0 && res.data){
  40. uni.navigateTo({
  41. url:'/pages/powerchange/index?stationCode='+stationCode+'&exchangeNo='+res.data
  42. })
  43. }else{
  44. that.$utils.msg(res.msg)
  45. }
  46. })
  47. // let that=this
  48. // uni.scanCode({
  49. // success: function (res) {
  50. // that.stationCode=res.result.split("=")[1]
  51. // that.$http.getStationExchange({stationCode:that.stationCode}).then(res=>{
  52. // if(res.code === 0 && res.data){
  53. // uni.navigateTo({
  54. // url:'/pages/powerchange/index?stationCode='+that.stationCode+'&exchangeNo='+res.data
  55. // })
  56. // }else{
  57. // that.$utils.msg(res.msg)
  58. // }
  59. // })
  60. // }
  61. // });
  62. }else{
  63. uni.navigateTo({
  64. url: '/pages/public/login',
  65. });
  66. }
  67. }else{
  68. if(this.$storage.getJson("token")){
  69. uni.switchTab({
  70. url: '/pages/ucenter/index',
  71. });
  72. }else{
  73. uni.navigateTo({
  74. url: '/pages/public/login',
  75. });
  76. }
  77. }
  78. },
  79. getRoute(){
  80. let curPage = getCurrentPages();
  81. let route = curPage[curPage.length - 1].route
  82. if(route === 'pages/index/index'){
  83. this.currentPage=1
  84. }else if(route === 'pages/ucenter/index'){
  85. this.currentPage=3
  86. }
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .footer{
  93. width: 100%;
  94. height: 106rpx;
  95. background-image: url(~@/static/bbg.png);
  96. background-size: 100% 100%;
  97. position: fixed;
  98. left: 0;
  99. right: 0;
  100. bottom: 0;
  101. display: flex;
  102. justify-content: space-around;
  103. padding-top: 15rpx;
  104. box-sizing: border-box;
  105. font-size: 26rpx;
  106. image{
  107. width: 39rpx;
  108. height: 39rpx;
  109. }
  110. .index{
  111. width: 300rpx;
  112. text-align: center;
  113. }
  114. .scan{
  115. position: relative;
  116. display: flex;
  117. flex: 1;
  118. text-align: center;
  119. view:first-child{
  120. position: absolute;
  121. bottom: 30rpx;
  122. width: 100%;
  123. }
  124. view:last-child{
  125. position: absolute;
  126. bottom: 6rpx;
  127. width: 100%;
  128. }
  129. image{
  130. width: 106rpx;
  131. height: 106rpx;
  132. }
  133. }
  134. .hover{
  135. color: #58be6b;
  136. }
  137. .current{
  138. color: #959ea8;
  139. }
  140. }
  141. </style>