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 }