html 监听错误和重定向 console

This commit is contained in:
fofolee 2022-04-29 16:44:10 +08:00
parent 3e3248162f
commit de01de24bb
3 changed files with 29 additions and 17 deletions

View File

@ -58,6 +58,7 @@ export default {
enableHtml: Boolean, enableHtml: Boolean,
runResultStatus: Boolean, runResultStatus: Boolean,
runResult: Object, runResult: Object,
maxHeight: Number,
frameInitHeight: Number, frameInitHeight: Number,
}, },
computed: { computed: {
@ -67,7 +68,7 @@ export default {
src() { src() {
return this.showFrame return this.showFrame
? window.URL.createObjectURL( ? window.URL.createObjectURL(
new Blob([this.frameStyle].concat(this.runResult), { new Blob([this.frameStyle, this.runResult], {
type: "text/html", type: "text/html",
}) })
) )
@ -82,16 +83,30 @@ export default {
frameInit() { frameInit() {
let cfw = this.$refs?.iframe?.contentWindow; let cfw = this.$refs?.iframe?.contentWindow;
if (!cfw) return; if (!cfw) return;
let showError = (...args) => {
quickcommand.showMessageBox(args.join(" "), "error", 0);
};
let showLog = (...args) => {
quickcommand.showMessageBox(args.join(" "), "success", 0);
};
let ctx = { let ctx = {
quickcommand: _.cloneDeep(quickcommand), quickcommand: _.cloneDeep(quickcommand),
utools: _.cloneDeep(utools), utools: _.cloneDeep(utools),
parent: undefined, parent: undefined,
console: {
log: showLog,
error: showError,
},
onerror: (e) => showError(e),
}; };
Object.assign(cfw, ctx); Object.assign(cfw, ctx);
cfw.onload = () => { cfw.onload = () => {
let clientHeight = this.frameHeight = Math.min(
cfw.document.documentElement.getBoundingClientRect().height; cfw.document.body.innerText
this.frameHeight = clientHeight === 20 ? 0 : clientHeight; ? cfw.document.documentElement.getBoundingClientRect().height
: 0,
this.maxHeight
);
this.$emit("frameLoad", this.frameHeight); this.$emit("frameLoad", this.frameHeight);
}; };
}, },

View File

@ -92,6 +92,15 @@ export default {
message: message, message: message,
timeout: time, timeout: time,
position: "top", position: "top",
actions:
time === 0
? [
{
label: "确定",
color: "white",
},
]
: [],
}); });
}, },

View File

@ -138,7 +138,7 @@ interface quickcommandApi {
* ``` * ```
* @param message * @param message
* @param icon success * @param icon success
* @param time 3000 * @param time 3000 0
*/ */
showMessageBox( showMessageBox(
message: string, message: string,
@ -352,18 +352,6 @@ interface quickcommandApi {
*/ */
simulatePaste(); simulatePaste();
/**
*
*/
readClipboard(): text<string>;
/**
*
*
* @param text
*/
writeClipboard(text: string);
/** /**
* uTools * uTools
* *