import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store/index'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueAMap from 'vue-amap';
//引入一个reset.css 让所有手机上的基础标签的样式统一
import './assets/styles/reset.css'
//移动端1px像素边框的问题，保证所有手机都是真正的1px
import './assets/styles/border.css'
import md5 from 'js-md5';
import {BASE_URL, PHOTO_BASE_URL} from "./api/baseUrl";

Vue.prototype.$md5 = md5;
// Vue.prototype.serverUrl = BASE_URL;
Vue.prototype.serverUrl = PHOTO_BASE_URL;

Vue.use(ElementUI);
Vue.use(VueAMap);


VueAMap.initAMapApiLoader({
  // 申请的高德key
  // key: '83d8a321d186d9839c39811ed9955dcc',
  // key:'6c087d703e652767650a6b3208f76c40',
  key:'06aca1524b2ab9a95043f69b21930f38',
  // 插件集合
  plugin: [
    "AMap.Autocomplete", //输入提示插件
    "AMap.PlaceSearch", //POI搜索插件
    "AMap.Scale", //右下角缩略图插件 比例尺
    "AMap.OverView", //地图鹰眼插件
    "AMap.ToolBar", //地图工具条
    "AMap.MapType", //类别切换控件，实现默认图层与卫星图、实施交通图层之间切换的控制
    "AMap.PolyEditor", //编辑 折线多，边形
    "AMap.CircleEditor", //圆形编辑器插件
    "AMap.Geolocation", //定位控件，用来获取和展示用户主机所在的经纬度位置
    "AMap.Geocoder",
    "AMap.GeometryUtil"
  ],
  v: '1.4.4',
  uiVersion: '1.0.11' // ui版本号
});


const errorHandler = (error, vm) => {
  console.error('系统异常，请联系管理员');
  console.error("js异常", error, vm);
};

Vue.config.errorHandler = errorHandler;

Vue.prototype.$throw = (error) => errorHandler(error, this);

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title || '吉林省民政厅居家老年人巡视关爱探访系统';
  const type = to.meta.type;
  if (window.localStorage.getItem('openId')) {
    next();
  }
  else if(type === 'login'){
       next('/login');
  }else if(type === 'dependentsLogin'){
       next('/dependant/login');
  }else if(type === 'independentLogin'){
    next('/independent');
  }else {
    // independentLogin
    next();
  }
});

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
