OutPutEditor添加键入建议变量名功能,并加入重名检测

This commit is contained in:
fofolee 2025-01-26 17:25:58 +08:00
parent baf5217132
commit 73684865ae
8 changed files with 124 additions and 48 deletions

View File

@ -146,12 +146,10 @@ export default defineComponent({
}, },
}, },
setup(props) { setup(props) {
const getCurrentExistingVar = inject("getCurrentExistingVar");
// commandIndex // commandIndex
const commandIndex = computed(() => props.commandIndex); const commandIndex = computed(() => props.commandIndex);
// VariableInput // VariableInput
provide("commandIndex", commandIndex); provide("commandIndex", commandIndex);
return { getCurrentExistingVar };
}, },
methods: { methods: {
handleOutputVariableUpdate(result) { handleOutputVariableUpdate(result) {

View File

@ -90,10 +90,6 @@ export default defineComponent({
default: true, default: true,
}, },
}, },
setup() {
const getCurrentExistingVar = inject("getCurrentExistingVar");
return { getCurrentExistingVar };
},
emits: ["update:modelValue", "add-command", "action"], emits: ["update:modelValue", "add-command", "action"],
data() { data() {
return { return {

View File

@ -151,7 +151,7 @@ export default defineComponent({
const getOutputVariables = (flow = getCurrentFlow()) => { const getOutputVariables = (flow = getCurrentFlow()) => {
const variables = []; const variables = [];
for (const [index, cmd] of flow.commands.entries()) { for (const [index, cmd] of flow.commands.entries()) {
if (cmd.outputVariable) { if (cmd.outputVariable && cmd.asyncMode !== "then") {
const { name, details = {} } = cmd.outputVariable; const { name, details = {} } = cmd.outputVariable;
variables.push( variables.push(
...[name, ...Object.values(details)].map((variable) => ({ ...[name, ...Object.values(details)].map((variable) => ({
@ -199,12 +199,6 @@ export default defineComponent({
provide("getCurrentVariables", getCurrentVariables); provide("getCurrentVariables", getCurrentVariables);
const getCurrentExistingVar = () => {
return [...getCurrentVariables(), ...getCurrentFunctions()];
};
provide("getCurrentExistingVar", getCurrentExistingVar);
return { return {
flows, flows,
mainFlow, mainFlow,
@ -352,6 +346,7 @@ export default defineComponent({
"placeholder", "placeholder",
"summary", "summary",
"type", "type",
"defaultOutputVariable",
]; ];
uselessProps.forEach((prop) => delete cmdCopy[prop]); uselessProps.forEach((prop) => delete cmdCopy[prop]);
return cmdCopy; return cmdCopy;

View File

@ -3,7 +3,7 @@
<OperationCard <OperationCard
v-if="hasSubCommands" v-if="hasSubCommands"
:model-value="funcName" :model-value="funcName"
@update:model-value="funcName = $event" @update:model-value="updateFuncName"
:options="localCommand.subCommands" :options="localCommand.subCommands"
/> />
<ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" /> <ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" />
@ -204,6 +204,15 @@ export default defineComponent({
width: `calc(${columnWidth}% - var(--grid-gap))`, width: `calc(${columnWidth}% - var(--grid-gap))`,
}; };
}, },
updateFuncName(value) {
this.funcName = value;
//
const selectSubCommand = this.getSelectSubCommand(value);
if (!selectSubCommand) return;
const newModelValue = { ...this.modelValue, value: value };
delete newModelValue.outputVariable;
this.$emit("update:modelValue", newModelValue);
},
}, },
mounted() { mounted() {
const argvs = this.modelValue.argvs || this.defaultArgvs; const argvs = this.modelValue.argvs || this.defaultArgvs;

View File

@ -10,6 +10,7 @@
<OutputField <OutputField
v-model="simpleOutputVar" v-model="simpleOutputVar"
:label="currentOutputs?.label || '输出变量名'" :label="currentOutputs?.label || '输出变量名'"
:suggest-name="currentOutputs?.suggestName"
autofocus autofocus
:show-variable-list="true" :show-variable-list="true"
class="q-px-sm" class="q-px-sm"
@ -131,6 +132,12 @@ export default defineComponent({
(cmd) => cmd.value === this.command.value (cmd) => cmd.value === this.command.value
); );
}, },
defaultOutputVariable() {
return (
this.currentSubCommand?.defaultOutputVariable ||
this.command.defaultOutputVariable
);
},
commandName() { commandName() {
return this.currentSubCommand.label || this.command.label; return this.currentSubCommand.label || this.command.label;
}, },
@ -158,35 +165,36 @@ export default defineComponent({
}, },
watch: { watch: {
"command.outputVariable": { "command.outputVariable": {
immediate: true, handler(value) {
deep: true, this.initOutputVars(value);
handler(newValue) {
this.initOutputVars(newValue);
}, },
immediate: true,
}, },
"command.asyncMode": { "command.asyncMode": {
immediate: true, handler(value) {
handler(newValue) { this.asyncMode = value;
this.asyncMode = newValue;
}, },
immediate: true,
}, },
"command.callbackFunc": { "command.callbackFunc": {
immediate: true, handler(value) {
handler(newValue) { this.callbackFunc = value;
this.callbackFunc = newValue;
}, },
immediate: true,
}, },
}, },
methods: { methods: {
initOutputVars(outputVariable) { initOutputVars(value) {
const outputVariable = value || this.defaultOutputVariable;
// //
if (!outputVariable) return; if (!outputVariable) {
this.simpleOutputVar = outputVariable.name || ""; this.simpleOutputVar = "";
this.outputVars = {};
if (this.currentOutputs) { return;
// 使
this.outputVars = outputVariable?.details || {};
} }
this.simpleOutputVar = outputVariable.name;
this.outputVars = outputVariable.details;
}, },
handleConfirm() { handleConfirm() {
const outputVariable = {}; const outputVariable = {};

View File

@ -13,6 +13,21 @@
<div class="variable-label">{{ label }}</div> <div class="variable-label">{{ label }}</div>
</template> </template>
<template v-slot:append> <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 <VariableList
:show-variable-list="showVariableList" :show-variable-list="showVariableList"
:show-function-list="showFunctionList" :show-function-list="showFunctionList"
@ -35,7 +50,7 @@
</template> </template>
<script> <script>
import { defineComponent } from "vue"; import { defineComponent, inject } from "vue";
import VariableList from "components/composer/common/varinput/VariableList.vue"; import VariableList from "components/composer/common/varinput/VariableList.vue";
export default defineComponent({ export default defineComponent({
@ -55,6 +70,10 @@ export default defineComponent({
type: String, type: String,
default: "", default: "",
}, },
suggestName: {
type: String,
default: "",
},
autofocus: { autofocus: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -77,6 +96,31 @@ export default defineComponent({
updateValBySelect(_type, val) { updateValBySelect(_type, val) {
this.$emit("update:modelValue", 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> </script>
@ -118,7 +162,7 @@ export default defineComponent({
} }
.variable-list-btn { .variable-list-btn {
padding: 0 12px; padding: 0 12px 0 3px;
} }
/* 去掉下拉按钮的焦点效果 */ /* 去掉下拉按钮的焦点效果 */

View File

@ -11,6 +11,7 @@
@update:model-value="updateField(subKey, $event)" @update:model-value="updateField(subKey, $event)"
:label="subOutput.label" :label="subOutput.label"
:placeholder="subOutput.placeholder" :placeholder="subOutput.placeholder"
:suggest-name="subOutput.suggestName"
autofocus autofocus
/> />
</div> </div>
@ -25,6 +26,7 @@
@update:model-value="updateField('', $event)" @update:model-value="updateField('', $event)"
:label="output.label" :label="output.label"
:placeholder="output.placeholder" :placeholder="output.placeholder"
:suggest-name="output.suggestName"
autofocus autofocus
/> />
</div> </div>
@ -78,18 +80,23 @@ export default defineComponent({
default: () => ({}), default: () => ({}),
}, },
}, },
data() {
return {
fixedFields: ["label", "placeholder", "suggestName"],
};
},
emits: ["update:modelValue"], emits: ["update:modelValue"],
computed: { computed: {
hasNestedFields() { hasNestedFields() {
if (!this.output) return false; if (!this.output) return false;
return Object.keys(this.output).some( return Object.keys(this.output).some(
(key) => key !== "label" && key !== "placeholder" (key) => !this.fixedFields.includes(key)
); );
}, },
getNestedFields() { getNestedFields() {
const fields = {}; const fields = {};
Object.entries(this.output).forEach(([key, value]) => { Object.entries(this.output).forEach(([key, value]) => {
if (key !== "label" && key !== "placeholder") { if (!this.fixedFields.includes(key)) {
fields[key] = value; fields[key] = value;
} }
}); });

View File

@ -15,31 +15,46 @@ export const macosCommands = {
icon: "front_hand", icon: "front_hand",
outputs: { outputs: {
label: "前台应用信息", label: "前台应用信息",
suggestName: "frontmostApp",
structure: { structure: {
name: { label: "应用名称" }, name: { label: "应用名称", suggestName: "appName" },
displayedName: { label: "应用显示名称" }, displayedName: {
path: { label: "应用路径" }, label: "应用显示名称",
version: { label: "应用版本" }, suggestName: "appDisplayName",
pid: { label: "应用进程ID" }, },
backgroundOnly: { label: "是否后台运行" }, path: { label: "应用路径", suggestName: "appPath" },
visible: { label: "是否可见" }, version: { label: "应用版本", suggestName: "appVersion" },
frontmost: { label: "是否前台运行" }, pid: { label: "应用进程ID", suggestName: "appPid" },
backgroundOnly: {
label: "是否后台运行",
suggestName: "appBackgroundOnly",
},
visible: { label: "是否可见", suggestName: "appVisible" },
frontmost: { label: "是否前台运行", suggestName: "appFrontmost" },
window: { window: {
label: "窗口信息", label: "窗口信息",
name: { label: "窗口名称" }, name: { label: "窗口名称", suggestName: "windowName" },
title: { label: "窗口标题" }, title: { label: "窗口标题", suggestName: "windowTitle" },
index: { label: "窗口索引" }, index: { label: "窗口索引", suggestName: "windowIndex" },
position: { position: {
label: "窗口位置", label: "窗口位置",
placeholder: placeholder:
"数组, 第一个元素是 x 坐标,第二个元素是 y 坐标", "数组, 第一个元素是 x 坐标,第二个元素是 y 坐标",
suggestName: "windowPosition",
}, },
size: { size: {
label: "窗口大小", label: "窗口大小",
placeholder: "数组, 第一个元素是宽度,第二个元素是高度", placeholder: "数组, 第一个元素是宽度,第二个元素是高度",
suggestName: "windowSize",
},
minimized: {
label: "是否最小化",
suggestName: "windowMinimized",
},
fullscreen: {
label: "是否全屏",
suggestName: "windowFullscreen",
}, },
minimized: { label: "是否最小化" },
fullscreen: { label: "是否全屏" },
}, },
}, },
}, },
@ -48,6 +63,10 @@ export const macosCommands = {
value: "quickcomposer.macos.app.getRunningApps", value: "quickcomposer.macos.app.getRunningApps",
label: "获取活动应用", label: "获取活动应用",
icon: "list", icon: "list",
outputs: {
label: "活动应用列表(数组)",
suggestName: "runningApps",
},
}, },
{ {
value: "quickcomposer.macos.app.launch", value: "quickcomposer.macos.app.launch",