index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="nft-page-wrapper" ref="pageWrapperDom" @scroll="pageScroll">
  3. <div class="content" ref="pageListDom">
  4. <div class="item" v-for="(item, index) in listData" :key="index" @click="clickNFT(item)">
  5. <img :src="item.imagePath" class="img">
  6. <div class="name">{{ item.nftItemName }}</div>
  7. </div>
  8. </div>
  9. <join-group-finish-dialog :dialogVisible="joinGroupFinishShow" :position="'absolute'" :contentStyle="{
  10. width: '315px',
  11. }" :iconStyle="{ width: '80px', marginTop: '26px' }"
  12. :descStyle="{ marginTop: '24px', marginBottom: '25px', fontSize: '19px' }" @confirm="confirmFinish">
  13. </join-group-finish-dialog>
  14. </div>
  15. </template>
  16. <script setup>
  17. import { ref, onMounted, onBeforeUnmount } from "vue";
  18. import router from "@/router/popup.js";
  19. import { nftListMine } from "@/http/nft.js";
  20. import joinGroupFinishDialog from "@/view/components/join-group-finish-dialog.vue";
  21. let listData = ref([]);
  22. let NFTReqParams = {
  23. params: {
  24. pageNum: 1,
  25. pageSize: 30,
  26. },
  27. loadMore: false,
  28. };
  29. let pageWrapperDom = ref(null);
  30. let pageListDom = ref(null);
  31. let joinGroupFinishShow = ref(false);
  32. const clickNFT = (params) => {
  33. router.push({
  34. path: '/NFTDetail',
  35. query: {
  36. params: JSON.stringify(params)
  37. }
  38. })
  39. }
  40. const getNFTListMine = () => {
  41. nftListMine({
  42. params: NFTReqParams.params,
  43. }).then((res) => {
  44. if (res.data && res.data.length) {
  45. if (NFTReqParams.params.pageNum < 2) {
  46. listData.value = res.data;
  47. } else {
  48. let data = listData.value;
  49. data = data.concat(res.data);
  50. listData.value = data;
  51. }
  52. NFTReqParams.loadMore = false;
  53. }
  54. });
  55. }
  56. const pageScroll = (e) => {
  57. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  58. let pageListHeight = pageListDom.value.offsetHeight;
  59. let scrollTop = e.target.scrollTop || 0;
  60. if (
  61. NFTReqParams.loadMore === false &&
  62. wrapperHeight + scrollTop >= pageListHeight - 60
  63. ) {
  64. NFTReqParams.loadMore = true;
  65. NFTReqParams.params.pageNum++;
  66. getNFTListMine();
  67. }
  68. };
  69. const onMessage = () => {
  70. chrome.runtime.onMessage.addListener(msgListener);
  71. }
  72. const msgListener = (req, sender, sendResponse) => {
  73. ;
  74. switch (req.actionType) {
  75. case 'CONTENT_POPUP_PAGE_SHOW':
  76. getNFTListMine();
  77. showJoinFinishHandler(req.data);
  78. break;
  79. }
  80. }
  81. const showJoinFinishHandler = (params) => {
  82. let { path, showJoinGroupFinish } = params;
  83. if (path == '/NFT' && showJoinGroupFinish) {
  84. joinGroupFinishShow.value = true;
  85. } else if (joinGroupFinishShow.value) {
  86. joinGroupFinishShow.value = false;
  87. }
  88. }
  89. const confirmFinish = () => {
  90. joinGroupFinishShow.value = false;
  91. }
  92. onMounted(() => {
  93. onMessage();
  94. getNFTListMine();
  95. })
  96. onBeforeUnmount(() => {
  97. chrome.runtime.onMessage.removeListener(msgListener);
  98. })
  99. </script>
  100. <style scoped lang="scss">
  101. .nft-page-wrapper {
  102. width: 100%;
  103. height: 100%;
  104. overflow-y: auto;
  105. .content {
  106. width: 100%;
  107. display: flex;
  108. flex-wrap: wrap;
  109. padding: 5px 2px 0 16px;
  110. box-sizing: border-box;
  111. .item {
  112. width: 33%;
  113. box-sizing: border-box;
  114. padding-right: 14px;
  115. margin-top: 15px;
  116. cursor: pointer;
  117. .img {
  118. width: 100%;
  119. border-radius: 5px;
  120. height: 104px;
  121. object-fit: cover;
  122. }
  123. .name {
  124. font-weight: 400;
  125. font-size: 12px;
  126. margin-top: 6px;
  127. }
  128. }
  129. }
  130. }
  131. </style>