You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

136 lines
3.5 KiB

  1. <template>
  2. <view class="tab">
  3. <view v-for="(item,index) in list" :key="index" class="tab-item" @click="switchTab(item, index)">
  4. <img class="tab_img" :src="selectedPath == item.pagePath ? item.selectedIconPath : item.iconPath"></img>
  5. <view class="tab_text" :style="{color: selectedPath == item.pagePath ? selectedColor : color}">{{item.text}}</view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name:'tabBar',
  12. props: {
  13. selectedPath: { // 当前选中的tab index
  14. default: '/pages/home'
  15. },
  16. },
  17. data() {
  18. return {
  19. color: "#8c8c8c",
  20. selectedColor: "#3398DC",
  21. list: [],
  22. // currentIndex:0,
  23. }
  24. },
  25. watch: {
  26. "$store.state.loginUser":{
  27. handler:function(newVal,oldVal){
  28. this.setList(newVal.Description)
  29. }
  30. }
  31. },
  32. created() {
  33. // let index = this.list.findIndex(e=>e.pagePath==this.selectedPath)
  34. // this.currentIndex = index;
  35. let userInfo = this.GET_GLOBAL("loginUser");
  36. if(!userInfo)return
  37. this.setList(userInfo.Description)
  38. },
  39. methods: {
  40. setList(role){
  41. if (role=="学生") {
  42. this.list = [
  43. {
  44. "index":0,
  45. "pagePath": "/pages/home",
  46. "iconPath": "static/img-bar/tab-home.png",
  47. "selectedIconPath": "static/img-bar/tab-home-active.png",
  48. "text": "首页"
  49. },
  50. {
  51. "index":3,
  52. "pagePath": "/pages/my",
  53. "iconPath": "static/img-bar/tab-my.png",
  54. "selectedIconPath": "static/img-bar/tab-my-active.png",
  55. "text": "我的"
  56. }
  57. ]
  58. }else{
  59. this.list = [
  60. {
  61. "index":0,
  62. "pagePath": "/pages/home",
  63. "iconPath": "static/img-bar/tab-home.png",
  64. "selectedIconPath": "static/img-bar/tab-home-active.png",
  65. "text": "首页"
  66. },
  67. // {
  68. // "index":1,
  69. // "pagePath": "/pages/msg",
  70. // "iconPath": "static/img-bar/tab-msg.png",
  71. // "selectedIconPath": "static/img-bar/tab-msg-active.png",
  72. // "text": "消息"
  73. // },
  74. {
  75. "index":2,
  76. "pagePath": "/pages/contact",
  77. "iconPath": "static/img-bar/tab-contact.png",
  78. "selectedIconPath": "static/img-bar/tab-contact-active.png",
  79. "text": "通讯录"
  80. },
  81. {
  82. "index":3,
  83. "pagePath": "/pages/my",
  84. "iconPath": "static/img-bar/tab-my.png",
  85. "selectedIconPath": "static/img-bar/tab-my-active.png",
  86. "text": "我的"
  87. }
  88. ]
  89. }
  90. },
  91. switchTab(item, index) {
  92. // this.currentIndex = item.index;
  93. let url = item.pagePath;
  94. uni.switchTab({
  95. url: url
  96. });
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .tab {
  103. background: rgb(245, 245, 245);
  104. position: fixed;
  105. bottom: 0;
  106. left: 0;
  107. right: 0;
  108. height: 100rpx;
  109. display: flex;
  110. justify-content: center;
  111. align-items: center;
  112. padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
  113. border-top: 2rpx solid #CDCDCD;
  114. z-index:999;
  115. .tab-item {
  116. flex: 1;
  117. text-align: center;
  118. display: flex;
  119. justify-content: center;
  120. align-items: center;
  121. flex-direction: column;
  122. .tab_img {
  123. width: 48rpx;
  124. height: 48rpx;
  125. }
  126. .tab_text {
  127. font-size: 20rpx;
  128. margin-top: 6rpx;
  129. }
  130. }
  131. }
  132. </style>