custom-tabbar.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="ezy-custom-tabbar">
  3. <view class="tabbar-item-box">
  4. <view class="tabbar-item" v-for="(item, index) in tabList" :key="index" @click="switchTab(item.path)"
  5. :style="{backgroundImage: 'url(' + item.iconPath + ')'}"></view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. useTabBarHistory
  12. } from '@/utils/emitEvents.js';
  13. import {
  14. toast
  15. } from '@/utils/common'
  16. export default {
  17. data() {
  18. return {
  19. tabList: [{
  20. iconPath: 'static/images/tabbar/unselect/plan-sj.png',
  21. path: `/pages/study/index`
  22. },
  23. {
  24. iconPath: 'static/images/tabbar/unselect/develop-sj.png',
  25. path: '/pages/study/index2'
  26. },
  27. {
  28. iconPath: 'static/images/tabbar/unselect/partner-sj.png',
  29. path: '/pages/study/index3'
  30. },
  31. {
  32. iconPath: 'static/images/tabbar/unselect/my-sj.png',
  33. path: `/pages/my/index`
  34. },
  35. // 更多 Tab 项...
  36. ]
  37. };
  38. },
  39. methods: {
  40. switchTab(path, params = {}) {
  41. if(path =='/pages/study/index2'||path =='/pages/study/index3'){
  42. toast("此功能页面暂未开放!")
  43. return false
  44. }
  45. let storage = useTabBarHistory().getTabBarStorage()
  46. let queryString = Object.keys(storage).map(key =>
  47. `${encodeURIComponent(key)}=${encodeURIComponent(storage[key])}`).join('&');
  48. if (queryString) {
  49. path += `?${queryString}`;
  50. }
  51. uni.navigateTo({
  52. url: path
  53. });
  54. // 使用 uni.switchTab 进行跳转(适用于 tabBar 页面)
  55. // if (this.isTabBarPage(path)) {
  56. // uni.switchTab({
  57. // url: path
  58. // });
  59. // } else {
  60. // // 使用 uni.navigateTo 进行跳转(适用于非 tabBar 页面)
  61. // uni.navigateTo({
  62. // url: path
  63. // });
  64. // }
  65. },
  66. isTabBarPage(path) {
  67. // 根据你的 tabBar 页面路径进行判断
  68. const tabBarPages = ['/pages/study/index', '/pages/study/index', '/pages/study/index', '/pages/my/index'];
  69. return tabBarPages.includes(path);
  70. }
  71. },
  72. created() {
  73. }
  74. }
  75. </script>
  76. <style scoped>
  77. .custom-tabbar {
  78. display: flex;
  79. justify-content: space-around;
  80. align-items: center;
  81. /* 其他样式 */
  82. }
  83. .tab-item {
  84. flex: 1;
  85. /* 样式 */
  86. }
  87. .tab-icon {
  88. /* 图标样式 */
  89. }
  90. </style>