wujingjing
2024-12-11 2b7205559426f63a43bb7df31400ba00b2276730
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<template>
    <AHMContainer type="card">
        <template #aside>
            <LeftTreeByMgr
                v-loading="treeLoading"
                class="h100"
                ref="leftTreeRef"
                :defaultProps="{
                    id: 'group_id',
                    label: 'group_name',
                    children: 'children',
                }"
                defaultExpandAll
                :treedata="listTreeData"
                title-name="分组列表"
                :show-more-operate="false"
                :show-add="false"
                :current-node-key="currentListID"
                :node-icon="() => 'ele-Document'"
                @click="handleClickNode"
            >
            </LeftTreeByMgr>
        </template>
 
        <template #header>
            <!-- 查询、重置、排序、增加表单 -->
            <el-form :inline="true" :model="queryParams">
                <el-form-item label="名称" prop="title">
                    <el-input
                        v-model="queryParams.title"
                        style="width: 226.4px"
                        placeholder="文件名称"
                        clearable
                        @input="debounceQueryTable"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button icon="ele-Refresh" @click="resetQuery">重置 </el-button>
                    <el-button icon="ele-Plus" @click="openOptDlg()" type="primary"> 添加 </el-button>
                </el-form-item>
            </el-form></template
        >
        <template #main
            ><!-- 数据展示表格 -->
            <div class="flex-auto flex-column h-full" v-if="state.isShowTrendFun">
                <el-table
                    v-loading="workFlowDataLoading"
                    ref="draggableFormulaTableRef"
                    border
                    row-key="id"
                    class="flex-auto"
                    :row-class-name="isFormulaTableDrag ? 'cursor-move' : 'cursor-pointer'"
                    :header-cell-style="{ textAlign: 'center' }"
                    :data="displayTableData"
                    highlight-current-row
                >
                    <el-table-column prop="title" label="工作流名称" fixed="left" show-overflow-tooltip align="left" />
                    <el-table-column prop="prompt" width="280" label="工作流提示" show-overflow-tooltip align="center"> </el-table-column>
                    <el-table-column prop="published" width="120" label="发布状态" show-overflow-tooltip align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.published === SupervisorPublished.Y ? 'primary' : 'info'">{{
                                supervisorPublishedMap[scope.row.published]
                            }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="create_user" width="100" label="创建者" show-overflow-tooltip align="center" />
                    <el-table-column prop="create_time" width="180" label="创建时间" show-overflow-tooltip align="center" />
                    <el-table-column prop="note" width="180" label="说明" show-overflow-tooltip align="center" />
                    <el-table-column label="操作" width="120" fixed="right" show-overflow-tooltip align="center">
                        <template #default="scope">
                            <div class="space-x-2.5">
                                <el-tooltip effect="dark" content="编辑" placement="top">
                                    <i class="ywifont ywicon-bianji !text-[15px] text-blue-400 cursor-pointer"></i>
                                </el-tooltip>
                                <el-tooltip effect="dark" content="删除" placement="top">
                                    <i
                                        class="ywifont ywicon-shanchu !text-[17px] text-red-400 cursor-pointer"
                                        @click="deleteCurrentFormulaRow(scope.row)"
                                    ></i>
                                </el-tooltip>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </template>
        <OptDlg v-model="optDlgIsShow" :item="optDlgMapRow" @insert="insertOpt" :currentListID="currentListID"></OptDlg>
    </AHMContainer>
