custom-tabbar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if (path === '/pages/game/index') {
  57. // 游戏需要返回功能
  58. uni.navigateTo({
  59. url: path
  60. });
  61. return ;
  62. }
  63. uni.redirectTo({
  64. url: path + '?nianji=' + this.nianji + '&cardId=' + this.cardId + '&zhangId=' + this
  65. .zhangId
  66. });
  67. } else {
  68. if (path === '/pages/game/index') {
  69. // 游戏需要返回功能
  70. uni.navigateTo({
  71. url: path
  72. });
  73. return;
  74. }
  75. uni.redirectTo({
  76. url: path
  77. });
  78. }
  79. },
  80. },
  81. created() {
  82. console.log(this.nianji);
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .custom-tabbar {
  88. display: flex;
  89. justify-content: space-around;
  90. align-items: center;
  91. /* 其他样式 */
  92. }
  93. .tab-item {
  94. flex: 1;
  95. /* 样式 */
  96. }
  97. .tab-icon {
  98. /* 图标样式 */
  99. }
  100. </style>