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

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))
},
},
}