/** * Copyright 2019 Han Guoshuai * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ window.onerror = (msg, uri, line, col, err) => { if (err) { alert("Error:\n" + err.message + "\n" + err.stack + "\nLine: " + line + "\nColumn: " + col); } else { console.log(msg); } }; let ROOT_PATH = "/"; (() => { let temp = document.querySelectorAll("head > script"); let scriptEle = temp[temp.length - 1]; ROOT_PATH = scriptEle.src.slice(0, scriptEle.src.lastIndexOf("/") + 1); })(); document.addEventListener("touchstart", function() {}); // --- 网页 DOM 加载完成后开始执行 --- document.addEventListener("DOMContentLoaded", function () { // --- z-index 1999 比 dialog、alert 等层级低 --- document.getElementsByTagName("body")[0].innerHTML = `` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
Loading...
`; // --- 加载 config --- let configEle = document.querySelector("script[type=deskrt-config]"); if (!configEle) { alert("[Error] Config not found."); return; } let config = (new Function("return " + configEle.innerHTML.trim()))(); config.pre = config.pre || ""; config.end = config.end || ""; config.localePath = config.localePath || ""; config.locales = config.locales || ["en", "zh-CN"]; config.frame = config.frame || ""; config.main = config.main || ""; config.logo = config.logo || ""; config.size = config.size || ""; config.paths = config.paths || {}; config.paths.deskrt = ROOT_PATH + "deskrt"; config.asideWidth = config.asideWidth || "200px"; config.const = config.const || {}; config.global = config.global || {}; config.theme = config.theme || ""; // --- 加载 System.js --- let script = document.createElement("script"); script.addEventListener("load", async function() { // --- 加载 core --- System.config({ packages: { "http:": { defaultExtension: "js?" + config.end }, "https:": { defaultExtension: "js?" + config.end } }, map: config.paths }); let core = await System.import(ROOT_PATH + "core"); // --- 加载条 --- let epc = (document.getElementById("el-progress-chunk")); epc.style.transition = "width 1s ease-out"; epc.style.width = 1 / 6 * 100 + "%"; core.onReady(config, ROOT_PATH); }); script.addEventListener("error", function(e) { alert("[Error] " + e.message); }); script.src = "https://cdn.jsdelivr.net/npm/systemjs@0.21.6/dist/system.js"; document.getElementsByTagName("head")[0].appendChild(script); // --- 加载条 --- setTimeout(function() { (document.getElementById("el-progress-chunk")).style.width = 1 / 6 * 100 + "%"; }, 0); });