index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="content">
  3. <!-- 比赛 -->
  4. <view :style="{'display':show_index == 0 ?'block':'none'}">
  5. <tab-game ref="game"></tab-game>
  6. </view>
  7. <!-- 发现 -->
  8. <view :style="{'display':show_index == 1 ?'flex':'none'}">
  9. <tab-discovery ref="discovery"></tab-discovery>
  10. </view>
  11. <!-- 数据 -->
  12. <view :style="{'display':show_index == 2? 'block':'none'}">
  13. <tab-data ref="data"></tab-data>
  14. </view>
  15. <!-- 资讯 -->
  16. <view :style="{'display':show_index == 3 ?'block':'none'}">
  17. <tab-information ref="information"></tab-information>
  18. </view>
  19. <!-- 个人中心 -->
  20. <view :style="{'display':show_index == 4 ? 'flex':'none'}">
  21. <tab-mycenter :style="{'display':show_index == 4 ? 'flex':'none'}" ref="mycenter"></tab-mycenter>
  22. </view>
  23. <!-- is_lhp判断是否为刘海屏在main.js里,好像uniapp有一个css变量获取刘海屏的安全区域 -->
  24. <view class="tabBar" :style="{height:is_lhp?'140rpx':'98rpx'}">
  25. <!-- 导航的中间圆圈 -->
  26. <view class="border_box" :style="{paddingBottom:is_lhp?'40rpx':''}">
  27. <view class="tabBar_miden_border"></view>
  28. </view>
  29. <view class="tabBar_list" :style="{paddingBottom:is_lhp?'40rpx':''}">
  30. <view v-for="(item) in tab_nav_list" :key="item.id" :class="{'tabBar_item':item.id!=2,'tabBar_item2':item.id==2}" @tap="cut_index(item.id)">
  31. <image v-if="show_index == item.id" :src="`../../static/tabBar/${item.id+1}${item.id+1}.png`"></image>
  32. <image v-else :src="`../../static/tabBar/${item.id+1}.png`"></image>
  33. <view :class="{'tabBar_name':true,'nav_active':show_index == item.id}">{{item.name}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import tabGame from '@/components/tabBar/game.vue'
  41. import tabDiscovery from '@/components/tabBar/discovery.vue'
  42. import tabInformation from '@/components/tabBar/information.vue'
  43. import tabData from '@/components/tabBar/Data.vue'
  44. import tabMycenter from '@/components/tabBar/mycenter.vue'
  45. export default {
  46. components: {
  47. tabGame,//比赛 0
  48. tabDiscovery,//发现 1
  49. tabInformation,//资讯 2
  50. tabData,//数据 3
  51. tabMycenter//个人中心 4
  52. },
  53. data() {
  54. return {
  55. show_index:0,//控制显示那个组件
  56. tab_nav_list :[{'id':0,'name':'首页'},{'id':1,'name':'分类'},{'id':2,'name':'推荐'},{'id':3,'name':'购物车'},{'id':4,'name':'我'}],//菜单列表
  57. is_lhp:false
  58. }
  59. },
  60. onLoad() {
  61. let _this = this
  62. this.is_lhp = this.$is_bang
  63. this.$nextTick(function(){
  64. // 一定要等视图更新完再调用方法 -----------++++++++++++++++重要
  65. setTimeout(function(){
  66. uni.setNavigationBarColor({
  67. frontColor: '#ffffff',
  68. backgroundColor: '#6739b6'
  69. })
  70. _this.$refs.game.ontrueGetList()//初次加载第一个页面的请求数据
  71. },100)
  72. })
  73. console.log("是否为刘海屏",this.is_lhp )
  74. },
  75. methods: {
  76. // 切换组件
  77. cut_index(type){
  78. console.log('----------------------------------',type)
  79. let _this = this
  80. _this.show_index = type
  81. if(_this.show_index == 0){
  82. uni.setNavigationBarColor({
  83. frontColor: '#ffffff',
  84. backgroundColor: '#6739b6'
  85. })
  86. _this.$refs.game.ontrueGetList()
  87. }
  88. else if(_this.show_index == 1){
  89. _this.$refs.discovery.ontrueGetList()
  90. }
  91. else if(_this.show_index == 2){
  92. _this.$refs.data.ontrueGetList()
  93. }
  94. else if(_this.show_index == 3){
  95. uni.setNavigationBarColor({
  96. frontColor: '#ffffff',
  97. backgroundColor: '#ec008c'
  98. })
  99. _this.$refs.information.ontrueGetList()
  100. }
  101. else if(_this.show_index == 4){
  102. _this.$refs.mycenter.ontrueGetList()
  103. }
  104. },
  105. onPullDownRefresh(){
  106. uni.showToast({
  107. title:`第${this.show_index+1}个页面的刷新`
  108. })
  109. setTimeout(function(){
  110. uni.stopPullDownRefresh()
  111. },2000)
  112. console.log('下拉刷新四个组件公用的下拉刷新方法,根据在哪个页面下拉执行哪个页面的刷新方方法即可')
  113. console.log('如果想要自定义刷新的话,插件市场就有一个 非常好用也非常容易入手')
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. .tabBar{ width:100%;height: 98rpx;background: #fff;border-top:1px solid #E5E5E5;position: fixed;bottom:0px;left:0px;right:0px;display: flex;align-items: center;justify-content: center;
  120. .tabBar_list{ width:86%;display: flex;justify-content: space-between;
  121. image{ width:48rpx;height: 48rpx;margin-bottom:2rpx}
  122. .tabBar_item{ width:68rpx;display: flex;justify-content: center;align-items: center;flex-direction: column;font-size: 20rpx;color: #969BA3;}
  123. .tabBar_item2{
  124. width:68rpx;height:100%;display: flex;justify-content: center;align-items: center;flex-direction: column;font-size: 20rpx;color: #969BA3;margin-top:-20rpx;position: relative;z-index: 101;
  125. image{ width:68rpx;height: 68rpx;}
  126. }
  127. }
  128. }
  129. .border_box{
  130. // pointer-events: none; 事件穿透解决z-index层级问题
  131. width:100%;height: 100rpx;display: flex;justify-content: center;align-items: center;position: fixed;left:0px;bottom:50rpx;z-index: 100;pointer-events: none;
  132. .tabBar_miden_border{ width:100rpx;height:50rpx;border-top:2rpx solid #E5E5E5;border-radius:50rpx 50rpx 0 0; /* 左上、右上、右下、左下 */background: #fff;}
  133. }
  134. .nav_active{color: #007AFF;}
  135. </style>