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.

130 lines
3.7 KiB

8 months ago
8 months ago
  1. <template>
  2. <view class="tab-bar">
  3. <view v-for="(item,index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
  4. <image class="tab_img" :src="name == item.text ? item.selectedIconPath : item.iconPath"></image>
  5. <view class="tab_text" :style="{color: name == item.text ? selectedColor : color}">{{item.text}}</view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. props: {
  12. name: { // 当前选中的tab index
  13. default: 0
  14. },
  15. },
  16. data() {
  17. return {
  18. color: "#999",
  19. selectedColor: "#218DFF",
  20. list: [],
  21. currentIndex:0,
  22. }
  23. },
  24. watch: {
  25. identity(newVal) {
  26. this.initTabbar()
  27. }
  28. },
  29. created() {
  30. this.currentName = this.name;
  31. this.initTabbar()
  32. },
  33. methods: {
  34. switchTab(item, index) {
  35. this.currentName = item.text;
  36. let url = item.pagePath;
  37. console.log(url)
  38. uni.switchTab({
  39. url
  40. })
  41. // uni.reLaunch({url:url})
  42. },
  43. initTabbar() {
  44. if (this.identity == '实操教练') {
  45. //教练
  46. this.list = [
  47. {
  48. "pagePath": "/pages/tabbar/statistics/index",
  49. "text": "统计",
  50. "iconPath": require("../../static/images/tabbar/tj.png"),
  51. "selectedIconPath": require("../../static/images/tabbar/tjActive.png")
  52. },
  53. {
  54. "pagePath": "/pages/tabbar/student/index",
  55. "text": "学员",
  56. "iconPath": require("../../static/images/tabbar/xy.png"),
  57. "selectedIconPath": require("../../static/images/tabbar/xyActive.png")
  58. },
  59. {
  60. "pagePath": "/pages/tabbar/operateTrain/index",
  61. "text": "实操训练",
  62. "iconPath": require("../../static/images/tabbar/sc.png"),
  63. "selectedIconPath": require("../../static/images/tabbar/scActive.png")
  64. },
  65. {
  66. "pagePath": "/pages/tabbar/mine/index",
  67. "text": "我的",
  68. "iconPath": require("../../static/images/tabbar/wd.png"),
  69. "selectedIconPath": require("../../static/images/tabbar/wdActive.png")
  70. }
  71. ]
  72. } else if(this.identity == '校长'|| this.identity == '驾校财务') {
  73. //校长
  74. this.list = [{
  75. "pagePath": "/pages/tabbar/statistics/index",
  76. "text": "统计",
  77. "iconPath": require("../../static/images/tabbar/tj.png"),
  78. "selectedIconPath": require("../../static/images/tabbar/tjActive.png")
  79. },
  80. {
  81. "pagePath": "/pages/tabbar/student/index",
  82. "text": "学员",
  83. "iconPath": require("../../static/images/tabbar/xy.png"),
  84. "selectedIconPath": require("../../static/images/tabbar/xyActive.png")
  85. },
  86. {
  87. "pagePath": "/pages/tabbar/mine/index",
  88. "text": "我的",
  89. "iconPath": require("../../static/images/tabbar/wd.png"),
  90. "selectedIconPath": require("../../static/images/tabbar/wdActive.png")
  91. }
  92. ]
  93. }
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. .tab-bar {
  100. position: fixed;
  101. bottom: 0;
  102. left: 0;
  103. right: 0;
  104. height: 100rpx;
  105. background: white;
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
  110. .tab-bar-item {
  111. flex: 1;
  112. text-align: center;
  113. display: flex;
  114. justify-content: center;
  115. align-items: center;
  116. flex-direction: column;
  117. .tab_img {
  118. width: 48rpx;
  119. height: 48rpx;
  120. }
  121. .tab_text {
  122. font-size: 24rpx;
  123. margin-top: 4rpx;
  124. }
  125. }
  126. }
  127. </style>