You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
3 years ago
|
(() => {
|
||
|
window.BIScore = window.BIScore || {};
|
||
|
|
||
|
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,
|
||
|
});
|
||
|
const fileInput = document.getElementById("file-input");
|
||
|
const fileInputButton = document.getElementById("file-input-button");
|
||
|
let entries;
|
||
|
let selectedFile;
|
||
|
fileInput.onchange = selectFile;
|
||
|
fileInputButton.onclick = clickInputButton;
|
||
|
|
||
|
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) => {
|
||
|
console.log(JSON.parse(content));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
})();
|
||
|
|
||
|
})();
|