diff --git a/Yi.Bbs.Vue3/src/views/chathub/Index.vue b/Yi.Bbs.Vue3/src/views/chathub/Index.vue index a3806008..3a7d4d26 100644 --- a/Yi.Bbs.Vue3/src/views/chathub/Index.vue +++ b/Yi.Bbs.Vue3/src/views/chathub/Index.vue @@ -46,9 +46,10 @@ const startCountTip = () => { } }, 1000); }; - +let codeCopyDic=[]; //当前聊天框显示的消息 const currentMsgContext = computed(() => { + if (selectIsAll()) { return chatStore.allMsgContext; } @@ -57,6 +58,7 @@ const currentMsgContext = computed(() => { // console.log(chatStore.aiMsgContext, "chatStore.aiMsgContext"); // return chatStore.aiMsgContext; let tempHtml = []; + codeCopyDic=[]; chatStore.aiMsgContext.forEach(element => { tempHtml.push({ content: toMarkDownHtml(element.content), messageType: 'Ai', sendUserId: element.sendUserId, sendUserInfo: element.sendUserInfo }); @@ -88,7 +90,6 @@ const toMarkDownHtml = (text) => { tables: true,//支持表格 breaks: true, sanitize: false, - smartLists: true, smartypants: false, xhtml: false, smartLists: true, @@ -102,7 +103,7 @@ const toMarkDownHtml = (text) => { return soureHtml; } -let codeCopyDic=[]; + //code部分处理、高亮 const codeHandler = (code, language) => { const codeIndex = parseInt(Date.now() + "") + Math.floor(Math.random() * 10000000); @@ -204,20 +205,25 @@ onUnmounted(() => { }) +const clickCopyEvent=async function(event) { + const spanId=event.target.id; + console.log(codeCopyDic,"codeCopyDic") + console.log(spanId,"spanId") + await navigator.clipboard.writeText(codeCopyDic.filter(x=>x.id==spanId)[0].code); + ElMessage({ + message: "代码块复制成功", + type: "success", + duration: 2000, + }); +} //代码copy事件 const addCopyEvent=()=>{ const copySpans = document.querySelectorAll('.copy'); // 为每个 copy span 元素添加点击事件 copySpans.forEach(span => { - - span.addEventListener('click', async function() { - await navigator.clipboard.writeText(codeCopyDic.filter(x=>x.id==span.id)[0].code ); - ElMessage({ - message: "代码块复制成功", - type: "success", - duration: 2000, - }); - }); + //先移除,再新增 + span.removeEventListener('click',clickCopyEvent ); + span.addEventListener('click', clickCopyEvent); }); } @@ -412,7 +418,7 @@ const getLastMessage = ((receiveId, itemType) => {