//通过云端一体模板来登陆的,返回用户id、手机号等信息。
import {
    store
} from '@/uni_modules/uni-id-pages/common/store.js'
// 用户信息、是否登陆
let userInfoCloud = store.userInfo || {},
    isLogin = Boolean(Object.keys(userInfoCloud).length);
// {
//     "_id": "668ca11209664cbba01ed3c7",
//     "mobile": "18608981880",
//     "realNameAuth": {
//         "errCode": 0,
//         "realName": "",
//         "identity": ""
//     }
// }

// let user = uniCloud.getCurrentUserInfo();
// {
//     "uid": "668ca11209664cbba01ed3c7",
//     "role": [],
//     "permission": [],
//     "uniIdVersion": "1.0.17",
//     "tokenExpired": 1720499506000
// }

let state = {
        //是否已经登录
        hasLogin: isLogin,
        //用户信息
        info: userInfoCloud,
        openid: userInfoCloud._id || '',
        mobile: userInfoCloud.mobile || '',
    },
    getters = {
        info(state) {
            return state.info;
        },
        hasLogin(state) {
            return state.hasLogin;
        },
        openid(state) {
            return state.openid;
        },
        mobile(state) {
            return state.mobile;
        }
    },
    mutations = {
        logout(state) {
            state.info = {};
            state.hasLogin = false;
            uni.setStorageSync('uni-id-pages-userInfo', {});
        }
    }
export default {
    namespaced: true,
    state,
    getters,
    mutations
}