custom-tabbar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm"
  10. :content="MESSAGE_VISITER_TO_LOGIN"></tip-middle-dialog>
  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 {
  18. useTabBarHistory
  19. } from '@/utils/emitEvents.js';
  20. import cacheManager from "@/utils/cacheManager.js";
  21. import {
  22. toast,
  23. getUserIdentity
  24. } from "@/utils/common";
  25. import {
  26. nextTick,
  27. } from "vue";
  28. export default {
  29. components: {
  30. tipMiddleDialog
  31. },
  32. data() {
  33. return {
  34. tabList: [{
  35. iconPath: 'static/images/tabbar/unselect/plan-sj.png',
  36. activePath: 'static/images/tabbar/select/plan-sj.png',
  37. path: `/pages/study/index`
  38. },
  39. {
  40. iconPath: 'static/images/tabbar/unselect/partner-sj.png',
  41. activePath: 'static/images/tabbar/select/partner-sj.png',
  42. path: '/pages/game/index'
  43. },
  44. {
  45. iconPath: 'static/images/tabbar/unselect/my-sj.png',
  46. activePath: 'static/images/tabbar/select/my-sj.png',
  47. path: `/pages/my/index`
  48. },
  49. ],
  50. currentTab: 0,
  51. MESSAGE_VISITER_TO_LOGIN
  52. };
  53. },
  54. props: {
  55. nianji: {
  56. type: String,
  57. },
  58. cardId: {
  59. type: String,
  60. },
  61. zhangId: {
  62. type: String,
  63. },
  64. currentTabNumber: {
  65. type: String,
  66. },
  67. },
  68. methods: {
  69. // 游客弹窗---确定
  70. ykConfirm() {
  71. uni.redirectTo({
  72. url: '/pages/login/index'
  73. });
  74. },
  75. switchTab(path, index) {
  76. this.currentTab = index;
  77. uni.redirectTo({
  78. url: path
  79. });
  80. if (getUserIdentity() == 'Visitor') {
  81. if (path === '/pages/game/index') {
  82. this.$refs.youkeDialogRef.handleShow();
  83. return;
  84. }
  85. uni.redirectTo({
  86. url: path + '?nianji=' + this.nianji + '&cardId=' + this.cardId + '&zhangId=' +
  87. this
  88. .zhangId
  89. });
  90. } else {
  91. if (path === '/pages/game/index') {
  92. // 游戏需要返回功能
  93. uni.navigateTo({
  94. url: path
  95. });
  96. return;
  97. }
  98. uni.redirectTo({
  99. url: path
  100. });
  101. }
  102. },
  103. },
  104. created() {
  105. this.currentTab =this.currentTabNumber
  106. }
  107. }
  108. </script>
  109. <style scoped>
  110. .custom-tabbar {
  111. display: flex;
  112. justify-content: space-around;
  113. align-items: center;
  114. /* 其他样式 */
  115. }
  116. .tab-item {
  117. flex: 1;
  118. /* 样式 */
  119. }
  120. .tab-icon {
  121. /* 图标样式 */
  122. }
  123. </style>