perf: Add log download button

pull/13459/head
wangruidong 2024-06-19 10:30:01 +08:00 committed by w940853815
parent 5b548d8d57
commit 92790d711e
1 changed files with 22 additions and 1 deletions

View File

@ -80,6 +80,12 @@
</style> </style>
</head> </head>
<div class="container"> <div class="container">
<div style="position: absolute; top: 10px; right: 12px;">
<button id="download-log-btn"
style="background-color: #1ab394; color: white; padding: 5px 10px; border: none; border-radius: 4px; cursor: pointer;">
{% trans 'Download' %}
</button>
</div>
<div class="header"> <div class="header">
<ul class="info"> <ul class="info">
<li class="item"> <li class="item">
@ -111,7 +117,6 @@
var term; var term;
var ws; var ws;
var extraQuery = Object.fromEntries(new URLSearchParams(window.location.search)); var extraQuery = Object.fromEntries(new URLSearchParams(window.location.search));
$(document).ready(function () { $(document).ready(function () {
term = new Terminal({ term = new Terminal({
cursorBlink: false, cursorBlink: false,
@ -164,4 +169,20 @@
} }
}) })
} }
function downloadLog() {
term.selectAll()
let logData = term.getSelection()
const blob = new Blob([logData], {type: 'text/plain'});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `log_${taskId}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}
document.getElementById('download-log-btn').addEventListener('click', downloadLog);
</script> </script>