你可以通过调整配色、添加渐变效果、更多细节化设计来增强界面美观度。我将对现有代码稍作美化,以满足你的需求:
以下是改进后的CSS和前面代码的更新版本:
<template>
<div class="app">
<SystemAnnouncement/>
<div class="header">
<h1>Chat with OpenAI Chat Gpt</h1>
</div>
<div class="chat-box">
<div class="messages">
<!-- 显示对话记录 -->
<div
v-for="(i, index) in chatDatas"
:key="index"
:class="['message', i.role]"
>
<div class="message-box">
<div v-html="md.render(i.content)" ref="markdownContent"></div>
</div>
</div>
</div>
</div>
<!-- 输入框和发送按钮 -->
<div class="input-box">
<input
type="text"
v-model="userInput"
:disabled="isReplying"
@keyup.enter="sendMessage"
placeholder="输入消息后按 Enter 发送"
/>
<button :disabled="isReplying" @click="sendMessage">
{{ isReplying ? "处理中..." : "发送" }}
</button>
</div>
</div>
</template>
<style scoped>
/* ********** 应用布局样式 ********** */
body {
margin: 0;
padding: 0;
overflow-x: hidden; /* 禁止水平滚动条 */
}
.app {
font-family: "Arial", sans-serif;
width: 70%; /* 宽度为屏幕的 70%,适配不同分辨率 */
max-width: 1000px; /* 最大宽度适配超宽屏幕 */
margin: 30px auto; /* 页面居中,同时增加顶部间距 */
display: flex;
flex-direction: column;
gap: 20px;
height: 90vh; /* 页面占屏幕的 90% */
padding: 20px; /* 优雅间距 */
background: linear-gradient(135deg, #f0f5ff, #ffffff);
border-radius: 16px;
overflow: hidden;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
/* ********** 标题样式 ********** */
.header {
text-align: center;
}
.header h1 {
margin: 0;
background: linear-gradient(90deg, #7b80ff, #6678db);
color: white;
line-height: 70px;
font-size: 28px;
font-weight: 600;
letter-spacing: 1px;
text-shadow: 1px 2px 4px rgba(0, 0, 0, 0.2);
border-radius: 12px;
padding: 5px 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
/* ********** 聊天区域 ********** */
.chat-box {
flex: 1;
overflow-y: auto; /* 启用垂直滚动条 */
background: white;
padding: 15px;
border-radius: 14px;
border: 1px solid #dde3f2;
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.05);
box-sizing: border-box;
}
.messages {
display: flex;
flex-direction: column;
gap: 15px; /* 增加间距,让消息之间更清晰 */
}
/* 单条信息气泡 */
.message {
display: flex;
max-width: 80%;
word-break: break-word; /* 长单词换行 */
}
.message.user {
align-self: flex-end;
}
.message.user .message-box {
background: linear-gradient(135deg, #dcf8c6, #bde5a5); /* 优雅渐变颜色 */
color: #4a4a4a; /* 改善文字对比度 */
border-radius: 16px 0 16px 16px; /* 调整气泡样式 */
padding: 10px 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.message.ai {
align-self: flex-start;
}
.message.ai .message-box {
background: linear-gradient(135deg, #f1f5ff, #d9e8ff); /* AI 气泡的渐变效果 */
color: #34495e; /* AI 消息字体颜色 */
border-radius: 0 16px 16px 16px; /* 调整气泡样式 */
padding: 10px 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.message-box {
font-size: 15px;
line-height: 1.5em; /* 改善文本可读性 */
}
/* ********** 输入区域样式 ********** */
.input-box {
display: flex;
gap: 10px;
}
.input-box input {
flex-grow: 1;
padding: 15px;
border: 1px solid rgba(200, 200, 200, 0.5);
border-radius: 25px;
font-size: 15px;
transition: all 0.3s ease; /* 平滑过渡效果 */
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.input-box input:focus {
outline: none;
border-color: #7b80ff;
box-shadow: 0 2px 6px rgba(123, 128, 255, 0.3); /* 聚焦时添加阴影 */
}
.input-box input:disabled {
background: #f7f7f7;
cursor: not-allowed;
}
.input-box button {
background-color: #7b80ff;
color: white;
border: none;
padding: 15px 25px;
font-size: 14px;
font-weight: bold;
border-radius: 25px;
cursor: pointer;
box-shadow: 0 2px 6px rgba(123, 128, 255, 0.3);
transition: all 0.3s ease;
}
.input-box button:hover {
background: #5f67d6;
}
.input-box button:disabled {
background-color: #cccccc; /* 当按钮被禁用时的颜色 */
cursor: not-allowed;
}
.input-box button:disabled:hover {
background-color: #cccccc;
}
</style>
改进点:
- 渐变效果:
标题、消息框等地方引入线性渐变,增加界面层次感。
- 圆角与阴影:
为按钮、消息框、输入框等增加更柔和的圆角,并加入适度的阴影以体现立体感。
- 配色优化:
使用了更加现代化的浅色和对比鲜明的颜色,提供更好的阅读体验。
- 交互动画:
按钮和输入框的 hover 和焦点效果更显时尚感和动效。
- 更大的间距:
为聊天条目、输入框等增加了部分间距,界面显得更加清晰。
这样的样式能够提供更现代、清晰且用户友好的设计,同时保留原始功能性和简洁性。希望能让你的界面更加吸引人!