From f04c923e5eafd2df88c3297f539ada7c6eef2232 Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期日, 03 十一月 2024 11:00:40 +0800 Subject: [PATCH] 添加常用语内容 --- src/components/chat/components/playBar/phrase/CommonPhrases.vue | 147 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 120 insertions(+), 27 deletions(-) diff --git a/src/components/chat/components/playBar/phrase/CommonPhrases.vue b/src/components/chat/components/playBar/phrase/CommonPhrases.vue index b99dd18..d3a1ff4 100644 --- a/src/components/chat/components/playBar/phrase/CommonPhrases.vue +++ b/src/components/chat/components/playBar/phrase/CommonPhrases.vue @@ -5,18 +5,28 @@ <span class="ywifont ywicon-guanbi text-[15px] cursor-pointer text-[#767a97]" @click="closeCommonPhrases"></span> </div> <div class="container_content"> - <div class="set_phrases" :style="{ height: commonPhrases.length * 40 + 'px' }"> + <div class="set_phrases" :style="{ height: commonPhrases.length * 46 + 'px' }"> <div class="w-full h-full absolute top-0"> <div class="py-0 mt-0 box-border h-full"> <div style="overflow-anchor: none" v-for="(item, index) in commonPhrases" :key="index"> <div class="phase_item"> <div class="flex flex-col"> - <div class="title"> + <div class="title" @click="titleClick(item)"> {{ item.title }} </div> - <div class="content"> + <!-- <div class="content"> {{ item.content }} - </div> + </div> --> + </div> + <div class="py-2"> + <span + class="ywifont ywicon-bianji cursor-pointer text-[#767a97] pt-[4px] pr-[6px] pb-[2px] pl-0 rounded-lg !text-[13px]" + @click="editCommonPhrases(item)" + ></span> + <span + class="ywifont ywicon-shanchu3 cursor-pointer text-[red] pt-[4px] pr-[6px] pb-[2px] pl-0 rounded-lg" + @click="deleteCommonPhrases(item)" + ></span> </div> </div> </div> @@ -24,39 +34,115 @@ </div> </div> </div> - <div class="container_add"> + <div class="container_add" @click="addCommonPhrases"> <span class="ywifont ywicon-jia text-[15px] cursor-pointer text-[#767a97]"></span> + <div class="grow">娣诲姞甯哥敤璇�</div> </div> + <el-dialog + v-model="state.useCommonPhrasesDialog" + :title="`${showCommonPhrases}甯哥敤璇璥" + width="500" + :before-close="handleClose" + style="z-index: 999" + > + <el-input v-model="state.inputCommonPhrases" :rows="10" type="textarea" placeholder="鑷畾涔夊父鐢ㄨ"></el-input> + <template #footer> + <div class="dialog-footer"> + <el-button @click="handleClose">鍙栨秷</el-button> + <el-button type="primary" @click="submitCommonPhrases" :disabled="is_input_title"> + {{ showCommonPhrases }} + </el-button> + </div> + </template> + </el-dialog> </div> </template> <script setup lang="ts"> -import { ref } from 'vue'; -const commonPhrases = ref([ - { - id: 1, - title: '浣犲ソ锛岃闂湁浠�涔堝彲浠ュ府鍔╂偍锛�', - content: '鎮ㄥソ锛屾垜鎯冲挩璇竴涓嬪叧浜庢偍鐨勮鍗曘��', - }, - { - id: 2, - title: '娴嬭瘯1?', - content: '鎴戞兂鍜ㄨ涓�涓嬪叧浜庢偍鐨勮鍗曘��', - }, - { - id: 3, - title: '娴嬭瘯2?', - content: '鎴戞兂鍜ㄨ涓�涓嬪叧浜庢偍鐨勮鍗曘��', - }, -]); +import { ElMessageBox } from 'element-plus'; +import { computed, reactive, ref } from 'vue'; +import { addUserSample } 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, +}); +const commonPhrases = ref([]); const props = defineProps(['isHome']); -const closeCommonPhrases = () => {}; +const isShow = defineModel('isShow', { + type: Boolean, +}); +//#region ====================== 鏄惁鏄剧ず甯哥敤璇� ====================== +const showCommonPhrases = computed(() => { + return state.show_sample_title == true ? (state.sample_title = '缂栬緫') : (state.sample_title = '娣诲姞'); +}); +const is_input_title = computed(() => { + return state.inputCommonPhrases == '' ? true : false; +}); +const closeCommonPhrases = () => { + isShow.value = false; +}; +//#endregion + +//#region ====================== 娣诲姞甯哥敤璇� ====================== +//鍏抽棴甯哥敤璇脊绐� +const handleClose = () => { + state.useCommonPhrasesDialog = false; +}; +//鎵撳紑甯哥敤璇脊绐� +const addCommonPhrases = () => { + state.useCommonPhrasesDialog = true; + state.show_sample_title = false; + state.inputCommonPhrases = ''; +}; +const editCommonPhrases = (item) => { + state.useCommonPhrasesDialog = true; + state.inputCommonPhrases = item.content; + state.show_sample_title = true; +}; +const deleteCommonPhrases = (item) => { + ElMessageBox.confirm(`浣犵‘瀹氳鍒犻櫎甯哥敤璇悧?<div style="white-space: pre-line;">[${item.title}]</div>`, '鎻愮ず', { + confirmButtonText: '纭畾', + cancelButtonText: '鍙栨秷', + type: 'warning', + dangerouslyUseHTMLString: true, + }).then(async () => { + commonPhrases.value = commonPhrases.value.filter((i) => i.id !== item.id); + }); +}; +//鎻愪氦甯哥敤璇� +const submitCommonPhrases = async () => { + const res = await addUserSample({ + question: state.inputCommonPhrases, + group_type: activeGroupType.value, + }); + if (res.json_ok) { + commonPhrases.value.push({ + id: res.sample_id, + title: state.inputCommonPhrases, + }); + state.useCommonPhrasesDialog = false; + } +}; +//#endregion +//#region ====================== 甯哥敤璇埌瀵硅瘽妗� ====================== +const emits = defineEmits<{ + (event: 'updateCommonChatInput', val): void; +}>(); +const titleClick = (item) => { + emits('updateCommonChatInput', item.title); + setRoomConfig(activeRoomId.value, 'isAnswerByLLM', false); + activeSampleId.value = item.id; +}; +//#endregion </script> <style scoped lang="scss"> .container { position: absolute; width: 100%; - max-height: 45vh; + max-height: 40vh; padding: 0 8px 8px; left: 0px; border-radius: 12px; @@ -65,7 +151,7 @@ box-shadow: 0px 8px 25px 0px #0000000d; display: flex; flex-direction: column; - z-index: 100; + z-index: 990; &_header { width: 100%; display: flex; @@ -86,8 +172,9 @@ } &_content { width: 100%; - max-height: 40vh; + max-height: 35vh; height: fit-content; + overflow-y: auto; .set_phrases { outline: none; overflow-y: auto; @@ -104,6 +191,9 @@ background: #fff; border-radius: 8px; width: 100%; + &:hover { + background: #e5e7ed; + } .title { font-size: 14px; color: #060607; @@ -133,6 +223,9 @@ padding: 6px 8px; background: #fff; border-radius: 8px; + &:hover { + background: #e5e7ed; + } } } </style> -- Gitblit v1.9.3