From 70a2fb68bb66cee4b48b8633d1389900a0c05509 Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 28 Feb 2025 09:35:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0console.clear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/preload.js | 3 +++ src/components/CommandRunResult.vue | 8 ++++++-- src/plugins/monaco/types/common.d.ts | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/preload.js b/plugin/preload.js index 53460f6..d5ce128 100644 --- a/plugin/preload.js +++ b/plugin/preload.js @@ -179,6 +179,9 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => { error: (...stderr) => { callback(null, stderr); }, + clear: () => { + callback({ __clearQuickcommandRunResult: true }, null); + }, }; let sandboxWithAD = Object.assign(addVars, sandbox); sandboxWithAD.quickcommand = window.lodashM.cloneDeep(quickcommand); diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index f94bf38..a8c5856 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -301,9 +301,13 @@ export default { }, // 显示运行结果 async showRunResult(content, isSuccess) { - content = await this.handleContent(content); + if (content.__clearQuickcommandRunResult) { + this.runResult = []; + } else { + content = await this.handleContent(content); + this.runResult = this.runResult.concat(content); + } this.runResultStatus = isSuccess; - this.runResult = this.runResult.concat(content); // 刷新组件 this.isResultShow ? (this.timeStamp = new Date().getTime()) diff --git a/src/plugins/monaco/types/common.d.ts b/src/plugins/monaco/types/common.d.ts index e254b83..26864a8 100644 --- a/src/plugins/monaco/types/common.d.ts +++ b/src/plugins/monaco/types/common.d.ts @@ -86,7 +86,8 @@ declare function fetch( // console declare var console: { log(message?: any): void, - error(message?: any): void + error(message?: any): void, + clear(): void, } declare var setTimeout: (callback: () => void, ms: number) => number;