feat: 聊天页面
This commit is contained in:
63
src/views/asistant/components/ChatLoading.vue
Normal file
63
src/views/asistant/components/ChatLoading.vue
Normal file
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div class="chat-loading">
|
||||
<div class="loading-container flex flex-column flex-align-center">
|
||||
<img src="@/assets/images/chat_loading.png" alt="Loading" class="loading-image" />
|
||||
<!-- 阴影效果 -->
|
||||
<div class="loading-shadow"></div>
|
||||
<div class="loading-text">Analyzing the Outfit...</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 这个组件只负责显示loading动画
|
||||
interface LoadingProps {
|
||||
// 可以在这里定义props类型
|
||||
}
|
||||
|
||||
// 定义组件props类型
|
||||
const props = defineProps<LoadingProps>()
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.chat-loading {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading-image {
|
||||
width: 36.4rem;
|
||||
height: 36.4rem;
|
||||
animation: rotate 1s linear infinite;
|
||||
}
|
||||
|
||||
.loading-shadow {
|
||||
width: 19.6rem;
|
||||
height: 5.2rem;
|
||||
background-color: #d9d9d9;
|
||||
border-radius: 50%;
|
||||
filter: blur(35.5px);
|
||||
margin-top: 5.1rem;
|
||||
margin-bottom: 6.4rem;
|
||||
}
|
||||
|
||||
.loading-text{
|
||||
font-family: 'satoshiRegular';
|
||||
font-size: 4.8rem;
|
||||
letter-spacing: 0.02em;
|
||||
line-height: 124%;
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
121
src/views/asistant/components/InputArea.vue
Normal file
121
src/views/asistant/components/InputArea.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<div class="input-area">
|
||||
<div class="input-container">
|
||||
<!-- 加号图标 -->
|
||||
<div class="icon-wrapper">
|
||||
<SvgIcon name="plus" size="40" />
|
||||
</div>
|
||||
|
||||
<!-- 分隔线 -->
|
||||
<div class="divider"></div>
|
||||
|
||||
<!-- 输入框 -->
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
v-model="inputValue"
|
||||
type="text"
|
||||
placeholder="Ask anything about your desired outfit"
|
||||
class="text-input"
|
||||
@keyup.enter="handleSend"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 语音图标 -->
|
||||
<div class="icon-wrapper">
|
||||
<SvgIcon name="audio" size="52" />
|
||||
</div>
|
||||
|
||||
<!-- 发送图标 -->
|
||||
<div class="icon-wrapper send-icon" @click="handleSend">
|
||||
<SvgIcon name="send" size="46" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import SvgIcon from '@/components/SvgIcon/index.vue'
|
||||
|
||||
interface InputAreaEmits {
|
||||
'send-message': [message: string]
|
||||
}
|
||||
|
||||
const inputValue = ref<string>('')
|
||||
|
||||
const emit = defineEmits<InputAreaEmits>()
|
||||
|
||||
const handleSend = (): void => {
|
||||
if (inputValue.value.trim()) {
|
||||
console.log('input发送消息:', inputValue.value)
|
||||
emit('send-message', inputValue.value)
|
||||
inputValue.value = ''
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.input-area {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.input-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: #efefef;
|
||||
padding: 0 4.85rem 0 5.2rem;
|
||||
height: 19.3rem;
|
||||
}
|
||||
|
||||
.icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
&.send-icon {
|
||||
margin-left: 4.38rem;
|
||||
}
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 2px;
|
||||
height: 14.9rem;
|
||||
margin-left: 5.59rem;
|
||||
margin-right: 3.5rem;
|
||||
background-color: #888;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.text-input {
|
||||
width: 100%;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
font-size: 4rem;
|
||||
font-family: 'robotoBold';
|
||||
font-weight: 400;
|
||||
line-height: 121%;
|
||||
// padding-right: 2rem;
|
||||
margin-right: 4.21rem;
|
||||
color: #888;
|
||||
|
||||
&::placeholder {
|
||||
color: #888;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保图标颜色为 #6d6868
|
||||
:deep(.svg-icon) {
|
||||
color: #6d6868;
|
||||
|
||||
svg {
|
||||
fill: #6d6868;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
149
src/views/asistant/components/NoticeItem.vue
Normal file
149
src/views/asistant/components/NoticeItem.vue
Normal file
@@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<div
|
||||
class="chat-message"
|
||||
:class="{ 'user-message': value.userId === '1', 'ai-message': value.userId !== '1' }"
|
||||
>
|
||||
<!-- AI消息显示头像 -->
|
||||
<div v-if="value.userId !== '1'" class="chat-avatar">
|
||||
<img :src="value.thumb" alt="AI Avatar" />
|
||||
</div>
|
||||
|
||||
<!-- 消息内容 -->
|
||||
<div class="message-content">
|
||||
<div class="message-text">
|
||||
{{ value.content }}
|
||||
</div>
|
||||
<!-- AI消息显示操作栏 -->
|
||||
<div v-if="value.userId !== '1'" class="message-actions flex">
|
||||
<SvgIcon
|
||||
v-for="item in actionList"
|
||||
:key="item.value"
|
||||
:name="item.icon"
|
||||
size="39"
|
||||
@click.stop="handleClickAction(item.value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 定义消息类型
|
||||
interface ChatMessage {
|
||||
id: string
|
||||
content: string
|
||||
userId: string
|
||||
time: string
|
||||
thumb: string
|
||||
}
|
||||
|
||||
// 定义操作项类型
|
||||
interface ActionItem {
|
||||
value: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
// 定义组件props类型
|
||||
interface NoticeItemProps {
|
||||
value: ChatMessage
|
||||
}
|
||||
|
||||
const props = defineProps<NoticeItemProps>()
|
||||
|
||||
const handleClickAction = (value: string): void => {
|
||||
console.log('click Action', value)
|
||||
}
|
||||
|
||||
const actionList: ActionItem[] = [
|
||||
{
|
||||
value: 'thumbup',
|
||||
icon: 'thumbup'
|
||||
},
|
||||
{
|
||||
value: 'thumbdown',
|
||||
icon: 'thumbdown'
|
||||
},
|
||||
{
|
||||
value: 'refresh',
|
||||
icon: 'refresh'
|
||||
},
|
||||
{
|
||||
value: 'upload',
|
||||
icon: 'upload'
|
||||
},
|
||||
{
|
||||
value: 'more',
|
||||
icon: 'more'
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.chat-message {
|
||||
display: flex;
|
||||
margin-bottom: 16px;
|
||||
align-items: flex-start;
|
||||
.message-text {
|
||||
font-size: 4.2rem;
|
||||
font-family: 'robotoBold';
|
||||
line-height: 121%;
|
||||
font-weight: 400;
|
||||
background-color: #efefef;
|
||||
padding: 4.95rem 3.95rem;
|
||||
}
|
||||
|
||||
&.user-message {
|
||||
justify-content: flex-end;
|
||||
|
||||
.message-content {
|
||||
align-items: flex-end;
|
||||
|
||||
.message-text {
|
||||
border-radius: 2rem 2rem 0 2rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.ai-message {
|
||||
justify-content: flex-start;
|
||||
|
||||
.message-content {
|
||||
align-items: flex-start;
|
||||
|
||||
.message-text {
|
||||
color: #000;
|
||||
border-radius: 0 2rem 2rem 2rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chat-avatar {
|
||||
width: 7.8rem;
|
||||
height: 7.4rem;
|
||||
border-radius: 50%;
|
||||
margin-right: 1.88rem;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.message-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 70%;
|
||||
}
|
||||
|
||||
.message-actions {
|
||||
margin-top: 2.6rem;
|
||||
color: #6b6b6b;
|
||||
column-gap: 1.61rem;
|
||||
.svg-icon {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
103
src/views/asistant/components/NoticeList.vue
Normal file
103
src/views/asistant/components/NoticeList.vue
Normal file
@@ -0,0 +1,103 @@
|
||||
<template>
|
||||
<div class="chat-list">
|
||||
<div class="chat-message-item" v-for="message in chatMessages" :key="message.id">
|
||||
<NoticeItem :value="message" @send-message="handleSendMessage" />
|
||||
</div>
|
||||
<!-- Loading效果 -->
|
||||
<div v-if="isLoading" class="chat-message-item">
|
||||
<ChatLoading />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import NoticeItem from './NoticeItem.vue'
|
||||
import ChatLoading from './ChatLoading.vue'
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
// 定义消息类型
|
||||
interface ChatMessage {
|
||||
id: string
|
||||
content: string
|
||||
userId: string
|
||||
time: string
|
||||
thumb: string
|
||||
}
|
||||
|
||||
// 定义组件暴露的方法类型
|
||||
interface NoticeListExpose {
|
||||
simulateSendMessage: () => void
|
||||
}
|
||||
|
||||
const isLoading = ref<boolean>(false)
|
||||
let loadingTimer: any = null
|
||||
|
||||
const chatMessages = ref<ChatMessage[]>([
|
||||
{
|
||||
id: '1',
|
||||
content: 'I want a chic outfit for dinner.',
|
||||
userId: '1',
|
||||
time: '14:30',
|
||||
thumb: ''
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
content:
|
||||
"Hey there! A chic dinner outfit, I love that! To give you the perfect recommendations, tell me: is this a romantic date, business dinner, or celebration with friends? And what's your go-to style vibe: classic elegance or something with more edge?",
|
||||
userId: '2',
|
||||
time: '14:31',
|
||||
thumb: 'https://files-dev.deercal.com/uploads/platforms/logo_code/669933e1b873e798.jpg'
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
content: "It's a romantic date, and I prefer classic elegance.",
|
||||
userId: '1',
|
||||
time: '14:32',
|
||||
thumb: ''
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
content:
|
||||
"Perfect! For a romantic dinner with classic elegance, I'd suggest a little black dress with delicate jewelry and elegant heels. Would you like me to show you some specific options?",
|
||||
userId: '2',
|
||||
time: '14:33',
|
||||
thumb: 'https://files-dev.deercal.com/uploads/platforms/logo_code/669933e1b873e798.jpg'
|
||||
}
|
||||
])
|
||||
|
||||
const handleSendMessage = (message: string): void => {
|
||||
console.log('list发送消息:', message)
|
||||
}
|
||||
|
||||
const simulateSendMessage = (): void => {
|
||||
isLoading.value = true
|
||||
|
||||
loadingTimer = setTimeout(() => {
|
||||
const newMessage: ChatMessage = {
|
||||
id: Date.now().toString(),
|
||||
content:
|
||||
"Thanks for your message! I'm processing your request and will provide you with the best fashion advice.",
|
||||
userId: '2',
|
||||
time: new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }),
|
||||
thumb: 'https://files-dev.deercal.com/uploads/platforms/logo_code/669933e1b873e798.jpg'
|
||||
}
|
||||
|
||||
chatMessages.value.push(newMessage)
|
||||
isLoading.value = false
|
||||
}, 3000)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.chat-list {
|
||||
padding: 16px;
|
||||
background-color: #fff;
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.chat-message-item {
|
||||
margin-bottom: 4.84rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user