diff --git a/src/router.js b/src/router.js index 13ea784..4e3b7fd 100644 --- a/src/router.js +++ b/src/router.js @@ -4,9 +4,9 @@ import store from './store' import Home from './views/Home' import Login from './views/Login' -import Owner from './views/Owner' -import Netnode from './views/Netnode' -import Network from './views/Network' +import Users from './views/Users' +import Actions from './views/Actions' +import Tickets from './views/Tickets' Vue.use(Router) @@ -21,20 +21,20 @@ const router = new Router({ component: Login, }, { - path: 'owner', - component: Owner, + path: 'users', + component: Users, }, { - path: 'netnode', - component: Netnode, + path: 'actions', + component: Actions, }, { - path: 'network', - component: Network, + path: 'tickets', + component: Tickets, }, { path: '*', - redirect: 'owner', + redirect: 'users', }, ], }, diff --git a/src/store/modules/actions.js b/src/store/modules/actions.js new file mode 100644 index 0000000..79d27cd --- /dev/null +++ b/src/store/modules/actions.js @@ -0,0 +1,69 @@ +import axios from 'axios' +import { app } from '../../services' +import { ticApi } from '../../services/api' + +export default { + namespaced: true, + + state: { + pageEntity: [10, 20], + headers: [ + { 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' }, + ], + itemList: [ + { + type: 'loading', + _id: 'loading', + tokenType: 'loading', + createdAt: 'loading', + amount: 'loading', + }, + ], + + userNumSum: 0, + + }, + + mutations: { + inputFilter(state, filter) { + state.filter = filter + }, + + setUserNumSum(state, address) { + state.address = address + }, + + setUserList(state, actions) { + state.itemList = actions + }, + }, + + actions: { + async queryUserInfo({ state, commit }) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { userId, type = 0, op } = state + const pageSize = 20 + const pageIndex = 1 + const result = await axios.post('admin/actions', { query: { userId, type, op }, option: { pageSize, pageIndex } }, { headers: { token } }) + const arr = result.data && result.data.data || [] + commit('setUserList', arr) + }, + async nextPage({ state, commit }, event) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { page, rowsPerPage } = event + // commit('nextPage', page) + const { userId, type = 0, op } = state + const pageSize = rowsPerPage + const pageIndex = page + const result = await axios.post('admin/actions', { query: { userId, type, op }, option: { pageSize, pageIndex } }, { headers: { token } }) + const arr = result.data && result.data.data || [] + commit('setUserList', arr) + } + }, + + getters: {}, +} diff --git a/src/store/modules/index.js b/src/store/modules/index.js index 01f25e3..8336f12 100644 --- a/src/store/modules/index.js +++ b/src/store/modules/index.js @@ -1,4 +1,4 @@ -export { default as network } from './network' -export { default as netnode } from './netnode' -export { default as owner } from './owner' +export { default as network } from './tickets' +export { default as netnode } from './actions' +export { default as owner } from './users' export { default as login } from './login' diff --git a/src/store/modules/netnode.js b/src/store/modules/netnode.js deleted file mode 100644 index a9426d0..0000000 --- a/src/store/modules/netnode.js +++ /dev/null @@ -1,106 +0,0 @@ -import axios from 'axios' -import { app } from '../../services' -import { ticApi } from '../../services/api' - -export default { - namespaced: true, - - state: { - pageEntity: [5, 10, 25], - headers: [ - { 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' }, - ], - itemList: [ - { - type: 'loading', - _id: 'loading', - tokenType: 'loading', - createdAt: 'loading', - amount: 'loading', - }, - ], - - userNumSum: 0, - - }, - - mutations: { - inputFilter(state, filter) { - state.filter = filter - }, - - setUserNumSum(state, address) { - state.address = address - }, - - setUserList(state, actions) { - state.itemList = actions - }, - }, - - actions: { - 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) - }, - }, - - getters: {}, -} diff --git a/src/store/modules/owner.js b/src/store/modules/owner.js deleted file mode 100644 index 8237789..0000000 --- a/src/store/modules/owner.js +++ /dev/null @@ -1,55 +0,0 @@ -import axios from 'axios' -import { app } from '../../services' -import { ticApi } from '../../services/api' - -export default { - namespaced: true, - - state: { - pageEntity: [5, 10, 25], - headers: [ - { 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', - phone: 'loading', - group: 'loading', - vic: 'loading', - }, - ], - - userNumSum: 0, - }, - - mutations: { - inputFilter(state, filter) { - state.filter = filter - }, - - setUserNumSum(state, sum) { - state.userNumSum = sum - }, - - setUserList(state, actions) { - state.itemList = actions - }, - }, - - actions: { - 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) - }, - }, - - getters: {}, -} diff --git a/src/store/modules/network.js b/src/store/modules/tickets.js similarity index 66% rename from src/store/modules/network.js rename to src/store/modules/tickets.js index 8ba2243..a733b9b 100644 --- a/src/store/modules/network.js +++ b/src/store/modules/tickets.js @@ -6,7 +6,7 @@ export default { namespaced: true, state: { - pageEntity: [5, 10, 25], + pageEntity: [10, 20], headers: [ { text: '类型', value: 'type', align: 'center' }, { text: '用户id', value: 'userId', align: 'center' }, @@ -24,6 +24,7 @@ export default { amount: 'loading', }, ], + currentPage: 1, }, mutations: { @@ -34,6 +35,12 @@ export default { updateTickets(state, tickets) { state.itemList = tickets }, + nextPage(state, page) { + state.page = page + }, + setRowsPerPage(state, num) { + state.rowsPerPage = num + }, }, actions: { @@ -46,6 +53,17 @@ export default { const arr = result.data && result.data.data || [] commit('updateTickets', arr) }, + async nextPage({ state, commit }, event) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { page, rowsPerPage } = event + commit('nextPage', page) + const { userId, type = 0, op } = state + const pageSize = rowsPerPage + const pageIndex = page + const result = await axios.post('admin/tickets', { query: { userId, type, op }, option: { pageSize, pageIndex } }, { headers: { token } }) + const arr = result.data && result.data.data || [] + commit('updateTickets', arr) + } }, getters: {}, diff --git a/src/store/modules/users.js b/src/store/modules/users.js new file mode 100644 index 0000000..6503690 --- /dev/null +++ b/src/store/modules/users.js @@ -0,0 +1,90 @@ +import axios from 'axios' +import { app } from '../../services' +import { ticApi } from '../../services/api' + +export default { + namespaced: true, + + state: { + pageEntity: [10, 20], + headers: [ + { 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', + phone: 'loading', + group: 'loading', + vic: 'loading', + }, + ], + + userNumSum: 0, + itemSum: 100, + }, + + mutations: { + inputFilter(state, filter) { + state.filter = filter + }, + + setUserNumSum(state, sum) { + state.userNumSum = sum + }, + + setUserList(state, actions) { + state.itemList = actions + }, + }, + + actions: { + async queryUserInfo({ state, commit }) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { id, phone } = state + const pageSize = 20 + const pageIndex = 1 + const result = await axios.post('admin/users', { query: { id, phone }, option: { pageSize, pageIndex } }, { headers: { token } }) + const arr = result.data && result.data.data || [] + const sum = result.data && result.data.sum || 0 + commit('setUserList', arr) + commit('setUserNumSum', sum) + }, + async nextPage({ state, commit }, event) { + const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + const { page, rowsPerPage } = event + // commit('nextPage', page) + const pageSize = rowsPerPage + const pageIndex = page + const { id, phone } = state + const result = await axios.post('admin/users', { query: { id, phone }, option: { pageSize, pageIndex } }, { headers: { token } }) + const arr = result.data && result.data.data || [] + const sum = result.data && result.data.sum || 0 + commit('setUserList', arr) + commit('setUserNumSum', sum) + }, + async searchUser ({ state, commit }, event) { + // const { token } = JSON.parse(sessionStorage.getItem('KEY_ACCOUNT')) + // const { page, rowsPerPage } = event + console.log(state.filter) + try { + console.log(`{${state.filter.x}}`) + const query = JSON.parse(`{${state.filter}}`) + } catch (error) { + console.log(error) + alert('输入格式错误!') + } + // commit('nextPage', page) + // const pageSize = rowsPerPage + // const pageIndex = page + // const { id, phone } = state + // const result = await axios.post('admin/users', { query: { id, phone }, option: { pageSize, pageIndex } }, { headers: { token } }) + // const arr = result.data && result.data.data || [] + // commit('setUserList', arr) + }, + }, + + getters: {}, +} diff --git a/src/store/rootStore.js b/src/store/rootStore.js index b89b69d..98729f8 100644 --- a/src/store/rootStore.js +++ b/src/store/rootStore.js @@ -24,17 +24,17 @@ const sideMenus = [ { title: 'home.titleOwner', icon: 'group', - path: '/owner', + path: '/users', }, { title: 'home.titleNode', icon: 'all_inclusive', - path: '/netnode', + path: '/actions', }, { title: 'home.titleNetwork', icon: 'public', - path: '/network', + path: '/tickets', }, // { // title: 'home.titleChain', diff --git a/src/views/Netnode.vue b/src/views/Actions.vue similarity index 97% rename from src/views/Netnode.vue rename to src/views/Actions.vue index 9ea3d29..96cbe25 100644 --- a/src/views/Netnode.vue +++ b/src/views/Actions.vue @@ -19,6 +19,7 @@ :rows-per-page-items="pageEntity" :loading="fetching" class="panel-content elevation-1" + @update:pagination="nextPage" >