mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 22:51:25 +08:00
优化varinput可选变量的获取逻辑
This commit is contained in:
parent
4b3323c5db
commit
d3709db4b3
@ -43,12 +43,17 @@ export default defineComponent({
|
|||||||
// 提供获取当前变量的函数,直接返回解析后的变量列表
|
// 提供获取当前变量的函数,直接返回解析后的变量列表
|
||||||
const getCurrentVariables = () => {
|
const getCurrentVariables = () => {
|
||||||
const variables = [];
|
const variables = [];
|
||||||
for (const cmd of commandFlow.value) {
|
for (const [index, cmd] of commandFlow.value.entries()) {
|
||||||
if (cmd.saveOutput && cmd.outputVariable) {
|
if (cmd.saveOutput && cmd.outputVariable) {
|
||||||
variables.push(
|
variables.push(
|
||||||
...parseVariables(cmd.outputVariable).map((variable) => ({
|
...parseVariables(cmd.outputVariable).map((variable) => ({
|
||||||
name: variable,
|
name: variable,
|
||||||
sourceCommand: cmd,
|
// 提供来源命令的标志信息
|
||||||
|
sourceCommand: {
|
||||||
|
label: cmd.label,
|
||||||
|
id: cmd.id,
|
||||||
|
index,
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, inject } from "vue";
|
import { defineComponent, inject, provide, computed } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import MultiParams from "components/composer/MultiParams.vue";
|
import MultiParams from "components/composer/MultiParams.vue";
|
||||||
import CommandHead from "components/composer/card/CommandHead.vue";
|
import CommandHead from "components/composer/card/CommandHead.vue";
|
||||||
@ -85,6 +85,10 @@ export default defineComponent({
|
|||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
commandIndex: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ["remove", "run", "addBranch", "toggle-collapse", "update:modelValue"],
|
emits: ["remove", "run", "addBranch", "toggle-collapse", "update:modelValue"],
|
||||||
computed: {
|
computed: {
|
||||||
@ -109,8 +113,12 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup() {
|
setup(props) {
|
||||||
const getCurrentVariables = inject("getCurrentVariables");
|
const getCurrentVariables = inject("getCurrentVariables");
|
||||||
|
// 创建响应式的commandIndex
|
||||||
|
const commandIndex = computed(() => props.commandIndex);
|
||||||
|
// 主要用于VariableInput组件的变量选择下拉框,获取当前命令的索引
|
||||||
|
provide("commandIndex", commandIndex);
|
||||||
return { getCurrentVariables };
|
return { getCurrentVariables };
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
>
|
>
|
||||||
<ComposerCard
|
<ComposerCard
|
||||||
v-model="commands[index]"
|
v-model="commands[index]"
|
||||||
|
:command-index="index"
|
||||||
@remove="removeCommand(index)"
|
@remove="removeCommand(index)"
|
||||||
@run="handleRunCommand"
|
@run="handleRunCommand"
|
||||||
@add-branch="addBranch"
|
@add-branch="addBranch"
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
}"
|
}"
|
||||||
class="variable-dropdown prepend-btn"
|
class="variable-dropdown prepend-btn"
|
||||||
size="sm"
|
size="sm"
|
||||||
@click="variables = getCurrentVariables()"
|
@click="variables = getAvailableVariables()"
|
||||||
>
|
>
|
||||||
<q-list class="variable-list">
|
<q-list class="variable-list">
|
||||||
<q-item-label header class="variable-label">
|
<q-item-label header class="variable-label">
|
||||||
@ -115,14 +115,12 @@
|
|||||||
<div class="q-gutter-md">
|
<div class="q-gutter-md">
|
||||||
<div class="row items-center justify-center text-grey-6">
|
<div class="row items-center justify-center text-grey-6">
|
||||||
<q-icon name="info" size="20px" class="q-mr-sm" />
|
<q-icon name="info" size="20px" class="q-mr-sm" />
|
||||||
<span>无可用变量</span>
|
<span>当前命令没有可用变量</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row items-center justify-center">
|
<div class="row items-center justify-center text-grey-7">
|
||||||
<span class="text-grey-7"
|
<div class="text-grey-7">点击其他命令卡片右上角的</div>
|
||||||
>点击命令卡片右上角的
|
|
||||||
<q-icon name="output" size="16px" class="q-mx-xs" />
|
<q-icon name="output" size="16px" class="q-mx-xs" />
|
||||||
按钮添加输出变量
|
<div>按钮添加输出变量</div>
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</q-item-label>
|
</q-item-label>
|
||||||
@ -198,7 +196,18 @@ export default defineComponent({
|
|||||||
emits: ["update:modelValue"],
|
emits: ["update:modelValue"],
|
||||||
setup() {
|
setup() {
|
||||||
const getCurrentVariables = inject("getCurrentVariables");
|
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() {
|
data() {
|
||||||
|
@ -22,11 +22,11 @@
|
|||||||
v-if="isDev"
|
v-if="isDev"
|
||||||
>
|
>
|
||||||
</q-btn>
|
</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-tooltip>退出可视化编排</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-separator vertical />
|
<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-tooltip>插入到编辑器光标处</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn dense flat icon="done_all" @click="$emit('action', 'apply')">
|
<q-btn dense flat icon="done_all" @click="$emit('action', 'apply')">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user