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.

163 lines
5.0 KiB

7 months ago
7 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. }else if(this.identity == '考场模拟教练'){
  94. this.list = [{
  95. "pagePath": "/pages/tabbar/statistics/index",
  96. "text": "统计",
  97. "iconPath": require("../../static/images/tabbar/tj.png"),
  98. "selectedIconPath": require("../../static/images/tabbar/tjActive.png")
  99. },
  100. {
  101. "pagePath": "/pages/tabbar/examSimulation/index",
  102. "text": "预约记录",
  103. "iconPath": require("../../static/images/tabbar/kc.png"),
  104. "selectedIconPath": require("../../static/images/tabbar/kcActive.png")
  105. },
  106. {
  107. "pagePath": "/pages/tabbar/mine/index",
  108. "text": "我的",
  109. "iconPath": require("../../static/images/tabbar/wd.png"),
  110. "selectedIconPath": require("../../static/images/tabbar/wdActive.png")
  111. }]
  112. }else if(this.identity == '模拟器老师'){
  113. this.list = [
  114. {
  115. "pagePath": "/pages/tabbar/examSimulation/index",
  116. "text": "学员评价",
  117. "iconPath": require("../../static/images/tabbar/kc.png"),
  118. "selectedIconPath": require("../../static/images/tabbar/kcActive.png")
  119. },
  120. {
  121. "pagePath": "/pages/tabbar/mine/index",
  122. "text": "我的",
  123. "iconPath": require("../../static/images/tabbar/wd.png"),
  124. "selectedIconPath": require("../../static/images/tabbar/wdActive.png")
  125. }]
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. .tab-bar {
  133. position: fixed;
  134. bottom: 0;
  135. left: 0;
  136. right: 0;
  137. height: 100rpx;
  138. background: white;
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
  143. .tab-bar-item {
  144. flex: 1;
  145. text-align: center;
  146. display: flex;
  147. justify-content: center;
  148. align-items: center;
  149. flex-direction: column;
  150. .tab_img {
  151. width: 48rpx;
  152. height: 48rpx;
  153. }
  154. .tab_text {
  155. font-size: 24rpx;
  156. margin-top: 4rpx;
  157. }
  158. }
  159. }
  160. </style>