From 4b2ce62cea395394f7f1c7ffda0315369e7d2d67 Mon Sep 17 00:00:00 2001 From: zhangdongxue Date: Wed, 29 Sep 2021 21:37:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=AE=A1=E7=AE=97trades?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/api/interfaces/block.ts | 2 +- src/hooks/useGetMaxHeight.ts | 5 ++++- src/store/index.ts | 17 ++++++++++++++--- src/types/block.d.ts | 11 +++++++++++ src/utils/filters.ts | 32 ++++++++++++++++++++++++++++++++ src/views/Home/index.vue | 26 +++++++++++++++++++++----- src/views/Trade/index.vue | 17 ++++++++++++++--- yarn.lock | 5 +++++ 9 files changed, 103 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 7f9d899..8631da1 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@element-plus/icons": "^0.0.11", "axios": "^0.21.4", "element-plus": "^1.1.0-beta.16", + "js-base64": "^3.7.2", "vue": "^3.2.11", "vue-router": "^4.0.11", "vuex": "^4.0.2", diff --git a/src/api/interfaces/block.ts b/src/api/interfaces/block.ts index 0d98977..bf750fc 100644 --- a/src/api/interfaces/block.ts +++ b/src/api/interfaces/block.ts @@ -1,3 +1,3 @@ import Chain33Rpc from '@33cn/chain33-rpc-api' -export default new Chain33Rpc('http://47.100.214.15:8080/api', null) +export default new Chain33Rpc('https://explorer.lianshang.vip/api', null) diff --git a/src/hooks/useGetMaxHeight.ts b/src/hooks/useGetMaxHeight.ts index 7b73bbb..d4241b2 100644 --- a/src/hooks/useGetMaxHeight.ts +++ b/src/hooks/useGetMaxHeight.ts @@ -6,6 +6,7 @@ import { onBeforeRouteLeave } from 'vue-router' export default () => { const maxHeight = computed(() => vuex.getters.maxHeight) + const lastHash = computed(() => vuex.getters.lastHash) // eslint-disable-next-line no-undef const interval = ref() @@ -26,6 +27,7 @@ export default () => { }) } else if (maxHeight.value !== res.result.height) { vuex.dispatch('setMaxHeight', res.result.height).then() + vuex.dispatch('setLastHash', res.result.hash).then() } }) } @@ -35,6 +37,7 @@ export default () => { }) return { - maxHeight + maxHeight, + lastHash } } diff --git a/src/store/index.ts b/src/store/index.ts index 654dae9..2451025 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -17,6 +17,7 @@ export interface State { openId: string loginAt: number maxHeight: number + lastHash: string user: BaseInfo auth?: AuthState refresh?: RefreshState @@ -31,6 +32,7 @@ export default createStore({ openId: '', loginAt: 0, maxHeight: 0, + lastHash: '', user: {} as BaseInfo }, getters: { @@ -48,6 +50,9 @@ export default createStore({ }, symbol: (): string => { return process.env.VUE_APP_MAIN_COIN_SYMBOL as string + }, + lastHash: (state: State): string => { + return state.lastHash } }, mutations: { @@ -74,17 +79,23 @@ export default createStore({ }, setMaxHeight: (state: State, height: number): void => { state.maxHeight = height + }, + setLastHash: (state: State, hash: string): void => { + state.lastHash = hash } }, actions: { - setUserInfo: ({ commit }, info: BaseInfo): void => { + setUserInfo: ({commit}, info: BaseInfo): void => { commit('setUserInfo', info) }, - setOpenId: ({ commit }, openId: string): void => { + setOpenId: ({commit}, openId: string): void => { commit('setOpenId', openId) }, - setMaxHeight: ({ commit }, height: number): void => { + setMaxHeight: ({commit}, height: number): void => { commit('setMaxHeight', height) + }, + setLastHash: ({commit}, hash: string): void => { + commit('setLastHash', hash) } }, modules: { diff --git a/src/types/block.d.ts b/src/types/block.d.ts index fa5f65f..ab6a5a8 100644 --- a/src/types/block.d.ts +++ b/src/types/block.d.ts @@ -95,3 +95,14 @@ export declare type BlockDetail = { tyName: string } } + +export declare type TradeItem = { + txHash: string + blockTime: number + fromAddr: string + amount: number + assets: any + tx: { + to: string + } +} \ No newline at end of file diff --git a/src/utils/filters.ts b/src/utils/filters.ts index 26ca5b1..c947019 100644 --- a/src/utils/filters.ts +++ b/src/utils/filters.ts @@ -28,3 +28,35 @@ export const timestampToTime = (timestamp: number) => { const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds() return Y + M + D + h + m + s } + +export function bin2hex(str:string):string { + let ret = '' + const r = /[0-9a-zA-Z_.~!*()]/ + for (let i = 0, l = str.length; i < l; i++) { + if (r.test(str.charAt(i))) { + ret += str.charCodeAt(i).toString(16); + console.log(ret) + } else { + ret += encodeURIComponent(str.charAt(i)).replace(/%/g, ''); + } + } + return ret; +} + +export const hex2bin = (str: string): string => { + let ret = '' + let tmp = '' + for (let i = 0; i < str.length - 1; i += 2) { + const c = String.fromCharCode(parseInt(str.substr(i, 2), 16)) + if (c.charCodeAt(1) > 127) { + tmp += '%' + str.substr(i, 2); + if (tmp.length == 9) { + ret += decodeURIComponent(tmp); + tmp = ''; + } + } else { + ret += c; + } + } + return ret; +} diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index b084956..bc8605f 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -80,7 +80,7 @@ export default { import { block } from '@/api' import { Banner, TimeFormat } from '@/components' import useGetMaxHeight from '@/hooks/useGetMaxHeight' -import { BlockItem } from '@/types/block' +import { BlockItem, TradeItem } from '@/types/block' import { filterHash, parseSymbol } from '@/utils/filters' import { onMounted, ref, watch } from 'vue' import { useRouter } from 'vue-router' @@ -103,20 +103,36 @@ watch(maxHeight, (newValue, oldValue) => { }) const blockList = ref([]) -const tradeList = ref([]) +const tradeList = ref([]) if (blockList.value.length === 0) { - let initBlock = { + const initBlock = { height: 0, - hash: 'x', + hash: ' ', txCount: 0, blockTime: 0 - } + } as BlockItem for (let i = 0; i < 6; i++) { blockList.value.push(initBlock) } } +if (tradeList.value.length === 0) { + const initTrade = { + txHash: ' ', + blockTime: 0, + fromAddr: ' ', + amount: 0, + assets: null, + tx: { + to: ' ' + } + } as TradeItem + for (let i = 0; i < 6; i++) { + tradeList.value.push(initTrade) + } +} + const getBlockList = () => { const start = maxHeight.value - pageSize + 1 > 0 ? maxHeight.value - pageSize + 1 : 0 diff --git a/src/views/Trade/index.vue b/src/views/Trade/index.vue index f39fb36..96a3836 100644 --- a/src/views/Trade/index.vue +++ b/src/views/Trade/index.vue @@ -25,11 +25,22 @@