wujingjing
2024-12-12 6ee230ce0a8d338609ab96cebdeafc1e62f6e918
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
    <div class="absolute bottom-0 left-0 right-0 top-0 bg-gray text-base">
        <div class="relative flex h-full w-full flex-col">
            <Header v-if="flowAgent" :flowAgent="flowAgent" :queryId="queryId" />
            <main class="relative flex h-full w-full flex-1">
                <Sidebar @dragstart="handleOnDragStart" />
                <div class="relative h-full flex-1 overflow-hidden" v-if="flowJson">
                    <MainCanvas :flowJson="flowJson" :agentNames="agentNames" />
                </div>
            </main>
        </div>
    </div>
    <!-- <Toaster /> -->
</template>
<script setup lang="ts">
// import { PlusIcon, GhostIcon } from 'lucide-vue-next'
import { useVueFlow } from '@vue-flow/core';
import { useClipboard } from '@vueuse/core';
// import MainCanvas from '@/components/vue-flow/MainCanvas.vue';
import { computed, onMounted, ref } from 'vue';
import Header from './components/Header.vue';
import Sidebar from './components/Sidebar.vue';
import { get_agent_names, get_workflow_agent_list, get_workflow_json_flow } from '/@/api/workflow';
import MainCanvas from '/@/components/vue-flow/MainCanvas.vue';
import router from '/@/router';
 
// import { Button } from '@/components/ui/button';
// import { Toaster, useToast } from '@/components/ui/toast';
 
function handleOnDragStart(event: DragEvent, nodeType: any) {
    if (event.dataTransfer) {
        event.dataTransfer.setData('application/vueflow', nodeType);
        event.dataTransfer.effectAllowed = 'move';
    }
}
 
const queryId = computed(() => router.currentRoute.value.query.id as string);
 
const { toObject } = useVueFlow();
const { copy } = useClipboard();
 
const flowJson = ref(null);
 
const flowAgent = ref(null);
 
const handleGetJSON = async (id: string) => {
    const res = await get_workflow_json_flow({
        agent_id: id,
    });
    flowJson.value = res.json_ok ? res.json_flow ?? {} : {};
};
 
const getFlowAgent = async () => {
    const res = await get_workflow_agent_list();
    const flowAgentList = res.values ?? [];
    const currentFlowAgent = flowAgentList.find((item: any) => item.id === queryId.value);
    flowAgent.value = currentFlowAgent;
};
 
const agentNames = ref([]);
const getAgentNames = async () => {
    const res = await get_agent_names();
    agentNames.value = res.agents ?? [];
};
 
onMounted(() => {
    if (!queryId.value) return;
    handleGetJSON(queryId.value);
    getFlowAgent();
    getAgentNames();
});
</script>