fixed bug for ctrl + enter key start a new row

This commit is contained in:
RockYang 2023-04-23 15:00:51 +08:00
parent 646c39792b
commit d2201596f6
3 changed files with 51 additions and 18 deletions

View File

@ -33,7 +33,7 @@ const routes = [
},
{
name: 'free', path: '/free', component: ChatFree, meta: {
title: '【文心一言】免费版'
title: 'Chat-Plus AI 助理'
}
},
{

View File

@ -105,7 +105,7 @@
v-on:focus="focus"
autofocus
type="textarea"
placeholder="开始你的提问"
placeholder="输入 Ctrl + Enter 换行"
/>
</div>
@ -308,9 +308,11 @@ export default defineComponent({
}
this.activelyClose = false;
//
this.chatData.push(this.helloMsg);
//
this.fetchChatHistory(this.curChat.id);
if (this.chatData.length === 0) { //
this.chatData.push(this.helloMsg);
}
});
socket.addEventListener('message', event => {
@ -319,6 +321,10 @@ export default defineComponent({
reader.readAsText(event.data, "UTF-8");
reader.onload = () => {
const data = JSON.parse(String(reader.result));
if (data['is_hello_msg'] === true) { //
return;
}
if (data.type === 'start') {
this.chatData.push({
type: "reply",
@ -326,13 +332,8 @@ export default defineComponent({
icon: this.replyIcon,
content: "",
});
if (data['is_hello_msg'] !== true) {
this.canReGenerate = true;
}
} else if (data.type === 'end') {
this.sending = false;
if (data['is_hello_msg'] !== true) {
this.showReGenerate = true;
//
appendChatHistory(this.curChat.id, this.curPrompt);
appendChatHistory(this.curChat.id, {
@ -341,8 +342,9 @@ export default defineComponent({
icon: this.replyIcon,
content: this.lineBuffer,
})
}
this.sending = false;
this.showStopGenerate = false;
this.showReGenerate = true;
this.lineBuffer = ''; //
//
@ -441,6 +443,11 @@ export default defineComponent({
inputKeyDown: function (e) {
if (e.keyCode === 13) {
if (e.ctrlKey) { // Ctrl + Enter
this.inputValue += "\n";
return;
}
if (this.sending) {
e.preventDefault();
} else {
@ -660,6 +667,8 @@ export default defineComponent({
this.appendChat();
this.chatData = [];
this.curChat = chat;
this.showStopGenerate = false;
this.showReGenerate = false;
this.connect();
},
@ -1024,6 +1033,18 @@ export default defineComponent({
}
}
}
nav {
ul {
.active {
a {
.btn {
display inline
}
}
}
}
}
}
.sidebar.show {

View File

@ -114,6 +114,8 @@
</el-icon>
</el-tooltip>
<span class="text">Ctrl + Enter 换行</span>
</el-row>
<div class="input-box">
@ -457,6 +459,11 @@ export default defineComponent({
inputKeyDown: function (e) {
if (e.keyCode === 13) {
if (e.ctrlKey) { // Ctrl + Enter
this.inputValue += "\n";
return;
}
if (this.sending) {
ElMessage.warning("AI 正在作答中,请稍后...");
e.preventDefault();
@ -812,6 +819,11 @@ export default defineComponent({
background-color #232425
cursor pointer
}
.text {
margin-left 10px;
font-size 12px;
color #9f9f9f;
}
}
.input-box {