custom-tabbar.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. export default {
  11. data() {
  12. return {
  13. tabList: [
  14. {iconPath: 'static/images/tabbar/unselect/plan-sj.png',path:`/pages/study/index?zhangId=${this.$state.zhangId}&nianji=${this.$state.nianji}&xueqi=${this.$state.xueqi}` },
  15. {iconPath: 'static/images/tabbar/unselect/develop-sj.png',path:'/pages/study/index' },
  16. {iconPath: 'static/images/tabbar/unselect/partner-sj.png',path:'/pages/study/index' },
  17. {iconPath: 'static/images/tabbar/unselect/my-sj.png',path:`/pages/my/index?zhangId=${this.$state.zhangId}&nianji=${this.$state.nianji}&xueqi=${this.$state.xueqi}` },
  18. // 更多 Tab 项...
  19. ]
  20. };
  21. },
  22. methods: {
  23. switchTab(path, params = {}) {
  24. // 将参数拼接到路径中
  25. let queryString = Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&');
  26. if (queryString) {
  27. path += `?${queryString}`;
  28. }
  29. uni.navigateTo({
  30. url: path
  31. });
  32. // 使用 uni.switchTab 进行跳转(适用于 tabBar 页面)
  33. // if (this.isTabBarPage(path)) {
  34. // uni.switchTab({
  35. // url: path
  36. // });
  37. // } else {
  38. // // 使用 uni.navigateTo 进行跳转(适用于非 tabBar 页面)
  39. // uni.navigateTo({
  40. // url: path
  41. // });
  42. // }
  43. },
  44. isTabBarPage(path) {
  45. // 根据你的 tabBar 页面路径进行判断
  46. const tabBarPages = ['/pages/study/index', '/pages/study/index','/pages/study/index','/pages/my/index'];
  47. return tabBarPages.includes(path);
  48. }
  49. },
  50. created() {
  51. console.log(this.$state);
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. .custom-tabbar {
  57. display: flex;
  58. justify-content: space-around;
  59. align-items: center;
  60. /* 其他样式 */
  61. }
  62. .tab-item {
  63. flex: 1;
  64. /* 样式 */
  65. }
  66. .tab-icon {
  67. /* 图标样式 */
  68. }
  69. </style>