tabbar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/healthy/index',
  78. isshowed:true
  79. },
  80. {
  81. iconPath: "/static/images/mall.png",
  82. selectedIconPath: "/static/images/mall_on.png",
  83. Text: '健康产品',
  84. url: '/pages/shopping/index',
  85. isshowed:true
  86. },
  87. {
  88. iconPath: "/static/images/mine.png",
  89. selectedIconPath: "/static/images/mine_on.png",
  90. Text: '我的',
  91. url: '/pages/user/index',
  92. isshowed:true
  93. },
  94. ]
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .tabbar {
  101. display: flex;
  102. position: fixed;
  103. bottom: 0;
  104. left: 0;
  105. right: 0;
  106. background-color: #fff;
  107. z-index: 1000;
  108. height: 100rpx;
  109. padding: 20rpx 0rpx;
  110. image{
  111. margin-bottom: 4rpx;
  112. width: 48rpx;
  113. height: 48rpx;
  114. }
  115. }
  116. .tablist {
  117. width: 25%;
  118. }
  119. .morecolor{
  120. color: #626468;
  121. }
  122. .actcolor{
  123. color: #018C39;
  124. }
  125. .tabbar-list{
  126. display: flex;
  127. flex-direction: column;
  128. align-items: center;
  129. font-size: 24rpx
  130. }
  131. </style>