custom-tabbar.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="ezy-custom-tabbar">
  3. <view class="tabbar-item-box" v-for="(item, index) in tabList" :key="index" @click="switchTab(item.path,index)">
  4. <view class="tabbar-item"
  5. :style="{ backgroundImage: 'url(' + (currentTab == index ? item.activePath : item.iconPath) + ')' }">
  6. </view>
  7. </view>
  8. </view>
  9. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  10. <tishiDlVue ref="popupRef"></tishiDlVue>
  11. </template>
  12. <script>
  13. import {
  14. MESSAGE_VISITER_TO_LOGIN
  15. } from "@/utils/constant.js"
  16. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  17. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  18. import {
  19. useTabBarHistory
  20. } from '@/utils/emitEvents.js';
  21. import cacheManager from "@/utils/cacheManager.js";
  22. import {
  23. toast,
  24. getUserIdentity
  25. } from "@/utils/common";
  26. import {
  27. nextTick,
  28. } from "vue";
  29. import tishiDlVue from './tishiDl.vue';
  30. export default {
  31. components: {
  32. tipMiddleDialog,
  33. tipBigDialog,
  34. tishiDlVue
  35. },
  36. data() {
  37. return {
  38. tabList: [{
  39. iconPath: 'static/images/tabbar/unselect/xuanke-sj.png',
  40. activePath: 'static/images/tabbar/select/xuanke-sj.png',
  41. path: `/pages/chanpinXuanze/index`
  42. },
  43. {
  44. iconPath: 'static/images/tabbar/unselect/xuexi-sj.png',
  45. activePath: 'static/images/tabbar/select/xuexi-sj.png',
  46. path: `/pages/chanpinneirong/index`
  47. },
  48. {
  49. iconPath: 'static/images/tabbar/unselect/faxian-sj.png',
  50. activePath: 'static/images/tabbar/select/faxian-sj.png',
  51. path: '/pages/game/index'
  52. },
  53. {
  54. iconPath: 'static/images/tabbar/unselect/wode-sj.png',
  55. activePath: 'static/images/tabbar/select/wode-sj.png',
  56. path: `/pages/chanpinMy/my`
  57. },
  58. ],
  59. currentTab: 0,
  60. isNavigating: false,
  61. MESSAGE_VISITER_TO_LOGIN
  62. };
  63. },
  64. props: {
  65. levelId: {
  66. type: String,
  67. },
  68. typeId: {
  69. type: String,
  70. },
  71. subjectId: {
  72. type: String,
  73. },
  74. currentTabNumber: {
  75. type: Number,
  76. },
  77. tipFlag: {
  78. type: String,
  79. },
  80. },
  81. methods: {
  82. // 游客弹窗---确定
  83. ykConfirm() {
  84. uni.redirectTo({
  85. url: '/pages/login/index'
  86. });
  87. },
  88. // 新增:判断是否是目标页面的方法
  89. isTargetPage(route, tabIndex) {
  90. const routeMap = {
  91. 0: 'pages/chanpinXuanze/index',
  92. 1: 'pages/chanpinneirong/index',
  93. 2: 'pages/game/index',
  94. 3: 'pages/chanpinMy/my'
  95. };
  96. return route === routeMap[tabIndex];
  97. },
  98. switchTab(path, index) {
  99. if (index == this.currentTab) {
  100. // 同页面不刷新
  101. return;
  102. }
  103. if (path == '/pages/chanpinneirong/index' && !cacheManager.get('auth').chanpinId) {
  104. this.$refs.popupRef.open();
  105. return false
  106. }
  107. // 新增:检查目标页面是否已经在页面栈中
  108. const pages = getCurrentPages();
  109. console.log('pages1', pages);
  110. let targetPage = null;
  111. for (let i = pages.length - 1; i >= 0; i--) {
  112. const page = pages[i];
  113. console.log('pages2', page);
  114. // 判断是否是目标页面(这里需要根据你的页面路径判断)
  115. if (page.route && this.isTargetPage(page.route, index)) {
  116. targetPage = page;
  117. break;
  118. }
  119. }
  120. this.currentTab = index
  121. console.log('targetPage', targetPage);
  122. if (targetPage) {
  123. // 如果页面已经在栈中,使用 navigateBack 返回
  124. const delta = pages.length - pages.indexOf(targetPage) - 1;
  125. console.log('delta', delta);
  126. uni.navigateBack({
  127. delta: delta
  128. });
  129. } else {
  130. console.log('11111');
  131. this.navigateToEditPage(path);
  132. }
  133. },
  134. navigateToEditPage(path) {
  135. if (this.isNavigating) {
  136. uni.showToast({
  137. title: '正在跳转中...',
  138. icon: 'none'
  139. });
  140. return;
  141. }
  142. this.isNavigating = true;
  143. uni.showLoading({
  144. title: '加载中'
  145. }); // 显示Loading
  146. uni.navigateTo({
  147. url: path,
  148. complete: () => {
  149. uni.hideLoading();
  150. this.isNavigating = false;
  151. }
  152. });
  153. }
  154. },
  155. created() {
  156. this.currentTab = this.currentTabNumber
  157. }
  158. }
  159. </script>