wujingjing
2025-01-14 d5c759fb1c54679a27c20a3a2ed2c7e082820462
src/views/project/ch/home/component/waterRight/center.vue
@@ -6,17 +6,17 @@
            <span class="split"></span>
            <span class="change cursor-pointer" @click="advanceExampleClick">高级示例 ></span>
         </div>
         <div class="cursor-pointer">
            <span class="mr-1 changeBatch" @click="batchChange">换一批</span>
         <div class="cursor-pointer" @click="batchChange">
            <span class="mr-1 changeBatch">换一批</span>
            <i class="myiconfont icon-shuaxin"></i>
         </div>
      </div>
      <div class="main">
         <el-carousel height="80" :interval="6000" indicator-position="none">
            <el-carousel-item v-for="group in batchSourceData" :key="group" class="set-carousel-item">
            <el-carousel-item v-for="(group, index) in state.m_groupArr" :key="index" class="set-carousel-item">
               <div
                  class="main_item flex items-center cursor-pointer"
                  v-for="(item, index) in state.exampleContent"
                  v-for="(item, index) in group"
                  :key="index"
                  :class="{ main_item_active: item.sample_id === activeSampleId }"
                  @click="changeExample(item)"
@@ -36,98 +36,59 @@
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import { getSelectSample } from '/@/api/ai/chat';
import { activeRoomId, activeSampleId, activeSectionAId, setRoomConfig } from '/@/stores/chatRoom';
import { reactive } from 'vue';
import { activeRoomId, activeSampleId, exampleSceneList, setRoomConfig } from '/@/stores/chatRoom';
let state = reactive({
   exampleContent: [],
   exampleRandomContent: [],
   isShowExample: false,
   m_groupArr: [],
});
const exampleList = ref([]); //模版列表
const emits = defineEmits<{
   (event: 'advanceExampleClick', data): void;
   (event: 'updateChatInput', val): void;
}>();
onMounted(() => {
   getSelectListSample();
});
//换一批数据源
const groupedArray = computed(() => {
const initGroupedArr = () => {
   const groups = [];
   let i = 0;
   while (state.exampleRandomContent.length > i) {
      groups.push(state.exampleRandomContent.slice(i, (i += 4)));
   while (state.exampleContent.length > i) {
      groups.push(state.exampleContent.slice(i, (i += 4)));
   }
   return groups;
});
//自动播放
const batchSourceData = computed(() => {
   const batch = [];
   let i = 0;
   while (exampleList.value.length > i) {
      batch.push(exampleList.value.slice(i, (i += 4)));
   }
   return batch;
});
//获取模版列表
const getSelectListSample = async () => {
   const res = await getSelectSample({});
   state.exampleRandomContent = res.samples;
   const array = [];
   res.samples.forEach((sample, index) => {
      sample.Icon = '/static/images/wave/ChatImg.png';
      sample.BgColor = randomHexColor();
      if (index < 4) {
         array.push(sample);
      }
   });
   exampleList.value = res.samples;
   state.exampleContent = array;
   state.m_groupArr = groups;
};
const changeExample = (item) => {
   emits('updateChatInput', item.sample_question);
   setRoomConfig(activeRoomId.value, 'isAnswerByLLM', false);
   activeSampleId.value = item.sample_id;
   activeSectionAId.value = item.section_a_id;
};
//换一批
const batchChange = () => {
   const index = Math.floor(Math.random() * groupedArray.value.length);
   state.exampleContent = groupedArray.value[index];
   let groups = state.m_groupArr;
   // 打乱批次顺序
   for (let i = groups.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      [groups[i], groups[j]] = [groups[j], groups[i]];
   }
   state.m_groupArr = groups;
};
//打开高级示例
const advanceExampleClick = () => {
   emits('advanceExampleClick', true);
};
const tagListClick = (group_item) => {
   const curGroupID = group_item.p_group_id;
   const curID = group_item.group_id;
   const exampleContent = exampleList.value;
   let curGroupIDs = [];
   if (!curGroupID) {
      curGroupIDs.push(curID);
   } else {
      exampleContent.forEach((item) => {
         curGroupIDs.push(item.group_id);
      });
   }
const tagListClick = (tagList) => {
   let result = [];
   curGroupIDs.forEach((curItem) => {
      exampleContent.forEach((sample) => {
         if (curItem == sample.group_id) result.push(sample);
   tagList.forEach((tag) => {
      exampleSceneList.value.forEach((sample) => {
         if (tag == sample.group_id) {
            result.push(sample);
         }
      });
   });
   batchChange();
};
//随机生成颜色
const randomHexColor = () => {
   return `#${Math.floor(Math.random() * 16777215)
      .toString(16)
      .padEnd(6, '0')}`;
   state.exampleContent = result;
   initGroupedArr();
};
defineExpose({
   getSelectListSample,
   tagListClick,
});
</script>
@@ -172,6 +133,7 @@
         width: calc(50% - 16px);
         margin: 8px;
         padding: 12px;
         height: 84px;
         border: 1px solid #d9dbde;
         border-radius: 5px;
         background-color: transparent;
@@ -206,6 +168,9 @@
               font-weight: 500;
               height: 16px;
               transition: background-color 0.2s;
               overflow: hidden;
               text-overflow: ellipsis;
               white-space: nowrap;
            }
            p {
               font-size: 12px;