king
2020-12-30 e003a8ee8843aa60b0b7135f413b2b99857acff9
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
import React from 'react'
import ReactDOM from 'react-dom'
import {Provider} from 'react-redux'
import Route from './router'
import store from '@/store'
import './index.css'
import * as serviceWorker from './serviceWorker'
// import VConsole from 'vconsole/dist/vconsole.min.js'
 
// new VConsole()
 
const render  = Component => {
  ReactDOM.render(
    <Provider store={store}>
      <Component/>
    </Provider>,
    document.getElementById('root')
  )
}
 
if (!localStorage.getItem('SessionUid')) {
  localStorage.setItem('SessionUid', (() => {
    let uuid = []
    let _options = '0123456789abcdefghigklmnopqrstuv'
    for (let i = 0; i < 32; i++) {
      uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
    }
    return uuid.join('')
  })())
}
 
fetch(`./options.json`)
  .then(response => response.json())
  .catch(() => {
    document.getElementById('root').innerHTML = '系统配置信息获取失败,请联系管理员!'
    document.getElementById('root').className = 'config-error'
  })
  .then(config => {
    if (!config) return
 
    window.GLOB = {}
    window.GLOB.appId = config.appId || ''
    window.GLOB.mainSystemApi = config.mainSystemApi || ''
    window.GLOB.filter = config.filter || ''
    window.GLOB.appkey = config.appkey
    window.GLOB.systemType = 'H5'
 
    let agent = navigator.userAgent.toLowerCase()
    console.log(agent)
    if (agent.indexOf('android') > -1) {
      window.GLOB.systemType = 'android'
    } else if (agent.indexOf('iphone') > -1 || agent.indexOf('ipad') > -1) {
      window.GLOB.systemType = 'ios'
    }
 
    if (window.wx && window.wx.miniProgram && agent.match(/MicroMessenger/i) === 'micromessenger') {
      window.wx.miniProgram.getEnv((res) => {
        if (res.miniprogram) {
          window.GLOB.systemType = 'miniProgram'
        }
      })
    }
 
    console.log('systemType: ' + window.GLOB.systemType)
 
    if (process.env.NODE_ENV === 'production') { // 用于校验是否存在开发权限
      window.GLOB.service = window.location.href.replace(/\/mob(.*)/ig, '').replace(new RegExp(document.location.origin + '/?', 'ig'), '')
    } else {
      window.GLOB.service = 'mkwms/'
    }
 
    render(Route)
  })
 
serviceWorker.unregister()