import axios from 'axios'

const serverConfig = {
  state: {
    config: {}
  },

  mutations: {
    SET_CONFIG: (state, config) => {
      state.config = config
    }
  },

  actions: {
    ChangeConfig({ commit }) {
      return new Promise((resolve, reject) => {
        axios.get('/static/config/serverConfig.json').then(result => {
          const config = result.data
          commit('SET_CONFIG', config)
          resolve(resolve)
        }).catch(err => {
          reject(err)
          console.error(`请确认 static/config/serveConfig.json 文件是否存在！${err}`)
        })
      })
    }
  }
}

export default serverConfig
