| | |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import { 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: [], |
| | | isShowExample: false, |
| | | m_groupArr: [], |
| | | }); |
| | | const exampleList = ref([]); //模版列表 |
| | | const emits = defineEmits<{ |
| | | (event: 'advanceExampleClick', data): void; |
| | | (event: 'updateChatInput', val): void; |
| | | }>(); |
| | | onMounted(() => { |
| | | getSelectListSample(); |
| | | }); |
| | | |
| | | const initGroupedArr = () => { |
| | | const groups = []; |
| | | let i = 0; |
| | |
| | | state.m_groupArr = groups; |
| | | }; |
| | | |
| | | //获取模版列表 |
| | | const getSelectListSample = async () => { |
| | | const res = await getSelectSample({}); |
| | | 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; |
| | | }; |
| | | |
| | | 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 j = Math.floor(Math.random() * (i + 1)); |
| | | [groups[i], groups[j]] = [groups[j], groups[i]]; |
| | | } |
| | | |
| | | state.m_groupArr = groups; |
| | | }; |
| | | //打开高级示例 |
| | |
| | | const tagListClick = (tagList) => { |
| | | let result = []; |
| | | tagList.forEach((tag) => { |
| | | exampleList.value.forEach((sample) => { |
| | | exampleSceneList.value.forEach((sample) => { |
| | | if (tag == sample.group_id) { |
| | | result.push(sample); |
| | | } |
| | | }); |
| | | }); |
| | | state.exampleContent = result; |
| | | |
| | | initGroupedArr(); |
| | | }; |
| | | //随机生成颜色 |
| | | const randomHexColor = () => { |
| | | return `#${Math.floor(Math.random() * 16777215) |
| | | .toString(16) |
| | | .padEnd(6, '0')}`; |
| | | }; |
| | | defineExpose({ |
| | | getSelectListSample, |
| | | tagListClick, |
| | | }); |
| | | </script> |