main.js
2.57 KB
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
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2021-06-07 14:12:32
* @LastEditors: limin
* @LastEditTime: 2021-06-29 15:35:47
*/
// 兼容 IE
// https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#babelpolyfill
// import 'core-js/stable'
// import 'regenerator-runtime/runtime'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import api from './api'
import { fetchConfig, cfg } from '@/config'
import '@/assets/css/index.scss'
import { bus, tools, store as local, util } from './utils'
import './utils/util'
import 'components'
import { components } from '@/plugins/vant'
import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)
components.forEach(component => Vue.use(component))
Vue.prototype.api = api
Vue.prototype.bus = bus
Vue.prototype.tools = tools
Vue.prototype.local = local
Vue.prototype.to = function (name, params) {
if (name === -1) {
router.go(-1)
return
}
router.push({ name, params })
}
// 移动端适配 rem
// import 'lib-flexible/flexible.js'
import VConsole from 'vconsole'
const ua = navigator.userAgent.toLowerCase()
let body = document.getElementsByTagName('head')[0],
WXJDK = document.createElement('script'),
WWJDK = document.createElement('script'),
ISWXWORK = false,
IsIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent),
ISMiniprogram = window.__wxjs_environment === 'miniprogram'
WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.2.0.js'
if (Boolean(ua.match(/MicroMessenger/i)) && Boolean(ua.match(/wxwork/i))) { //是否企微
// WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.2.0.js'
WWJDK.src = '//open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js'
ISWXWORK = true
}
window.$ISWXWORK = ISWXWORK
util.setLocalStorage('is_wxwork', ISWXWORK)
Vue.prototype.ISWXWORK = ISWXWORK
Vue.prototype.ISMOBILE = util.isMobileDevice()
body.appendChild(WXJDK)
if (WWJDK.src) body.appendChild(WWJDK)
window.$IsIOS = IsIOS
Vue.prototype.IsIOS = IsIOS
window.$ISMiniprogram = ISMiniprogram
Vue.prototype.ISMiniprogram = ISMiniprogram
const isMock = ['prod', 'production'].includes(process.env.NODE_ENV)
fetchConfig(!isMock).then(res => {
// 从配置服务器获取动态配置
// 设置 js中可以访问 $cdn
Vue.use(cfg)
window.$fetchConfig = res
if (res.vconsole) new VConsole()
/**登录过期 重新登录 */
window.reLogin = () => {
console.log('重新登录')
util.clearSessionId()
store.dispatch('navigation')
}
window.vm = new Vue({
el: '#app',
router,
store,
render: h => h(App)
})
})