You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
3.1 KiB
159 lines
3.1 KiB
<template>
|
|
<div :class="{ 'chat-message': true, 'user-message': isUserMessage, 'bot-message':!isUserMessage }">
|
|
<p v-if="isLoading" class="loading"><img src="images/loading.webp" alt=""></p>
|
|
<p v-else>
|
|
{{ content }}
|
|
<span
|
|
v-if="!isUserMessage &&!isWelcomeMessage"
|
|
:class="{ 'stop-btn': isTyping, 'remove-btn':!isTyping && isStopped }"
|
|
@click="stopTyping($event)"
|
|
>
|
|
{{ isTyping? '停止输出' : (isStopped? '用户取消' : '') }}
|
|
</span>
|
|
</p>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
content: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
isUserMessage: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
isLoading: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
isWelcomeMessage: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
isTyping: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
isStopped: false
|
|
}
|
|
},
|
|
methods: {
|
|
stopTyping(event) {
|
|
this.isTyping = false
|
|
this.isStopped = true
|
|
this.$emit('stop-typing', event)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
/* 可以在这里添加组件特定的样式 */
|
|
.chat-message {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
font-size: 22px;
|
|
color: #fff;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.chat-message p {
|
|
position: relative;
|
|
line-height: 30px;
|
|
padding: 10px 16px;
|
|
background: rgba(0, 0, 0, 0.2);
|
|
border-radius: 28px 10px 28px 28px;
|
|
max-width: 90%;
|
|
}
|
|
|
|
.chat-message p span.stop-btn {
|
|
position: absolute;
|
|
left: 4px;
|
|
bottom: -40px;
|
|
width: 100px;
|
|
padding-left: 24px;
|
|
height: 32px;
|
|
text-align: center;
|
|
line-height: 30px;
|
|
border: 1px solid #4CA7FF;
|
|
color: #4CA7FF;
|
|
border-radius: 10px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.chat-message p span.stop-btn::before {
|
|
content: '';
|
|
position: absolute;
|
|
left: 4px;
|
|
top: 50%;
|
|
width: 24px;
|
|
height: 24px;
|
|
background: url("~@/assets/images/index-img7.png") no-repeat left top;
|
|
background-size: 100% 100%;
|
|
margin-top: -12px;
|
|
}
|
|
|
|
.chat-message p span.stop-btn:hover {
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.chat-message p span.remove-btn {
|
|
position: absolute;
|
|
left: 4px;
|
|
bottom: -40px;
|
|
padding-left: 0;
|
|
border: none;
|
|
color: #999;
|
|
width: 100px;
|
|
padding-left: 24px;
|
|
height: 32px;
|
|
text-align: center;
|
|
line-height: 30px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.chat-message p span.remove-btn::before {
|
|
border: none;
|
|
color: #999;
|
|
background: none;
|
|
}
|
|
|
|
.chat-message p span.remove-btn:hover {
|
|
background-color: transparent;
|
|
cursor: default;
|
|
}
|
|
|
|
.bot-message {
|
|
display: flex;
|
|
flex-direction: row-reverse;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.bot-message p {
|
|
line-height: 48px;
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
border-radius: 8px 28px 28px 28px;
|
|
}
|
|
|
|
.loading {
|
|
position: relative;
|
|
display: flex;
|
|
justify-content: flex-start;
|
|
align-items: center;
|
|
height: 66px;
|
|
}
|
|
|
|
.loading img {
|
|
display: block;
|
|
width: 67px;
|
|
margin: 0 10px;
|
|
}
|
|
</style>
|