整理聊天函数

This commit is contained in:
aixianling
2023-05-12 17:32:54 +08:00
parent 912c7fb079
commit 795f6cd652
6 changed files with 182 additions and 55 deletions

View File

@@ -15,7 +15,7 @@
</el-row>
</el-row>
<thinking-bar v-show="loading"/>
<chat-content class="fill"/>
<chat-content class="fill" :list="chatHistory"/>
<el-row class="mar-t8" align="middle">
<chat-input class="fill mar-r8" v-model="inputText"/>
<el-button type="primary" @click="handleSend">发送</el-button>
@@ -24,9 +24,11 @@
</template>
<script>
import {dayjs} from "element-plus";
import ChatContent from "../components/chatContent";
import ChatInput from "../components/chatInput";
import ThinkingBar from "../components/thinkingBar";
import {USER_AVATAR} from "../utils/env";
export default {
name: "chat",
@@ -38,11 +40,26 @@ export default {
return {
loading: false,
inputText: "",
chatHistory: []
}
},
methods: {
handleSend() {
if (!!this.inputText) {
const myMsg = {
headImg: USER_AVATAR,
name: "我",
time: dayjs().format("YYYY-MM-DD HH:mm:ss"),
msg: this.inputText,
chatType: 0, //信息类型0文字1图片
uid: "me", //uid
}
this.chatHistory.push(myMsg)
this.loading = true
this.settings.model.chat().finally(() => this.loading = false)
} else {
this.$message.error("请不要发送空消息!")
}
}
}
}