爱简收旧衣按件回收前端代码仓库
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.

131 lines
2.6 KiB

2 weeks ago
  1. <template>
  2. <view class="tab-bar">
  3. <view
  4. v-for="(item, index) in tabList"
  5. :key="index"
  6. class="tab-item"
  7. :class="{ active: currentPath === item.pagePath }"
  8. @tap="switchTab(item.pagePath)"
  9. >
  10. <view class="icon-box">
  11. <image
  12. :src="currentPath === item.pagePath ? item.selectedIcon : item.icon"
  13. mode="aspectFit"
  14. class="tab-icon"
  15. />
  16. </view>
  17. <text class="tab-text">{{ item.text }}</text>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'AdminTabBar',
  24. data() {
  25. return {
  26. currentPath: '',
  27. tabList: [
  28. {
  29. pagePath: '/pages/component/admin_home',
  30. text: '首页',
  31. icon: '/static/logo.png',
  32. selectedIcon: '/static/111.png'
  33. },
  34. {
  35. pagePath: '/pages/component/role_management',
  36. text: '角色管理',
  37. icon: '/static/logo.png',
  38. selectedIcon: '/static/111.png'
  39. },
  40. {
  41. pagePath: '/pages/component/admin_my',
  42. text: '我的',
  43. icon: '/static/logo.png',
  44. selectedIcon: '/static/111.png'
  45. }
  46. ]
  47. }
  48. },
  49. methods: {
  50. switchTab(path) {
  51. // 更新当前路径
  52. this.currentPath = path
  53. console.log(path);
  54. // 执行页面跳转
  55. uni.switchTab({
  56. url: path,
  57. fail: () => {
  58. // this.$forceUpdate();
  59. uni.navigateTo({
  60. url: path
  61. })
  62. }
  63. })
  64. this.currentPath = path
  65. },
  66. // 初始化当前页面路径
  67. initCurrentPath() {
  68. const pages = getCurrentPages()
  69. if (pages.length > 0) {
  70. const currentPage = pages[pages.length - 1]
  71. this.currentPath = `/${currentPage.route}`
  72. }
  73. }
  74. },
  75. mounted() {
  76. this.initCurrentPath()
  77. },
  78. onShow() {
  79. this.initCurrentPath()
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .tab-bar {
  85. position: fixed;
  86. bottom: 0;
  87. left: 0;
  88. right: 0;
  89. height: 120rpx;
  90. background: #FFFFFF;
  91. display: flex;
  92. padding-bottom: env(safe-area-inset-bottom);
  93. border-top: 1rpx solid #F5F5F5;
  94. z-index: 1000;
  95. .tab-item {
  96. flex: 1;
  97. display: flex;
  98. flex-direction: column;
  99. align-items: center;
  100. justify-content: center;
  101. padding: 10rpx 0;
  102. .icon-box {
  103. width: 56rpx;
  104. height: 56rpx;
  105. display: flex;
  106. align-items: center;
  107. justify-content: center;
  108. .tab-icon {
  109. width: 44rpx;
  110. height: 44rpx;
  111. }
  112. }
  113. .tab-text {
  114. font-size: 24rpx;
  115. color: #999999;
  116. margin-top: 4rpx;
  117. }
  118. &.active {
  119. .tab-text {
  120. color: #00C853;
  121. }
  122. }
  123. }
  124. }
  125. </style>