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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
// 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'
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
 
import JsonExcel from 'vue-json-excel'
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()