import Cookie from 'js-cookie'
import Locale from '~/locales'
// 获取编译启动的默认语言
const ENV_LANGUAGE = process.env.LANGUAGE ? process.env.LANGUAGE : 'zh'

export const state = () => ({
  locales: Locale(), //语言种类
  locale: Cookie.get('language') || ENV_LANGUAGE, // 初始语言
  errMsg: ''
})

export const mutations = {
  /** 保存全局默认语言 **/
  SET_LANGUAGE(state, locale) {
    if (state.locales.indexOf(locale) !== -1) {
      Cookie.set('language', locale) //用于刷新页面时调用
      state.locale = locale
    }
  },
  /**
   * 变更后台返回的错误消息
   */
  handleChangeErrMsg(state,errMsg) {
    state.errMsg = errMsg
  }
}

export const actions = {}