diff --git a/src/i18n/zh-CN.js b/src/i18n/zh-CN.js index f81810f..51ad2b3 100644 --- a/src/i18n/zh-CN.js +++ b/src/i18n/zh-CN.js @@ -7,9 +7,9 @@ export default { errorMnemonic: '输入的密语无效', }, home: { - titleOwner: '账户', - titleNode: '节点', - titleNetwork: '网络', + titleOwner: '账户信息', + titleNode: '用户操作', + titleNetwork: '提现申请', titleChain: '数据', titleToken: '通证', titleMarket: '应用', diff --git a/src/router.js b/src/router.js index b860fad..fc2b7a4 100644 --- a/src/router.js +++ b/src/router.js @@ -5,10 +5,8 @@ import store from './store' import Home from './views/Home' import Login from './views/Login' import Owner from './views/Owner' -import Chain from './views/Chain' import Netnode from './views/Netnode' import Network from './views/Network' -import Market from './views/Market' Vue.use(Router) diff --git a/src/services/axios.js b/src/services/axios.js index cb06430..d0a9cf4 100644 --- a/src/services/axios.js +++ b/src/services/axios.js @@ -2,7 +2,7 @@ import axios from 'axios' // import app from './app' // let baseURL = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/api/` // let baseURL = `${location.protocol}//${location.hostname}:80/api/` -let baseURL = `http://server4test.vic.yuanjin.net/v1/` +let baseURL = `http://localhost:80/v1/` // 控制台应当默认访问控制台所在主机(localhost 或者 window.location.hostname)的 TIC后台,或者让用户在控制台启动时,自己设置一个节点主机。 axios.defaults.baseURL = baseURL diff --git a/src/store/modules/chain.js b/src/store/modules/chain.js deleted file mode 100644 index 4f294b3..0000000 --- a/src/store/modules/chain.js +++ /dev/null @@ -1,67 +0,0 @@ -import axios from 'axios' - -export default { - namespaced: true, - - state: { - pageEntity: [5, 10, 25], - headers: [ - { text: 'chain.thHeight', value: 'height', align: 'center' }, - { text: 'chain.thTimestamp', value: 'timestamp', align: 'center' }, - { text: 'chain.thType', value: 'type', align: 'center', sortable: false }, - { text: 'chain.thHash', value: 'hash', align: 'center' }, - ], - itemList: [ - { - height: 'loading', - timestamp: 'loading', - type: 'loading', - hash: 'loading', - }, - ], - fetching: false, - filter: '', - modal: false, - isConnected: false, - }, - - mutations: { - inputFilter(state, filter) { - state.filter = filter - }, - - showModal(state) { - state.modal = true - }, - - hideModal(state) { - state.modal = false - }, - - setItemList(state, blockList) { - state.itemList = blockList - }, - - addItem(state, block) { - let temp = [block] - state.itemList = temp.concat(state.itemList) - }, - - SOCKET_CONNECT(state, status) { - state.isConnected = true - }, - }, - - actions: { - async queryBlockList({ state, commit }) { - let result = await axios.post('Block/getBlockList', { config: { order: 'height DESC' } }) - commit('setItemList', result.data || []) - }, - addNewBlock({ state, commit }, block) { - console.log(block) - commit('addItem', JSON.parse(block)) - }, - }, - - getters: {}, -} diff --git a/src/store/modules/index.js b/src/store/modules/index.js index d2bedd3..01f25e3 100644 --- a/src/store/modules/index.js +++ b/src/store/modules/index.js @@ -1,6 +1,4 @@ -export { default as chain } from './chain' -export { default as market } from './market' -export { default as network } from './network' +export { default as network } from './network' export { default as netnode } from './netnode' export { default as owner } from './owner' export { default as login } from './login' diff --git a/src/store/modules/login.js b/src/store/modules/login.js index f717d43..7f4506a 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -4,32 +4,39 @@ import { i18n } from '../../i18n' import _ from 'lodash' import ticCrypto from 'tic.crypto' import axios from 'axios' +import * as Ticrypto from 'tic.crypto' export default { namespaced: true, state: { - user: '', + username: '', passwd: '', - errorMnemonic: '', + erroruser: '', signing: false, renewing: false, }, getters: { - inputError: state => !!state.errorMnemonic, + inputError: state => !!state.erroruser, }, mutations: { - updateMnemonic(state, mnemonic) { + updateUserName(state, username) { if (state.errorMnemonic) { state.errorMnemonic = '' } - state.mnemonic = mnemonic + state.username = username + }, + updatePasswd(state, passwd) { + if (state.errorMnemonic) { + state.errorMnemonic = '' + } + state.passwd = passwd }, updateError(state, error) { - state.errorMnemonic = error + state.erroruser = error }, updateSign(state, signing) { @@ -39,15 +46,17 @@ export default { actions: { async login({ state, commit }) { + console.log(state) commit('updateSign', true) - let result = await axios.post('admin/in', { name: 'jojo', passwd: '941411d944c479af9a5e9d29d7430722d90a8e34d9585014e2f2c12b21db143d' }) + const passwd = Ticrypto.hash(state.passwd) + let result = await axios.post('admin/in', { name: state.username, passwd }) commit('updateSign', false) - console.log(result.data) - if (result.code === 0) { - commit('updateAccount', 'xxx', { root: true }) + if (result.data.code === 0) { + commit('updateAccount', result.data.data, { root: true }) + commit('updatePasswd', '') router.push('/home') } else { - commit('updateError', '用户名或密码错误') + commit('updateError', result.data.msg) } }, async createSecword({ state, commit }) { diff --git a/src/store/modules/market.js b/src/store/modules/market.js deleted file mode 100644 index 50d191e..0000000 --- a/src/store/modules/market.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - namespaced: true, - state: {}, - mutations: {}, - actions: {}, - getters: {}, -} diff --git a/src/store/modules/netnode.js b/src/store/modules/netnode.js index 4edbdb0..a9426d0 100644 --- a/src/store/modules/netnode.js +++ b/src/store/modules/netnode.js @@ -1,58 +1,104 @@ import axios from 'axios' +import { app } from '../../services' +import { ticApi } from '../../services/api' export default { namespaced: true, + state: { pageEntity: [5, 10, 25], headers: [ - { text: 'netnode.thHeight', value: 'height', align: 'center' }, - { text: 'netnode.thType', value: 'type', align: 'center' }, - { text: 'netnode.thHash', value: 'hash', align: 'center' }, - { text: 'netnode.thTimestamp', value: 'timestamp', align: 'center' }, - // { text: 'netnode.thWinner', value: 'winnerPubkey', align: 'center' }, - { text: 'netnode.thPacker', value: 'packerPubkey', align: 'center' }, - { text: 'netnode.thRewardPacker', value: 'rewardPacker', align: 'center' }, + { text: '类型', value: 'type', align: 'center' }, + { text: '用户id', value: '_id', align: 'center' }, + { text: '资金类型', value: 'tokenType', align: 'center' }, + { text: '金额', value: 'amount', align: 'center' }, + { text: '创建时间', value: 'createdAt', align: 'center' }, ], - blockList: [ + itemList: [ { - height: 'loading', - timestamp: 'loading', type: 'loading', - hash: 'loading', - rewardPacker: 'loading', - winnerPubkey: 'loading', - packerPubkey: 'loading', + _id: 'loading', + tokenType: 'loading', + createdAt: 'loading', + amount: 'loading', }, ], - fetching: false, - filter: '', - modal: false, - ipAddress: '', + + userNumSum: 0, + }, mutations: { inputFilter(state, filter) { state.filter = filter }, - setIpAddress(state, ipAddress) { - state.ipAddress = ipAddress + + setUserNumSum(state, address) { + state.address = address }, - setBlockList(state, blockList) { - state.blockList = blockList + + setUserList(state, actions) { + state.itemList = actions }, }, actions: { - async updateNodeInfo({ state, commit }) { - let account = sessionStorage.getItem('KEY_ACCOUNT') - commit('setIpAddress', axios.defaults.baseURL) - try { - account = JSON.parse(account) - const myBlocks = await axios.post('Block/getBlockList', { - Block: { packerPubkey: account.pubkey }, - }) - commit('setBlockList', myBlocks && myBlocks.data ? myBlocks.data : []) - } catch (e) {} + async queryUserInfo({ state, commit }) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { userId, type = 0, op } = state + const result = await axios.post('admin/actions', { userId, type, op }, { headers: { token } }) + axios.post('admin/actions', { userId, type, op }, { headers: { token } }) + const arr = result.data && result.data.data || [] + commit('setUserList', arr) + }, + async performTransfer({ state, commit, rootState }) { + commit('updateSubmitting', true) + const { + targetAddress, + transferAmount, + transferFee, + // transferRemark, + } = state + let wrongAddress, wrongAmount, wrongFee + if (!(await ticApi.isAddress(targetAddress))) { + wrongAddress = '错误的地址' + } else { + wrongAddress = '' + } + if (!(+transferAmount > 0)) { + wrongAmount = '请输入正确的交易金额' + } else { + wrongAmount = '' + } + if (!(+transferFee > 0)) { + wrongFee = '请输入正确的手续费' + } else { + wrongFee = '' + } + commit('updateWrongAddress', wrongAddress) + commit('updateWrongAmount', wrongAmount) + commit('updateWrongFee', wrongFee) + if (wrongAddress || wrongAmount || wrongFee) { + commit('updateSubmitting', false) + return + } + + const res = await ticApi.transferTic({ + mnemonic: rootState.account.mnemonic, + to: targetAddress, + amount: +transferAmount, + fee: +transferFee, + }) + if (res) { + // success + commit('updateTransferResult', '转账成功') + await app.delay(1000) + commit('toggleTransferDlg', false) + } else { + // fail + commit('updateTransferResult', '转账失败') + } + commit('updateSubmitting', false) }, }, diff --git a/src/store/modules/network.js b/src/store/modules/network.js index 5094703..f8893fe 100644 --- a/src/store/modules/network.js +++ b/src/store/modules/network.js @@ -1,4 +1,6 @@ import axios from 'axios' +import { app } from '../../services' +import { ticApi } from '../../services/api' export default { namespaced: true, @@ -6,43 +8,43 @@ export default { state: { pageEntity: [5, 10, 25], headers: [ - { text: 'network.thIndex', value: 'index', align: 'center' }, - { text: 'network.thAccessPoint', value: 'accessPoint', align: 'center' }, - { text: 'network.thOwnerAddress', value: 'ownerAddress', align: 'center' }, - { text: 'network.thStatus', value: 'status', align: 'center' }, + { text: '类型', value: 'type', align: 'center' }, + { text: '用户id', value: 'userId', align: 'center' }, + { text: '状态', value: 'status', align: 'center' }, + { text: '目标地址', value: 'amount', align: 'center' }, + { text: '目标地址', value: 'targetAddress', align: 'center' }, + { text: '创建时间', value: 'createdAt', align: 'center' }, ], itemList: [ { - index: 'loading', - accessPoint: 'loading', - ownerAddress: 'loading', - status: 'loading', + type: 'loading', + _id: 'loading', + tokenType: 'loading', + createdAt: 'loading', + amount: 'loading', }, ], - fetching: false, - filter: '', - nodeNumber: 'unknown', }, mutations: { inputFilter(state, filter) { state.filter = filter }, - setNodeNumber(state, nodeNumber) { - state.nodeNumber = nodeNumber - }, - setItemList(state, nodeList) { - state.itemList = nodeList + + updateTickets(state, tickets) { + state.itemList = tickets }, }, actions: { - async updateNetInfo({ state, commit }) { - let result = await axios.post('Netnode/nodeStat', {}) - - commit('setNodeNumber', (result && result.data) ? result.data.length : 0) - - commit('setItemList', result.data || []) + async queryTickets({ state, commit }) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { userId, type = 0, op } = state + const result = await axios.post('admin/tickets', { userId, type, op }, { headers: { token } }) + axios.post('admin/tickets', { userId, type, op }, { headers: { token } }) + const arr = result.data && result.data.data || [] + console.log(arr) + commit('updateTickets', arr) }, }, diff --git a/src/store/modules/owner.js b/src/store/modules/owner.js index 7d5a39a..f7f1499 100644 --- a/src/store/modules/owner.js +++ b/src/store/modules/owner.js @@ -8,44 +8,21 @@ export default { state: { pageEntity: [5, 10, 25], headers: [ - { text: 'owner.thId', value: 'id', align: 'center' }, - { text: 'owner.thType', value: 'type', align: 'center' }, - { text: 'owner.thSender', value: 'sender', align: 'center' }, - { text: 'owner.thReceiver', value: 'receiver', align: 'center' }, - { text: 'owner.thDate', value: 'date', align: 'center' }, - { text: 'owner.thAmount', value: 'amount', align: 'center' }, - { text: 'owner.thFee', value: 'fee', align: 'center' }, - { text: 'owner.thRemark', value: 'remark', align: 'center' }, + { text: '用户id', value: 'id', align: 'center' }, + { text: '手机号', value: 'phone', align: 'center' }, + { text: '邀请人数', value: 'group', align: 'center' }, + { text: '持有vic', value: 'vic', align: 'center' }, ], itemList: [ { id: 'loading', - type: 'loading', - sender: 'loading', - receiver: 'loading', - date: 'loading', - amount: 'loading', - fee: 'loading', - remark: 'loading', + phone: 'loading', + group: 'loading', + vic: 'loading', }, ], - fetching: false, - filter: '', - balance: 0, - address: '', - transferVisible: false, - submitting: false, // 提交转账 - - targetAddress: '', - transferAmount: '', - transferFee: '', - transferRemark: '', - - wrongAddress: '', - wrongAmount: '', - wrongFee: '', - transferResult: '', + userNumSum: 0, }, mutations: { @@ -53,75 +30,24 @@ export default { state.filter = filter }, - setBalance(state, balance) { - state.balance = balance + setUserNumSum(state, sum) { + state.userNumSum = sum }, - setAddress(state, address) { - state.address = address - }, - - setActions(state, actions) { + setUserList(state, actions) { state.itemList = actions }, - - toggleTransferDlg(state, value) { - state.transferVisible = value - state.transferResult = '' - }, - - changeTargetAddress(state, value) { - state.targetAddress = value - }, - - changeTransferAmount(state, value) { - state.transferAmount = value - }, - - changeTransferFee(state, value) { - state.transferFee = value - }, - - changeTransferRemark(state, value) { - state.transferRemark = value - }, - - updateSubmitting(state, submitting) { - state.submitting = submitting - }, - - updateWrongAddress(state, msg) { - state.wrongAddress = msg - }, - - updateWrongAmount(state, msg) { - state.wrongAmount = msg - }, - - updateWrongFee(state, msg) { - state.wrongFee = msg - }, - - updateTransferResult(state, msg) { - state.transferResult = msg - }, }, actions: { - async updateOwnerInfo({ state, commit }) { - let account = sessionStorage.getItem('KEY_ACCOUNT') - try { - account = JSON.parse(account) - commit('setAddress', account.address) - const balance = await axios.post('Account/getBalance', { - Account: { address: account.address }, - }) - commit('setBalance', (balance && balance.data) ? balance.data : 0) - const actions = await axios.post('Action/getActionList', { - Action: { actorAddress: account.address }, - }) - commit('setActions', actions && actions.data ? actions.data : []) - } catch (e) {} + async queryUserInfo({ state, commit }) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { id, phone } = state + const result = await axios.post('admin/users', { id, phone }, { headers: { token } }) + const arr = result.data && result.data.data || [] + const sum = result.data && result.data.sum || 0 + commit('setUserList', arr) + commit('setUserNumSum', sum) }, async performTransfer({ state, commit, rootState }) { diff --git a/src/store/rootStore.js b/src/store/rootStore.js index a9e35c0..b89b69d 100644 --- a/src/store/rootStore.js +++ b/src/store/rootStore.js @@ -36,16 +36,16 @@ const sideMenus = [ icon: 'public', path: '/network', }, - { - title: 'home.titleChain', - icon: 'timeline', - path: '/chain', - }, - { - title: 'home.titleMarket', - icon: 'apps', - path: '/market', - }, + // { + // title: 'home.titleChain', + // icon: 'timeline', + // path: '/chain', + // }, + // { + // title: 'home.titleMarket', + // icon: 'apps', + // path: '/market', + // }, ] export default { @@ -58,7 +58,7 @@ export default { }, getters: { - isLogin: state => state.account.pubkey, + isLogin: state => state.account.token, currentPath: () => router.currentRoute.path, }, diff --git a/src/views/Chain.vue b/src/views/Chain.vue deleted file mode 100644 index 4448b6a..0000000 --- a/src/views/Chain.vue +++ /dev/null @@ -1,186 +0,0 @@ - - - - - diff --git a/src/views/Login.vue b/src/views/Login.vue index 1e9dd2f..041cfb1 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -9,11 +9,11 @@ dark autofocus single-line :error="inputError" - :error-messages="errorMnemonic" + :error-messages="erroruser" :value="user" :loading="signing" :renewing="renewing" - @input="updateMnemonic" + @input="updateUserName" label="用户名" /> @@ -72,7 +73,7 @@ export default { ...mapState([ 'user', 'passwd', - 'errorMnemonic', + 'erroruser', 'signing', 'renewing', ]), @@ -87,7 +88,8 @@ export default { methods: { ...mapMutations([ - 'updateMnemonic', + 'updateUserName', + 'updatePasswd' ]), ...mapActions([ 'login', diff --git a/src/views/Market.vue b/src/views/Market.vue deleted file mode 100644 index 1dc5e30..0000000 --- a/src/views/Market.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/src/views/Netnode.vue b/src/views/Netnode.vue index 83a9863..9ea3d29 100644 --- a/src/views/Netnode.vue +++ b/src/views/Netnode.vue @@ -1,15 +1,5 @@