import Vue from 'vue' import 'normalize.css/normalize.css' // A modern alternative to CSS resets import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' // import locale from 'element-ui/lib/locale/lang/en' // lang i18n import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n import '@/styles/index.scss' // global css import App from './App' import axios from 'axios' import store from './store' import router from './router' import Cookies from 'js-cookie' import Bus from '@/Bus' import '@/icons' // icon import '@/permission' // permission control // clipboard是一款实现复制文本到剪贴板功能的JS插件 import clipboard from 'clipboard' // 高德地图 import AMap from 'vue-amap' // crypto加密 import { Encrypt } from '@/utils/AES.js' import { getToken } from '@/utils/auth' import request from '@/utils/request' // Vue.prototype.$postRequest=request.reqServe1 /** * If you don't want to use mock-server * you want to use MockJs for mock api * you can execute: mockXHR() * * Currently MockJs will be used in the production environment, * please remove it before going online! ! ! */ import { mockXHR } from '../mock' import echarts from 'echarts' import JsonExcel from 'vue-json-excel' // 注册到vue原型上 Vue.prototype.$clipboard = clipboard Vue.use(AMap) AMap.initAMapApiLoader({ key: 'f4ba1c4d94654309b97a557d41857b48', plugin: [ 'AMap.moveAnimation', 'AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.DistrictSearch', 'AMap.Geolocation' ], // 默认高德 sdk 版本为 1.4.4 v: '1.4.4' }) window._AMapSecurityConfig = { securityJsCode: 'ef9c2027d42f060b979814c849eea7b9' } Vue.prototype.$AMap = AMap Vue.prototype.$request = request.service Vue.prototype.$axiosRequest = request.reqServe if (process.env.NODE_ENV === 'production') { mockXHR() } Vue.prototype.$Cookies = Cookies Vue.prototype.$echarts = echarts Vue.prototype.$getToken = getToken Vue.prototype.$encrypt = Encrypt Vue.prototype.$axios = axios Vue.use(ElementUI, { locale }) Vue.config.productionTip = false Vue.prototype.$axios = axios Vue.prototype.$Bus = Bus Vue.component('DownloadExcel', JsonExcel) function getServerConfig() { return new Promise((resolve, reject) => { axios .get('/serverConfig.json') .then(result => { // console.log(result) // 看打印出来的结果 const config = result.data for (const key in config) { Vue.prototype[key] = config[key] } // 验证是否已经把属性挂在了Vue上 // console.log(Vue.prototype.BASE_ADDR) resolve() }) .catch(error => { console.log(error) reject() }) }) } async function init() { await getServerConfig() axios.defaults.baseURL = Vue.prototype.BASE_API axios.defaults.headers['token'] = getToken() new Vue({ router, store, render: h => h(App) }).$mount('#app') } Vue.prototype.dateTypeFormat = function (fmt, date) { let ret const opt = { 'Y+': date.getFullYear().toString(), // 年 'm+': (date.getMonth() + 1).toString(), // 月 'd+': date.getDate().toString(), // 日 'H+': date.getHours().toString(), // 时 'M+': date.getMinutes().toString(), // 分 'S+': date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 } for (const k in opt) { ret = new RegExp('(' + k + ')').exec(fmt) if (ret) { fmt = fmt.replace( ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, '0') ) } } return fmt } init()