custom-tabbar.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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,index)"
  5. :style="{ backgroundImage: 'url(' + (currentTab === index ? item.activePath : item.iconPath) + ')' }">
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import {
  12. useTabBarHistory
  13. } from '@/utils/emitEvents.js';
  14. import cacheManager from "@/utils/cacheManager.js";
  15. import {
  16. toast,
  17. getUserIdentity
  18. } from "@/utils/common";
  19. export default {
  20. data() {
  21. return {
  22. tabList: [{
  23. iconPath: 'static/images/tabbar/unselect/plan-sj.png',
  24. activePath: 'static/images/tabbar/select/plan-sj.png',
  25. path: `/pages/study/index`
  26. },
  27. {
  28. iconPath: 'static/images/tabbar/unselect/partner-sj.png',
  29. activePath: 'static/images/tabbar/select/partner-sj.png',
  30. path: '/pages/game/index'
  31. },
  32. {
  33. iconPath: 'static/images/tabbar/unselect/my-sj.png',
  34. activePath: 'static/images/tabbar/select/my-sj.png',
  35. path: `/pages/my/index`
  36. },
  37. ],
  38. currentTab: 0
  39. };
  40. },
  41. props: {
  42. nianji: {
  43. type: String,
  44. },
  45. cardId: {
  46. type: String,
  47. },
  48. zhangId: {
  49. type: String,
  50. },
  51. },
  52. methods: {
  53. switchTab(path, index) {
  54. this.currentTab = index;
  55. if (getUserIdentity() == 'Visitor') {
  56. uni.redirectTo({
  57. url: path + '?nianji=' + this.nianji + '&cardId=' + this.cardId + '&zhangId=' + this
  58. .zhangId
  59. });
  60. } else {
  61. if (path === '/pages/game/index') {
  62. // 游戏需要返回功能
  63. uni.navigateTo({
  64. url: path
  65. });
  66. return;
  67. }
  68. uni.redirectTo({
  69. url: path
  70. });
  71. }
  72. },
  73. },
  74. created() {
  75. console.log(this.nianji);
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. .custom-tabbar {
  81. display: flex;
  82. justify-content: space-around;
  83. align-items: center;
  84. /* 其他样式 */
  85. }
  86. .tab-item {
  87. flex: 1;
  88. /* 样式 */
  89. }
  90. .tab-icon {
  91. /* 图标样式 */
  92. }
  93. </style>