From d03cef96857319dacb7d5c62d992b6c5e4bb0773 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 30 Sep 2021 16:56:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Pagination.vue | 18 +-- src/views/Address/index.vue | 251 ++++++++++++++++++++-------------- 2 files changed, 156 insertions(+), 113 deletions(-) diff --git a/src/components/Pagination.vue b/src/components/Pagination.vue index 93100a6..14f460d 100644 --- a/src/components/Pagination.vue +++ b/src/components/Pagination.vue @@ -2,14 +2,16 @@

{{ title }}

- - + + + +
diff --git a/src/views/Address/index.vue b/src/views/Address/index.vue index f7ab188..523a2a9 100644 --- a/src/views/Address/index.vue +++ b/src/views/Address/index.vue @@ -60,73 +60,83 @@
- - + + @@ -138,12 +148,12 @@ import { useStore } from '@/store' import { AddrOverview, BlockDetail, TokenAssetItem } from '@/types/block' import { filterHash, parseSymbol } from '@/utils/filters' import { DArrowLeft, DArrowRight, Warning } from '@element-plus/icons' -import { computed, ref } from 'vue' +import { computed, onMounted, reactive, ref, watch } from 'vue' import { useRoute } from 'vue-router' const store = useStore() const route = useRoute() -const address = route.params.address as string +const address = computed(() => route.params.address as string) const pageSize = Number(process.env.VUE_APP_BLOCK_DETAIL_LIST_SIZE) const balance = ref({ @@ -151,61 +161,92 @@ const balance = ref({ reciver: 0, txCount: 0 }) - -/** - * 获取地址的基本信息 - */ -block.getAddrOverview(address).then(res => { - balance.value.balance = res.result.balance ? res.result.balance / 1e8 : 0 - balance.value.reciver = res.result.reciver ? res.result.reciver / 1e8 : 0 - balance.value.txCount = res.result.txCount ? res.result.txCount : 0 -}) - const sended = computed(() => balance.value.reciver - balance.value.balance) const frozen = ref(0) -/** - * 获取冻结的主代币 - */ -block.getAllExecBalance(address).then(res => { - if (res.result.execAccount) { - frozen.value = res.result.execAccount.find((item: { execer: string }) => item.execer == 'coins').account.frozen / 1e8 +const records = ref([]) +const token = ref('') +const assets = ref([]) +const loading = ref(false) + +watch(route, (to) => { + if (to.name == 'Address') { + records.value = [] + initAddressData() } }) -const records = ref([]) -/** - * 获取全部交易 - */ -block.getTxByAddr({ - addr: address, +onMounted(() => { + initAddressData() +}) + +const initAddressData = () => { + /** + * 获取地址的基本信息 + */ + block.getAddrOverview(address.value).then(res => { + balance.value.balance = res.result.balance ? res.result.balance / 1e8 : 0 + balance.value.reciver = res.result.reciver ? res.result.reciver / 1e8 : 0 + balance.value.txCount = res.result.txCount ? res.result.txCount : 0 + }) + /** + * 获取冻结的主代币 + */ + block.getAllExecBalance(address.value).then(res => { + if (res.result.execAccount) { + frozen.value = res.result.execAccount.find((item: { execer: string }) => item.execer == 'coins').account.frozen / 1e8 + } + }) + + block.getAddrTokenAssets(address.value, 'token').then(res => { + if (res.error == null) { + console.log(res) + assets.value = res.result.tokenAssets + } + }) + loadTradeList() +} + +const initParams = { + addr: address.value, flag: 0, count: pageSize, direction: 0, height: -1, - index: 1 -}).then(res => { - if (res.error == null) { - let hashes = res.result.txInfos.map((item: { hash: string }) => item.hash) - - block.getTxByHashes(hashes).then(res => { - records.value = res.result.txs - }) - } -}) - + index: 0 +} +const pageParams = reactive(initParams) const handleCurrentChange = (e: number) => { - console.log(e) + if (e === 1) { + pageParams.direction = 0 + pageParams.height = -1 + } else { + pageParams.direction = 0 + pageParams.height = records.value[records.value.length - 1].height + pageParams.index = records.value[records.value.length - 1].index + } + console.log(pageParams) + records.value = [] + loadTradeList() } -const token = ref('') -const assets = ref([]) +const loadTradeList = () => { + loading.value = true -block.getAddrTokenAssets(address, 'token').then(res => { - if (res.error == null) { - console.log(res) - assets.value = res.result.tokenAssets - } -}) + block.getTxByAddr(pageParams).then(res => { + if (res.error == null) { + let hashes = res.result.txInfos.map((item: { hash: string }) => item.hash) + + block.getTxByHashes(hashes).then(res => { + console.log(' pageParams.height ', pageParams.height) + records.value = res.result.txs + }).finally(() => { + loading.value = false + }) + } else { + loading.value = false + } + }) +}