</template>
 
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus';
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
import OptDlg from './optDlg/OptDlg.vue';
import * as agentGroupApi from '/@/api/ai/agentGroup';
import { delete_workflow_agent, get_workflow_agent_list } from '/@/api/workflow/index';
import AHMContainer from '/@/components/layout/AHMContainer.vue';
import LeftTreeByMgr from '/@/components/tree/leftTreeByMgr.vue';
import { useQueryTable } from '/@/hooks/useQueryTable';
import { useCompRef } from '/@/utils/types';
import { convertListToTree, debounce } from '/@/utils/util';
import { SupervisorPublished, supervisorPublishedMap } from '/@/views/project/yw/lowCode/sqlAmis/types';
import { OptClassificationMap, classificationEnum } from '/@/views/types/metrics';
const state = reactive({
    tableParams: {
        PageIndex: 1,
        PageSize: 10,
    },
    tableTotal: 0,
    isShowTrendFun: true,
    showViewBack: false,
    detailTitle: '',
});
//#region ====================== 左侧树数据,tree init ======================
const leftTreeRef = useCompRef(LeftTreeByMgr);
const treeLoading = ref(false);
const listData = ref([]);
const currentListID = computed(() => currentNode.value?.group_id);
const currentNode = ref(null);
const listTreeData = computed(() => {
    const byParentData = convertListToTree(listData.value, {
        ID: 'group_id',
        ParentID: 'p_group_id',
        Children: 'children',
    });
    const result = [];
    byParentData.forEach((item) => {
        if (item.group_type == OptClassificationMap[classificationEnum.Knowledge]) {
            result.push(item);
        }
    });
    return result;
});
 
const handleClickNode = (data) => {
    nextTick(() => {
        leftTreeRef.value?.treeRef.setCurrentKey(data.id);
    });
    currentNode.value = data;
    getWorkFlowData();
};
const getListTreeData = async () => {
    const res = await agentGroupApi.getSceneGroupTreeByPost();
    listData.value = res.groups || [];
    const firstListTreeNode = listTreeData.value[0];
    if (firstListTreeNode) {
        handleClickNode(firstListTreeNode);
    } else {
        tableData.value = [];
        currentNode.value = null;
    }
};
//#endregion
//#region ====================== 获取、删除表格数据 ======================
const workFlowDataLoading = ref(false);
const workFlowTableData = ref([]);
const tableData = ref([]);
const isFormulaTableDrag = ref(false);
const getWorkFlowData = async () => {
    workFlowDataLoading.value = true;
    const res = await get_workflow_agent_list().finally(() => {
        workFlowDataLoading.value = false;
    });
    if (res?.json_ok) {
        const resData = res.values ?? [];
        resData.forEach((item) => {
            item.published = item.published;
            item.create_time = item.create_time.slice(0, 19);
            item.prompt = item.supervisor.prompt;
            item.note = item.note;
            item.create_user = item.create_user;
        });
        workFlowTableData.value = resData;
    } else {
        workFlowDataLoading.value = false;
        ElMessage.error('获取工作流列表失败' + (res?.json_msg ? `,${JSON.stringify(res.json_msg)}` : ''));
    }
    tableData.value = workFlowTableData.value.filter(
        (item) =>
            item.agent_group === currentListID.value ||
            currentNode.value.children?.some((treeItem) => treeItem.group_id === item.agent_group)
    );
};
const deleteCurrentFormulaRow = (row: any) => {
    ElMessageBox.confirm(`确定删除工作流:【${row.title}】?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(async () => {
        const res = await delete_workflow_agent({
            agent_id: row.id,
        });
 
        if (res.json_ok) {
            ElMessage.success('删除工作流成功');
            const index = tableData.value.findIndex((d) => d.id === row.id);
            tableData.value.splice(index, 1);
        } else {
            ElMessage.error('删除工作流失败' + (res?.json_msg ? `,${JSON.stringify(res.json_msg)}` : ''));
        }
    });
};
//#endregion
//#region ====================== 添加修改操作 ======================
const optDlgIsShow = ref(false);
const optDlgMapRow = ref(null);
const openOptDlg = (row?: any) => {
    optDlgMapRow.value = row;
    optDlgIsShow.value = true;
};
 
const updateOpt = (formValue) => {};
//新增一条信息
const insertOpt = (newData) => {
    tableData.value.unshift({ ...newData });
};
//#endregion
//#region ====================== 表格查询、排序,search form init ======================
 
const queryParams = ref({
    title: '',
});
const { resetQuery, handleQueryTable, displayTableData } = useQueryTable(tableData, queryParams, () => {
    displayTableData.value = tableData.value;
});
const debounceQueryTable = debounce(handleQueryTable, 400);
//#endregion
 
//#region ====================== 挂载时获取初始数据 ======================
onMounted(() => {
    getListTreeData();
});
//#endregion
</script>
<style scoped lang="scss">
:deep(.el-card__body) {
    padding-bottom: unset;
}
</style>