优化varinput可选变量的获取逻辑

This commit is contained in:
fofolee 2025-01-07 09:21:53 +08:00
parent 4b3323c5db
commit d3709db4b3
5 changed files with 38 additions and 15 deletions

View File

@ -43,12 +43,17 @@ export default defineComponent({
//
const getCurrentVariables = () => {
const variables = [];
for (const cmd of commandFlow.value) {
for (const [index, cmd] of commandFlow.value.entries()) {
if (cmd.saveOutput && cmd.outputVariable) {
variables.push(
...parseVariables(cmd.outputVariable).map((variable) => ({
name: variable,
sourceCommand: cmd,
//
sourceCommand: {
label: cmd.label,
id: cmd.id,
index,
},
}))
);
}

View File

@ -65,7 +65,7 @@
</template>
<script>
import { defineComponent, inject } from "vue";
import { defineComponent, inject, provide, computed } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import MultiParams from "components/composer/MultiParams.vue";
import CommandHead from "components/composer/card/CommandHead.vue";
@ -85,6 +85,10 @@ export default defineComponent({
type: Object,
required: true,
},
commandIndex: {
type: Number,
required: true,
},
},
emits: ["remove", "run", "addBranch", "toggle-collapse", "update:modelValue"],
computed: {
@ -109,8 +113,12 @@ export default defineComponent({
);
},
},
setup() {
setup(props) {
const getCurrentVariables = inject("getCurrentVariables");
// commandIndex
const commandIndex = computed(() => props.commandIndex);
// VariableInput
provide("commandIndex", commandIndex);
return { getCurrentVariables };
},
methods: {

View File

@ -49,6 +49,7 @@
>
<ComposerCard
v-model="commands[index]"
:command-index="index"
@remove="removeCommand(index)"
@run="handleRunCommand"
@add-branch="addBranch"

View File

@ -79,7 +79,7 @@
}"
class="variable-dropdown prepend-btn"
size="sm"
@click="variables = getCurrentVariables()"
@click="variables = getAvailableVariables()"
>
<q-list class="variable-list">
<q-item-label header class="variable-label">
@ -115,14 +115,12 @@
<div class="q-gutter-md">
<div class="row items-center justify-center text-grey-6">
<q-icon name="info" size="20px" class="q-mr-sm" />
<span>可用变量</span>
<span>当前命令没有可用变量</span>
</div>
<div class="row items-center justify-center">
<span class="text-grey-7"
>点击命令卡片右上角的
<div class="row items-center justify-center text-grey-7">
<div class="text-grey-7">点击其他命令卡片右上角的</div>
<q-icon name="output" size="16px" class="q-mx-xs" />
按钮添加输出变量
</span>
<div>按钮添加输出变量</div>
</div>
</div>
</q-item-label>
@ -198,7 +196,18 @@ export default defineComponent({
emits: ["update:modelValue"],
setup() {
const getCurrentVariables = inject("getCurrentVariables");
return { getCurrentVariables };
const commandIndex = inject("commandIndex", null);
const getAvailableVariables = () => {
// commandIndex 使 value
return getCurrentVariables().filter(
(variable) => variable.sourceCommand.index < commandIndex.value
);
};
return {
getAvailableVariables,
};
},
data() {

View File

@ -22,11 +22,11 @@
v-if="isDev"
>
</q-btn>
<q-btn icon="logout" dense flat v-close-popup>
<q-btn icon="close" dense flat v-close-popup>
<q-tooltip>退出可视化编排</q-tooltip>
</q-btn>
<q-separator vertical />
<q-btn dense icon="publish" flat @click="$emit('action', 'insert')">
<q-btn dense icon="read_more" flat @click="$emit('action', 'insert')">
<q-tooltip>插入到编辑器光标处</q-tooltip>
</q-btn>
<q-btn dense flat icon="done_all" @click="$emit('action', 'apply')">