结构调整

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

View File

@ -79,15 +79,24 @@ export default {
}, },
methods: { methods: {
frameInit() { frameInit() {
let cfw = this.$refs?.iframe?.contentWindow; if (!this.showFrame) return;
if (!cfw) 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) => { let showError = (...args) => {
quickcommand.showMessageBox(args.join(" "), "error", 0); quickcommand.showMessageBox(args.join(" "), "error", 0);
}; };
let showLog = (...args) => { let showLog = (...args) => {
quickcommand.showMessageBox(args.join(" "), "success", 0); quickcommand.showMessageBox(args.join(" "), "success", 0);
}; };
let ctx = { return {
quickcommand: _.cloneDeep(quickcommand), quickcommand: _.cloneDeep(quickcommand),
utools: _.cloneDeep(utools), utools: _.cloneDeep(utools),
parent: undefined, parent: undefined,
@ -97,13 +106,6 @@ export default {
}, },
onerror: (e) => showError(e), 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);
};
}, },
}, },
}; };