import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import '../theme/index.css' // 引入自定义主题
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * This project originally used easy-mock to simulate data,
 * but its official service is very unstable,
 * and you can build your own service if you need it.
 * So here I use Mock.js for local emulation,
 * it will intercept your request, so you won't see the request in the network.
 * If you remove `../mock` it will automatically request easy-mock data.
 */
// 兼容IE11
import 'babel-polyfill'

// import '../mock' // simulation data
import { hasPermission, showWellType, showDeviceType, showIpConfig, isOperation } from './utils/permission'

Vue.prototype.hasPerm = hasPermission
Vue.prototype.showWellType = showWellType
Vue.prototype.showDeviceType = showDeviceType
Vue.prototype.showIpConfig = showIpConfig
Vue.prototype.isOperation = isOperation
// 引入Element-ui
Vue.use(ElementUI, { locale })

// 自定义表格项组件
import TableCellRead from './components/TableCell'
Vue.use(TableCellRead)

// 引入高德地图
// import VueAMap from 'vue-amap'
// Vue.use(VueAMap)
// VueAMap.initAMapApiLoader({
//   key: 'b6c27a2051691fcb386543c800356e05',
//   plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor']
// })
// Vue.config.productionTip = false

// 引入v-charts
import VCharts from 'v-charts'
Vue.use(VCharts)

// 注册全局自定义布局组件
import NormalTable from '@/components/NormalTable/index'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import AppContainer from '@/components/layout/AppContainer'

Vue.component('app-container', AppContainer)
Vue.component('normal-table', NormalTable)
Vue.component('search-area', SearchArea)
Vue.component('search-item', SearchItem)

// leaflet

import 'leaflet/dist/leaflet.css'
import 'esri-leaflet/dist/esri-leaflet.js'
import 'esri-leaflet-renderers/dist/esri-leaflet-renderers.js'
// 引入Leaflet对象 挂载到Vue上，便于全局使用，也可以单独页面中单独引用
import * as L from 'leaflet'
import 'leaflet.pm'
import 'leaflet.pm/dist/leaflet.pm.css'

Vue.config.productionTip = false
Vue.L = Vue.prototype.$L = L

/* leaflet icon */
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('leaflet/dist/images/marker-icon.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png')
})

// 先加载配置文件后，new Vue
/* eslint-disable no-new */
import axios from 'axios'
import service from '@/utils/request'
axios.get('./static/project.config.json').then((result) => {
  console.log('get config')
  Vue.prototype.baseConfig = result.data
  document.title = result.data.title // 首先设置网页的title
  service.defaults.baseURL = result.data.baseUrl // 设置默认请求网址
  new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  })
}).catch((error) => {
  console.log('get baseConfig error...' + error)
})

