mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 21:13:02 +08:00
引入tree
This commit is contained in:
parent
b02ac2f09e
commit
77bd51acdb
@ -463,7 +463,7 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => {
|
|||||||
sandbox.console = {
|
sandbox.console = {
|
||||||
log: (...stdout) => {
|
log: (...stdout) => {
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
callback(parseStdout(stdout), null)
|
callback(stdout, null)
|
||||||
},
|
},
|
||||||
error: (...stderr) => {
|
error: (...stderr) => {
|
||||||
callback(null, parseStdout(stderr))
|
callback(null, parseStdout(stderr))
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div v-if="!fromUtools">
|
<div v-if="!fromUtools">
|
||||||
<q-dialog v-model="isResultShow" position="bottom" @hide="stopRun">
|
<q-dialog v-model="isResultShow" position="bottom" @hide="stopRun">
|
||||||
<q-card style="max-width: 700px; min-width: 500px; overflow: hidden">
|
<q-card style="max-width: 700px; min-width: 700px; overflow: hidden">
|
||||||
<q-toolbar>
|
<q-toolbar>
|
||||||
<q-avatar>
|
<q-avatar>
|
||||||
<q-icon
|
<q-icon
|
||||||
@ -23,6 +23,7 @@
|
|||||||
<ResultArea
|
<ResultArea
|
||||||
v-if="isResultShow"
|
v-if="isResultShow"
|
||||||
@frameLoad="frameLoad"
|
@frameLoad="frameLoad"
|
||||||
|
@expandTrees="outputAutoHeight(fromUtools)"
|
||||||
:frameInitHeight="frameInitHeight"
|
:frameInitHeight="frameInitHeight"
|
||||||
:enableHtml="enableHtml"
|
:enableHtml="enableHtml"
|
||||||
:runResultStatus="runResultStatus"
|
:runResultStatus="runResultStatus"
|
||||||
@ -38,6 +39,7 @@
|
|||||||
<ResultArea
|
<ResultArea
|
||||||
v-if="isResultShow"
|
v-if="isResultShow"
|
||||||
@frameLoad="frameLoad"
|
@frameLoad="frameLoad"
|
||||||
|
@expandTrees="outputAutoHeight(fromUtools)"
|
||||||
:frameInitHeight="frameInitHeight"
|
:frameInitHeight="frameInitHeight"
|
||||||
:enableHtml="enableHtml"
|
:enableHtml="enableHtml"
|
||||||
:runResultStatus="runResultStatus"
|
:runResultStatus="runResultStatus"
|
||||||
@ -61,7 +63,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isResultShow: false,
|
isResultShow: false,
|
||||||
runResult: "",
|
runResult: [],
|
||||||
runResultStatus: true,
|
runResultStatus: true,
|
||||||
subInputValue: "",
|
subInputValue: "",
|
||||||
subInputListener: null,
|
subInputListener: null,
|
||||||
@ -230,16 +232,17 @@ export default {
|
|||||||
this.isResultShow = true;
|
this.isResultShow = true;
|
||||||
this.timeStamp = new Date().getTime();
|
this.timeStamp = new Date().getTime();
|
||||||
this.runResultStatus = isSuccess;
|
this.runResultStatus = isSuccess;
|
||||||
let contlength = content?.length || 0;
|
// let contlength = content?.length || 0;
|
||||||
if (contlength > this.resultMaxLength)
|
// if (contlength > this.resultMaxLength)
|
||||||
content =
|
// content =
|
||||||
content.slice(0, this.resultMaxLength - 100) +
|
// content.slice(0, this.resultMaxLength - 100) +
|
||||||
`\n\n...\n${
|
// `\n\n...\n${
|
||||||
contlength - this.resultMaxLength - 100
|
// contlength - this.resultMaxLength - 100
|
||||||
} 字省略\n...\n\n` +
|
// } 字省略\n...\n\n` +
|
||||||
content.slice(contlength - 100);
|
// content.slice(contlength - 100);
|
||||||
let pretreatment = action(content);
|
// let pretreatment = action(content);
|
||||||
pretreatment && (this.runResult += pretreatment);
|
// pretreatment && (this.runResult += pretreatment);
|
||||||
|
this.runResult = this.runResult.concat(content);
|
||||||
this.outputAutoHeight(this.fromUtools);
|
this.outputAutoHeight(this.fromUtools);
|
||||||
},
|
},
|
||||||
// 根据输出自动滚动及调整 utools 高度
|
// 根据输出自动滚动及调整 utools 高度
|
||||||
@ -258,7 +261,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
stopRun() {
|
stopRun() {
|
||||||
this.runResult = "";
|
this.runResult = [];
|
||||||
if (!!this.subInputListener) {
|
if (!!this.subInputListener) {
|
||||||
this.subInputValue = "";
|
this.subInputValue = "";
|
||||||
utools.removeSubInput();
|
utools.removeSubInput();
|
||||||
|
@ -9,20 +9,22 @@
|
|||||||
@load="frameLoad"
|
@load="frameLoad"
|
||||||
v-if="showFrame"
|
v-if="showFrame"
|
||||||
></iframe>
|
></iframe>
|
||||||
<pre
|
<div v-else v-show="!!runResult" :class="{ 'text-red': !runResultStatus }">
|
||||||
v-else
|
<div v-for="item in runResult" :key="item">
|
||||||
v-show="!!runResult"
|
<ObjectTree
|
||||||
:class="{
|
:obj="item"
|
||||||
'text-red': !runResultStatus,
|
v-if="typeof item === 'object'"
|
||||||
'q-pa-md': 1,
|
@expandTrees="$emit('expandTrees')"
|
||||||
result: 1,
|
/>
|
||||||
}"
|
<pre class="q-pa-md result" v-text="item" v-else></pre>
|
||||||
v-text="runResult"
|
</div>
|
||||||
></pre>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ObjectTree from "components/popup/ObjectTree";
|
||||||
|
|
||||||
const frameStyle = `<style>::-webkit-scrollbar {
|
const frameStyle = `<style>::-webkit-scrollbar {
|
||||||
width: 6px;
|
width: 6px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
@ -47,13 +49,14 @@ body {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: { ObjectTree },
|
||||||
data() {
|
data() {
|
||||||
return { frameStyle: frameStyle, frameHeight: this.frameInitHeight };
|
return { frameStyle: frameStyle, frameHeight: this.frameInitHeight };
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
enableHtml: Boolean,
|
enableHtml: Boolean,
|
||||||
runResultStatus: Boolean,
|
runResultStatus: Boolean,
|
||||||
runResult: String,
|
runResult: Object,
|
||||||
maxHeight: Number,
|
maxHeight: Number,
|
||||||
frameInitHeight: Number,
|
frameInitHeight: Number,
|
||||||
},
|
},
|
||||||
@ -73,6 +76,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.frameInit();
|
this.frameInit();
|
||||||
|
console.log(this.runResult);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
frameInit() {
|
frameInit() {
|
||||||
|
62
src/components/popup/ObjectTree.vue
Normal file
62
src/components/popup/ObjectTree.vue
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<template>
|
||||||
|
<div class="q-pa-xs q-gutter-sm">
|
||||||
|
<q-tree :nodes="trees" node-key="label" @lazy-load="showChildren" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { toRaw } from "vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
trees: [
|
||||||
|
{
|
||||||
|
label: "object",
|
||||||
|
lazy: true,
|
||||||
|
item: this.obj,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
obj: Object,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
liteItem(item) {
|
||||||
|
if (typeof item === "undefined") return "undefined";
|
||||||
|
if (typeof item === "number") return item;
|
||||||
|
if (typeof item === "function")
|
||||||
|
return `[Function: ${item.name ? item.name : "(anonymous)"}]`;
|
||||||
|
if (typeof item !== "object") return item.toString();
|
||||||
|
if (_.isBuffer(item)) {
|
||||||
|
var bufferString = `[Buffer ${item
|
||||||
|
.slice(0, 50)
|
||||||
|
.toString("hex")
|
||||||
|
.match(/\w{1,2}/g)
|
||||||
|
.join(" ")}`;
|
||||||
|
if (item.length > 50)
|
||||||
|
bufferString += `...${(item.length / 1000).toFixed(2)} kb `;
|
||||||
|
return bufferString + "]";
|
||||||
|
}
|
||||||
|
if (item instanceof ArrayBuffer) return `ArrayBuffer(${item.byteLength})`;
|
||||||
|
if (item instanceof Blob)
|
||||||
|
return `Blob { size: ${item.size}, type: "${item.type}" }`;
|
||||||
|
return "object";
|
||||||
|
},
|
||||||
|
showChildren({ node, key, done, fail }) {
|
||||||
|
let children = [];
|
||||||
|
for (let key in node.item) {
|
||||||
|
let value = toRaw(node.item)[key];
|
||||||
|
children.push({
|
||||||
|
label: `${key}: ${this.liteItem(value)}`,
|
||||||
|
lazy: typeof value === "object",
|
||||||
|
item: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
done(children);
|
||||||
|
this.$emit("expandTrees");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
x
Reference in New Issue
Block a user