From 7866aa30bd13dab1fc0662e1baf6675d0dc1b282 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 02 四月 2025 15:42:30 +0800 Subject: [PATCH] 修改意见 --- src/components/chat/components/playBar/phrase/CommonPhrases.vue | 167 +++++++++++++++++++------------------------------------ 1 files changed, 57 insertions(+), 110 deletions(-) diff --git a/src/components/chat/components/playBar/phrase/CommonPhrases.vue b/src/components/chat/components/playBar/phrase/CommonPhrases.vue index 5ebd163..61bde4d 100644 --- a/src/components/chat/components/playBar/phrase/CommonPhrases.vue +++ b/src/components/chat/components/playBar/phrase/CommonPhrases.vue @@ -1,5 +1,5 @@ <template> - <div class="container" :class="isHome ? 'top-[100%] mt-[8px]' : 'bottom-[100%] mb-[8px]'"> + <div ref="commonPhrasesRef" class="container" :class="isHome ? 'top-[100%] mt-[8px]' : 'bottom-[100%] mb-[8px]'"> <div class="container_header"> <div class="question">甯哥敤璇�</div> <span class="ywifont ywicon-guanbi text-[15px] cursor-pointer text-[#767a97]" @click="closeCommonPhrases"></span> @@ -59,10 +59,11 @@ </template> <script setup lang="ts"> -import { ElMessageBox } from 'element-plus'; +import { ElMessage, ElMessageBox } from 'element-plus'; import { computed, onMounted, reactive, ref } from 'vue'; import { addUserSample, deleteUserSample, listUserSample, updateUserSample } from '/@/api/ai/chat'; import { activeGroupType, activeRoomId, activeSampleId, setRoomConfig } from '/@/stores/chatRoom'; +import { onClickOutside } from '@vueuse/core'; const state = reactive({ useCommonPhrasesDialog: false, show_sample_title: false, @@ -71,7 +72,9 @@ sample_id: null, }); const commonPhrases = ref([]); -const props = defineProps(['isHome']); +const props = defineProps({ + isHome: Boolean, +}); const isShow = defineModel('isShow', { type: Boolean, }); @@ -87,7 +90,7 @@ }; //#endregion //#region ====================== 鑾峰彇甯哥敤璇� ====================== -const getCommonPhrases = async () => { +const updatePhrase = async () => { const res = await listUserSample({ group_type: activeGroupType.value, }); @@ -118,6 +121,7 @@ confirmButtonText: '纭畾', cancelButtonText: '鍙栨秷', dangerouslyUseHTMLString: true, + closeOnClickModal: false, type: 'warning', }).then(async () => { const res = await deleteUserSample({ @@ -140,129 +144,72 @@ handleClose(); } } else { - const res = await addUserSample({ + addCommonPhrasesData(); + } +}; +//娣诲姞涓�鏉℃暟鎹簮 +const addCommonPhrasesData = async () => { + const res = await addUserSample({ + question: state.inputCommonPhrases, + group_type: activeGroupType.value, + }); + if (res.json_ok) { + commonPhrases.value.push({ + id: res.sample_id, question: state.inputCommonPhrases, - group_type: activeGroupType.value, }); - if (res.json_ok) { - commonPhrases.value.push({ - id: res.sample_id, - question: state.inputCommonPhrases, - }); - handleClose(); - } + handleClose(); } }; //#endregion //#region ====================== 甯哥敤璇埌瀵硅瘽妗� ====================== const emits = defineEmits<{ - (event: 'updateCommonChatInput', val): void; + (event: 'updateInput', val): void; }>(); const titleClick = (item) => { - emits('updateCommonChatInput', item.question); + emits('updateInput', item.question); + isShow.value = false; setRoomConfig(activeRoomId.value, 'isAnswerByLLM', false); activeSampleId.value = item.id; }; const commonChatByUser = (data) => { - commonPhrases.value.push(data); + const question = data.question; + const isCommon = commonPhrases.value.findIndex((item) => item.question === question) > -1; + if (isCommon) { + return ElMessage.warning('璇ラ棶棰樺凡瀛樺湪甯哥敤璇腑'); + } else { + state.inputCommonPhrases = question; + addCommonPhrasesData(); + } }; //#endregion -onMounted(() => { - getCommonPhrases(); -}); -defineExpose({ commonChatByUser }); -</script> -<style scoped lang="scss"> -.container { - position: absolute; - width: 100%; - max-height: 40vh; - padding: 0 8px 8px; - left: 0px; - border-radius: 12px; - background-color: #ffffff; - border: 1px solid #e5e5e5; - box-shadow: 0px 8px 25px 0px #0000000d; - display: flex; - flex-direction: column; - z-index: 990; - &_header { - width: 100%; - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; - padding: 10px 6px; - color: #060607; - .question { - font-size: 14px; - color: #060607; - font-weight: 600; - line-height: 20px; - letter-spacing: 0.25px; - flex-grow: 1; - display: flex; - } - } - &_content { - width: 100%; - max-height: 35vh; - height: fit-content; - overflow-y: auto; - .set_phrases { - outline: none; - overflow-y: auto; - position: relative; - transition: height 0.1s linear; - .phase_item { - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; - cursor: pointer; - padding: 6px 8px; - flex-shrink: 0; - background: #fff; - border-radius: 8px; - width: 100%; - &:hover { - background: #e5e7ed; - } - .question { - font-size: 14px; - color: #8d8e99; - font-weight: 400; - font-style: normal; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - &:hover { - color: #060607; - } - } - .content { - font-size: 12px; - color: #5e6772; - font-family: PingFang SC; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - } - } - } +const commonPhrasesRef = ref<HTMLDivElement>(null); +onClickOutside( + commonPhrasesRef, + () => { + isShow.value = false; + }, + { + ignore: ['.el-message-box'], } - &_add { - display: flex; - flex-direction: row; - align-items: center; - cursor: pointer; - padding: 6px 8px; - background: #fff; - border-radius: 8px; - &:hover { - background: #e5e7ed; - } +); + +const addPhrase = (val) =>{ + if (!props.isHome) { + let obj = { + id: val?.historyId, + question: val?.content.values, + }; + commonChatByUser(obj); + isShow.value = true; } } +onMounted(() => { + updatePhrase(); +}); +defineExpose({ addPhrase, updatePhrase }); +</script> +<style scoped lang="scss"> +@use './index.scss'; </style> -- Gitblit v1.9.3