jian
2 years ago
commit
2dfd358193
6 changed files with 101 additions and 0 deletions
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>Document</title> |
||||
<link rel='stylesheet' type='text/css' href="./index.css" /> |
||||
</head> |
||||
<body> |
||||
<div id="container"> |
||||
<label> |
||||
<span class="form-label">choose a zip file</span> |
||||
<button id="file-input-button">Open...</button> |
||||
<input type="file" id="file-input" accept="application/zip" hidden> |
||||
</label> |
||||
</div> |
||||
<script src="./third/zip-no-worker-inflate.min.js"></script> |
||||
<script src="./index.js"></script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,78 @@
|
||||
(() => { |
||||
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)); |
||||
}); |
||||
} |
||||
|
||||
})(); |
||||
|
||||
})(); |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue