引入socket

This commit is contained in:
lulu
2018-10-23 16:07:51 +08:00
committed by Nova
parent 673e4a11b7
commit 9bedf5dccf
8 changed files with 59 additions and 29 deletions

View File

@@ -35,12 +35,12 @@ export default {
tableNone: '暂无数据',
},
chain: {
tableHeader: '区块列表',
tableHeader: 'Block List',
searchHolder: '请输入该输入的',
thHeight: '区块高度',
thTimestamp: '时间戳',
thType: '区块类型',
thId: '区块 ID',
thHeight: 'Height',
thTimestamp: 'Timestamp',
thType: 'Type',
thHash: 'Hash',
tableNone: '暂无数据',
},
}

View File

@@ -36,11 +36,11 @@ export default {
},
chain: {
tableHeader: '区块列表',
searchHolder: '输入该输入的',
searchHolder: '输入要查询的区块高度或者区块哈希',
thHeight: '区块高度',
thTimestamp: '时间戳',
thType: '区块类型',
thId: '区块 ID',
thHash: '区块哈希',
tableNone: '暂无数据',
},
}

View File

@@ -1,4 +1,4 @@
import axios from 'axios'
import app from './app'
axios.defaults.baseURL = app.dev ? 'http://localhost:6842/' : 'http://test-sg.bittic.net:6842/'
axios.defaults.baseURL = app.dev ? 'http://test-jp.bittic.net:6842/api/' : 'http://test-sg.bittic.net:6842/api/'

View File

@@ -1,3 +1,5 @@
import axios from 'axios'
export default {
namespaced: true,
@@ -7,19 +9,20 @@ export default {
{ text: 'chain.thHeight', value: 'height', align: 'center' },
{ text: 'chain.thTimestamp', value: 'timestamp', align: 'center' },
{ text: 'chain.thType', value: 'type', align: 'center' },
{ text: 'chain.thId', value: 'id', align: 'center' },
{ text: 'chain.thHash', value: 'hash', align: 'center' },
],
desserts: [
{
height: '1',
timestamp: '2011-11-20',
type: '0',
id: 'ajlk;gaklewklgjqwejj',
hash: 'null',
},
],
fetching: false,
filter: '',
modal: false,
isConnected: false,
},
mutations: {
@@ -34,9 +37,30 @@ export default {
hideModal(state) {
state.modal = false
},
updateDesserts(state, blockList) {
state.desserts = blockList
},
addDesserts(state, block) {
state.desserts.push(block)
},
SOCKET_CONNECT(state, status) {
state.isConnected = true
},
},
actions: {},
actions: {
async queryBlockList({ state, commit }) {
let result = await axios.post('Block/getBlockList', { config: { order: 'height DESC' } })
commit('updateDesserts', result.data || [])
},
addNewBlock({ state, commit }, block) {
console.log(block)
commit('addDesserts', JSON.parse(block))
},
},
getters: {},
}

View File

@@ -47,7 +47,7 @@ export default {
let account = sessionStorage.getItem('KEY_ACCOUNT')
try {
account = JSON.parse(account)
const result = await axios.post('api/Account/getBalance', {
const result = await axios.post('Account/getBalance', {
Account: { address: account.address },
})
commit('updateBalance', result.data || 0)

View File

@@ -36,7 +36,7 @@
<td>{{ props.item.height }}</td>
<td>{{ props.item.timestamp }}</td>
<td>{{ props.item.type }}</td>
<td>{{ props.item.id }}</td>
<td>{{ props.item.hash }}</td>
</template>
<template slot="no-results">
{{ $t('chain.tableNone') }}
@@ -64,7 +64,7 @@
<td>{{ props.item.height }}</td>
<td>{{ props.item.timestamp }}</td>
<td>{{ props.item.type }}</td>
<td>{{ props.item.id }}</td>
<td>{{ props.item.hash }}</td>
</template>
<template slot="no-results">
{{ $t('chain.tableNone') }}
@@ -85,17 +85,16 @@ import {
createNamespacedHelpers,
} from 'vuex'
import Vue from 'vue'
import store from '../store'
import VueSocketio from 'vue-socket.io'
import io from 'socket.io-client'
const { mapState, mapGetters, mapActions, mapMutations } = createNamespacedHelpers('chain')
Vue.use(VueSocketio, io('http://localhost:6842'), store)
export default {
name: 'Chain',
data(){
return {
blockList:[],
}
},
computed: {
...mapState([
'headers',
@@ -107,23 +106,28 @@ export default {
]),
...mapGetters([]),
},
created: async function(){
let result=await axios({
method:'post',
url:location.protocol+'//'+location.hostname+':6842/api/Block/getBlockList',
data: {config:{order:'height DESC'}}
})
this.blockList=result.data||[]
sockets: {
connect() {
console.log('socket connected')
},
newBlock(msg) {
this.addNewBlock(msg)
},
},
mounted() {
this.queryBlockList()
},
methods: {
...mapActions([
'queryBlockList',
'addNewBlock',
]),
...mapMutations([
'inputFilter',
'showModal',
'hideModal',
'addDesserts',
]),
},
}

View File

@@ -59,7 +59,6 @@ export default {
sideSelected: this.$route.path,
}
},
computed: {
...mapState([
'sideMenus',
@@ -71,7 +70,9 @@ export default {
'isLogin',
]),
},
mounted() {
},
methods: {
...mapMutations([
'updateRoute',