tabbar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="tabbar align-center" >
  3. <view v-for="(item, index) in tabbarList" :key="index" @click="switchTabs(item)"
  4. class="tablist" v-if="item.isshowed">
  5. <view class="tabbar-list" >
  6. <image :src="actindex==index?item.selectedIconPath:item.iconPath"></image>
  7. <text class="fs24 base-textcol"
  8. :class="actindex==index?'actcolor':'morecolor'">{{item.Text}}</text>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import {getUserInfo} from '@/api/user'
  15. export default {
  16. name: "tabbar",
  17. props: {
  18. actindex: {
  19. type: Number,
  20. default: 0,
  21. }
  22. },
  23. data() {
  24. return {
  25. tabbarList: [],
  26. userinfoa:[],
  27. isuser:false
  28. };
  29. },
  30. mounted() {
  31. this.themeicon()
  32. this.$nextTick(()=>{
  33. if(uni.getStorageSync('AppToken')){
  34. this.getUserInfos()
  35. }else{
  36. this.isuser=true
  37. this.tabbarList[2].isshowed=true
  38. }
  39. })
  40. },
  41. methods: {
  42. getUserInfos(){
  43. getUserInfo().then(
  44. res => {
  45. if(res.code==200){
  46. if(res.user!=null){
  47. this.userinfoa=res.user
  48. }
  49. }else{
  50. uni.showToast({
  51. icon:'none',
  52. title: "请求失败",
  53. });
  54. }
  55. },
  56. rej => {}
  57. );
  58. },
  59. switchTabs(item) {
  60. console.log(12223)
  61. uni.switchTab({
  62. url: item.url
  63. })
  64. },
  65. themeicon() {
  66. this.tabbarList = [{
  67. iconPath: "/static/images/home.png",
  68. selectedIconPath: "/static/images/home_on.png",
  69. Text: '首页',
  70. url: '/pages/home/index',
  71. isshowed:true
  72. },
  73. {
  74. iconPath: "/static/images/ENCYCLOPEDIA.png",
  75. selectedIconPath: "/static/images/ENCYCLOPEDIA_on.png",
  76. Text: '学习',
  77. url: '/pages/course/index',
  78. isshowed:true
  79. },
  80. {
  81. iconPath: "/static/images/ENCYCLOPEDIA.png",
  82. selectedIconPath: "/static/images/ENCYCLOPEDIA_on.png",
  83. Text: '健康百科',
  84. url: '/pages/healthy/index',
  85. isshowed:true
  86. },
  87. {
  88. iconPath: "/static/images/mall.png",
  89. selectedIconPath: "/static/images/mall_on.png",
  90. Text: '健康产品',
  91. url: '/pages/shopping/index',
  92. isshowed:true
  93. },
  94. {
  95. iconPath: "/static/images/mine.png",
  96. selectedIconPath: "/static/images/mine_on.png",
  97. Text: '我的',
  98. url: '/pages/user/index',
  99. isshowed:true
  100. },
  101. ]
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .tabbar {
  108. display: flex;
  109. position: fixed;
  110. bottom: 0;
  111. left: 0;
  112. right: 0;
  113. background-color: #fff;
  114. z-index: 1000;
  115. height: 50px;
  116. // padding: 20rpx 0rpx;
  117. box-sizing: border-box;
  118. image{
  119. margin-bottom: 4rpx;
  120. width: 48rpx;
  121. height: 48rpx;
  122. }
  123. }
  124. .tablist {
  125. width: 25%;
  126. }
  127. .morecolor{
  128. color: #626468;
  129. }
  130. .actcolor{
  131. color: #018C39;
  132. }
  133. .tabbar-list{
  134. height: 100%;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. justify-content: center;
  139. font-size: 10px;
  140. text-align: center;
  141. }
  142. </style>