import user from "@/core/models/user";
export default {
    namespaced: true,
    state: {
        showLoginModal: false,
        openId: "",
        token: "",
        info: {
            id: 0,
            avatar: "",
            nickname: "",
            openid: "",
            mobile: "",
            create_time: 0,
        },
    },
    getters: {
        isLogin(state) {
            return state.token && state.token.length > 0;
        },
    },
    mutations: {
        showLoginModal(state, data) {
            state.showLoginModal = data;
        },
        openId(state, data) {
            state.openId = data;
        },
        token(state, data) {
            state.token = data;
        },
        info(state, data) {
            state.info = data;
        }
    },
    actions: {
        info(context, refresh) {
            user.info(refresh).then(info => {
                context.commit('info', info);
            });
        },
        logout(context) {
            context.commit('info', null);
        },
    }
}
