mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-10 23:54:57 +08:00
运行脚本和新建代码片段支持引入变量
This commit is contained in:
parent
d9e542d4f2
commit
37f5ee2160
@ -187,7 +187,7 @@ export default {
|
|||||||
this.showComposer = true;
|
this.showComposer = true;
|
||||||
break;
|
break;
|
||||||
case "insert-text":
|
case "insert-text":
|
||||||
this.$refs.editor.repacleEditorSelection(data);
|
this.$refs.editor.replaceEditorSelection(data);
|
||||||
break;
|
break;
|
||||||
case "restore":
|
case "restore":
|
||||||
this.restoreHistory(data);
|
this.restoreHistory(data);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<div class="script-editor">
|
<div class="script-editor">
|
||||||
<!-- 代码编辑器 -->
|
<!-- 代码编辑器 -->
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
|
ref="codeEditor"
|
||||||
:model-value="argvs.code"
|
:model-value="argvs.code"
|
||||||
@update:modelValue="updateArgvs('code', $event)"
|
@update:modelValue="updateArgvs('code', $event)"
|
||||||
:language="argvs.language"
|
:language="argvs.language"
|
||||||
@ -34,6 +35,19 @@
|
|||||||
</q-item>
|
</q-item>
|
||||||
</template>
|
</template>
|
||||||
</q-select>
|
</q-select>
|
||||||
|
<q-field filled dense class="col-auto">
|
||||||
|
<template v-slot:control>
|
||||||
|
<div class="variable-label">插入变量</div>
|
||||||
|
</template>
|
||||||
|
<template v-slot:append>
|
||||||
|
<VariableList
|
||||||
|
:show-variable-list="true"
|
||||||
|
:show-function-list="false"
|
||||||
|
:show-global-variables="true"
|
||||||
|
@emit-value="insertVariable"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</q-field>
|
||||||
|
|
||||||
<!-- 编码设置 -->
|
<!-- 编码设置 -->
|
||||||
<q-select
|
<q-select
|
||||||
@ -137,6 +151,7 @@ import BorderLabel from "components/composer/common/BorderLabel.vue";
|
|||||||
import CheckButton from "components/composer/common/CheckButton.vue";
|
import CheckButton from "components/composer/common/CheckButton.vue";
|
||||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
||||||
import programs from "js/options/programs";
|
import programs from "js/options/programs";
|
||||||
|
import VariableList from "components/composer/common/varinput/VariableList.vue";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "ScriptEditor",
|
name: "ScriptEditor",
|
||||||
@ -146,6 +161,7 @@ export default defineComponent({
|
|||||||
ArrayEditor,
|
ArrayEditor,
|
||||||
BorderLabel,
|
BorderLabel,
|
||||||
CheckButton,
|
CheckButton,
|
||||||
|
VariableList,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
modelValue: Object,
|
modelValue: Object,
|
||||||
@ -212,10 +228,19 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
generateCode(argvs = this.argvs) {
|
generateCode(argvs = this.argvs) {
|
||||||
|
const variables = argvs.code.match(/___([^_]+?)___/g);
|
||||||
|
const replaceStr =
|
||||||
|
variables
|
||||||
|
?.map((variable) => {
|
||||||
|
return `.replace("${variable}", ${variable.slice(3, -3)})`;
|
||||||
|
})
|
||||||
|
.join("") || "";
|
||||||
if (this.isCodeSnippet) {
|
if (this.isCodeSnippet) {
|
||||||
return `quickcomposer.coding.base64Decode("${quickcomposer.coding.base64Encode(
|
return (
|
||||||
argvs.code
|
`quickcomposer.coding.base64Decode("${quickcomposer.coding.base64Encode(
|
||||||
)}")`;
|
argvs.code
|
||||||
|
)}")` + replaceStr
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const options = {
|
const options = {
|
||||||
language: argvs.language,
|
language: argvs.language,
|
||||||
@ -239,7 +264,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return `${this.modelValue.value}(${stringifyArgv(
|
return `${this.modelValue.value}(${stringifyArgv(
|
||||||
argvs.code
|
argvs.code
|
||||||
)}, ${stringifyArgv(options)})`;
|
)}${replaceStr}, ${stringifyArgv(options)})`;
|
||||||
},
|
},
|
||||||
getSummary(argvs) {
|
getSummary(argvs) {
|
||||||
return `运行${argvs.language}代码`;
|
return `运行${argvs.language}代码`;
|
||||||
@ -268,6 +293,9 @@ export default defineComponent({
|
|||||||
argvs,
|
argvs,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
insertVariable(_, variable) {
|
||||||
|
this.$refs.codeEditor.replaceEditorSelection("___" + variable + "___");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
||||||
|
@ -388,7 +388,7 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
// 替换选中的文本,供外部调用
|
// 替换选中的文本,供外部调用
|
||||||
repacleEditorSelection(text) {
|
replaceEditorSelection(text) {
|
||||||
var selection = this.codeEditor.getSelection();
|
var selection = this.codeEditor.getSelection();
|
||||||
var range = new monaco.Range(
|
var range = new monaco.Range(
|
||||||
selection.startLineNumber,
|
selection.startLineNumber,
|
||||||
@ -413,7 +413,7 @@ export default defineComponent({
|
|||||||
if (type === "replace") {
|
if (type === "replace") {
|
||||||
this.codeEditor.setValue(value);
|
this.codeEditor.setValue(value);
|
||||||
} else if (type === "insert") {
|
} else if (type === "insert") {
|
||||||
this.repacleEditorSelection(value);
|
this.replaceEditorSelection(value);
|
||||||
}
|
}
|
||||||
this.$emit("saveHistory", value);
|
this.$emit("saveHistory", value);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user