import * as types from '../mutation-types' const state = { btnCode: getBtnCode(), } const mutations = { getBtnObj(state, btnCodeObj) { // 登录成功后获取--按钮权限 state.btnCode = btnCodeObj; }, } const getters = { btnCode: state => state.btnCode } const actions = { actionsBtnList({ commit }, btnlist) { commit('getBtnObj', setBtnList(btnlist)) }, } // 按钮--权限 function setBtnList(list) { // 解决刷新后才出现按钮--权限的数据 let codeObj = { '100010': btnCode('100010', list), // xxx按钮code码; } sessionStorage.setItem('btnObj', JSON.stringify(codeObj)); let btnCodeObj = JSON.parse(sessionStorage.getItem('btnObj')) || {} return btnCodeObj } function getBtnCode() { return sessionStorage.getItem('btnObj') ? JSON.parse(sessionStorage.getItem('btnObj')) : {} } function btnCode(code, list) { // console.log(list,'按钮list') return list.findIndex(e => { return e.buttonCode == code }) } export default { state, mutations, getters, actions }