From 33dc44c4c7ef26778ad8ab50009e420af46e9360 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 29 Sep 2021 18:09:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=9C=80=E6=96=B0=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E7=9A=84=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useGetMaxHeight.ts | 7 +-- src/views/Home/index.vue | 101 ++++++++++++++++++++++++----------- src/views/Token/index.vue | 8 ++- src/views/Trade/detail.vue | 1 - 4 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/hooks/useGetMaxHeight.ts b/src/hooks/useGetMaxHeight.ts index 5196d0c..7b73bbb 100644 --- a/src/hooks/useGetMaxHeight.ts +++ b/src/hooks/useGetMaxHeight.ts @@ -1,9 +1,10 @@ import { block } from '@/api' import vuex from '@/store' import { ElMessage } from 'element-plus' -import { computed, onBeforeUnmount, onMounted, ref } from 'vue' +import { computed, onMounted, ref } from 'vue' +import { onBeforeRouteLeave } from 'vue-router' -export default function () { +export default () => { const maxHeight = computed(() => vuex.getters.maxHeight) // eslint-disable-next-line no-undef @@ -29,7 +30,7 @@ export default function () { }) } - onBeforeUnmount(() => { + onBeforeRouteLeave(() => { clearInterval(Number(interval.value)) }) diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index 690d40b..b084956 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -33,12 +33,37 @@ 查看全部 -
+
- {{ item.from }} - {{ item.to }} - {{ item.hash }} - {{ item.feefmt }} +
+
+ 交易哈希: + + {{ filterHash(item.txHash, 10) }} + +
+
+ +
+
+
+
+ 发送方: + + {{ filterHash(item.fromAddr, 10) }} + +
+
+ 接收方: + + {{ filterHash(item.tx.to, 10) }} + +
+
+
+
交易资产
+
{{ item.amount }} {{ parseSymbol(item.assets) }}
+
@@ -56,7 +81,7 @@ import { block } from '@/api' import { Banner, TimeFormat } from '@/components' import useGetMaxHeight from '@/hooks/useGetMaxHeight' import { BlockItem } from '@/types/block' -import { filterHash } from '@/utils/filters' +import { filterHash, parseSymbol } from '@/utils/filters' import { onMounted, ref, watch } from 'vue' import { useRouter } from 'vue-router' @@ -65,6 +90,7 @@ const { maxHeight } = useGetMaxHeight() const pageSize = Number(process.env.VUE_APP_HOME_LIST_SIZE) const blockLoading = ref(true) +const tradeLoading = ref(true) onMounted(() => { getBlockList() @@ -96,31 +122,30 @@ const getBlockList = () => { block.getHeaders(start, maxHeight.value, false).then(res => { blockList.value = res.result.items.reverse() + getTradeList() }).finally(() => { blockLoading.value = false }) - // block.getBlocks(start, maxHeight.value, false).then(res => { - // res.result.items.reverse().forEach((item) => { - // - // blockList.value.push({ - // height: item.block.height, - // blockTime: item.block.blockTime, - // txCount: item.block.txs.length, - // // hash: block.getBlockHash(item.block.height) - // }) - // - // // block.getBlockHash(item.block.height).then(hash => { - // // blockList.value.push({ - // // height: item.block.height, - // // blockTime: item.block.blockTime, - // // txCount: item.block.txs.length, - // // hash: hash.result.hash - // // }) - // // }) - // tradeList.value.push(...item.block.txs) - // console.log(tradeList.value) - // }) - // }) +} + +async function getTradeList () { + let txHashes = [] + for (let i = 0; i < blockList.value.length; i++) { + let res = await block.getBlockOverview(blockList.value[i].hash) + txHashes.push(...res.result.txHashes) + + if (txHashes.length > pageSize) { + txHashes = txHashes.slice(0, 6) + break + } + } + + block.getTxByHashes(txHashes).then(res => { + console.log(res.result.txs) + tradeList.value = res.result.txs + }).finally(() => { + tradeLoading.value = false + }) } @@ -161,6 +186,10 @@ const getBlockList = () => { height: 90px; padding: 16px; display: flex; + + .time { + color: #9ea2a9; + } } } } @@ -198,18 +227,26 @@ const getBlockList = () => { .num { color: #6368de; + margin-right: 16px; } - .time { - margin-left: 16px; - color: #9ea2a9; - } } } } .trades { + .item { + justify-content: space-between; + + .hash, + .addr, + .asset { + display: flex; + flex-direction: column; + justify-content: space-between; + } + } } } diff --git a/src/views/Token/index.vue b/src/views/Token/index.vue index 5ee7a86..9b9367e 100644 --- a/src/views/Token/index.vue +++ b/src/views/Token/index.vue @@ -16,7 +16,11 @@ - + + +