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

    // 仓库
    state: {
        user:null,
        token:'',
        tokenExpires:'',
        uvId:'',
        init:false,
        userInfo:null,
        login:false,
    },

    // 同步方法
    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.visitor || null
            state.token = data.token || ''
            state.uvId = data.uvId || ''
            state.tokenExpires = data.tokenExpires || ''
            state.login = data.visitor.nickName ? true : false
            // state.init = true;
        },

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

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

export default module
