import Vue from "vue";
import App from "@pc/App.vue";
import VueI18n from "vue-i18n";
import store from './store'

import 'virtual:windi.css'
import router from "@pc/router";
import zhCN from "../common/locales/zh-CN";
import zhTW from "../common/locales/zh-TW";
import en from "../common/locales/en";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@pc/assets/css/index.css'
import axios from "axios";
import qs from "qs";
import api from "../common/config/api";
import {Dialog} from "vant";
Vue.use(ElementUI);

Vue.config.productionTip = false;
Vue.config.devtools = true;
Vue.prototype.$api = api;
Vue.prototype.$http = axios;
//http响应拦截器
Vue.prototype.$http.interceptors.response.use(async (resp) => {

  console.log(resp);
  //如果未授权，则跳转至授权页面
  if(resp.data.status === 401 && !qs.parse(resp.config.data)['unAuth']){

    store.commit('SHOW_LOGIN_BOX');


  }



  return resp;

}, error => {
  console.log(error);
  return Promise.reject(error)
});
Vue.prototype.$qs = qs;
Vue.use(VueI18n);
const messages = {
  "zh-CN": zhCN,
  "zh-TW": zhTW,
  "en": en,
};
const i18n = new VueI18n({
  locale: "zh-TW", // set locale
  messages, // set locale messages
});

Vue.prototype.$store= store;

/* eslint-disable no-new */
new Vue({
  el: "#app",
  store,
  router,
  render: (h) => h(App),
  i18n,
});
