结构调整

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,42 +116,59 @@ export default {
setTimeout(() => { setTimeout(() => {
utools.outPlugin(); utools.outPlugin();
}, 500); }, 500);
if (currentCommand.program === "quickcommand") { switch (currentCommand.program) {
window.runCodeInSandbox( case "quickcommand":
currentCommand.cmd, window.runCodeInSandbox(
(stdout, stderr) => { currentCommand.cmd,
this.handleResult(stdout, stderr, { outPlugin, action, earlyExit }); (stdout, stderr) => {
}, this.handleResult(stdout, stderr, {
{ enterData: this.$root.enterData } outPlugin,
); action,
} else if (currentCommand.program === "html") { earlyExit,
this.showRunResult(currentCommand.cmd, true); });
} else { },
let option = { enterData: this.$root.enterData }
currentCommand.program === "custom" );
? currentCommand.customOptions break;
: this.$root.programs[currentCommand.program]; case "html":
option.scptarg = currentCommand.scptarg || ""; this.showRunResult(currentCommand.cmd, true);
option.charset = currentCommand.charset || {}; break;
this.childProcess = window.runCodeFile( default:
currentCommand.cmd, this.childProcess = window.runCodeFile(
option, currentCommand.cmd,
currentCommand.output === "terminal", this.getCommandOpt(currentCommand),
(stdout, stderr) => { currentCommand.output === "terminal",
this.handleResult(stdout, stderr, { outPlugin, action, earlyExit }); (stdout, stderr) => {
} this.handleResult(stdout, stderr, {
); outPlugin,
// ctrl c action,
this.ctrlCListener = (e) => { earlyExit,
if (e.key === "c" && e.ctrlKey) { });
quickcommand.kill(this.childProcess.pid); }
quickcommand.showMessageBox("命令已终止"); );
document.removeEventListener("keydown", this.ctrlCListener); this.listenStopSign();
} break;
};
document.addEventListener("keydown", this.ctrlCListener);
} }
}, },
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) {
quickcommand.kill(this.childProcess.pid);
quickcommand.showMessageBox("命令已终止");
document.removeEventListener("keydown", this.ctrlCListener);
}
};
document.addEventListener("keydown", this.ctrlCListener);
},
// //
assignSpecialVars(cmd) { assignSpecialVars(cmd) {
let userData = this.$root.utools.userData.all(); let userData = this.$root.utools.userData.all();
@ -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,21 +297,16 @@ export default {
}, },
// //
async cacheScript(content) { async cacheScript(content) {
if (!this.enableHtml) return; let html = quickcommand.htmlParse(content.join(""));
let htmls = []; let scriptDoms = html.querySelectorAll("script");
for (let item of content) { for (let i = 0; i < scriptDoms.length; i++) {
let html = quickcommand.htmlParse(item); let src = scriptDoms[i].src;
let scriptDoms = html.querySelectorAll("script"); if (!this.urlReg.test(src)) continue;
for (let i = 0; i < scriptDoms.length; i++) { let dest = window.getQuickcommandTempFile("js", "remoteScript_" + i);
let src = scriptDoms[i].src; await quickcommand.downloadFile(src, dest);
if (!this.urlReg.test(src)) continue; scriptDoms[i].src = "file://" + dest;
let dest = window.getQuickcommandTempFile("js", "remoteScript_" + i);
await quickcommand.downloadFile(src, dest);
scriptDoms[i].src = "file://" + dest;
}
htmls.push(html.documentElement.innerHTML);
} }
return htmls; return [html.documentElement.innerHTML];
}, },
}, },
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);
};
}, },
}, },
}; };