结构调整

This commit is contained in:
fofolee 2022-04-30 10:55:07 +08:00
parent 545d467b16
commit 619bf5789e
2 changed files with 74 additions and 59 deletions

View File

@ -116,31 +116,49 @@ export default {
setTimeout(() => {
utools.outPlugin();
}, 500);
if (currentCommand.program === "quickcommand") {
switch (currentCommand.program) {
case "quickcommand":
window.runCodeInSandbox(
currentCommand.cmd,
(stdout, stderr) => {
this.handleResult(stdout, stderr, { outPlugin, action, earlyExit });
this.handleResult(stdout, stderr, {
outPlugin,
action,
earlyExit,
});
},
{ enterData: this.$root.enterData }
);
} else if (currentCommand.program === "html") {
break;
case "html":
this.showRunResult(currentCommand.cmd, true);
} else {
let option =
currentCommand.program === "custom"
? currentCommand.customOptions
: this.$root.programs[currentCommand.program];
option.scptarg = currentCommand.scptarg || "";
option.charset = currentCommand.charset || {};
break;
default:
this.childProcess = window.runCodeFile(
currentCommand.cmd,
option,
this.getCommandOpt(currentCommand),
currentCommand.output === "terminal",
(stdout, stderr) => {
this.handleResult(stdout, stderr, { outPlugin, action, earlyExit });
this.handleResult(stdout, stderr, {
outPlugin,
action,
earlyExit,
});
}
);
this.listenStopSign();
break;
}
},
getCommandOpt(command) {
let option =
command.program === "custom"
? command.customOptions
: this.$root.programs[command.program];
option.scptarg = command.scptarg || "";
option.charset = command.charset || {};
},
listenStopSign() {
// ctrl c
this.ctrlCListener = (e) => {
if (e.key === "c" && e.ctrlKey) {
@ -150,7 +168,6 @@ export default {
}
};
document.addEventListener("keydown", this.ctrlCListener);
}
},
//
assignSpecialVars(cmd) {
@ -239,7 +256,7 @@ export default {
this.timeStamp = new Date().getTime();
this.runResultStatus = isSuccess;
if (!_.isArray(content)) content = [content];
content = await this.cacheScript(content);
if (this.enableHtml) content = await this.cacheScript(content);
this.runResult = this.runResult.concat(content);
this.autoScroll();
},
@ -253,6 +270,7 @@ export default {
if (this.enableHtml) return;
this.$nextTick(() => {
let results = document.querySelectorAll(".result");
if (!results.length) return;
results[results.length - 1].scrollIntoView({
block: "end",
behavior: "smooth",
@ -279,10 +297,7 @@ export default {
},
//
async cacheScript(content) {
if (!this.enableHtml) return;
let htmls = [];
for (let item of content) {
let html = quickcommand.htmlParse(item);
let html = quickcommand.htmlParse(content.join(""));
let scriptDoms = html.querySelectorAll("script");
for (let i = 0; i < scriptDoms.length; i++) {
let src = scriptDoms[i].src;
@ -291,9 +306,7 @@ export default {
await quickcommand.downloadFile(src, dest);
scriptDoms[i].src = "file://" + dest;
}
htmls.push(html.documentElement.innerHTML);
}
return htmls;
return [html.documentElement.innerHTML];
},
},
unmounted() {

View File

@ -79,15 +79,24 @@ export default {
},
methods: {
frameInit() {
let cfw = this.$refs?.iframe?.contentWindow;
if (!cfw) return;
if (!this.showFrame) return;
let cfw = this.$refs.iframe.contentWindow;
Object.assign(cfw, this.context());
cfw.onload = () => {
let clientHeight =
cfw.document.documentElement.getBoundingClientRect().height;
this.frameHeight = clientHeight === 20 ? 0 : clientHeight;
this.$emit("frameLoad", this.frameHeight);
};
},
context() {
let showError = (...args) => {
quickcommand.showMessageBox(args.join(" "), "error", 0);
};
let showLog = (...args) => {
quickcommand.showMessageBox(args.join(" "), "success", 0);
};
let ctx = {
return {
quickcommand: _.cloneDeep(quickcommand),
utools: _.cloneDeep(utools),
parent: undefined,
@ -97,13 +106,6 @@ export default {
},
onerror: (e) => showError(e),
};
Object.assign(cfw, ctx);
cfw.onload = () => {
let clientHeight =
cfw.document.documentElement.getBoundingClientRect().height;
this.frameHeight = clientHeight === 20 ? 0 : clientHeight;
this.$emit("frameLoad", this.frameHeight);
};
},
},
};