|
@@ -426,7 +426,7 @@ export default {
|
|
|
<style>
|
|
|
/* 保持原有样式 */
|
|
|
body {
|
|
|
- font-family: SimSun, serif; // 用宋体作为默认字体
|
|
|
+ font-family: SimSun, serif; // 用宋体作默认字体
|
|
|
font-size: 12pt;
|
|
|
line-height: 1.5;
|
|
|
margin: 0;
|
|
@@ -806,7 +806,7 @@ export default {
|
|
|
/*目前状态 */
|
|
|
getStatusName(statusId) {
|
|
|
const status = this.getstatusList.find((item) => item.value === statusId);
|
|
|
- return status ? status.label : "未��状态";
|
|
|
+ return status ? status.label : "未状态";
|
|
|
},
|
|
|
|
|
|
getStatusType(statusId) {
|
|
@@ -896,7 +896,7 @@ export default {
|
|
|
replaceTemplate(template) {
|
|
|
this.docAttr = template;
|
|
|
const TemList = JSON.parse(template.data);
|
|
|
- /* this.$confirm("确定要替换此模版吗?", "提示", {
|
|
|
+ /* this.$confirm("确定要替换此模吗?", "提示", {
|
|
|
confirmButtonText: "确",
|
|
|
cancelButtonText: "取消",
|
|
|
type: "warning",
|
|
@@ -978,7 +978,7 @@ export default {
|
|
|
|
|
|
// 调试用:打印每个匹配的详细信息
|
|
|
this.matchResults.forEach((match) => {
|
|
|
- // 据括号类型选择不同的切片方式
|
|
|
+ // 据括号类型选��不同的切片方式
|
|
|
const content = match.startsWith("【")
|
|
|
? match.slice(1, -1)
|
|
|
: match.slice(1, -1);
|
|
@@ -1144,7 +1144,7 @@ export default {
|
|
|
const replacementContent =
|
|
|
response.data.data.matched_data[0]?.content;
|
|
|
if (replacementContent) {
|
|
|
- // 处理富文本内容
|
|
|
+ // 处���富文本内容
|
|
|
this.TemList.forEach((el, index) => {
|
|
|
console.log(el, originalMatch, replacementContent);
|
|
|
const processedContent = this.processTableContent(
|
|
@@ -1164,7 +1164,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 修改单个替换方���
|
|
|
+ // 修改单个替换方法
|
|
|
async replaceItem(item) {
|
|
|
try {
|
|
|
const success = await this.processAndReplaceContent(this.TemList, item);
|
|
@@ -1187,7 +1187,7 @@ export default {
|
|
|
async replaceAll() {
|
|
|
this.batchReplaceLoading = true;
|
|
|
try {
|
|
|
- // 收集所有匹配
|
|
|
+ // 收��所有匹配
|
|
|
const allLocations = this.matchResults.map((item) => {
|
|
|
return item.replace(/[\[\]【】]/g, "");
|
|
|
});
|
|
@@ -1305,7 +1305,7 @@ export default {
|
|
|
return "other_location";
|
|
|
},
|
|
|
|
|
|
- // 修改处理���格内容的方法,添加对多个替换的支持
|
|
|
+ // 修改处理表格内容的方法,添加对多个替换的支持
|
|
|
processTableContent(content, searchItem, replacement) {
|
|
|
if (!content || !searchItem) return content;
|
|
|
|
|
@@ -1326,25 +1326,84 @@ export default {
|
|
|
const tempDiv = document.createElement("div");
|
|
|
tempDiv.innerHTML = content;
|
|
|
|
|
|
- const cleanupContent = (html) => {
|
|
|
- let cleaned = html.replace(/\s+/g, " ");
|
|
|
- cleaned = cleaned.replace(/<\/span><span[^>]*>/g, "");
|
|
|
- cleaned = cleaned.replace(/<span[^>]*>\s*<\/span>/g, "");
|
|
|
- return cleaned;
|
|
|
+ // 新增:递归处理HTML节点
|
|
|
+ const processNode = (node) => {
|
|
|
+ if (node.nodeType === 3) { // 文本节点
|
|
|
+ return node.textContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ let html = '';
|
|
|
+ for (const child of node.childNodes) {
|
|
|
+ html += processNode(child);
|
|
|
+ }
|
|
|
+ return html;
|
|
|
};
|
|
|
|
|
|
const handleSplitContent = () => {
|
|
|
+ // 先获取纯文本内容用于匹配
|
|
|
+ const plainText = processNode(tempDiv);
|
|
|
+
|
|
|
+ // 构建用于匹配分割标记的正则表达式
|
|
|
+ const splitRegex = new RegExp(`(\\[|【)(.*?)(${searchCode})(.*?)(\\]|】)`, 'g');
|
|
|
+
|
|
|
let currentHtml = tempDiv.innerHTML;
|
|
|
- currentHtml = cleanupContent(currentHtml);
|
|
|
+
|
|
|
+ // 查找所有可能的匹配
|
|
|
+ const matches = [...currentHtml.matchAll(/<[^>]+>|\[|\]|【|】|[^<\[\]【】]+/g)];
|
|
|
+
|
|
|
+ // 重建HTML,识别并替换目标编码
|
|
|
+ let rebuiltHtml = '';
|
|
|
+ let currentMatch = '';
|
|
|
+ let isCollecting = false;
|
|
|
+ let bracketCount = 0;
|
|
|
+
|
|
|
+ for (let i = 0; i < matches.length; i++) {
|
|
|
+ const part = matches[i][0];
|
|
|
+
|
|
|
+ if (part === '[' || part === '【') {
|
|
|
+ isCollecting = true;
|
|
|
+ bracketCount++;
|
|
|
+ currentMatch = part;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isCollecting) {
|
|
|
+ currentMatch += part;
|
|
|
+
|
|
|
+ if (part === ']' || part === '】') {
|
|
|
+ bracketCount--;
|
|
|
+ if (bracketCount === 0) {
|
|
|
+ // 检查收集到的内容是否包含目标编码
|
|
|
+ const cleanText = currentMatch.replace(/<[^>]+>/g, '');
|
|
|
+ if (cleanText.includes(searchCode)) {
|
|
|
+ rebuiltHtml += replacement;
|
|
|
+ isCollecting = false;
|
|
|
+ currentMatch = '';
|
|
|
+ } else {
|
|
|
+ rebuiltHtml += currentMatch;
|
|
|
+ isCollecting = false;
|
|
|
+ currentMatch = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ rebuiltHtml += part;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理未闭合的标记
|
|
|
+ if (currentMatch) {
|
|
|
+ rebuiltHtml += currentMatch;
|
|
|
+ }
|
|
|
|
|
|
- // 查找并替换匹配的内容
|
|
|
- const pattern = new RegExp(
|
|
|
- `\\[${searchCode}\\]|【${searchCode}】`,
|
|
|
- "g"
|
|
|
- );
|
|
|
- currentHtml = currentHtml.replace(pattern, replacement);
|
|
|
+ // 清理可能的残留标签
|
|
|
+ rebuiltHtml = rebuiltHtml
|
|
|
+ .replace(/(<span[^>]*>)\s*(<\/span>)/g, '')
|
|
|
+ .replace(/(<\/span>)(<span[^>]*>)/g, '')
|
|
|
+ .replace(/<a[^>]*><\/a>/g, '')
|
|
|
+ .replace(/\s+/g, ' ');
|
|
|
|
|
|
- tempDiv.innerHTML = currentHtml;
|
|
|
+ tempDiv.innerHTML = rebuiltHtml;
|
|
|
};
|
|
|
|
|
|
handleSplitContent();
|
|
@@ -1730,7 +1789,7 @@ export default {
|
|
|
);
|
|
|
|
|
|
if (!isDuplicate) {
|
|
|
- // 如果不是重复项,��添加到结果数组中
|
|
|
+ // 如果不是重复项,添加到结果数组中
|
|
|
return [...acc, current];
|
|
|
}
|
|
|
return acc;
|