mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
尝试 html 输出放在 iframe 里
This commit is contained in:
parent
6d1e7f8347
commit
3ede4cdd73
@ -451,7 +451,7 @@ let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
|
|||||||
|
|
||||||
// 屏蔽危险函数
|
// 屏蔽危险函数
|
||||||
window.getuToolsLite = () => {
|
window.getuToolsLite = () => {
|
||||||
var utoolsLite = Object.assign({}, utools)
|
var utoolsLite = Object.assign({}, _.cloneDeep(utools))
|
||||||
// if (utools.isDev()) return utoolsLite
|
// if (utools.isDev()) return utoolsLite
|
||||||
// 数据库相关接口
|
// 数据库相关接口
|
||||||
delete utoolsLite.db
|
delete utoolsLite.db
|
||||||
@ -473,12 +473,12 @@ window.getuToolsLite = () => {
|
|||||||
|
|
||||||
let getSandboxFuns = () => {
|
let getSandboxFuns = () => {
|
||||||
var sandbox = {
|
var sandbox = {
|
||||||
|
fetch: fetch.bind(window),
|
||||||
utools: getuToolsLite(),
|
utools: getuToolsLite(),
|
||||||
quickcommand,
|
quickcommand,
|
||||||
electron,
|
electron,
|
||||||
axios,
|
axios,
|
||||||
Audio,
|
Audio,
|
||||||
fetch,
|
|
||||||
_,
|
_,
|
||||||
// 兼容老版本
|
// 兼容老版本
|
||||||
fs,
|
fs,
|
||||||
@ -503,8 +503,7 @@ utools.isDev() && (window.godMode = code => eval(code))
|
|||||||
|
|
||||||
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
|
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
|
||||||
window.evalCodeInSandbox = (code, userVars = {}) => {
|
window.evalCodeInSandbox = (code, userVars = {}) => {
|
||||||
let sandbox = getSandboxFuns()
|
let sandboxWithUV = Object.assign(userVars, getSandboxFuns())
|
||||||
let sandboxWithUV = Object.assign(userVars, sandbox)
|
|
||||||
try {
|
try {
|
||||||
return new Compartment(sandboxWithUV).evaluate(code);
|
return new Compartment(sandboxWithUV).evaluate(code);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -16,12 +16,19 @@
|
|||||||
>
|
>
|
||||||
</q-toolbar>
|
</q-toolbar>
|
||||||
<q-card-section class="row items-center">
|
<q-card-section class="row items-center">
|
||||||
|
<iframe
|
||||||
|
ref="iframe"
|
||||||
|
:srcdoc="runResult"
|
||||||
|
frameborder="0"
|
||||||
|
v-if="htmlOutput"
|
||||||
|
></iframe>
|
||||||
<pre
|
<pre
|
||||||
|
v-else
|
||||||
:class="{
|
:class="{
|
||||||
'text-red': !runResultStatus,
|
'text-red': !runResultStatus,
|
||||||
result: 1,
|
result: 1,
|
||||||
}"
|
}"
|
||||||
v-html="runResult"
|
v-text="runResult"
|
||||||
></pre>
|
></pre>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-actions align="right">
|
<q-card-actions align="right">
|
||||||
@ -31,14 +38,21 @@
|
|||||||
</q-dialog>
|
</q-dialog>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
|
<iframe
|
||||||
|
ref="iframe"
|
||||||
|
:srcdoc="runResult"
|
||||||
|
frameborder="0"
|
||||||
|
v-if="htmlOutput"
|
||||||
|
></iframe>
|
||||||
<pre
|
<pre
|
||||||
|
v-else
|
||||||
v-show="!!runResult"
|
v-show="!!runResult"
|
||||||
:class="{
|
:class="{
|
||||||
'text-red': !runResultStatus,
|
'text-red': !runResultStatus,
|
||||||
'q-pa-md': 1,
|
'q-pa-md': 1,
|
||||||
result: 1,
|
result: 1,
|
||||||
}"
|
}"
|
||||||
v-html="runResult"
|
v-text="runResult"
|
||||||
></pre>
|
></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -49,7 +63,6 @@
|
|||||||
import outputTypes from "../js/options/outputTypes.js";
|
import outputTypes from "../js/options/outputTypes.js";
|
||||||
import specialVars from "../js/options/specialVars.js";
|
import specialVars from "../js/options/specialVars.js";
|
||||||
import commandTypes from "../js/options/commandTypes.js";
|
import commandTypes from "../js/options/commandTypes.js";
|
||||||
import { event } from "quasar";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -61,6 +74,7 @@ export default {
|
|||||||
listener: null,
|
listener: null,
|
||||||
history: [],
|
history: [],
|
||||||
historyIdx: null,
|
historyIdx: null,
|
||||||
|
htmlOutput: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
@ -80,6 +94,9 @@ export default {
|
|||||||
needTempPayload() {
|
needTempPayload() {
|
||||||
return ["edit", "new", "config"].includes(this.action.type);
|
return ["edit", "new", "config"].includes(this.action.type);
|
||||||
},
|
},
|
||||||
|
iframeCtw() {
|
||||||
|
return this.$refs?.iframe?.contentWindow;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 运行命令
|
// 运行命令
|
||||||
@ -91,6 +108,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async fire(currentCommand) {
|
async fire(currentCommand) {
|
||||||
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
|
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
|
||||||
|
this.htmlOutput = currentCommand.output === "html";
|
||||||
let { hideWindow, outPlugin, action } =
|
let { hideWindow, outPlugin, action } =
|
||||||
outputTypes[currentCommand.output];
|
outputTypes[currentCommand.output];
|
||||||
// 需要隐藏的提前隐藏窗口
|
// 需要隐藏的提前隐藏窗口
|
||||||
@ -203,6 +221,7 @@ export default {
|
|||||||
// 显示运行结果
|
// 显示运行结果
|
||||||
showRunResult(content, isSuccess, action) {
|
showRunResult(content, isSuccess, action) {
|
||||||
this.isResultShow = true;
|
this.isResultShow = true;
|
||||||
|
this.setIframe();
|
||||||
this.runResultStatus = isSuccess;
|
this.runResultStatus = isSuccess;
|
||||||
let contlength = content?.length || 0;
|
let contlength = content?.length || 0;
|
||||||
if (contlength > this.resultMaxLength)
|
if (contlength > this.resultMaxLength)
|
||||||
@ -239,6 +258,17 @@ export default {
|
|||||||
document.removeEventListener("keydown", this.listener, true);
|
document.removeEventListener("keydown", this.listener, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setIframe() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (!this.iframeCtw) return;
|
||||||
|
let ctx = {
|
||||||
|
quickcommand,
|
||||||
|
utools,
|
||||||
|
parent: undefined,
|
||||||
|
};
|
||||||
|
Object.assign(this.iframeCtw, _.cloneDeep(ctx));
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.stopRun();
|
this.stopRun();
|
||||||
@ -253,4 +283,8 @@ export default {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: 550px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -80,7 +80,8 @@
|
|||||||
<q-card-section class="q-gutter-sm">
|
<q-card-section class="q-gutter-sm">
|
||||||
<div>「uTools 会员」或「插件会员」均可享受本插件的会员功能</div>
|
<div>「uTools 会员」或「插件会员」均可享受本插件的会员功能</div>
|
||||||
<div class="text-weight-bolder">
|
<div class="text-weight-bolder">
|
||||||
本插件会员仅需 {{ memberPrice }} 元,一次性付费,uTools 会员享 9 折优惠
|
本插件会员仅需 {{ memberPrice }} 元,一次性付费,uTools 会员享 9
|
||||||
|
折优惠
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
会员功能将在保障用户完整的插件功能体验的前提下,提供以下个性化功能:
|
会员功能将在保障用户完整的插件功能体验的前提下,提供以下个性化功能:
|
||||||
@ -158,7 +159,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getUserInfo() {
|
getUserInfo() {
|
||||||
Object.assign(this.userInfo, utools.getUser());
|
Object.assign(this.userInfo, this.$root.utools.whole.getUser());
|
||||||
let statisticsData = this.$root.utools.getDB(
|
let statisticsData = this.$root.utools.getDB(
|
||||||
this.$root.utools.DBPRE.CFG + "statisticsData"
|
this.$root.utools.DBPRE.CFG + "statisticsData"
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,7 @@ const outputTypes = {
|
|||||||
name: "text",
|
name: "text",
|
||||||
label: "纯文本输出",
|
label: "纯文本输出",
|
||||||
icon: "text_snippet",
|
icon: "text_snippet",
|
||||||
action: result => window.htmlEncode(result)
|
action: result => result
|
||||||
},
|
},
|
||||||
html: {
|
html: {
|
||||||
name: "html",
|
name: "html",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user