/*
 * @Descripttion: 
 * @version: 
 * @Author: kBank
 * @Date: 2022-10-24 10:45:39
 */
import { getInfo, logout } from '@/api/login.js'
import { removeToken } from '@/config/auth.js'
const getDefaultState = () => {
  return {
    user: '',
  }
}

const state = getDefaultState()

const mutations = {
  SET_USER: (state, user) => {
    state.user = user
  },
}

const actions = {
  // 获取用户信息
  GetInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo().then(res => {
        if (res) {
          commit('SET_USER', res.data)
          uni.setStorageSync('buttons', JSON.stringify(res.buttons))
          uni.setStorageSync('userInfo', JSON.stringify(res.user))
          uni.setStorageSync('pkCountry', res.user.pkCountry)
          uni.setStorageSync('userAll', JSON.stringify(res))
          resolve(res)
        }
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  state,
  mutations,
  actions
}

