From d5d9c78c913cef915dafef58711c2449b7bbb942 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 15 May 2025 22:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=20InvokePluginAction=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=92=8C=E5=8A=A8=E4=BD=9C=E9=80=89=E9=A1=B9=E7=9A=84=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflow/InvokePluginAction.vue | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/components/workflow/InvokePluginAction.vue b/src/components/workflow/InvokePluginAction.vue index 76a99af5..0d0d5f10 100644 --- a/src/components/workflow/InvokePluginAction.vue +++ b/src/components/workflow/InvokePluginAction.vue @@ -2,7 +2,6 @@ import api from '@/api' import { Handle, Position } from '@vue-flow/core' import { useI18n } from 'vue-i18n' -import type { Plugin } from '@/api/types' const { t } = useI18n() @@ -22,11 +21,32 @@ interface ActionItem { name: string } +interface PluginAction { + plugin_id: string + plugin_name: string + actions: ActionItem[] +} + +// 插件所有动作 +const pluginActions = ref([]) + // 插件选项 -const pluginOptions = ref<{ title: string; value: string }[]>([]) +const pluginOptions = computed(() => { + return pluginActions.value.map((item: PluginAction) => ({ + title: item.plugin_name, + value: item.plugin_id, + })) +}) // 动作选项 -const actionOptions = ref<{ title: string; value: string }[]>([]) +const actionOptions = computed(() => { + return pluginActions.value + .find((item: PluginAction) => item.plugin_id === props.data.plugin_id) + ?.actions.map((item: ActionItem) => ({ + title: item.name, + value: item.id, + })) +}) // 用于在文本框显示和保存时转换action_params const actionParamsText = computed({ @@ -51,45 +71,17 @@ const actionParamsText = computed({ }, }) -// 加载所有插件 -async function loadPluginSetting() { - try { - const plugins: Plugin[] = await api.get('plugin/', { - params: { - state: 'installed', - }, - }) - pluginOptions.value = plugins.map((item: Plugin) => ({ - title: item.plugin_name, - value: item.id, - })) - } catch (error) { - console.error(error) - } -} - // 加载动作选项 -async function loadPluginActions(pluginId: string) { +async function loadPluginActions() { try { - const actions: ActionItem[] = await api.get(`workflow/actions/${pluginId}`) - actionOptions.value = actions.map((item: ActionItem) => ({ - title: item.name, - value: item.id, - })) + pluginActions.value = await api.get('workflow/plugin/actions') } catch (error) { console.error(error) } } -watch( - () => props.data.plugin_id, - newVal => { - loadPluginActions(newVal) - }, -) - onMounted(() => { - loadPluginSetting() + loadPluginActions() })