/*
 * @Description: 
 * @Author: 欧阳承珺
 * @LastEditors: 欧阳承珺
 * @Date: 2022-10-25 17:19:19
 * @LastEditTime: 2022-11-02 16:03:41
 */
export const state = () => ({
  userInfo: {
    memberInfo: {},
    pricingList: [],
    setPricingList: [],
  },
  token: '',
  globalLoginVisiable: false,
  globalInterfaceType: false
})

export const mutations = {
  setUser(state, data) {
    state.userInfo = data
  },
  SET_TOKEN(state, data) {
    state.token = data
  },
  DEL_TOKEN(state,data) {
    state.token = data
  },
  OPEN_LOGIN(state, data) {
    state.globalLoginVisiable = data
  },
  SET_INTERFACE(state, data) {
    state.globalInterfaceType = data
  }
}


export const actions = {

  nuxtServerInit ({commit, state}, {req}) {
      if (req && req.headers && req.headers.token) {
        commit('SET_TOKEN', req.headers.token)
      }
  },

  login ({ commit }, params) {
    return new Promise((resolve, reject) => {
      this.$axios.get(`auth/getToken?code=${params}`).then(res => {
        const token = res.result.accessToken
        localStorage.setItem('token',token)
        commit('SET_TOKEN', token)
        resolve(token)
      }).catch(err => {
        reject(err)
      })
    })
  },
} 