forked from UzTech/Vue3-typescript-demo
types
This commit is contained in:
@@ -24,10 +24,10 @@ const navList = ref<NavItem[]>([
|
||||
title: '查看区块',
|
||||
route: 'Block'
|
||||
},
|
||||
{
|
||||
title: '查看数据',
|
||||
route: 'Trade'
|
||||
},
|
||||
// {
|
||||
// title: '查看数据',
|
||||
// route: 'Trade'
|
||||
// },
|
||||
{
|
||||
title: 'Token',
|
||||
route: 'Token'
|
||||
@@ -43,10 +43,6 @@ const navList = ref<NavItem[]>([
|
||||
{
|
||||
title: '广播数据',
|
||||
route: 'Broadcast'
|
||||
},
|
||||
{
|
||||
title: '我的钱包',
|
||||
route: 'Wallet'
|
||||
}
|
||||
])
|
||||
const linkTo = (name: string) => {
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import { block } from '@/api'
|
||||
import vuex from '@/store'
|
||||
import { TotalFee } from '@/types/block'
|
||||
import { hexCharCodeToStr } from '@/utils/filters'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, ComputedRef, onActivated, ref } from 'vue'
|
||||
import { onBeforeRouteLeave } from 'vue-router'
|
||||
|
||||
export default () => {
|
||||
const maxHeight = computed(() => vuex.getters.maxHeight)
|
||||
const lastHash = computed(() => vuex.getters.lastHash)
|
||||
export default function (): {
|
||||
maxHeight: ComputedRef<number>;
|
||||
queryTotalFee: () => Promise<TotalFee>;
|
||||
lastHash: ComputedRef<string>;
|
||||
} {
|
||||
const maxHeight: ComputedRef<number> = computed(() => vuex.getters.maxHeight)
|
||||
const lastHash: ComputedRef<string> = computed(() => vuex.getters.lastHash)
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const interval = ref<NodeJS.Timeout | null>()
|
||||
|
||||
onMounted(() => {
|
||||
onActivated(() => {
|
||||
getLastHeader()
|
||||
console.log('开始轮询头信息')
|
||||
interval.value = setInterval(() => {
|
||||
@@ -23,8 +28,9 @@ export default () => {
|
||||
/**
|
||||
* 获取最新的区块
|
||||
*/
|
||||
const getLastHeader = () => {
|
||||
const getLastHeader = (): void => {
|
||||
block.getLastHeader().then(res => {
|
||||
console.log('获取最新区块', res.result.height)
|
||||
if (res.error) {
|
||||
clearInterval(Number(interval.value))
|
||||
return ElMessage.error({
|
||||
@@ -32,8 +38,6 @@ export default () => {
|
||||
offset: 300
|
||||
})
|
||||
} else if (maxHeight.value !== res.result.height) {
|
||||
console.log('获取最新区块', res.result.height)
|
||||
|
||||
vuex.dispatch('setMaxHeight', res.result.height).then()
|
||||
vuex.dispatch('setLastHash', res.result.hash).then()
|
||||
}
|
||||
@@ -43,7 +47,7 @@ export default () => {
|
||||
/**
|
||||
* 查询从交易量和交易费
|
||||
*/
|
||||
const queryTotalFee = () => {
|
||||
const queryTotalFee = (): Promise<TotalFee> => {
|
||||
return block.queryTotalFee(hexCharCodeToStr(lastHash.value))
|
||||
}
|
||||
|
||||
|
||||
@@ -99,17 +99,6 @@ export default [
|
||||
showTabBar: true
|
||||
},
|
||||
component: () => import(/* webpackChunkName: "other" */ '@/views/Token/index.vue')
|
||||
},
|
||||
{
|
||||
path: '/wallet',
|
||||
name: 'Wallet',
|
||||
meta: {
|
||||
title: '我的钱包',
|
||||
keepAlive: false,
|
||||
requiresAuth: true,
|
||||
showTabBar: true
|
||||
},
|
||||
component: () => import(/* webpackChunkName: "wallet" */ '@/views/Wallet/index.vue')
|
||||
},
|
||||
}
|
||||
] as MyRouteRecordRaw[]
|
||||
|
||||
|
||||
11
src/types/block.d.ts
vendored
11
src/types/block.d.ts
vendored
@@ -105,4 +105,13 @@ export declare type TradeItem = {
|
||||
tx: {
|
||||
to: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export declare type TotalFee = {
|
||||
error: string | null
|
||||
id: number
|
||||
result: {
|
||||
fee: number
|
||||
txCount: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
登录
|
||||
<button @click="onLogin">一键登录</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -14,7 +13,7 @@ const route = useRoute()
|
||||
const store = useStore()
|
||||
|
||||
const onLogin = () => {
|
||||
store.dispatch('auth/Login', { username: '15555555555', password: '123123' }).then(() => {
|
||||
store.dispatch('auth/Login', { username: '', password: '' }).then(() => {
|
||||
route.query.to ? router.replace({ path: route.query.to as string }) : router.replace({ name: 'Home' })
|
||||
}).catch(err => {
|
||||
alert(err.message)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<template>
|
||||
注册
|
||||
|
||||
<button @click="onRegister">注册一个号</button>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
@@ -71,6 +71,7 @@ const end = computed(() => {
|
||||
const blockList = ref([])
|
||||
|
||||
onMounted(() => {
|
||||
console.log('BLOCK INDEX')
|
||||
getBlockList()
|
||||
})
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<div class="trades">
|
||||
<div class="head">
|
||||
<h1>最新交易</h1>
|
||||
<router-link :to="{name: 'Trade'}">查看全部</router-link>
|
||||
<!-- <router-link :to="{name: 'Trade'}">查看全部</router-link>-->
|
||||
</div>
|
||||
|
||||
<div class="items" v-loading="tradeLoading">
|
||||
|
||||
@@ -31,10 +31,13 @@ export default {
|
||||
<script lang="ts" setup>
|
||||
import { Breadcrumb, Pagination } from '@/components'
|
||||
import useGetMaxHeight from '@/hooks/useGetMaxHeight'
|
||||
import { ref } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
const { queryTotalFee } = useGetMaxHeight()
|
||||
|
||||
onMounted(() => {
|
||||
console.log('TRADE onMounted')
|
||||
})
|
||||
const txCount = ref<number>(0)
|
||||
|
||||
queryTotalFee().then(res => {
|
||||
|
||||
Reference in New Issue
Block a user