Improved the style of the chat window, using message bubbles.

This commit is contained in:
Rafi
2023-03-04 20:25:52 +08:00
parent 6402f156dd
commit 002db29717
5 changed files with 40 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<img alt="demo" src="./demos/demo.gif?v=1"> <img alt="demo" src="./demos/demo.png?v=1">
</p> </p>
# ChatGPT UI # ChatGPT UI

View File

@@ -20,6 +20,7 @@ const contentHtml = computed(() => {
<template> <template>
<div <div
v-html="contentHtml" v-html="contentHtml"
class="text-body-1 text-justify"
></div> ></div>
</template> </template>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

BIN
demos/demo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

View File

@@ -3,6 +3,7 @@ definePageMeta({
middleware: ["auth"] middleware: ["auth"]
}) })
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source' import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
import { nextTick } from 'vue'
const { $i18n, $auth } = useNuxtApp() const { $i18n, $auth } = useNuxtApp()
const runtimeConfig = useRuntimeConfig() const runtimeConfig = useRuntimeConfig()
@@ -49,7 +50,7 @@ const fetchReply = async (message, parentMessageId) => {
onerror(err) { onerror(err) {
throw err; throw err;
}, },
onmessage(message) { async onmessage(message) {
// console.log(message) // console.log(message)
const event = message.event const event = message.event
const data = JSON.parse(message.data) const data = JSON.parse(message.data)
@@ -119,28 +120,49 @@ const showSnackbar = (text) => {
snackbar.value = true snackbar.value = true
} }
</script> </script>
<template> <template>
<div <div
v-if="currentConversation.messages.length > 0" v-if="currentConversation.messages.length > 0"
ref="chatWindow" ref="chatWindow"
>
<v-card
rounded="0"
elevation="0"
v-for="(conversation, index) in currentConversation.messages"
:key="index"
:variant="conversation.is_bot ? 'tonal' : 'text'"
> >
<v-container> <v-container>
<v-card-text class="text-caption text-disabled">{{ $t(`roles.${conversation.is_bot?'ai':'me'}`) }}</v-card-text> <v-row>
<v-col
v-for="(message, index) in currentConversation.messages" :key="index"
cols="12"
>
<div
class="d-flex"
:class="message.is_bot ? 'justify-start mr-16' : 'justify-end ml-16'"
>
<v-card
:color="message.is_bot ? '' : 'primary'"
rounded="lg"
elevation="2"
>
<v-card-text> <v-card-text>
<MsgContent :content="conversation.message" /> <MsgContent :content="message.message" />
</v-card-text> </v-card-text>
</v-container>
<v-divider></v-divider> <!-- <v-card-actions-->
<!-- v-if="message.is_bot"-->
<!-- >-->
<!-- <v-spacer></v-spacer>-->
<!-- <v-tooltip text="Copy">-->
<!-- <template v-slot:activator="{ props }">-->
<!-- <v-btn v-bind="props" icon="content_copy"></v-btn>-->
<!-- </template>-->
<!-- </v-tooltip>-->
<!-- </v-card-actions>-->
</v-card> </v-card>
</div>
</v-col>
</v-row>
</v-container>
<div ref="grab" class="w-100" style="height: 200px;"></div> <div ref="grab" class="w-100" style="height: 200px;"></div>
</div> </div>
<Welcome v-else /> <Welcome v-else />