From 7b3007ec9f73024a6d8435b750c55fe06ab8fd27 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 20 Feb 2023 16:00:20 +0800 Subject: [PATCH 1/7] feat: add supports for download log file in actuator page (#867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature #### What this PR does / why we need it: 在系统概览页面支持下载运行日志。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3188 #### Screenshots: image #### Special notes for your reviewer: 测试方式: 1. 进入系统概览页面,点击运行日志的下载按钮。 2. 检查是否成功下载了日志文件。 #### Does this PR introduce a user-facing change? ```release-note Console 端的系统概览页面支持下载运行日志。 ``` --- src/modules/system/actuator/Actuator.vue | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/modules/system/actuator/Actuator.vue b/src/modules/system/actuator/Actuator.vue index 81fbf013..09a5288b 100644 --- a/src/modules/system/actuator/Actuator.vue +++ b/src/modules/system/actuator/Actuator.vue @@ -85,6 +85,28 @@ const handleCopy = () => { Toast.success("复制成功"); }; + +const handleDownloadLogfile = () => { + axios + .get(`${import.meta.env.VITE_API_URL}/actuator/logfile`) + .then((response) => { + const blob = new Blob([response.data]); + const downloadElement = document.createElement("a"); + const href = window.URL.createObjectURL(blob); + downloadElement.href = href; + downloadElement.download = `halo-log-${formatDatetime(new Date())}.log`; + document.body.appendChild(downloadElement); + downloadElement.click(); + document.body.removeChild(downloadElement); + window.URL.revokeObjectURL(href); + + Toast.success("下载成功"); + }) + .catch((e) => { + Toast.error("下载失败"); + console.log("Failed to download log file.", e); + }); +};