From ffdd85649d262bfacdee2dd6c1b1157ecdf2f59f Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期日, 03 十一月 2024 15:52:47 +0800 Subject: [PATCH] 分组统计数量 --- src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue | 103 +++++++++++++++++++++++++++------------------------ 1 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue b/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue index e814883..c399695 100644 --- a/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue +++ b/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue @@ -11,7 +11,7 @@ label: 'group_name', children: 'children', }" - :treedata="listTreeData" + :treedata="listLeftData" title-name="鍦烘櫙鍒楄〃" :show-more-operate="false" :show-add="false" @@ -105,67 +105,71 @@ //#region ====================== 宸︿晶鏍戞暟鎹紝tree init ====================== const leftTreeRef = useCompRef(LeftTreeByMgr); const treeLoading = ref(false); -const listData = ref([]); +const listLeftData = 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.Office] && - item.group_type != OptClassificationMap[classificationEnum.Knowledge] - ) { - result.push(item); - } - }); - return result; -}); const handleClickNode = (data) => { nextTick(() => { leftTreeRef.value?.treeRef.setCurrentKey(data.group_id); }); currentNode.value = data; - getTableData(); + terminologyData.value = data.sampleList; }; -const getListTreeData = async () => { - const res = await agentGroupApi.getSceneGroupTreeByPost(); - listData.value = res.groups || []; - const firstListTreeNode = listTreeData.value[0]; - currentNode.value = firstListTreeNode; - getTableData(); -}; + //#endregion //#region ====================== 鎺ㄨ崘闂 ====================== -const terminologyData = ref([]); +const terminologyData = ref([]); //鏄剧ず鐨勬暟鎹簮 //鑾峰彇鍦烘櫙list -const getTableData = async () => { - let selNode = currentNode.value; - let curGroupID = []; - if (selNode.children && selNode.children.length > 0) { - selNode.children.forEach((item) => { - curGroupID.push(item.group_id); - }); - } else { - curGroupID.push(selNode.group_id); - } - const res = await get_scene_group_sample(); - res.samples.forEach((sample, index) => { - sample.Icon = '/static/images/wave/ChatImg.png'; - sample.BgColor = randomHexColor(); +const initData = async () => { + const [treeData, sampleData] = await Promise.all([agentGroupApi.getSceneGroupTreeByPost(), get_scene_group_sample()]); + const tree_Data = treeData.groups ?? []; + const sample_Data = sampleData.samples ?? []; + let result = []; + let new_tree_Data = []; + tree_Data.forEach((node, index) => { + if ( + node.group_type != OptClassificationMap[classificationEnum.Office] && + node.group_type != OptClassificationMap[classificationEnum.Knowledge] + ) { + new_tree_Data.push(node); + } }); - let terminology_Data = []; - curGroupID.forEach((curItem) => { - res.samples.forEach((sample) => { - if (curItem == sample.group_id) terminology_Data.push(sample); + + new_tree_Data.forEach((node, index) => { + node.sampleList = []; + sample_Data.forEach((sample, index) => { + sample.Icon = '/static/images/wave/ChatImg.png'; + sample.BgColor = randomHexColor(); + if (node.group_id == sample.group_id) { + node.sampleList.push(sample); + } }); + if (node.p_group_id) { + node.group_name = `${node.group_name} (${node.sampleList.length})`; + } }); - terminologyData.value = terminology_Data; + + const byParentData = convertListToTree(new_tree_Data, { + ID: 'group_id', + ParentID: 'p_group_id', + Children: 'children', + }); + byParentData.forEach((item) => { + if (item.children && item.children.length > 0) { + item.children.forEach((child_node) => { + item.sampleList = item.sampleList.concat(child_node.sampleList); + }); + } + result.push(item); + + item.group_name = `${item.group_name} (${item.sampleList.length})`; + }); + listLeftData.value = byParentData; + const firstListTreeNode = byParentData[0]; + terminologyData.value = firstListTreeNode.sampleList; + currentNode.value = firstListTreeNode; }; + //闅忔満鐢熸垚棰滆壊 const randomHexColor = () => { return `#${Math.floor(Math.random() * 16777215) @@ -176,6 +180,7 @@ const changeExample = (item) => { openChatTest(item); }; + //#endregion //#region ====================== 琛ㄦ牸鏌ヨ銆佹帓搴忥紝search form init ====================== const queryParams = ref({ @@ -240,8 +245,8 @@ return res; }; //#endregion -onMounted(() => { - getListTreeData(); +onMounted(async () => { + initData(); }); </script> <style scoped lang="scss"> -- Gitblit v1.9.3