tabbar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="tab-bar-wrappeer">
  3. <template
  4. v-for="(item, index) in tabbarData"
  5. :key="index">
  6. <div class="tab-item"
  7. v-if="item.path != '/NFT' || item.path == '/NFT' && showNFTTab"
  8. @click="tabbarHandler(item, index)">
  9. <red-dot class="red-dots"
  10. v-if="unReadCountTask > 0 && item.path == '/message' && currentTab.path != '/message'"
  11. ></red-dot>
  12. <img
  13. :src="
  14. index == currentTab.index
  15. ? item.iconActive
  16. : item.iconInActive
  17. "
  18. />
  19. <div
  20. class="text"
  21. :class="{ 'active-tab': index == currentTab.index }"
  22. >
  23. {{ item.name }}
  24. </div>
  25. </div>
  26. </template>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { ref, onMounted, defineProps, defineEmits, nextTick, watch } from "vue";
  31. import redDot from "@/view/components/red-dot.vue";
  32. import router from "@/router/popup.js";
  33. import { setBadgeInfo, hideBadge } from "@/logic/background/twitter";
  34. import { nftListMine } from "@/http/nft.js";
  35. import { getAllMessageInfo } from "@/http/messageApi"
  36. const props = defineProps({
  37. userInfo: {
  38. type: Object,
  39. default: () => {
  40. return {
  41. accessToken: undefined,
  42. };
  43. }
  44. },
  45. });
  46. watch(
  47. () => props.userInfo,
  48. (newVal) => {
  49. getNFTListMine();
  50. },
  51. {
  52. deep: true
  53. }
  54. );
  55. let currentTab = ref({
  56. index: 0,
  57. path: '/'
  58. });
  59. let unReadCountTask = ref(0);
  60. let showNFTTab = ref(true);
  61. let tabbarData = ref([
  62. {
  63. name: "Wallet",
  64. path: "/",
  65. iconActive: require("@/assets/svg/icon-tab-wallet-active.svg"),
  66. iconInActive: require("@/assets/svg/icon-tab-wallet.svg"),
  67. },
  68. {
  69. name: "NFTs",
  70. path: "/NFT",
  71. iconActive: require("@/assets/svg/icon-tab-NFT-active.svg"),
  72. iconInActive: require("@/assets/svg/icon-tab-NFT.svg"),
  73. },
  74. {
  75. name: "Message",
  76. path: "/message",
  77. iconActive: require("@/assets/svg/icon-tab-message-active.svg"),
  78. iconInActive: require("@/assets/svg/icon-tab-message.svg"),
  79. },
  80. {
  81. name: "More",
  82. path: "/more",
  83. iconActive: require("@/assets/svg/icon-tab-more-active.svg"),
  84. iconInActive: require("@/assets/svg/icon-tab-more.svg"),
  85. },
  86. ]);
  87. let NFTReqParams = {
  88. params: {
  89. pageNum: 1,
  90. pageSize: 20,
  91. },
  92. };
  93. const emits = defineEmits(["tabbarClick"]);
  94. const tabbarHandler = (params, index) => {
  95. setMessageCount();
  96. currentTab.value.index = index;
  97. currentTab.value.path = params.path;
  98. router.push(params.path);
  99. emits("tabbarClick", params);
  100. };
  101. const setActiveTab = () => {
  102. nextTick(() => {
  103. let path = router.currentRoute.value.path;
  104. let list = tabbarData.value;
  105. for (let i = 0; i < list.length; i++) {
  106. if (path == list[i].path) {
  107. currentTab.value.index = i;
  108. currentTab.value.path = path;
  109. break;
  110. }
  111. }
  112. })
  113. };
  114. const getNFTListMine = () => {
  115. console.log(props.userInfo.accessToken)
  116. if(!props.userInfo.accessToken) return;
  117. nftListMine({
  118. params: NFTReqParams.params,
  119. }).then((res) => {
  120. if (res.data && res.data.length) {
  121. showNFTTab.value = true;
  122. } else {
  123. showNFTTab.value = false;
  124. }
  125. });
  126. };
  127. const setMessageCount = () => {
  128. if(!props.userInfo.accessToken) return;
  129. getAllMessageInfo({params: {
  130. }}).then(res => {
  131. if(res.code == 0) {
  132. let {unReadCountTotal = 0, unReadCountWalletDetail = 0, unReadCountTaskLuckdrop = 0} = res.data;
  133. unReadCountTask.value = unReadCountTaskLuckdrop;
  134. if(unReadCountTotal > 0) {
  135. let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal+'';
  136. setBadgeInfo({data: {text}});
  137. } else {
  138. hideBadge();
  139. }
  140. }
  141. });
  142. }
  143. onMounted(() => {
  144. setActiveTab();
  145. setMessageCount();
  146. });
  147. </script>
  148. <style scoped lang="scss">
  149. .tab-bar-wrappeer {
  150. background: #ffffff;
  151. box-shadow: inset 0px 1px 0px #ececec;
  152. width: 100%;
  153. height: 70px;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. position: absolute;
  158. z-index: 1000;
  159. bottom: 0px;
  160. cursor: pointer;
  161. .tab-item {
  162. flex: 1;
  163. text-align: center;
  164. position: relative;
  165. .text {
  166. font-weight: 500;
  167. font-size: 12px;
  168. color: #c0c0c0;
  169. }
  170. .active-tab {
  171. color: #1d9bf0 !important;
  172. }
  173. .red-dots {
  174. position: absolute;
  175. right: 32%;
  176. top: 0px;
  177. }
  178. }
  179. }
  180. </style>