修复
This commit is contained in:
@@ -77,14 +77,32 @@ export const chatApi = {
|
||||
eventSource.addEventListener('message', (event) => {
|
||||
try {
|
||||
// 解析JSON字符串,处理Unicode转义
|
||||
const data = JSON.parse(event.data);
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
let data = JSON.parse(event.data);
|
||||
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||
if (typeof data === 'string') {
|
||||
data = data
|
||||
.replace(/^data:/gm, '')
|
||||
.replace(/^\s*[\r\n]/gm, '')
|
||||
.replace(/<\/?think>/gi, '');
|
||||
}
|
||||
if (data && data.trim()) {
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果不是JSON,直接使用原始数据
|
||||
const data = event.data;
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
let data = event.data;
|
||||
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||
if (typeof data === 'string') {
|
||||
data = data
|
||||
.replace(/^data:/gm, '')
|
||||
.replace(/^\s*[\r\n]/gm, '')
|
||||
.replace(/<\/?think>/gi, '');
|
||||
}
|
||||
if (data && data.trim()) {
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -345,14 +363,32 @@ export const chatApi = {
|
||||
eventSource.addEventListener('message', (event) => {
|
||||
try {
|
||||
// 解析JSON字符串,处理Unicode转义
|
||||
const data = JSON.parse(event.data);
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
let data = JSON.parse(event.data);
|
||||
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||
if (typeof data === 'string') {
|
||||
data = data
|
||||
.replace(/^data:/gm, '')
|
||||
.replace(/^\s*[\r\n]/gm, '')
|
||||
.replace(/<\/?think>/gi, '');
|
||||
}
|
||||
if (data && data.trim()) {
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果不是JSON,直接使用原始数据
|
||||
const data = event.data;
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
let data = event.data;
|
||||
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||
if (typeof data === 'string') {
|
||||
data = data
|
||||
.replace(/^data:/gm, '')
|
||||
.replace(/^\s*[\r\n]/gm, '')
|
||||
.replace(/<\/?think>/gi, '');
|
||||
}
|
||||
if (data && data.trim()) {
|
||||
fullMessage += data;
|
||||
callback?.onMessage?.(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -736,7 +736,6 @@ function formatTimestamp(timestamp: number): string {
|
||||
line-height: 1.6;
|
||||
color: #4A5565;
|
||||
font-size: 14px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
@@ -229,13 +229,14 @@
|
||||
|
||||
<!-- 文档分段对话框 -->
|
||||
<DocumentSegmentDialog
|
||||
v-if="selectedDocument && selectedDocument.difyDocumentId && props.knowledge?.difyDatasetId"
|
||||
v-if="segmentDialogVisible && selectedDocument && selectedDocument.difyDocumentId && props.knowledge?.difyDatasetId"
|
||||
:key="selectedDocument.difyDocumentId"
|
||||
:model-value="segmentDialogVisible"
|
||||
:dataset-id="props.knowledge.difyDatasetId"
|
||||
:document-id="selectedDocument.difyDocumentId"
|
||||
:can-write="hasWritePermission"
|
||||
:can-delete="hasDeletePermission"
|
||||
@update:model-value="segmentDialogVisible = $event"
|
||||
@update:model-value="handleSegmentDialogClose"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -407,13 +408,19 @@ function handleViewSegments(document: AiUploadFile) {
|
||||
segmentDialogVisible.value = true;
|
||||
}
|
||||
|
||||
// 关闭分段对话框
|
||||
function handleSegmentDialogClose(val: boolean) {
|
||||
segmentDialogVisible.value = val;
|
||||
if (!val) {
|
||||
selectedDocument.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
function handleDownload(document: AiUploadFile) {
|
||||
if (document.sysFileId) {
|
||||
window.open(`/api/file/download/${document.sysFileId}`, '_blank');
|
||||
} else if (document.filePath) {
|
||||
window.open(`/api/file/download/${document.filePath}`, '_blank');
|
||||
} else {
|
||||
window.open(`${FILE_DOWNLOAD_URL}${document.sysFileId}`, '_blank');
|
||||
}else {
|
||||
ElMessage.warning('文件路径不存在');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,6 +585,9 @@ function formatMessageTime(dateStr: string | undefined) {
|
||||
|
||||
function formatMarkdown(content: string) {
|
||||
let html = content;
|
||||
// 过滤掉思考标签和data:前缀
|
||||
html = html.replace(/<\/?think>/gi, '');
|
||||
html = html.replace(/^data:/gm, '');
|
||||
html = html.replace(/```([\s\S]*?)```/g, '<pre><code>$1</code></pre>');
|
||||
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
||||
html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
||||
|
||||
@@ -1114,6 +1114,10 @@ function formatMarkdown(content: string) {
|
||||
// 简单的 Markdown 转换(可以使用 marked.js 等库进行更复杂的转换)
|
||||
let html = content;
|
||||
|
||||
// 过滤掉思考标签和data:前缀
|
||||
html = html.replace(/<\/?think>/gi, '');
|
||||
html = html.replace(/^data:/gm, '');
|
||||
|
||||
// 代码块
|
||||
html = html.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user