diff --git a/changelog.md b/changelog.md index ddbca8226bdfed4758d54a19911d401a97350e32..7549131af33926d388ae2820cc46c7d22cb3b5bf 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 22751cd2fcc5e7befae44e115a1ddb478dfd195f..890c9b3776ccf8fea96809dd83a9aa85e5ddf6b8 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 ``; } }) @@ -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 dd66890bd0daee1bd463f6abb755379c86908d74..87b19cca45e97e9f5a335182ce620ccf887624ce 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 9891d7d3611bd748c059ad37366ebcf089a69452..b2eb0f28c1bb5a7dd5ba6e3c2c53705730a756df 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -29,9 +29,7 @@${html}
@@ -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 }