tabbar.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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, onBeforeUnmount } 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. import { getChromeStorage } from "@/uilts/chromeExtension";
  37. const props = defineProps({
  38. userInfo: {
  39. type: Object,
  40. default: () => {
  41. return {
  42. accessToken: undefined,
  43. };
  44. }
  45. },
  46. });
  47. watch(
  48. () => props.userInfo,
  49. (newVal) => {
  50. getNFTListMine();
  51. setMessageCount();
  52. },
  53. {
  54. deep: true
  55. }
  56. );
  57. let currentTab = ref({
  58. index: 0,
  59. path: '/'
  60. });
  61. let unReadCountTask = ref(0);
  62. let showNFTTab = ref(true);
  63. let tabbarData = ref([
  64. {
  65. name: "Wallet",
  66. path: "/",
  67. iconActive: require("@/assets/svg/icon-tab-wallet-active.svg"),
  68. iconInActive: require("@/assets/svg/icon-tab-wallet.svg"),
  69. },
  70. {
  71. name: "NFTs",
  72. path: "/NFT",
  73. iconActive: require("@/assets/svg/icon-tab-NFT-active.svg"),
  74. iconInActive: require("@/assets/svg/icon-tab-NFT.svg"),
  75. },
  76. {
  77. name: "Message",
  78. path: "/message",
  79. iconActive: require("@/assets/svg/icon-tab-message-active.svg"),
  80. iconInActive: require("@/assets/svg/icon-tab-message.svg"),
  81. },
  82. {
  83. name: "More",
  84. path: "/more",
  85. iconActive: require("@/assets/svg/icon-tab-more-active.svg"),
  86. iconInActive: require("@/assets/svg/icon-tab-more.svg"),
  87. },
  88. ]);
  89. let NFTReqParams = {
  90. params: {
  91. pageNum: 1,
  92. pageSize: 20,
  93. },
  94. };
  95. const emits = defineEmits(["tabbarClick"]);
  96. const tabbarHandler = (params, index) => {
  97. unReadCountTask.value = 0;
  98. setMessageCount();
  99. currentTab.value.index = index;
  100. currentTab.value.path = params.path;
  101. router.push(params.path);
  102. emits("tabbarClick", params);
  103. };
  104. const setActiveTab = () => {
  105. nextTick(() => {
  106. let path = router.currentRoute.value.path;
  107. let list = tabbarData.value;
  108. for (let i = 0; i < list.length; i++) {
  109. if (path == list[i].path) {
  110. currentTab.value.index = i;
  111. currentTab.value.path = path;
  112. break;
  113. }
  114. }
  115. })
  116. };
  117. const getNFTListMine = (params = {}) => {
  118. if(!props.userInfo.accessToken && !params.accessToken) return;
  119. nftListMine({
  120. params: NFTReqParams.params,
  121. }).then((res) => {
  122. if (res.data && res.data.length) {
  123. showNFTTab.value = true;
  124. } else {
  125. showNFTTab.value = false;
  126. }
  127. });
  128. };
  129. const setMessageCount = () => {
  130. if(!props.userInfo.accessToken) return;
  131. getAllMessageInfo({params: {
  132. }}).then(res => {
  133. if(res.code == 0) {
  134. let {unReadCountTotal = 0, unReadCountWalletDetail = 0, unReadCountTaskLuckdrop = 0} = res.data;
  135. unReadCountTask.value = unReadCountTaskLuckdrop;
  136. if(unReadCountTotal > 0) {
  137. let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal+'';
  138. setBadgeInfo({data: {text}});
  139. } else {
  140. hideBadge();
  141. }
  142. }
  143. });
  144. }
  145. const onMessage = () => {
  146. chrome.runtime.onMessage.addListener(msgListener)
  147. }
  148. const msgListener = (req, sender, sendResponse) => {
  149. sendResponse('');
  150. switch (req.actionType) {
  151. case 'CONTENT_POPUP_PAGE_SHOW':
  152. init();
  153. getNFTListMine();
  154. break;
  155. }
  156. }
  157. const init = () => {
  158. setActiveTab();
  159. setMessageCount();
  160. }
  161. const onPageVisbile = () => {
  162. document.addEventListener('visibilitychange', function () {
  163. let isHidden = document.hidden;
  164. if (!isHidden) {
  165. setTimeout(() => {
  166. getUserInfo((res) => {
  167. getNFTListMine(res);
  168. })
  169. }, 1200);
  170. }
  171. });
  172. }
  173. const getUserInfo = (cb) => {
  174. getChromeStorage("userInfo", (res) => {
  175. cb && cb(res || {});
  176. });
  177. };
  178. onMounted(() => {
  179. onMessage();
  180. init();
  181. });
  182. onBeforeUnmount(() => {
  183. chrome.runtime.onMessage.removeListener(msgListener);
  184. })
  185. </script>
  186. <style scoped lang="scss">
  187. .tab-bar-wrappeer {
  188. background: #ffffff;
  189. box-shadow: inset 0px 1px 0px #ececec;
  190. width: 100%;
  191. height: 70px;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. position: absolute;
  196. z-index: 1000;
  197. bottom: 0px;
  198. cursor: pointer;
  199. .tab-item {
  200. flex: 1;
  201. text-align: center;
  202. position: relative;
  203. .text {
  204. font-size: 12px;
  205. color: #c0c0c0;
  206. }
  207. .active-tab {
  208. color: #1d9bf0 !important;
  209. font-weight: 500;
  210. }
  211. .red-dots {
  212. position: absolute;
  213. right: 32%;
  214. top: 0px;
  215. }
  216. }
  217. }
  218. </style>