From 8d83544ff6e123df4facf40c446e7d9bf4a522b6 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期二, 31 十二月 2024 18:07:54 +0800 Subject: [PATCH] 序号 --- src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue | 106 ++++++++++++++++++++++++++++++---------------------- 1 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue b/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue index a753618..c399695 100644 --- a/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue +++ b/src/views/project/yw/systemManage/questionMgr/RecommendQuestions.vue @@ -11,8 +11,8 @@ label: 'group_name', children: 'children', }" - :treedata="listTreeData" - sample_title-name="鍒嗙粍鍒楄〃" + :treedata="listLeftData" + title-name="鍦烘櫙鍒楄〃" :show-more-operate="false" :show-add="false" :current-node-key="currentListID" @@ -105,56 +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, { +const handleClickNode = (data) => { + nextTick(() => { + leftTreeRef.value?.treeRef.setCurrentKey(data.group_id); + }); + currentNode.value = data; + terminologyData.value = data.sampleList; +}; + +//#endregion +//#region ====================== 鎺ㄨ崘闂 ====================== +const terminologyData = ref([]); //鏄剧ず鐨勬暟鎹簮 +//鑾峰彇鍦烘櫙list +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); + } + }); + + 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})`; + } + }); + + const byParentData = convertListToTree(new_tree_Data, { 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); + 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})`; }); - return result; -}); -const handleClickNode = (data) => { - nextTick(() => { - leftTreeRef.value?.treeRef.setCurrentKey(data.id); - }); - currentNode.value = data; - getTableData(); + listLeftData.value = byParentData; + const firstListTreeNode = byParentData[0]; + terminologyData.value = firstListTreeNode.sampleList; + currentNode.value = firstListTreeNode; }; -const getListTreeData = async () => { - const res = await agentGroupApi.getSceneGroupTreeByPost(); - listData.value = res.groups || []; - const firstListTreeNode = listTreeData.value[0]; - if (firstListTreeNode) { - handleClickNode(firstListTreeNode); - } else { - terminologyData.value = []; - currentNode.value = null; - } -}; -//#endregion -//#region ====================== 鎺ㄨ崘闂 ====================== -const terminologyData = ref([]); -//鑾峰彇鍦烘櫙list -const getTableData = async () => { - const res = await get_scene_group_sample(); - res.samples.forEach((sample, index) => { - sample.Icon = '/static/images/wave/ChatImg.png'; - sample.BgColor = randomHexColor(); - }); - terminologyData.value = res.samples; -}; + //闅忔満鐢熸垚棰滆壊 const randomHexColor = () => { return `#${Math.floor(Math.random() * 16777215) @@ -165,6 +180,7 @@ const changeExample = (item) => { openChatTest(item); }; + //#endregion //#region ====================== 琛ㄦ牸鏌ヨ銆佹帓搴忥紝search form init ====================== const queryParams = ref({ @@ -172,7 +188,7 @@ }); const { query: queryTerminology, queryData: showTerminologyList } = useSearch(terminologyData, queryParams); const finalTerminologyList = computed(() => { - const result = showTerminologyList.value.filter((item) => item.group_id == currentListID.value); + const result = showTerminologyList.value; return result ?? []; }); const terminologyQuery = debounce(queryTerminology); @@ -229,8 +245,8 @@ return res; }; //#endregion -onMounted(() => { - getListTreeData(); +onMounted(async () => { + initData(); }); </script> <style scoped lang="scss"> -- Gitblit v1.9.3