保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
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
const chunks = {} // chunkId => exports
const chunksInstalling = {} // chunkId => Promise
const failedChunks = {}
 
function importChunk(chunkId, src) {
  // Already installed
  if (chunks[chunkId]) {
    return Promise.resolve(chunks[chunkId])
  }
 
  // Failed loading
  if (failedChunks[chunkId]) {
    return Promise.reject(failedChunks[chunkId])
  }
 
  // Installing
  if (chunksInstalling[chunkId]) {
    return chunksInstalling[chunkId]
  }
 
  // Set a promise in chunk cache
  let resolve, reject
  const promise = chunksInstalling[chunkId] = new Promise((_resolve, _reject) => {
    resolve = _resolve
    reject = _reject
  })
 
  // Clear chunk data from cache
  delete chunks[chunkId]
 
  // Start chunk loading
  const script = document.createElement('script')
  script.charset = 'utf-8'
  script.timeout = 120
  script.src = src
  let timeout
 
  // Create error before stack unwound to get useful stacktrace later
  const error = new Error()
 
  // Complete handlers
  const onScriptComplete = script.onerror = script.onload = (event) => {
    // Cleanups
    clearTimeout(timeout)
    delete chunksInstalling[chunkId]
 
    // Avoid mem leaks in IE
    script.onerror = script.onload = null
 
    // Verify chunk is loaded
    if (chunks[chunkId]) {
      return resolve(chunks[chunkId])
    }
 
    // Something bad happened
    const errorType = event && (event.type === 'load' ? 'missing' : event.type)
    const realSrc = event && event.target && event.target.src
    error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')'
    error.name = 'ChunkLoadError'
    error.type = errorType
    error.request = realSrc
    failedChunks[chunkId] = error
    reject(error)
  }
 
  // Timeout
  timeout = setTimeout(() => {
    onScriptComplete({ type: 'timeout', target: script })
  }, 120000)
 
  // Append script
  document.head.appendChild(script)
 
  // Return promise
  return promise
}
 
export function installJsonp() {
  window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
  window.__NUXT_JSONP_CACHE__ = chunks
  window.__NUXT_IMPORT__ = importChunk
}