张卓
2022-09-29 4ef1c909df36c48f7f040e9ec408fc15e6745e71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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'
// 注册到vue原型上
Vue.prototype.$clipboard = clipboard
 
// 高德地图
import AMap from 'vue-amap'
Vue.use(AMap)
AMap.initAMapApiLoader({
  key: 'be57d4add7dc10fb7f7924763a2179ae',
  plugin: ['AMap.moveAnimation', 'AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale',
    'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor',
    'AMap.DistrictSearch'],
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.4'
})
 
Vue.prototype.$AMap = AMap
// crypto加密
import { Encrypt } from '@/utils/AES.js'
 
import { getToken } from '@/utils/auth'
 
import request from '@/utils/request'
 
Vue.prototype.$request = request.service
Vue.prototype.$axiosRequest = request.reqServe
/**
 * 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'
if (process.env.NODE_ENV === 'production') {
  mockXHR()
}
 
import echarts from 'echarts'
 
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
 
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')
}
 
init()