tabbar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: "../../static/tabbar/home.png",
  74. selectedIconPath: "../../static/tabbar/home_sel.png",
  75. Text: '首页',
  76. url: '/pages/home/index',
  77. isshowed:true
  78. },
  79. {
  80. iconPath: "../../static/manageTabIcon/training.png",
  81. selectedIconPath: "../../static/manageTabIcon/training_on.png",
  82. Text: '学习',
  83. url: '/pages/learn/index',
  84. isshowed:true
  85. },
  86. {
  87. iconPath: "../../static/tabbar/my.png",
  88. selectedIconPath: "../../static/tabbar/my_sel.png",
  89. Text: '我的',
  90. url: '/pages/user/index',
  91. isshowed:true
  92. },
  93. ]
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .tabbar {
  100. display: flex;
  101. position: fixed;
  102. bottom: 0;
  103. left: 0;
  104. right: 0;
  105. background-color: #fff;
  106. z-index: 1000;
  107. height: 100rpx;
  108. padding: 10rpx 0rpx 20rpx;
  109. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  110. image{
  111. margin-bottom: 4rpx;
  112. width: 44rpx;
  113. height: 44rpx;
  114. }
  115. }
  116. .tablist {
  117. flex: 1;
  118. }
  119. .morecolor{
  120. color: #999;
  121. }
  122. .actcolor{
  123. color: #5C4BFF;
  124. }
  125. .tabbar-list{
  126. display: flex;
  127. flex-direction: column;
  128. align-items: center;
  129. font-size: 20rpx;
  130. font-weight: 500;
  131. }
  132. </style>