mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-22 18:22:37 +08:00
OutPutEditor添加键入建议变量名功能,并加入重名检测
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<OutputField
|
||||
v-model="simpleOutputVar"
|
||||
:label="currentOutputs?.label || '输出变量名'"
|
||||
:suggest-name="currentOutputs?.suggestName"
|
||||
autofocus
|
||||
:show-variable-list="true"
|
||||
class="q-px-sm"
|
||||
@@ -131,6 +132,12 @@ export default defineComponent({
|
||||
(cmd) => cmd.value === this.command.value
|
||||
);
|
||||
},
|
||||
defaultOutputVariable() {
|
||||
return (
|
||||
this.currentSubCommand?.defaultOutputVariable ||
|
||||
this.command.defaultOutputVariable
|
||||
);
|
||||
},
|
||||
commandName() {
|
||||
return this.currentSubCommand.label || this.command.label;
|
||||
},
|
||||
@@ -158,35 +165,36 @@ export default defineComponent({
|
||||
},
|
||||
watch: {
|
||||
"command.outputVariable": {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
handler(newValue) {
|
||||
this.initOutputVars(newValue);
|
||||
handler(value) {
|
||||
this.initOutputVars(value);
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
"command.asyncMode": {
|
||||
immediate: true,
|
||||
handler(newValue) {
|
||||
this.asyncMode = newValue;
|
||||
handler(value) {
|
||||
this.asyncMode = value;
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
"command.callbackFunc": {
|
||||
immediate: true,
|
||||
handler(newValue) {
|
||||
this.callbackFunc = newValue;
|
||||
handler(value) {
|
||||
this.callbackFunc = value;
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
initOutputVars(outputVariable) {
|
||||
initOutputVars(value) {
|
||||
const outputVariable = value || this.defaultOutputVariable;
|
||||
// 初始化完整输出变量名
|
||||
if (!outputVariable) return;
|
||||
this.simpleOutputVar = outputVariable.name || "";
|
||||
|
||||
if (this.currentOutputs) {
|
||||
// 初始化详细输出变量,直接使用扁平化的结构
|
||||
this.outputVars = outputVariable?.details || {};
|
||||
if (!outputVariable) {
|
||||
this.simpleOutputVar = "";
|
||||
this.outputVars = {};
|
||||
return;
|
||||
}
|
||||
|
||||
this.simpleOutputVar = outputVariable.name;
|
||||
this.outputVars = outputVariable.details;
|
||||
},
|
||||
handleConfirm() {
|
||||
const outputVariable = {};
|
||||
|
||||
@@ -13,6 +13,21 @@
|
||||
<div class="variable-label">{{ label }}</div>
|
||||
</template>
|
||||
<template v-slot:append>
|
||||
<q-btn
|
||||
v-if="suggestName"
|
||||
flat
|
||||
dense
|
||||
@click="updateSuggestName(suggestName)"
|
||||
>
|
||||
<q-icon
|
||||
name="emoji_objects"
|
||||
size="14px"
|
||||
:style="{
|
||||
opacity: 0.8,
|
||||
}"
|
||||
/>
|
||||
<q-tooltip> 取名困难症?点我! </q-tooltip>
|
||||
</q-btn>
|
||||
<VariableList
|
||||
:show-variable-list="showVariableList"
|
||||
:show-function-list="showFunctionList"
|
||||
@@ -35,7 +50,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import { defineComponent, inject } from "vue";
|
||||
import VariableList from "components/composer/common/varinput/VariableList.vue";
|
||||
|
||||
export default defineComponent({
|
||||
@@ -55,6 +70,10 @@ export default defineComponent({
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
suggestName: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
autofocus: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -77,6 +96,31 @@ export default defineComponent({
|
||||
updateValBySelect(_type, val) {
|
||||
this.$emit("update:modelValue", val);
|
||||
},
|
||||
updateSuggestName(val) {
|
||||
const existingNames = this.getExistingFuncAndParams();
|
||||
// 重名检测,主要检测函数名和参数名
|
||||
if (existingNames.includes(val)) {
|
||||
quickcommand.showMessageBox(
|
||||
"和已有函数名和参数名重复,已自动添加下划线前缀",
|
||||
"warning"
|
||||
);
|
||||
val = "_" + val;
|
||||
}
|
||||
this.$emit("update:modelValue", val);
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const getCurrentFunctions = inject("getCurrentFunctions");
|
||||
const getCurrentVariables = inject("getCurrentVariables");
|
||||
const getExistingFuncAndParams = () => {
|
||||
return [
|
||||
...getCurrentFunctions(),
|
||||
...getCurrentVariables().filter((v) => v.type === "param"),
|
||||
].map((v) => v.name);
|
||||
};
|
||||
return {
|
||||
getExistingFuncAndParams,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -118,7 +162,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
.variable-list-btn {
|
||||
padding: 0 12px;
|
||||
padding: 0 12px 0 3px;
|
||||
}
|
||||
|
||||
/* 去掉下拉按钮的焦点效果 */
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
@update:model-value="updateField(subKey, $event)"
|
||||
:label="subOutput.label"
|
||||
:placeholder="subOutput.placeholder"
|
||||
:suggest-name="subOutput.suggestName"
|
||||
autofocus
|
||||
/>
|
||||
</div>
|
||||
@@ -25,6 +26,7 @@
|
||||
@update:model-value="updateField('', $event)"
|
||||
:label="output.label"
|
||||
:placeholder="output.placeholder"
|
||||
:suggest-name="output.suggestName"
|
||||
autofocus
|
||||
/>
|
||||
</div>
|
||||
@@ -78,18 +80,23 @@ export default defineComponent({
|
||||
default: () => ({}),
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
fixedFields: ["label", "placeholder", "suggestName"],
|
||||
};
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
computed: {
|
||||
hasNestedFields() {
|
||||
if (!this.output) return false;
|
||||
return Object.keys(this.output).some(
|
||||
(key) => key !== "label" && key !== "placeholder"
|
||||
(key) => !this.fixedFields.includes(key)
|
||||
);
|
||||
},
|
||||
getNestedFields() {
|
||||
const fields = {};
|
||||
Object.entries(this.output).forEach(([key, value]) => {
|
||||
if (key !== "label" && key !== "placeholder") {
|
||||
if (!this.fixedFields.includes(key)) {
|
||||
fields[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user