|
|
|
|
@ -368,10 +368,7 @@
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import {ref, reactive, computed, nextTick, onMounted, onUnmounted} from 'vue'
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import request from '@/utils/request';
|
|
|
|
|
import {getToken} from "@/utils/auth";
|
|
|
|
|
|
|
|
|
|
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
|
|
|
|
|
|
|
|
|
|
import {ElMessage, ElMessageBox} from 'element-plus'
|
|
|
|
|
@ -1109,12 +1106,56 @@ function scrollToBottom() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatMessage(content: string) {
|
|
|
|
|
// 简单的markdown格式化
|
|
|
|
|
return content
|
|
|
|
|
// 第一步:先处理转义的换行符(把 \\n 转成 \n),确保换行符能被识别
|
|
|
|
|
let formatted = content.replace(/\\n/g, '\n');
|
|
|
|
|
|
|
|
|
|
// 第二步:处理换行(优先处理,避免其他格式干扰)
|
|
|
|
|
formatted = formatted.replace(/\n/g, '<br>');
|
|
|
|
|
|
|
|
|
|
// 第三步:处理基础markdown格式(粗体、斜体、行内代码)
|
|
|
|
|
formatted = formatted
|
|
|
|
|
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
|
|
|
|
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
|
|
|
|
.replace(/`(.*?)`/g, '<code>$1</code>')
|
|
|
|
|
.replace(/\n/g, '<br>')
|
|
|
|
|
.replace(/`(.*?)`/g, '<code>$1</code>');
|
|
|
|
|
|
|
|
|
|
// 第四步:处理标题(###/##/#)
|
|
|
|
|
formatted = formatted
|
|
|
|
|
.replace(/### (.*?)<br>/g, '<h3>$1</h3><br>')
|
|
|
|
|
.replace(/## (.*?)<br>/g, '<h2>$1</h2><br>')
|
|
|
|
|
.replace(/# (.*?)<br>/g, '<h1>$1</h1><br>');
|
|
|
|
|
|
|
|
|
|
// 第五步:处理无序列表( - 开头的项)
|
|
|
|
|
formatted = formatted.replace(/ - (.*?)<br>/g, '<li>$1</li><br>');
|
|
|
|
|
// 将连续的li包裹成ul
|
|
|
|
|
formatted = formatted.replace(/(<li>.*?<\/li><br>)+/g, (match) => {
|
|
|
|
|
const cleanLi = match.replace(/<br>$/, '');
|
|
|
|
|
return `<ul style="padding-left: 20px;">${cleanLi}</ul><br>`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 第六步:处理分隔线(---)
|
|
|
|
|
formatted = formatted.replace(/---<br>/g, '<hr><br>');
|
|
|
|
|
|
|
|
|
|
// 第七步:处理表格(适配你的MES文本表格格式)
|
|
|
|
|
formatted = formatted.replace(/(\|.*?\|.*?<br>)+/g, (tableMatch) => {
|
|
|
|
|
const rows = tableMatch.split('<br>').filter(row => row.trim() !== '');
|
|
|
|
|
if (rows.length < 2) return tableMatch;
|
|
|
|
|
|
|
|
|
|
let tableHtml = '<table border="1" cellpadding="8" cellspacing="0" style="width: 100%; margin: 8px 0;"><tbody>';
|
|
|
|
|
rows.forEach((row, index) => {
|
|
|
|
|
const cells = row.split('|').filter(cell => cell.trim() !== '');
|
|
|
|
|
if (cells.length === 0) return;
|
|
|
|
|
const cellTag = index === 0 ? 'th' : 'td';
|
|
|
|
|
tableHtml += '<tr>';
|
|
|
|
|
cells.forEach(cell => {
|
|
|
|
|
tableHtml += `<${cellTag}>${cell.trim()}</${cellTag}>`;
|
|
|
|
|
});
|
|
|
|
|
tableHtml += '</tr>';
|
|
|
|
|
});
|
|
|
|
|
tableHtml += '</tbody></table><br>';
|
|
|
|
|
return tableHtml;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return formatted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatTime(timestamp: number) {
|
|
|
|
|
|