Commit ba77e352 authored by 水玉婷's avatar 水玉婷
Browse files

feat:添加tips

parent 136d1a8c
......@@ -145,7 +145,7 @@ const getChatRecordList = async () => {
});
if (res.data.code === 0) {
let { data = [], total = 0, totalInfo = {} } = res.data.data || [];
historyList.value = (data || []).map((item) => ({
historyList.value = (data.reverse() || []).map((item) => ({
...item,
isEdit: false,
}));
......
......@@ -920,6 +920,27 @@ li {
// =============================================
// Tips消息样式
// =============================================
:deep(.message-tips) {
width: 100%;
max-width: 100%;
margin: 8px 0 -1px;
padding: 12px 16px;
border-bottom: none;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
border-radius: 8px 8px 0 0;
position: relative;
background-color: @blue-light-2;
border-bottom: 1px solid @blue-light-3;
font-size: 14px;
color: @gray-7;
font-weight: 500;
line-height: 1.4;
}
// =============================================
// Markdown消息样式
// =============================================
......@@ -927,12 +948,29 @@ li {
:deep(.message-markdown) {
width: 100%;
max-width: 100%;
margin: 8px 0;
border-radius: 8px;
margin: -1px 0 8px;
border-radius: 0 0 8px 8px;
background-color: @white;
border: 1px solid @blue-light-3;
border-top: none;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
// 当markdown与tips相邻时,调整间距
+ :deep(.message-tips) {
margin-top: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-top: none;
}
// 当tips在markdown之前时,调整markdown的样式
:deep(.message-tips) + & {
margin-top: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-top: none;
}
.markdown-content {
padding: 12px 16px;
......
......@@ -11,6 +11,7 @@ import { markdownTemplate, isLastBlockMarkdown, getLastMarkdownBlockIndex, merge
markdown: (content: any, isStreaming?: boolean) => string;
option: (optionData: any) => string;
iframe: (iframeData: any) => string;
tips: (content: string) => string;
}
// 消息块类型定义
......@@ -197,6 +198,10 @@ export class ContentTemplateService {
onerror="console.error('iframe加载失败:', this.src)"
></iframe>
</div>`;
},
// tips标识模板
tips: (content: string) => {
return `<div class="message-tips">${content}</div>`;
}
};
}
......@@ -355,6 +360,18 @@ export class ContentTemplateService {
}
}
break;
case 5: // tips标识数据
if (updatedResponse) {
// 使用tips模板创建新的内容块
updatedResponse.contentBlocks.push({
content: this.templates.tips(messageContent || ''),
hasThinkBox: false,
thinkContent: '',
thinkBoxExpanded: false,
});
}
break;
default: // 默认处理
updatedResponse.contentBlocks.push({
......@@ -448,7 +465,7 @@ export class ContentTemplateService {
updatedBlockIndex = -1;
break;
default: // 普通内容
case 0: // 普通内容
if (updatedIsThinking && updatedResponse) {
if (updatedBlockIndex !== -1 && updatedResponse.contentBlocks[updatedBlockIndex]) {
// 获取当前思考内容
......@@ -465,32 +482,53 @@ export class ContentTemplateService {
updatedResponse.contentBlocks[updatedBlockIndex].thinkBoxExpanded = defaultThinkBoxExpanded;
}
} else if (updatedResponse) {
// 检查最后一个块是否是普通文本块,如果是则合并,否则创建新块
const isLastText = isLastBlockText(updatedResponse.contentBlocks);
if (isLastText) {
// 合并到现有的普通文本块
const lastTextIndex = getLastTextBlockIndex(updatedResponse.contentBlocks);
if (lastTextIndex !== -1) {
updatedResponse.contentBlocks[lastTextIndex].content =
mergeTextContent(
updatedResponse.contentBlocks[lastTextIndex].content,
messageContent
);
}
} else {
// 创建新的内容块
updatedBlockIndex = updatedResponse.contentBlocks.length;
// 特殊处理type=5的tips数据
if (contentType === 5) {
updatedResponse.contentBlocks.push({
content: this.templates.text(messageContent),
content: this.templates.tips(messageContent),
hasThinkBox: false,
thinkContent: '',
thinkBoxExpanded: false,
});
} else {
// 检查最后一个块是否是普通文本块,如果是则合并,否则创建新块
const isLastText = isLastBlockText(updatedResponse.contentBlocks);
if (isLastText) {
// 合并到现有的普通文本块
const lastTextIndex = getLastTextBlockIndex(updatedResponse.contentBlocks);
if (lastTextIndex !== -1) {
updatedResponse.contentBlocks[lastTextIndex].content =
mergeTextContent(
updatedResponse.contentBlocks[lastTextIndex].content,
messageContent
);
}
} else {
// 创建新的内容块
updatedBlockIndex = updatedResponse.contentBlocks.length;
updatedResponse.contentBlocks.push({
content: this.templates.text(messageContent),
hasThinkBox: false,
thinkContent: '',
thinkBoxExpanded: false,
});
}
}
}
break;
default: // 其他状态码
if (updatedResponse) {
updatedResponse.contentBlocks.push({
content: this.templates.text(messageContent || ''),
hasThinkBox: false,
thinkContent: '',
thinkBoxExpanded: false,
});
}
break;
}
return {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment