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

import 'virtual:windi.css'
import router from "@h5/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 '@h5/assets/css/index.css'
import Vant from 'vant';
import {Toast,Dialog} from  'vant'
import 'vant/lib/index.css';
import axios from "axios";
import qs from "qs";
import api from "../common/config/api";
import NutUI from '@nutui/nutui';
import '@nutui/nutui/dist/nutui.css';
NutUI.install(Vue);
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']){

    await Dialog.confirm( {
      message:'您未登录，是否现在去登录？',
      title:'提示',
      confirmButtonText: '去登录',
      cancelButtonText: '取消',
    });
    this.$router.push('/open-vip?back=true');


  }



  return resp;

}, error => {
  console.log(error);
  return Promise.reject(error)
});
Vue.prototype.$qs = qs;

Vue.prototype.$toast = Toast;
Vue.prototype.$dialog = Dialog;
Vue.prototype.$store = store;
Vue.use(Vant);
Vue.use(ElementUI);


Vue.config.productionTip = false;
Vue.config.devtools = true;

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
});

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


