import { observable } from 'mobx'

export interface UserInfoStore {
    isAuth: boolean,//是否授权获取头像信息,
    isVip: boolean,//是否是vip
    userInfo: {
        openId: string,
        nickname: string,
        avatarUrl: string
        vipExpireTime: string,//会员结束时间
        coinNum: number,//书币
    } | null,
    setData: (data: { [key: string]: any }) => void,
}
/**
 * 用户信息
 * */
const userInfoStore: UserInfoStore = observable({
    isAuth: false,
    isVip: false,
    userInfo: null,
    setData(data: { [key: string]: any }) {
        if (data) {
            Object.keys(data).forEach(key => {
                //数据不同才存放
                if (JSON.stringify(this[key]) !== JSON.stringify(data[key])) {
                    this[key] = data[key]
                }
            })
        }
    },
})

export default userInfoStore