import './permission'; // 权限
import './error';      // 日志
import './cache';      //页面缓存
import './styles/common.scss';
import './util/directive';
import '@smallwei/avue/lib/index.css';
import 'element-ui/lib/theme-chalk/display.css';
import './util/backTime'

import * as urls from '@/config/env';
import {iconfontUrl, iconfontVersion} from '@/config/env';
import website from '@/config/website';
import Avue from '@smallwei/avue';
import Element from 'element-ui';
import Vue from 'vue';
import VueAxios from 'vue-axios';

import App from './App';
import basicBlock from './components/basic-block/main'
import basicContainer from './components/basic-container/main'
import cityCascader from './components/city-cascader/main'
import cityLabelCascader from './components/city-cascader/label'
import goBack from './components/go-back/main'
import tagSelect from './components/tag-select/main'
import tooltip from './components/tooltip/index'
import superMapView from './components/map/selectLocation3';
import i18n from './lang' // Internationalization
import axios from './router/axios';
import router from './router/router';
import store from './store';
import {loadStyle} from './util/util';
import event from './event';

Vue.use(router);
Vue.use(VueAxios, axios);
Vue.use(Element, {i18n: (key, value) => i18n.t(key, value)});
Vue.use(Avue, {i18n: (key, value) => i18n.t(key, value)});
Vue.use(event);
//注册全局容器
Vue.component('basicContainer', basicContainer);
Vue.component('basicBlock', basicBlock);
Vue.component('jl-go-back', goBack);
Vue.component('jl-city-cascader', cityCascader);
Vue.component('jl-cityLabel-cascader', cityLabelCascader);
Vue.component('tag-select', tagSelect)
Vue.component('tool-tip', tooltip)
Vue.component('super-map-view', superMapView)
// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key];
});
// 加载website
Vue.prototype.website = website;
// 动态加载阿里云字体库
// iconfontVersion.forEach(ele => {
//   loadStyle(iconfontUrl.replace('$key', ele));
// });
// 睡眠函数
function sleep(time) {
  return new Promise((resolve) => setTimeout(resolve, time))
}

function filterObject(obj) {
  const filteredObj = {...obj}; // 创建对象的副本
  Object.keys(filteredObj).forEach(key => {
    // 判断属性名是否以 $ 开头 且值为 falsy
    if (key.startsWith('$') || !filteredObj[key] && filteredObj[key] !== 0) {
      delete filteredObj[key];
    }
  });
  return filteredObj;
}

Vue.prototype.$api = {sleep, filterObject}
Vue.config.productionTip = false;

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