This commit is contained in:
saplf
2018-09-29 21:33:23 +08:00
parent 0a2c4e30de
commit be7755c0f3
40 changed files with 936 additions and 73 deletions

View File

@@ -1,8 +0,0 @@
import Vuex from 'vuex'
export default new Vuex.Store({
state: {},
mutations: {},
actions: {},
getters: {},
})

View File

@@ -1,17 +1,27 @@
import Vue from 'vue'
import Vuex from 'vuex'
import chain from './chain'
import market from './market'
import network from './network'
import owner from './owner'
import * as modules from './modules'
import { app } from '../services'
import rootStore from './rootStore'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
chain,
owner,
market,
network,
},
/**
* @type {Store}
*/
const store = new Vuex.Store({
modules: { ...modules },
strict: app.dev,
...rootStore,
})
if (module.hot) {
module.hot.accept(['./modules'], () => {
const newModules = require('./modules')
store.hotUpdate({
modules: { ...newModules },
})
})
}
export default store

View File

@@ -0,0 +1,8 @@
export default {
namespaced: true,
state: {
},
mutations: {},
actions: {},
getters: {},
}

View File

@@ -0,0 +1,6 @@
export { default as chain } from './chain'
export { default as market } from './market'
export { default as network } from './network'
export { default as node } from './node'
export { default as owner } from './owner'
export { default as login } from './login'

View File

@@ -0,0 +1,50 @@
import { ticApi } from '../../services'
import router from '../../router'
import { i18n } from '../../i18n'
import _ from 'lodash'
export default {
namespaced: true,
state: {
mnemonic: '',
errorMnemonic: '',
signing: false,
},
getters: {
inputError: state => !!state.errorMnemonic,
},
mutations: {
updateMnemonic(state, mnemonic) {
if (state.errorMnemonic) {
state.errorMnemonic = ''
}
state.mnemonic = mnemonic
},
updateError(state, error) {
state.errorMnemonic = error
},
updateSign(state, signing) {
state.signing = signing
},
},
actions: {
async login({ state, commit }) {
commit('updateSign', true)
const account = (await ticApi.secword2Account(state.mnemonic)) || {}
console.log(account)
commit('updateSign', false)
if (await ticApi.isAddress(account.address)) {
commit('updateAccount', _.omit(account, 'seckey'), { root: true })
router.push('/owner')
} else {
commit('updateError', i18n.t('login.errorMnemonic'))
}
},
},
}

View File

@@ -1,8 +1,7 @@
import Vuex from 'vuex'
export default new Vuex.Store({
export default {
namespaced: true,
state: {},
mutations: {},
actions: {},
getters: {},
})
}

View File

@@ -1,8 +1,7 @@
import Vuex from 'vuex'
export default new Vuex.Store({
export default {
namespaced: true,
state: {},
mutations: {},
actions: {},
getters: {},
})
}

View File

@@ -1,8 +1,7 @@
import Vuex from 'vuex'
export default new Vuex.Store({
export default {
namespaced: true,
state: {},
mutations: {},
actions: {},
getters: {},
})
}

View File

@@ -1,8 +1,7 @@
import Vuex from 'vuex'
export default new Vuex.Store({
export default {
namespaced: true,
state: {},
mutations: {},
actions: {},
getters: {},
})
}

96
src/store/rootStore.js Normal file
View File

@@ -0,0 +1,96 @@
import { storage } from '../services'
import { loadLanguageAsync } from '../i18n'
import router from '../router'
const KEY_ACCOUNT = 'KEY_ACCOUNT'
function retrieveAccount() {
try {
return JSON.parse(sessionStorage.getItem(KEY_ACCOUNT))
} catch (e) {
return {}
}
}
function storeAccount(account) {
sessionStorage.setItem(KEY_ACCOUNT, JSON.stringify(account))
}
function clearAccount() {
sessionStorage.removeItem(KEY_ACCOUNT)
}
const sideMenus = [
{
title: 'home.titleOwner',
icon: 'group',
path: '/owner',
},
{
title: 'home.titleChain',
icon: 'public',
path: '/chain',
},
{
title: 'home.titleNode',
icon: 'all_inclusive',
path: '/node',
},
{
title: 'home.titleNetwork',
icon: 'language',
path: '/network',
},
{
title: 'home.titleMarket',
icon: 'apps',
path: '/market',
},
]
export default {
state: {
account: retrieveAccount() || {},
supportLangs: storage.supportLangs,
currentLang: storage.currentLanguage,
sideMenus,
sideCollapsed: false,
},
getters: {
isLogin: state => state.account.pubkey,
currentPath: () => router.currentRoute.path,
},
mutations: {
updateCurrentLang(state, lang) {
state.currentLang = lang
},
updateAccount(state, account) {
state.account = account || {}
storeAccount(state.account)
},
updateRoute(_, destination) {
router.push(destination)
},
toggleCollapse(state) {
state.sideCollapsed = !state.sideCollapsed
},
logout(state) {
state.account = {}
clearAccount()
router.push('/login')
},
},
actions: {
async updateCurrentLang({ commit }, lang) {
commit('updateCurrentLang', await loadLanguageAsync(lang))
},
},
}