From 3c2005f5b00449ea4197ad85710b346bb7e0c85d Mon Sep 17 00:00:00 2001 From: DCloud__JSON Date: Mon, 15 May 2023 17:48:49 +0800 Subject: [PATCH] =?UTF-8?q?1.0.10=E4=BF=AE=E5=A4=8D=20Vue3-web-pc=E7=AB=AF?= =?UTF-8?q?=20=E5=9B=9E=E8=BD=A6=E4=B8=8D=E8=83=BD=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E5=85=BC=E5=AE=B9=E6=96=B9=E6=A1=88=EF=BC=8C=E5=90=8E?= =?UTF-8?q?=E7=BB=ADtextarea=E7=BB=84=E4=BB=B6=E4=B8=8D=E6=94=AF=E6=8C=81@?= =?UTF-8?q?keydown=E7=9A=84=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=E5=90=8E?= =?UTF-8?q?=E4=BC=9A=E8=B0=83=E6=95=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 2 ++ package.json | 2 +- pages/chat/chat.vue | 34 ++++++++++++++++++- .../cloudfunctions/uni-ai-chat/index.obj.js | 5 ++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 6a336ac..412762e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,5 @@ +## 1.0.10(2023-05-15) +- 修复 Vue3-web-pc端 回车不能发送消息的问题(临时兼容方案,后续textarea组件不支持@keydown的问题修复后会调整) ## 1.0.9(2023-05-15) - 修复 非流式模式 uni-ai默认服务商 检测到内容涉及违规后 卡住的问题 ## 1.0.8(2023-05-15) diff --git a/package.json b/package.json index fa1e571..3616c31 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "uni-ai-chat", "name": "uni-ai-chat", - "version": "1.0.9", + "version": "1.0.10", "description": "基于uni-ai的聊天示例项目,支持流式、支持前文总结,云端一体", "main": "main.js", "scripts": { diff --git a/pages/chat/chat.vue b/pages/chat/chat.vue index f611dc0..4e9d2d1 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -190,9 +190,40 @@ }, matches => { this.isWidescreen = matches; }) + // #endif + + + // 兼容 Vue3下textarea不支持@keydown + // #ifdef H5 && VUE3 + //获得消息输入框对象 + let adjunctKeydown = false + const textareaDom = document.querySelector('.textarea-box textarea'); + if (textareaDom) { + //键盘按下时 + textareaDom.onkeydown = e => { + // console.log('onkeydown', e.keyCode) + if ([16, 17, 18, 93].includes(e.keyCode)) { + //按下了shift ctrl alt windows键 + adjunctKeydown = true; + } + if (e.keyCode == 13 && !adjunctKeydown) { + // 延迟兼容 v-model的时机小于onkeydown的问题 + setTimeout(()=> { + this.beforeSendMsg(); + }, 100); + } + }; + textareaDom.onkeyup = e => { + //松开adjunct键 + if ([16, 17, 18, 93].includes(e.keyCode)) { + adjunctKeydown = false; + } + }; + } // #endif }, methods: { + // #ifdef H5 && VUE2 onKeydown(keyname){ if(keyname == 'shift'){ //按下了shift键 @@ -211,6 +242,7 @@ shiftKeyPressed = false; } }, + // #endif // 此(惰性)函数,检查是否开通uni-push;决定是否启用enableStream async checkIsOpenPush() { try { @@ -538,7 +570,7 @@ this.showLastMsg() }) } else { - console.log('用户点击了清空按钮,跳过前一次请求的回调', res.data.reply); + console.log('用户点击了清空按钮,跳过前一次请求的回调。内容:', res.data.reply); } } }) diff --git a/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js b/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js index 8cf9704..a9fbafd 100644 --- a/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js +++ b/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js @@ -57,7 +57,7 @@ module.exports = { } // 从配置中心获取内容安全配置 - console.log('config.contentSecurity',config.contentSecurity); + // console.log('config.contentSecurity',config.contentSecurity); if (config.contentSecurity) { // 引入uni-sec-check模块 const UniSecCheck = safeRequire('uni-sec-check') @@ -117,13 +117,12 @@ module.exports = { console.log('contentString',contentString); // 对contentString进行文本安全检测 await this.textSecCheck(contentString) - } } }, async _after(error, result) { // 打印错误和结果 - console.log('_after',{error,result}); + // console.log('_after',{error,result}); // 如果有错误 if(error){ // 如果是内容安全检测错误 -- GitLab