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: { name: 'free', path: '/free', component: ChatFree, meta: {
title: '【文心一言】免费版' title: 'Chat-Plus AI 助理'
} }
}, },
{ {

View File

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

View File

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