tabbar.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if(this.userinfoa.isShow==0&&this.isuser==false){
  49. this.tabbarList[3].isshowed=false
  50. this.tabbarList[2].isshowed=true
  51. }else if(this.userinfoa.isShow==1){
  52. this.tabbarList[3].isshowed=true
  53. this.tabbarList[2].isshowed=false
  54. }
  55. }
  56. }else{
  57. uni.showToast({
  58. icon:'none',
  59. title: "请求失败",
  60. });
  61. }
  62. },
  63. rej => {}
  64. );
  65. },
  66. switchTabs(item) {
  67. uni.switchTab({
  68. url: item.url
  69. })
  70. },
  71. themeicon() {
  72. this.tabbarList = [{
  73. iconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/home.png",
  74. selectedIconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/home_sel.png",
  75. Text: '首页',
  76. url: '/pages/home/index',
  77. isshowed:true
  78. },
  79. {
  80. iconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/health.png",
  81. selectedIconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/health_sel.png",
  82. Text: '健康百科',
  83. url: '/pages/healthy/index',
  84. isshowed:true
  85. },
  86. {
  87. iconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/archive.png",
  88. selectedIconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/archive_sel.png",
  89. Text: '健康档案',
  90. url: '/pages/healthy/idea',
  91. isshowed:false
  92. },
  93. {
  94. iconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/shop_mall.png",
  95. selectedIconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/shop_mall_sel.png",
  96. Text: '健康产品',
  97. url: '/pages/shopping/index',
  98. isshowed:false
  99. },
  100. {
  101. iconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/my.png",
  102. selectedIconPath: "https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/my_sel.png",
  103. Text: '我的',
  104. url: '/pages/user/index',
  105. isshowed:true
  106. },
  107. ]
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .tabbar {
  114. display: flex;
  115. position: fixed;
  116. bottom: 0;
  117. left: 0;
  118. right: 0;
  119. background-color: #fff;
  120. z-index: 1000;
  121. height: 100rpx;
  122. padding: 20rpx 0rpx;
  123. image{
  124. margin-bottom: 4rpx;
  125. width: 48rpx;
  126. height: 48rpx;
  127. }
  128. }
  129. .tablist {
  130. width: 25%;
  131. }
  132. .morecolor{
  133. color: #626468;
  134. }
  135. .actcolor{
  136. color: #2BC7B9;
  137. }
  138. .tabbar-list{
  139. display: flex;
  140. flex-direction: column;
  141. align-items: center;
  142. font-size: 24rpx
  143. }
  144. </style>