Finish search bar

This commit is contained in:
liangping 2021-08-07 15:01:01 +08:00
parent 9d483c5a65
commit 6f7fcece61
3 changed files with 68 additions and 18 deletions

View File

@ -30,10 +30,11 @@
placeholder="Search Height/Transaction/Address" placeholder="Search Height/Transaction/Address"
autofocus autofocus
autocomplete="off" autocomplete="off"
@keyup.enter="doQuery"
/> />
<div <div
class="search-input-close" class="search-input-close"
@click="showSearchBar = false; resetsearchQuery()" @click="showSearchBar = false;"
> >
<feather-icon icon="XIcon" /> <feather-icon icon="XIcon" />
</div> </div>
@ -45,7 +46,7 @@
import { BFormInput } from 'bootstrap-vue' import { BFormInput } from 'bootstrap-vue'
import { ref } from '@vue/composition-api' import { ref } from '@vue/composition-api'
import { title } from '@core/utils/filter' import { title } from '@core/utils/filter'
import searchAndBookmarkData from '../search-and-bookmark-data' import store from '@/store'
export default { export default {
components: { components: {
@ -61,10 +62,34 @@ export default {
return { return {
showSearchBar, showSearchBar,
perfectScrollbarSettings, perfectScrollbarSettings,
searchAndBookmarkData,
title, title,
} }
}, },
data() {
return {
searchQuery: null,
}
},
methods: {
doQuery() {
const height = /^\d+$/
const txhash = /^[A-Z\d]{64}$/
const addr = /^[a-z]{2,6}1[a-z\d]{38}$/
const key = this.searchQuery
const c = store.state.chains.selected
if (!Object.values(this.$route.params).includes(key)) {
if (height.test(key)) {
this.$router.push({ name: 'block', params: { chain: c.chain_name, height: key } })
} else if (txhash.test(key)) {
this.$router.push({ name: 'transaction', params: { chain: c.chain_name, hash: key } })
} else if (addr.test(key)) {
// console.log('address', key)
}
}
// this.$router.push('/')
},
},
} }
</script> </script>

View File

@ -66,24 +66,36 @@ export default {
], ],
} }
}, },
beforeRouteUpdate(to, from, next) {
const { height } = to.params
if (height > 0 && height !== from.params.height) {
this.initData(height)
next()
}
},
created() { created() {
const { height } = this.$route.params const { height } = this.$route.params
this.$http.getBlockByHeight(height).then(res => { this.initData(height)
this.block = res },
const { txs } = res.block.data methods: {
const array = [] initData(height) {
for (let i = 0; i <= txs.length; i += 1) { this.$http.getBlockByHeight(height).then(res => {
try { this.block = res
const origin = decodeTxRaw(fromBase64(txs[i])) const { txs } = res.block.data
const tx = Tx.create(origin) const array = []
tx.setHash(txs[i]) for (let i = 0; i <= txs.length; i += 1) {
array.push(tx) try {
} catch (e) { const origin = decodeTxRaw(fromBase64(txs[i]))
const tx = Tx.create(origin)
tx.setHash(txs[i])
array.push(tx)
} catch (e) {
// catch errors // catch errors
}
} }
} if (array.length > 0) this.txs = array
if (array.length > 0) this.txs = array })
}) },
}, },
} }
</script> </script>

View File

@ -25,7 +25,10 @@
<b-tr> <b-tr>
<b-td> <b-td>
{{ 'height' }} {{ 'height' }}
</b-td><b-td>{{ tx.height }}</b-td> </b-td><b-td>
<router-link :to="`../blocks/${tx.height}`">
{{ tx.height }}
</router-link></b-td>
</b-tr> </b-tr>
<b-tr> <b-tr>
<b-td> <b-td>
@ -103,6 +106,16 @@ export default {
tx: { tx: {} }, tx: { tx: {} },
} }
}, },
beforeRouteUpdate(to, from, next) {
const { hash } = to.params
console.log(hash !== from.params.hash, hash, from.params)
if (hash !== from.params.hash) {
this.$http.getTxs(hash).then(res => {
this.tx = res
})
next()
}
},
created() { created() {
const { hash } = this.$route.params const { hash } = this.$route.params
this.$http.getTxs(hash).then(res => { this.$http.getTxs(hash).then(res => {