tab.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view>
  3. <view class="used-tools">
  4. <view class="tools-list">
  5. <view class="item" @click="goUrl(item, index)" v-for="(item,index) in list" :key="index">
  6. <image :src="item.status ? (item.img || defaultImage) : (item.img2 || defaultImage)"></image>
  7. <text :class="['text', {'blue': item.status}]">{{item.text}}</text>
  8. </view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. defaultImage: '/static/images/question.png', // 添加默认图片
  18. list: [
  19. {
  20. img: '../static/manageTabIcon/data_on.png',
  21. img2: '../static/manageTabIcon/data.png',
  22. text: '数据',
  23. Url: 'pages_watch/data/index',
  24. status: 0
  25. },
  26. {
  27. img: '../static/manageTabIcon/liveclasses_on.png',
  28. img2: '../static/manageTabIcon/liveclasses.png',
  29. text: '课程表',
  30. Url: 'pages_watch/course/course',
  31. status: 0
  32. },
  33. {
  34. img: '../static/manageTabIcon/vip_on.png',
  35. img2: '../static/manageTabIcon/vip.png',
  36. text: '会员',
  37. Url: 'pages_watch/data/customer/index',
  38. status: 0
  39. },
  40. {
  41. img: '../static/manageTabIcon/training_on.png',
  42. img2: '../static/manageTabIcon/training.png',
  43. text: '催课',
  44. Url: 'pages_watch/urgeCourse/urgeCourse',
  45. status: 0
  46. },
  47. {
  48. img: '../static/manageTabIcon/manage_on.png',
  49. img2: '../static/manageTabIcon/manage.png',
  50. text: '管理',
  51. Url: 'pages_watch/data/user/index',
  52. status: 0
  53. }
  54. ]
  55. }
  56. },
  57. onLoad() {
  58. this.setActiveTab();
  59. },
  60. onShow() {
  61. this.setActiveTab();
  62. },
  63. methods: {
  64. setActiveTab() {
  65. const pages = getCurrentPages();
  66. if (pages.length === 0) return;
  67. const currentRoute = pages[pages.length - 1].route;
  68. this.list.forEach(item => {
  69. item.status = item.Url.includes(currentRoute) ? 1 : 0;
  70. });
  71. },
  72. goUrl(item, index) {
  73. console.log("888")
  74. // 更新状态
  75. this.list.forEach((tab, i) => {
  76. tab.status = i === index ? 1 : 0;
  77. });
  78. // 跳转逻辑
  79. if (!item.Url || typeof item.Url !== 'string') {
  80. console.error('Invalid URL:', item.Url);
  81. return uni.showToast({ title: '跳转链接错误', icon: 'none' });
  82. }
  83. const url = item.Url.startsWith('/') ? item.Url : `/${item.Url}`;
  84. const pages = getCurrentPages();
  85. const isOverStackLimit = pages.length >= 10;
  86. const jumpMethod = isOverStackLimit ? uni.redirectTo : uni.navigateTo;
  87. jumpMethod({
  88. url: url,
  89. success: () => {
  90. console.log('跳转成功:', url);
  91. },
  92. fail: (err) => {
  93. console.error('跳转失败:', err);
  94. uni.showToast({ title: '页面不存在或跳转失败', icon: 'none' });
  95. // 恢复之前的状态
  96. this.setActiveTab();
  97. }
  98. });
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. page {
  105. background-color: #efefef;
  106. }
  107. .used-tools {
  108. z-index: 9999; /* 确保在最上层 */
  109. width: 100%;
  110. position: fixed;
  111. bottom: 0;
  112. box-sizing: border-box;
  113. background: #FFFFFF;
  114. border-radius: 16upx;
  115. padding: 8upx 30upx;
  116. .tools-list {
  117. margin-top: 50upx;
  118. display: flex;
  119. flex-wrap: wrap;
  120. width: 100%;
  121. .item {
  122. box-sizing: border-box;
  123. width: 20%;
  124. display: flex;
  125. flex-direction: column;
  126. align-items: center;
  127. justify-content: center;
  128. margin-bottom: 50upx;
  129. position: relative;
  130. image {
  131. width: 44upx;
  132. height: 44upx;
  133. }
  134. .text {
  135. font-size: 24upx;
  136. font-family: PingFang SC;
  137. font-weight: 500;
  138. color: #111111;
  139. line-height: 1;
  140. margin-top: 20upx;
  141. &.blue {
  142. color: #1794fb;
  143. }
  144. }
  145. }
  146. }
  147. }
  148. </style>