mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 06:16:27 +08:00
html 监听错误和重定向 console
This commit is contained in:
parent
3e3248162f
commit
de01de24bb
@ -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);
|
||||
};
|
||||
},
|
||||
|
@ -92,6 +92,15 @@ export default {
|
||||
message: message,
|
||||
timeout: time,
|
||||
position: "top",
|
||||
actions:
|
||||
time === 0
|
||||
? [
|
||||
{
|
||||
label: "确定",
|
||||
color: "white",
|
||||
},
|
||||
]
|
||||
: [],
|
||||
});
|
||||
},
|
||||
|
||||
|
14
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
14
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@ -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<string>;
|
||||
|
||||
/**
|
||||
* 写入剪贴板
|
||||
*
|
||||
* @param text 要写入的文本
|
||||
*/
|
||||
writeClipboard(text: string);
|
||||
|
||||
/**
|
||||
* 唤醒 uTools
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user