From 64fa8dd4c4d9bc0c8b9766927b91c0be317826e4 Mon Sep 17 00:00:00 2001 From: yuyongdong Date: Thu, 4 Jul 2024 18:56:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9listing=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/assets/collectibles.vue | 7 +-- src/components/assets/trading.vue | 77 +++++++++++++---------- src/components/home/HeroCard.vue | 1 - src/components/marketplace/mktContent.vue | 21 ++++--- 4 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/components/assets/collectibles.vue b/src/components/assets/collectibles.vue index b7e2e1b..6031fa5 100644 --- a/src/components/assets/collectibles.vue +++ b/src/components/assets/collectibles.vue @@ -83,12 +83,8 @@ const getMyAssets = async () => { try { let nftListBox let res = await apiAssetsState(myADdress, data) - // nftList.value = Array.from(new Set([...res.rows, ...nftList.value].map(JSON.stringify))).map(JSON.parse); - nftList.value = [...res.rows, ...nftList.value] - // console.log(toRaw(nftList.value)) - // debugger + nftList.value = [...nftList.value, ...res.rows] nftListBox = nftList.value.reduce((acc, obj) => { - // console.log(acc,obj) const existingObj = acc.find(item => item.token_id == obj.token_id) if(!existingObj) { acc.push(obj) @@ -96,7 +92,6 @@ const getMyAssets = async () => { return acc },[]) nftList.value = nftListBox - // console.log(nftListBox) marketplaceStore.cursorObj = res.page next_cursor.value = res.page.next_cursor } catch(e) { diff --git a/src/components/assets/trading.vue b/src/components/assets/trading.vue index b69d96d..0a348aa 100644 --- a/src/components/assets/trading.vue +++ b/src/components/assets/trading.vue @@ -40,18 +40,36 @@ const statusChild = (val) => { getHistoryList() } -const next_cursor = ref() +const next_cursor = ref({ + type: 0, + page_size: '20', + cursor: '', + search_name: '', + total_count: 0, +}) const getHistoryList = async () => { const myADdress = localWalletStore.address const data = { type: statusValue.value, page_size: '20', - cursor: '', + cursor: next_cursor.value.next_cursor, search_name: overviewValue.value, } if(myADdress) { + let nftListBox let res = await apiHistoryState(myADdress,data) - for (let sub of res.rows) { + console.log(res) + next_cursor.value = res.page + nftList.value = [...nftList.value, ...res.rows] + nftListBox = nftList.value.reduce((acc, obj) => { + const existingObj = acc.find(item => item.nft.token_id == obj.nft.token_id) + if(!existingObj) { + acc.push(obj) + } + return acc + },[]) + // nftList.value = nftListBox + for (let sub of nftListBox) { if (sub.event?.data) { const _data = parseTradeEvent(sub.event) sub.event.icon = _data.icon @@ -61,35 +79,28 @@ const getHistoryList = async () => { sub.event.decimals = _data.decimals } } - nftList.value = res.rows + nftList.value = nftListBox } } -// const handleScroll = () => { -// const myADdress = localWalletStore.address -// var scrollTop = -// document.documentElement.scrollTop || document.body.scrollTop; //变量windowHeight是可视区的高度 -// var windowHeight = -// document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度 -// var scrollHeight = -// document.documentElement.scrollHeight || document.body.scrollHeight; -// if (scrollTop + windowHeight == scrollHeight) { -// //请求数据接口 -// // this.seeMoreSchoolList(); -// // console.log('scrollTop + windowHeight == scrollHeight请求接口',toRaw(marketplaceStore.cursorObj), scrollTop, windowHeight, scrollHeight) -// if(myADdress) { -// // if(toRaw(marketplaceStore.cursorObj).remaining != 0) { -// getHistoryList() -// console.log('请求') -// // // } else { -// // // console.log('不用请求') -// // } else { -// // return false; -// // } -// // return false; -// } -// } -// } +const handleScroll = () => { + const myADdress = localWalletStore.address + var scrollTop = + document.documentElement.scrollTop || document.body.scrollTop; //变量windowHeight是可视区的高度 + var windowHeight = + document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度 + var scrollHeight = + document.documentElement.scrollHeight || document.body.scrollHeight; + if (scrollTop + windowHeight == scrollHeight) { + //请求数据接口 + // this.seeMoreSchoolList(); + // console.log('scrollTop + windowHeight == scrollHeight请求接口',toRaw(marketplaceStore.cursorObj), scrollTop, windowHeight, scrollHeight) + if(next_cursor.value.remaining != 0) { + getHistoryList() + } + return false; + } +} watch(localWalletStore,() => { if(!localWalletStore.token) { @@ -101,12 +112,12 @@ watch(localWalletStore,() => { onMounted(() => { getHistoryList() - // window.addEventListener("scroll", handleScroll, true); + window.addEventListener("scroll", handleScroll, true); }) -// onUnmounted(() => { -// window.removeEventListener('scroll', handleScroll) -// }) +onUnmounted(() => { + window.removeEventListener('scroll', handleScroll) +})