liu
3 天以前 ee7ac8df8bce38add1f75baf876b49de94b9e00a
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
/* Keep this file in ES5 syntax: it must run even when the application cannot. */
(function () {
  var finished = false;
  var lastError = '';
  var timer;
  function errorText(error) {
    return String(error && error.message ? error.message : error || '未知启动错误').slice(0, 300);
  }
  function showFailure(error) {
    if (finished || document.getElementById('mom-startup-error')) return;
    var box = document.createElement('section');
    box.id = 'mom-startup-error';
    box.setAttribute('role', 'alert');
    box.style.cssText = 'position:fixed;z-index:99999;left:0;right:0;top:0;bottom:0;overflow:auto;background:#fff;color:#0f172a;padding:24px;box-sizing:border-box;font:16px/1.6 sans-serif;';
    function line(tag, text) {
      var element = document.createElement(tag);
      element.textContent = text;
      element.style.wordBreak = 'break-word';
      box.appendChild(element);
      return element;
    }
    line('h2', '平台未能完成启动');
    line('p', '可能是浏览器兼容性或脚本加载失败。请打开检测页,将检测结果提供给管理员。');
    line('p', '启动信息:' + errorText(error));
    line('p', '浏览器:' + navigator.userAgent);
    var link = line('a', '打开浏览器检测页');
    link.href = document.querySelector('script[data-startup-check]').src.replace(/[^/]*$/, 'browser-check.html');
    link.style.cssText = 'display:block;min-height:48px;color:#0369a1;';
    var button = line('button', '重新加载');
    button.style.cssText = 'min-height:48px;padding:8px 20px;font-size:16px;';
    button.onclick = function () { window.location.reload(); };
    document.body.appendChild(box);
  }
  window.__MOM_STARTUP__ = {
    finish: function () {
      finished = true;
      window.clearTimeout(timer);
      var box = document.getElementById('mom-startup-error');
      if (box) box.parentNode.removeChild(box);
    },
    fail: function (error) { showFailure(error); }
  };
  window.addEventListener('error', function (event) {
    if (event.message) lastError = errorText(event.message);
    else if (event.target && event.target.tagName === 'SCRIPT') lastError = '脚本文件加载失败';
  }, true);
  window.addEventListener('unhandledrejection', function (event) { lastError = errorText(event.reason); });
  timer = window.setTimeout(function () {
    showFailure(lastError || '30 秒内未完成初始化;请检查浏览器能力与脚本请求。');
  }, 30000);
}());