From de01de24bba3cf49ce7910613ee14c2781f5099c Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 29 Apr 2022 16:44:10 +0800 Subject: [PATCH] =?UTF-8?q?html=20=E7=9B=91=E5=90=AC=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=92=8C=E9=87=8D=E5=AE=9A=E5=90=91=20console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ResultArea.vue | 23 +++++++++++++++---- .../quickcommandUI/QuickCommand.vue | 9 ++++++++ .../monaco/types/quickcommand.api.d.ts | 14 +---------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/components/ResultArea.vue b/src/components/ResultArea.vue index 388ecf6..a04ad3b 100644 --- a/src/components/ResultArea.vue +++ b/src/components/ResultArea.vue @@ -58,6 +58,7 @@ export default { enableHtml: Boolean, runResultStatus: Boolean, runResult: Object, + maxHeight: Number, frameInitHeight: Number, }, computed: { @@ -67,7 +68,7 @@ export default { src() { return this.showFrame ? window.URL.createObjectURL( - new Blob([this.frameStyle].concat(this.runResult), { + new Blob([this.frameStyle, this.runResult], { type: "text/html", }) ) @@ -82,16 +83,30 @@ export default { frameInit() { let cfw = this.$refs?.iframe?.contentWindow; if (!cfw) return; + let showError = (...args) => { + quickcommand.showMessageBox(args.join(" "), "error", 0); + }; + let showLog = (...args) => { + quickcommand.showMessageBox(args.join(" "), "success", 0); + }; let ctx = { quickcommand: _.cloneDeep(quickcommand), utools: _.cloneDeep(utools), parent: undefined, + console: { + log: showLog, + error: showError, + }, + onerror: (e) => showError(e), }; Object.assign(cfw, ctx); cfw.onload = () => { - let clientHeight = - cfw.document.documentElement.getBoundingClientRect().height; - this.frameHeight = clientHeight === 20 ? 0 : clientHeight; + this.frameHeight = Math.min( + cfw.document.body.innerText + ? cfw.document.documentElement.getBoundingClientRect().height + : 0, + this.maxHeight + ); this.$emit("frameLoad", this.frameHeight); }; }, diff --git a/src/components/quickcommandUI/QuickCommand.vue b/src/components/quickcommandUI/QuickCommand.vue index 6b2117d..ae07b4c 100644 --- a/src/components/quickcommandUI/QuickCommand.vue +++ b/src/components/quickcommandUI/QuickCommand.vue @@ -92,6 +92,15 @@ export default { message: message, timeout: time, position: "top", + actions: + time === 0 + ? [ + { + label: "确定", + color: "white", + }, + ] + : [], }); }, diff --git a/src/plugins/monaco/types/quickcommand.api.d.ts b/src/plugins/monaco/types/quickcommand.api.d.ts index 2c8c82d..edf94f9 100644 --- a/src/plugins/monaco/types/quickcommand.api.d.ts +++ b/src/plugins/monaco/types/quickcommand.api.d.ts @@ -138,7 +138,7 @@ interface quickcommandApi { * ``` * @param message 显示的消息内容 * @param icon 图标,默认为 success - * @param time 多少毫秒后消失,默认为 3000 + * @param time 多少毫秒后消失,默认为 3000,当设为 0 时则需要手动点击关闭 */ showMessageBox( message: string, @@ -352,18 +352,6 @@ interface quickcommandApi { */ simulatePaste(); - /** - * 读取剪贴板 - */ - readClipboard(): text; - - /** - * 写入剪贴板 - * - * @param text 要写入的文本 - */ - writeClipboard(text: string); - /** * 唤醒 uTools *