(() => { const model = (() => { return { getEntries(file) { return (new zip.ZipReader(new zip.BlobReader(file))).getEntries(); }, async getContent(entry) { const contentBlob = new TransformStream(); const contentBlobPromise = new Response(contentBlob.readable).text(); await entry.getData(contentBlob); const content = await contentBlobPromise; return content; } }; })(); (() => { zip.configure({ useWebWorkers: false, }); let report; const fileInput = document.getElementById("file-input"); const fileInputButton = document.getElementById("file-input-button"); const select = document.getElementById("select-elem"); const startButton = document.getElementById("start-score"); let entries; let selectedFile; fileInput.onchange = selectFile; fileInputButton.onclick = clickInputButton; startButton.onclick = function () { const val = select.value; let total_score = 0; switch(val) { case "1": total_score = new Paper_1(report).score(); break; case "2": total_score = new Paper_2(report).score(); break; } document.getElementById("total-score").innerText = total_score + "分"; } function clickInputButton() { fileInput.dispatchEvent(new MouseEvent("click")) } async function selectFile() { try { fileInputButton.disabled = true; selectedFile = fileInput.files[0]; await getReportJson(); } catch (error) { alert('zip 解析错误'); console.log(error); } finally { fileInputButton.disabled = false; fileInput.value = ""; } } async function getReportJson() { entries = await model.getEntries(selectedFile); const reportEntries = []; if (entries && entries.length) { entries.forEach((entry) => { if (entry.filename.indexOf('.fbi') > -1) { reportEntries.push(entry); } }); } if (reportEntries.length < 1) { alert('未找到仪表板'); return; } if (reportEntries.lenght > 1) { alert('只可导出一个仪表板'); } model.getContent(reportEntries[0]).then((content) => { report = JSON.parse(content); }); } })(); })();