wujingjing
2024-12-31 8d83544ff6e123df4facf40c446e7d9bf4a522b6
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">