From 545d467b169c8749c1f6c145f7437cdec4bbf16f Mon Sep 17 00:00:00 2001 From: fofolee Date: Sat, 30 Apr 2022 00:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=BC=93=E5=AD=98=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=84=9A=E6=9C=AC=E7=9A=84=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 33ed484..0a718f6 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -104,10 +104,7 @@ export default { }, async fire(currentCommand) { currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd); - if (currentCommand.output === "html") { - this.enableHtml = true; - currentCommand.cmd = await this.cacheScript(currentCommand.cmd); - } + this.enableHtml = currentCommand.output === "html"; let { hideWindow, outPlugin, action } = outputTypes[currentCommand.output]; // 需要隐藏的提前隐藏窗口 @@ -237,11 +234,12 @@ export default { : this.showRunResult(stdout, true); }, // 显示运行结果 - showRunResult(content, isSuccess) { + async showRunResult(content, isSuccess) { this.isResultShow = true; this.timeStamp = new Date().getTime(); this.runResultStatus = isSuccess; if (!_.isArray(content)) content = [content]; + content = await this.cacheScript(content); this.runResult = this.runResult.concat(content); this.autoScroll(); }, @@ -280,17 +278,22 @@ export default { this.frameInitHeight = initHeight; }, // 预先下载远程脚本 - async cacheScript(cmd) { - let html = quickcommand.htmlParse(cmd); - let scriptDoms = html.querySelectorAll("script"); - for (let i = 0; i < scriptDoms.length; i++) { - let src = scriptDoms[i].src; - if (!this.urlReg.test(src)) continue; - let dest = window.getQuickcommandTempFile("js", "remoteScript_" + i); - await quickcommand.downloadFile(src, dest); - scriptDoms[i].src = "file://" + dest; + async cacheScript(content) { + if (!this.enableHtml) return; + let htmls = []; + for (let item of content) { + let html = quickcommand.htmlParse(item); + let scriptDoms = html.querySelectorAll("script"); + for (let i = 0; i < scriptDoms.length; i++) { + let src = scriptDoms[i].src; + if (!this.urlReg.test(src)) continue; + let dest = window.getQuickcommandTempFile("js", "remoteScript_" + i); + await quickcommand.downloadFile(src, dest); + scriptDoms[i].src = "file://" + dest; + } + htmls.push(html.documentElement.innerHTML); } - return html.documentElement.innerHTML; + return htmls; }, }, unmounted() {