wujingjing
2025-03-19 172b2c1698ae0bca0436e54513a37f81c4c8b30c
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
240
241
242
<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="graphQueryParams">
                <el-form-item label="名称" prop="title">
                    <el-input v-model="graphQueryParams.title" style="width: 226.4px" placeholder="文件名称" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="ele-Search" @click="handleQueryTable"> 查询 </el-button>
                    <el-button icon="ele-Refresh" @click="resetQuery">重置 </el-button>
                    <el-button icon="ele-Plus" @click="importData()" 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="formulaTableLoading"
                    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 type="index" label="序号" width="55" fixed="left" align="center"></el-table-column>
                    <el-table-column prop="name" label="文件名称" fixed="left" show-overflow-tooltip align="left" />
                    <el-table-column prop="type" width="120" label="文件类型" show-overflow-tooltip align="center" />
                    <el-table-column prop="size" width="120" label="文件大小" show-overflow-tooltip align="center" />
                    <el-table-column prop="time" label="上传时间" show-overflow-tooltip width="280" align="center"></el-table-column>
                    <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-wendang !text-[17px] cursor-pointer text-blue-400"
                                        @click="openOperateDemoPage(scope.row)"
                                    ></i>
                                </el-tooltip>
                                <el-tooltip effect="dark" content="分块" placement="top">
                                    <i
                                        class="ywifont ywicon-01wenjianfenkuai !text-[17px] cursor-pointer text-blue-400"
                                        @click="handleViewKnowledgeFile(scope.row)"
                                    ></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>
    </AHMContainer>
</template>
 
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus';
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import * as agentGroupApi from '/@/api/ai/agentGroup';
import { delete_knowledge_file, list_knowledge_file } from '/@/api/knowledge/group';
import AHMContainer from '/@/components/layout/AHMContainer.vue';
import LeftTreeByMgr from '/@/components/tree/leftTreeByMgr.vue';
import { useQueryTable } from '/@/hooks/useQueryTable';
import mittBus from '/@/utils/mitt';
import { useCompRef } from '/@/utils/types';
import { convertFileSize, convertListToTree } from '/@/utils/util';
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;
    getCategoryTableData();
};
const getListTreeData = async () => {
    const res = await agentGroupApi.getSceneGroupTreeByPost();
    listData.value = res.groups || [];
    const firstListTreeNode = listTreeData.value[0];
    if (firstListTreeNode) {
        handleClickNode(firstListTreeNode);
    } else {
        categoryTableData.value = [];
        currentNode.value = null;
    }
};
//#endregion
//#region ====================== 获取、删除表格数据 ======================
const formulaTableLoading = ref(false);
const categoryTableData = ref([]);
const isFormulaTableDrag = ref(false);
const getCategoryTableData = async () => {
    const res = await list_knowledge_file({
        group_id: currentListID.value,
    }).finally(() => {});
    if (res?.json_ok) {
        const resData = (res.values || []) as [];
        resData.forEach((item) => {
            item.size = convertFileSize(item.size);
        });
        categoryTableData.value = resData;
    } else {
        ElMessage.error('获取文档列表失败' + (res?.json_msg ? `,${JSON.stringify(res.json_msg)}` : ''));
    }
};
const deleteCurrentFormulaRow = (row: any) => {
    ElMessageBox.confirm(`确定删除文档列表:【${row.name}】?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(async () => {
        const res = await delete_knowledge_file({
            file_id: row.id,
        });
 
        if (res.json_ok) {
            ElMessage.success('删除文档列表成功');
            const index = categoryTableData.value.findIndex((d) => d.id === row.id);
            categoryTableData.value.splice(index, 1);
        } else {
            ElMessage.error('删除文档列表失败' + (res?.json_msg ? `,${JSON.stringify(res.json_msg)}` : ''));
        }
    });
};
//#endregion
 
//#endregion
 
//#region ====================== 搜索表格,对表格排序 ======================
const graphQueryParams = ref({
    title: '',
});
const { resetQuery, handleQueryTable, displayTableData } = useQueryTable(categoryTableData, graphQueryParams, () => {
    displayTableData.value = categoryTableData.value;
});
//#endregion
 
//#region ====================== 跳转文档详情页面 init======================
const router = useRouter();
const openOperateDemoPage = (row: any) => {
    router.push({
        name: 'ViewFile',
        query: {
            id: row.id,
        },
    });
};
const handleViewKnowledgeFile = (row) => {
    router.push({
        name: 'ViewSegmentationFile',
        query: {
            id: row.id,
        },
    });
};
//导入数据
const importData = () => {
    router.push({
        name: 'AddGraph',
        query: {
            group_id: currentListID.value,
            title: currentNode.value.group_name,
        },
    });
};
//#endregion
//#region ====================== 挂载时获取初始数据 ======================
onMounted(() => {
    getListTreeData();
    mittBus.on('addGraphObj', (obj) => {
        categoryTableData.value.push(obj);
    });
});
//#endregion
</script>
<style scoped lang="scss">
:deep(.el-card__body) {
    padding-bottom: unset;
}
</style>