|
|
@ -53,6 +53,10 @@ import { useRouter } from 'vue-router' |
|
|
|
import { getFindTransactionListPage } from '@src/api/TransactionsController' |
|
|
|
import { middleDecimal, timeConvert } from '@src/utils/string' |
|
|
|
|
|
|
|
const props = defineProps({ |
|
|
|
isBlockWs: Boolean as any, |
|
|
|
}) |
|
|
|
|
|
|
|
const invariable = { |
|
|
|
...transactTableCollocate, |
|
|
|
pageSize: 10, // 每一页的数量 |
|
|
@ -66,6 +70,7 @@ const paginationState = reactive({ |
|
|
|
let currentPage = ref(1) // 当前页 |
|
|
|
let currentData = ref() // 当前页的数据 |
|
|
|
let loading = ref(true) // 骨架屏加载 |
|
|
|
let ws = ref<WebSocket>() // websocket |
|
|
|
// 请求数据 |
|
|
|
const initBlock = async (page: number) => { |
|
|
|
const params = { |
|
|
@ -86,12 +91,45 @@ const initBlock = async (page: number) => { |
|
|
|
gasPrice: middleDecimal(item?.gasPrice), |
|
|
|
isSuccess: item?.status === '0x1', |
|
|
|
result: item?.status === '0x1' ? 'Success' : 'Faild', |
|
|
|
// middleDecimal |
|
|
|
timestamp: timeConvert(item?.timestamp), |
|
|
|
})) |
|
|
|
// 骨架屏隐藏 |
|
|
|
loading.value = false |
|
|
|
} |
|
|
|
|
|
|
|
// 初始化websocket连接 |
|
|
|
const initWebSocket = () => { |
|
|
|
ws.value = new WebSocket('ws://wallet-chaindata-api.weirui0755.com/websocket') |
|
|
|
|
|
|
|
ws.value.addEventListener('open', () => { |
|
|
|
ws.value?.send(JSON.stringify({ type: 'add_transaction' })) |
|
|
|
}) |
|
|
|
|
|
|
|
ws.value.onmessage = (e: any) => { |
|
|
|
try { |
|
|
|
const res = JSON.parse(e.data) |
|
|
|
const item = res.value[0] |
|
|
|
const value = { |
|
|
|
...item, |
|
|
|
hash: middleDecimal(item?.hash), |
|
|
|
txnHash: item.hash, |
|
|
|
from: middleDecimal(item?.from), |
|
|
|
to: middleDecimal(item?.to), |
|
|
|
gasPrice: middleDecimal(item?.gasPrice), |
|
|
|
isSuccess: item?.status === '0x1', |
|
|
|
result: item?.status === '0x1' ? 'Success' : 'Faild', |
|
|
|
timestamp: timeConvert(item?.timestamp), |
|
|
|
} |
|
|
|
currentData.value = [value, ...currentData.value] |
|
|
|
currentData.value.length = 10 |
|
|
|
} catch (error) {} |
|
|
|
} |
|
|
|
|
|
|
|
ws.value.onclose = () => { |
|
|
|
console.log('ws 已关闭') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 监听分页更新 -> 请求数据 |
|
|
|
watchEffect(() => { |
|
|
|
// 如果屏幕尺寸小于1440px 则不执行 |
|
|
@ -100,6 +138,13 @@ watchEffect(() => { |
|
|
|
} |
|
|
|
loading.value = true |
|
|
|
initBlock(currentPage.value) |
|
|
|
if (props?.isBlockWs && currentPage.value === 1) { |
|
|
|
console.log('start ws') |
|
|
|
initWebSocket() |
|
|
|
} else { |
|
|
|
console.log('close ws') |
|
|
|
ws.value?.close() |
|
|
|
} |
|
|
|
}) |
|
|
|
// 路由跳转 |
|
|
|
const routerLink = (id: string | number) => id && router.push(`/tx/${id}`) |
|
|
|