Chat.vue
3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<script setup>
import { ref } from 'vue';
import hongmeng from '@/assets/hongmeng.wav';
const isReading = ref(false);
const readText = ref('');
const handleRead = () => {
isReading.value = true;
playAudio();
}
const playAudio = () => {
const audio = new Audio(hongmeng);
audio.play();
audio.addEventListener('ended', () => {
isReading.value = false;
});
audio.addEventListener('error', () => {
console.error('音频播放失败');
isReading.value = false;
});
};
</script>
<template>
<div class="container-wrap">
<div class="container">
<div class="left-wrap">
<div class="left-image">
<img v-show="isReading" class="image" src="@/assets/cover.webp" alt="">
<img v-show="!isReading" class="image" src="@/assets/default.png" alt="">
</div>
<div class="input-container">
<input type="text" placeholder="输入要朗读的文字" :value=readText>
<button @click="handleRead">朗读</button>
</div>
</div>
<div class="chat-container">
<div class="chat-messages" id="chat-messages"></div>
<div class="chat-input">
<input type="text" id="chat-input" placeholder="输入聊天消息">
<button id="send-btn">发送</button>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.container-wrap {
min-height: 100vh;
background: #f0f2f5;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
gap: 20px;
}
.container {
display: flex;
align-items: center;
gap: 20px;
.left-wrap {
display: flex;
flex-direction: column;
align-items: center;
gap: 32px;
.left-image {
width: 266px;
height: 200px;
border-radius: 12px;
.image {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 12px;
}
}
}
}
.input-container {
width: 100%;
max-width: 320px;
background: white;
padding: 15px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
gap: 8px;
}
input {
flex: 1;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
}
button {
white-space: nowrap;
padding: 8px 12px;
background: #1890ff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s;
}
button:hover {
background: #40a9ff;
}
/* 新增聊天窗口样式 */
.chat-container {
width: 550px;
height: 550px;
background: white;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
gap: 10px;
padding: 15px;
}
.chat-messages {
flex: 1;
height: 300px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 12px;
padding: 0 5px;
}
.chat-message {
max-width: 70%;
padding: 8px 12px;
border-radius: 8px;
font-size: 14px;
line-height: 1.4;
}
.chat-message.user {
background: #1890ff;
color: white;
align-self: flex-end;
}
.chat-message.bot {
background: #f0f2f5;
color: #333;
align-self: flex-start;
}
.chat-input {
display: flex;
gap: 8px;
}
</style>