// 用户信息
const module = {
    // 开启命名空间
    namespaced: true,

    // 仓库
    state: {
        user:null,
        token:'',
        tokenExpires:'',
        init:false,
        openId:'',
        noPower:null,
    },

    // 同步方法
    mutations: {
        // 更新数据
        update(state, data) {
            for (let key in data) {
                if (data.hasOwnProperty(key)) {
                    state[key] = data[key]
                }
            }
        },

        // 移除数据
        remove(state, name) {
            if (typeof name === 'string') {
                delete state[name]
            } else {
                for (let key in name) {
                    if (name.hasOwnProperty(key)) {
                        delete state[name[key]]
                    }
                }
            }
        },

        // 登录处理
        login(state, data) {
            state.user = data || null
            state.token = data.token || ''
            state.tokenExpires = data.tokenExpires || ''
            state.openId = '';
            state.init = true;
            state.noPower = false;
        },

        // 退出登录处理
        logout(state) {
            state.user = null
            state.token =  ''
            state.tokenExpires =  ''
            state.openId = '';
            state.init = false;
            state.noPower = true;
        },
    },

    // 异步方法
    actions: {},
}

export default module
