Sfoglia il codice sorgente

fix(平台适配): 修复构建后 document.body.onload 对 null 赋值导致 Playturbo 报错

- 移除 type="module" 后脚本在 <head> 中同步执行,此时 document.body 为 null
- 改为 window.addEventListener("load", ...),兼容 dev 和 prod 两种场景
- 同时修复 play.ts 相同问题
guoziyun 3 settimane fa
parent
commit
268e21fbff
2 ha cambiato i file con 4 aggiunte e 4 eliminazioni
  1. 2 2
      src/filler/index.ts
  2. 2 2
      src/filler/play.ts

+ 2 - 2
src/filler/index.ts

@@ -40,12 +40,12 @@ import logoTxtUrl from "/assets/img/logo-txt.png?url";
 import coloringPagesUrl from "/assets/img/coloring-pages.png?url";
 import slogonUrl from "/assets/img/slogon.png?url";
 
-document.body.onload = function () {
+window.addEventListener("load", () => {
   document.body.dataset.adPlatform = adPlatform.platform;
   adPlatform.init();
   initCta(adPlatform);
   init();
-};
+});
 
 async function test() {
   let canvas = document.querySelector("#canvas") as HTMLCanvasElement;

+ 2 - 2
src/filler/play.ts

@@ -14,7 +14,7 @@ import { FillerScene } from "./FillerScene";
 import { LineArtLayer } from "./LineArtLayer";
 import { WorkLayer } from "./WorkLayer";
 
-document.body.onload = function () {
+window.addEventListener("load", () => {
   function extractIdRegex(url: string) {
     const regex = /\/share\/([\w-]+)/;
     const match = url.match(regex);
@@ -46,7 +46,7 @@ document.body.onload = function () {
   // init(`http://localhost:6889/proxy/zips/v2/number_mini/1501/6735bd3ab494234e4abc1db1.zip`);
   // init(`http://localhost:6889/proxy/zips/v2/number_mini/1501/${id}.zip`);
   init(id, uuid, zipUrl);
-};
+});
 
 async function test() {
   let canvas = document.querySelector("#canvas") as HTMLCanvasElement;