From 1622a4d80dd86d0fde35af6908937f9be670fee3 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期二, 17 十二月 2024 10:13:00 +0800 Subject: [PATCH] 停止生成 --- src/components/chat/components/playBar/phrase/CommonPhrases.vue | 81 ++++++++++++++++++++++++++++++---------- 1 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/components/chat/components/playBar/phrase/CommonPhrases.vue b/src/components/chat/components/playBar/phrase/CommonPhrases.vue index 3bd4491..f650df3 100644 --- a/src/components/chat/components/playBar/phrase/CommonPhrases.vue +++ b/src/components/chat/components/playBar/phrase/CommonPhrases.vue @@ -1,7 +1,7 @@ <template> <div class="container" :class="isHome ? 'top-[100%] mt-[8px]' : 'bottom-[100%] mb-[8px]'"> <div class="container_header"> - <div class="title">甯哥敤璇�</div> + <div class="question">甯哥敤璇�</div> <span class="ywifont ywicon-guanbi text-[15px] cursor-pointer text-[#767a97]" @click="closeCommonPhrases"></span> </div> <div class="container_content"> @@ -11,8 +11,8 @@ <div style="overflow-anchor: none" v-for="(item, index) in commonPhrases" :key="index"> <div class="phase_item" @click="titleClick(item)"> <div class="flex flex-col"> - <div class="title"> - {{ item.title }} + <div class="question"> + {{ item.question }} </div> <!-- <div class="content"> {{ item.content }} @@ -59,15 +59,16 @@ </template> <script setup lang="ts"> -import { ElMessageBox } from 'element-plus'; -import { computed, reactive, ref } from 'vue'; -import { addUserSample } from '/@/api/ai/chat'; +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'; const state = reactive({ useCommonPhrasesDialog: false, show_sample_title: false, inputCommonPhrases: '', sample_title: null, + sample_id: null, }); const commonPhrases = ref([]); const props = defineProps(['isHome']); @@ -85,7 +86,16 @@ isShow.value = false; }; //#endregion - +//#region ====================== 鑾峰彇甯哥敤璇� ====================== +const getCommonPhrases = async () => { + const res = await listUserSample({ + group_type: activeGroupType.value, + }); + if (res.json_ok) { + commonPhrases.value = res.values; + } +}; +//#endregion //#region ====================== 娣诲姞甯哥敤璇� ====================== //鍏抽棴甯哥敤璇脊绐� const handleClose = () => { @@ -100,20 +110,42 @@ const editCommonPhrases = (item) => { state.useCommonPhrasesDialog = true; state.show_sample_title = true; - state.inputCommonPhrases = item.title; + state.inputCommonPhrases = item.question; + state.sample_id = item.id; }; -const deleteCommonPhrases = (item) => { - ElMessageBox.confirm(`浣犵‘瀹氳鍒犻櫎甯哥敤璇悧?<div style="white-space: pre-line;">[${item.title}]</div>`, '鎻愮ず', { +const deleteCommonPhrases = (row) => { + ElMessageBox.confirm(`浣犵‘瀹氳鍒犻櫎甯哥敤璇悧?`, '鎻愮ず', { confirmButtonText: '纭畾', cancelButtonText: '鍙栨秷', - type: 'warning', dangerouslyUseHTMLString: true, + closeOnClickModal: false, + type: 'warning', }).then(async () => { - commonPhrases.value = commonPhrases.value.filter((i) => i.id !== item.id); + const res = await deleteUserSample({ + sample_id: row.id, + }); + const foundIndex = commonPhrases.value.findIndex((item) => item === row); + foundIndex > -1 && commonPhrases.value.splice(foundIndex, 1); }); }; //鎻愪氦甯哥敤璇� const submitCommonPhrases = async () => { + if (state.show_sample_title) { + const res = await updateUserSample({ + sample_id: state.sample_id, + question: state.inputCommonPhrases, + }); + if (res.json_ok) { + const foundIndex = commonPhrases.value.findIndex((item) => item.id === state.sample_id); + foundIndex > -1 && (commonPhrases.value[foundIndex].question = state.inputCommonPhrases); + handleClose(); + } + } else { + addCommonPhrasesData(); + } +}; +//娣诲姞涓�鏉℃暟鎹簮 +const addCommonPhrasesData = async () => { const res = await addUserSample({ question: state.inputCommonPhrases, group_type: activeGroupType.value, @@ -121,27 +153,36 @@ if (res.json_ok) { commonPhrases.value.push({ id: res.sample_id, - title: state.inputCommonPhrases, + question: state.inputCommonPhrases, }); - state.useCommonPhrasesDialog = false; + handleClose(); } }; //#endregion //#region ====================== 甯哥敤璇埌瀵硅瘽妗� ====================== const emits = defineEmits<{ (event: 'updateCommonChatInput', val): void; - (event: 'updateCommonChatByUser', val): void; }>(); const titleClick = (item) => { - emits('updateCommonChatInput', item.title); + emits('updateCommonChatInput', item.question); 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(); + } }; -defineExpose({ commonChatByUser }); //#endregion +onMounted(() => { + getCommonPhrases(); +}); +defineExpose({ commonChatByUser, getCommonPhrases }); </script> <style scoped lang="scss"> .container { @@ -165,7 +206,7 @@ align-items: center; padding: 10px 6px; color: #060607; - .title { + .question { font-size: 14px; color: #060607; font-weight: 600; @@ -199,7 +240,7 @@ &:hover { background: #e5e7ed; } - .title { + .question { font-size: 14px; color: #8d8e99; font-weight: 400; -- Gitblit v1.9.3