index.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>qiankun 宿主(终稿验收临时宿主)</title>
  6. <style>
  7. html, body { margin: 0; padding: 0; height: 100%; background: #01060d; color: #e6f5ff;
  8. font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif; }
  9. #host-bar { height: 28px; line-height: 28px; padding: 0 10px; font-size: 12px;
  10. background: #0a2740; border-bottom: 1px solid #1b93cf; display: flex; gap: 16px; }
  11. #host-bar b { color: #4fd8ff; }
  12. #micro-container { position: absolute; top: 28px; left: 0; right: 0; bottom: 0; overflow: hidden; }
  13. #probe { position: absolute; right: 8px; top: 34px; z-index: 99999; font-size: 11px;
  14. background: rgba(2,10,20,.9); border: 1px solid #1b93cf; padding: 6px 8px; max-width: 420px;
  15. white-space: pre-wrap; line-height: 1.5; }
  16. </style>
  17. </head>
  18. <body>
  19. <div id="host-bar">
  20. <span>qiankun 宿主验收(临时)</span>
  21. <span>入口:<b>http://127.0.0.1:8000/</b></span>
  22. <span>appName:<b>TvT.js</b></span>
  23. </div>
  24. <div id="micro-container"></div>
  25. <div id="probe">probe: waiting…</div>
  26. <script src="./qiankun.umd.min.js"></script>
  27. <script>
  28. (function () {
  29. var log = [];
  30. function rec(k, v) { log.push(k + '=' + v); document.getElementById('probe').textContent = log.join('\n'); }
  31. window.__HOST_EVENTS__ = log;
  32. window.__HOST_REQUESTS__ = [];
  33. window.__HOST_ERRORS__ = [];
  34. // 记录被嵌应用发出的资源请求(含字体/图标),用于「宿主内资源解析」验收
  35. var origFetch = window.fetch;
  36. window.fetch = function (input, init) {
  37. var url = (typeof input === 'string') ? input : (input && input.url);
  38. window.__HOST_REQUESTS__.push(url);
  39. return origFetch.apply(this, arguments);
  40. };
  41. window.addEventListener('error', function (e) {
  42. window.__HOST_ERRORS__.push(String(e.message || e));
  43. }, true);
  44. window.addEventListener('unhandledrejection', function (e) {
  45. window.__HOST_ERRORS__.push('unhandledrejection: ' + String(e.reason));
  46. });
  47. rec('host', 'qiankun ' + (window.qiankun ? 'loaded' : 'MISSING'));
  48. rec('powered', String(!!window.__POWERED_BY_QIANKUN__));
  49. var ENTRY = 'http://127.0.0.1:8000/';
  50. var APP = 'TvT.js';
  51. try {
  52. qiankun.registerMicroApps([{
  53. name: APP,
  54. entry: ENTRY,
  55. container: '#micro-container',
  56. activeRule: function () { return true; },
  57. props: {
  58. // 被嵌侧 lifecycle.js 只在收到 url 时切 memory history 并 push 该路由;
  59. // 不传则停在宿主默认页,/cockpit 不会渲染。
  60. url: '/cockpit',
  61. onRouterInit: function (router) {
  62. rec('routerInit', String(!!router));
  63. }
  64. }
  65. }], {
  66. beforeLoad: [function (app) { rec('beforeLoad', app.name); }],
  67. beforeMount: [function (app) { rec('beforeMount', app.name); }],
  68. afterMount: [function (app) {
  69. rec('afterMount', app.name);
  70. rec('poweredAfterMount', String(!!window.__POWERED_BY_QIANKUN__));
  71. rec('injectedBase', String(window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || '(none)'));
  72. }],
  73. afterUnmount: [function (app) { rec('afterUnmount', app.name); }]
  74. });
  75. qiankun.start({ singular: true, sandbox: { experimentalStyleIsolation: false } })
  76. .then(function () { rec('start', 'ok'); })
  77. .catch(function (err) { rec('startError', String(err && err.message || err)); });
  78. } catch (err) {
  79. rec('registerError', String(err && err.message || err));
  80. }
  81. // 给外部读数的稳定窗口(含字体与图标请求统计)
  82. window.__HOST_REPORT__ = function () {
  83. var reqs = window.__HOST_REQUESTS__;
  84. var fonts = reqs.filter(function (u) { return /\.woff2(\?|$)/.test(u); });
  85. var icons = reqs.filter(function (u) { return /\/cockpit\/assets\/icons\//.test(u); });
  86. return {
  87. events: window.__HOST_EVENTS__.slice(),
  88. powered: !!window.__POWERED_BY_QIANKUN__,
  89. injectedBase: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || null,
  90. fontRequests: fonts,
  91. iconRequests: icons,
  92. totalRequests: reqs.length,
  93. errors: window.__HOST_ERRORS__.slice(),
  94. microRootHtmlLen: (function () {
  95. var el = document.querySelector('#micro-container');
  96. return el ? el.innerHTML.length : -1;
  97. })(),
  98. cockpitPresent: !!document.querySelector('#micro-container .cockpit-shell'),
  99. panelCount: document.querySelectorAll('#micro-container [data-panel-id]').length,
  100. markerCount: document.querySelectorAll('#micro-container [data-marker-overlay-key]').length
  101. };
  102. };
  103. })();
  104. </script>
  105. </body>
  106. </html>