From a2fb542eeda76f9595f921391d194db9f572321c Mon Sep 17 00:00:00 2001 From: DCloud__JSON Date: Fri, 2 Jun 2023 16:46:12 +0800 Subject: [PATCH] 1.0.18 --- changelog.md | 3 +++ components/uni-ai-msg/uni-ai-msg.vue | 37 ++++++++++++++------------- package.json | 7 +++-- pages/chat/chat.vue | 38 ++++++---------------------- 4 files changed, 35 insertions(+), 50 deletions(-) diff --git a/changelog.md b/changelog.md index ddbca82..7549131 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## 1.0.18(2023-06-02) +- 新增 支持一键复制代码块 +- 修复 部分情况下偶发,ai回复的内容会串到用户的提问内容中的问题 ## 1.0.17(2023-05-29) - 新增 显示代码行号 - 修复 代码块显示样式错误的问题 diff --git a/components/uni-ai-msg/uni-ai-msg.vue b/components/uni-ai-msg/uni-ai-msg.vue index 22751cd..890c9b3 100644 --- a/components/uni-ai-msg/uni-ai-msg.vue +++ b/components/uni-ai-msg/uni-ai-msg.vue @@ -66,7 +66,7 @@ // 在源码中启用 HTML 标签 html: true, // 如果结果以
'
 			
-			// #ifdef APP || H5
-				// // 复制功能~未完待续
-				// let tmpDom = document.createElement('div')
-				// tmpDom.innerHTML = html
-				// codeDataList.push(tmpDom.innerText)
-				// let codeDataIndex = Date.now()
-				// html = `复制` + html
-			// #endif
+			// 代码复制功能
+			codeDataList.push(str)
+			html = `复制` + html
 			return `
${html}
`; } }) @@ -224,16 +219,22 @@ }, trOnclick(e){ // console.log(e); - // let {attrs} = e.detail.node + let {attrs} = e.detail.node // console.log({attrs}); - // let {"code-data-index":codeDataIndex,"class":className} = attrs - // if(className == 'copy-btn'){ - // console.log('codeDataList[codeDataIndex]',codeDataList[codeDataIndex]); - // uni.setClipboardData({ - // data:codeDataList[codeDataIndex], - // showToast:false - // }) - // } + let {"code-data-index":codeDataIndex,"class":className} = attrs + if(className == 'copy-btn'){ + // console.log('codeDataList[codeDataIndex]',codeDataList[codeDataIndex]); + uni.setClipboardData({ + data:codeDataList[codeDataIndex], + showToast:false, + success() { + uni.showToast({ + title: '复制成功', + icon: 'none' + }); + } + }) + } }, // #ifdef H5 // 复制文本内容到系统剪切板 diff --git a/package.json b/package.json index dd66890..87b19cc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "uni-ai-chat", "name": "uni-ai-chat", - "version": "1.0.17", + "version": "1.0.18", "description": "基于uni-ai的聊天示例项目,支持流式、支持前文总结,云端一体", "main": "main.js", "scripts": { @@ -9,7 +9,10 @@ }, "repository": "https://gitcode.net/dcloud/uni-ai-chat", "keywords": [ - "uni-ai-chat" + "uni-ai-chat", + "gpt", + "chatgpt", + "openai" ], "author": "", "license": "ISC", diff --git a/pages/chat/chat.vue b/pages/chat/chat.vue index 9891d7d..b2eb0f2 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -29,9 +29,7 @@ @@ -209,8 +207,7 @@ this.showLastMsg() }) - // 兼容 Vue3下textarea不支持@keydown - // #ifdef H5 && VUE3 + // #ifdef H5 //获得消息输入框对象 let adjunctKeydown = false const textareaDom = document.querySelector('.textarea-box textarea'); @@ -223,10 +220,11 @@ adjunctKeydown = true; } if (e.keyCode == 13 && !adjunctKeydown) { - // 延迟兼容 v-model的时机小于onkeydown的问题 - this.content = textareaDom.value - // 执行发送 - this.beforeSendMsg(); + e.preventDefault() + // 执行发送 + setTimeout(()=>{ + this.beforeSendMsg(); + },300) } }; textareaDom.onkeyup = e => { @@ -239,26 +237,6 @@ // #endif }, methods: { - // #ifdef H5 && VUE2 - onKeydown(keyname) { - if (keyname == 'shift') { - //按下了shift键 - shiftKeyPressed = true; - } - // 按下了回车 且 之前没按下 shift - if (keyname == 'enter' && !shiftKeyPressed) { - this.$nextTick(() => { - this.beforeSendMsg(); - }) - } - }, - onKeyup(keyname) { - if (keyname == 'shift') { - //按下了shift键 - shiftKeyPressed = false; - } - }, - // #endif // 此(惰性)函数,检查是否开通uni-push;决定是否启用enableStream async checkIsOpenPush() { try { @@ -273,7 +251,7 @@ }, // 更新最后一条消息 updateLastMsg(param) { - let length = this.msgLength + let length = this.msgList.length if (length === 0) { return } -- GitLab