修改投稿系统预览文章显示页面
This commit is contained in:
192
js/article.js
192
js/article.js
@@ -8880,17 +8880,35 @@ ${header
|
|||||||
if (!cell || !cell.cellId) return '';
|
if (!cell || !cell.cellId) return '';
|
||||||
|
|
||||||
const content = cell.text || '';
|
const content = cell.text || '';
|
||||||
|
|
||||||
|
// 1. 判断是否是 Base64 图片 (用于点击预览逻辑)
|
||||||
const isBase64Image = /^<img\s+[^>]*src=["']data:image\//i.test(content);
|
const isBase64Image = /^<img\s+[^>]*src=["']data:image\//i.test(content);
|
||||||
|
|
||||||
const finalContent = isBase64Image
|
// 2. 判断是否是服务器特定的图片路径 (用于拼接域名)
|
||||||
? content.replace(
|
const isServerPathImage = /src=["']\/public\/articleTableImage/i.test(content);
|
||||||
|
|
||||||
|
let finalContent = content;
|
||||||
|
|
||||||
|
if (isBase64Image) {
|
||||||
|
// 处理 Base64:注入点击预览 picPreview
|
||||||
|
finalContent = content.replace(
|
||||||
/<img\s+([^>]*?)src=["'](data:image\/[^"']+)["']([^>]*)>/gi,
|
/<img\s+([^>]*?)src=["'](data:image\/[^"']+)["']([^>]*)>/gi,
|
||||||
(match, preAttrs, src, postAttrs) => {
|
(match, preAttrs, src, postAttrs) => {
|
||||||
const safeSrc = src.replace(/'/g, "\\'");
|
const safeSrc = src.replace(/'/g, "\\'");
|
||||||
return `<img ${preAttrs}src="${src}"${postAttrs} style="cursor:pointer;" onclick="picPreview('${safeSrc}')" />`;
|
return `<img ${preAttrs}src="${src}"${postAttrs} style="cursor:pointer; max-width:500px;" onclick="picPreview('${safeSrc}')" />`;
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
: content;
|
} else if (isServerPathImage) {
|
||||||
|
// 处理特定路径:拼接域名 https://submission.tmrjournals.com
|
||||||
|
finalContent = content.replace(
|
||||||
|
/<img\s+([^>]*?)src=["'](\/public\/articleTableImage[^"']+)["']([^>]*)>/gi,
|
||||||
|
(match, preAttrs, src, postAttrs) => {
|
||||||
|
const fullUrl = `https://submission.tmrjournals.com${src}`;
|
||||||
|
// 建议这里也加上 max-width 兼容性更好
|
||||||
|
return `<img ${preAttrs}src="${fullUrl}"${postAttrs} style="max-width:500px;" onclick="picPreview('${fullUrl}')" />`;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@@ -8974,7 +8992,7 @@ text-align:left;color:#333;" >${item.table.note ? item.table.note : ''
|
|||||||
updateCitationDisplayWithMyTable('.wen_rong .content-box .conthtmn', result.data.refers, {
|
updateCitationDisplayWithMyTable('.wen_rong .content-box .conthtmn', result.data.refers, {
|
||||||
writeInnerHTML: true,
|
writeInnerHTML: true,
|
||||||
hideEmptyCite: true
|
hideEmptyCite: true
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -8989,46 +9007,46 @@ function updateCitationDisplayWithMyTable(root, refers, opt) {
|
|||||||
// 1) 合法参考文献集合
|
// 1) 合法参考文献集合
|
||||||
var validRef = Object.create(null);
|
var validRef = Object.create(null);
|
||||||
(refers || []).forEach(function (r) {
|
(refers || []).forEach(function (r) {
|
||||||
if (r && r.p_refer_id != null) validRef[String(r.p_refer_id)] = true;
|
if (r && r.p_refer_id != null) validRef[String(r.p_refer_id)] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseIds(raw) {
|
function parseIds(raw) {
|
||||||
return String(raw || '')
|
return String(raw || '')
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(function (s) { return s.trim(); })
|
.map(function (s) { return s.trim(); })
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatNums(nums) {
|
function formatNums(nums) {
|
||||||
var a = nums.filter(function (n, i, arr) { return arr.indexOf(n) === i; })
|
var a = nums.filter(function (n, i, arr) { return arr.indexOf(n) === i; })
|
||||||
.sort(function (x, y) { return x - y; });
|
.sort(function (x, y) { return x - y; });
|
||||||
var out = [], i = 0;
|
var out = [], i = 0;
|
||||||
while (i < a.length) {
|
while (i < a.length) {
|
||||||
var j = i;
|
var j = i;
|
||||||
while (j < a.length - 1 && a[j + 1] === a[j] + 1) j++;
|
while (j < a.length - 1 && a[j + 1] === a[j] + 1) j++;
|
||||||
if (j - i >= 2) out.push(a[i] + '–' + a[j]);
|
if (j - i >= 2) out.push(a[i] + '–' + a[j]);
|
||||||
else for (var k = i; k <= j; k++) out.push(String(a[k]));
|
else for (var k = i; k <= j; k++) out.push(String(a[k]));
|
||||||
i = j + 1;
|
i = j + 1;
|
||||||
}
|
}
|
||||||
return out.join(', ');
|
return out.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) 建一个“表格索引”:tableId -> 真实表格节点
|
// 2) 建一个“表格索引”:tableId -> 真实表格节点
|
||||||
// 这里把常见承载节点都尝试一遍,你可按官网实际 class 再加
|
// 这里把常见承载节点都尝试一遍,你可按官网实际 class 再加
|
||||||
var tableMap = Object.create(null);
|
var tableMap = Object.create(null);
|
||||||
var tableCandidates = el.querySelectorAll(
|
var tableCandidates = el.querySelectorAll(
|
||||||
'table, .myeditabledivTable, .wordTableHtml, [data-table-id], [data-amt-id], [main-id]'
|
'table, .myeditabledivTable, .wordTableHtml, [data-table-id], [data-amt-id], [main-id]'
|
||||||
);
|
);
|
||||||
tableCandidates.forEach(function (node) {
|
tableCandidates.forEach(function (node) {
|
||||||
var ids = [
|
var ids = [
|
||||||
node.getAttribute('data-table-id'),
|
node.getAttribute('data-table-id'),
|
||||||
node.getAttribute('data-amt-id'),
|
node.getAttribute('data-amt-id'),
|
||||||
node.getAttribute('data-id'),
|
node.getAttribute('data-id'),
|
||||||
node.getAttribute('main-id')
|
node.getAttribute('main-id')
|
||||||
].filter(Boolean).map(String);
|
].filter(Boolean).map(String);
|
||||||
ids.forEach(function (id) {
|
ids.forEach(function (id) {
|
||||||
if (!tableMap[id]) tableMap[id] = node;
|
if (!tableMap[id]) tableMap[id] = node;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3) 全局编号状态
|
// 3) 全局编号状态
|
||||||
@@ -9037,86 +9055,86 @@ function updateCitationDisplayWithMyTable(root, refers, opt) {
|
|||||||
var nextNum = 1;
|
var nextNum = 1;
|
||||||
|
|
||||||
function assignId(id) {
|
function assignId(id) {
|
||||||
id = String(id);
|
id = String(id);
|
||||||
if (!validRef[id]) return null; // 不存在就不显示
|
if (!validRef[id]) return null; // 不存在就不显示
|
||||||
if (idToNum[id] == null) {
|
if (idToNum[id] == null) {
|
||||||
idToNum[id] = nextNum++;
|
idToNum[id] = nextNum++;
|
||||||
order.push(id);
|
order.push(id);
|
||||||
}
|
}
|
||||||
return idToNum[id];
|
return idToNum[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
function paintCiteNode(node, ids) {
|
function paintCiteNode(node, ids) {
|
||||||
var nums = [];
|
var nums = [];
|
||||||
ids.forEach(function (id) {
|
ids.forEach(function (id) {
|
||||||
var n = assignId(id);
|
var n = assignId(id);
|
||||||
if (n != null) nums.push(n);
|
if (n != null) nums.push(n);
|
||||||
});
|
});
|
||||||
nums = nums.filter(function (v, i, a) { return a.indexOf(v) === i; })
|
nums = nums.filter(function (v, i, a) { return a.indexOf(v) === i; })
|
||||||
.sort(function (a, b) { return a - b; });
|
.sort(function (a, b) { return a - b; });
|
||||||
|
|
||||||
if (!nums.length) {
|
if (!nums.length) {
|
||||||
node.removeAttribute('data-cite-label');
|
node.removeAttribute('data-cite-label');
|
||||||
if (opt.writeInnerHTML) node.innerHTML = '';
|
if (opt.writeInnerHTML) node.innerHTML = '';
|
||||||
if (opt.hideEmptyCite !== false) node.style.display = 'none';
|
if (opt.hideEmptyCite !== false) node.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var label = formatNums(nums);
|
var label = formatNums(nums);
|
||||||
node.setAttribute('data-cite-label', label);
|
node.setAttribute('data-cite-label', label);
|
||||||
if (opt.writeInnerHTML) node.innerHTML = '[' + label + ']';
|
if (opt.writeInnerHTML) node.innerHTML = '[' + label + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4) 扫描一个子树内 mycite/autocite
|
// 4) 扫描一个子树内 mycite/autocite
|
||||||
function scanCitesInSubtree(node) {
|
function scanCitesInSubtree(node) {
|
||||||
node.querySelectorAll('mycite, autocite').forEach(function (cite) {
|
node.querySelectorAll('mycite, autocite').forEach(function (cite) {
|
||||||
paintCiteNode(cite, parseIds(cite.getAttribute('data-id')));
|
paintCiteNode(cite, parseIds(cite.getAttribute('data-id')));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5) 主遍历:遇到 mytable 时“提前注入”对应表格引用
|
// 5) 主遍历:遇到 mytable 时“提前注入”对应表格引用
|
||||||
var consumedTableNode = new WeakSet();
|
var consumedTableNode = new WeakSet();
|
||||||
|
|
||||||
function walk(node) {
|
function walk(node) {
|
||||||
if (!node || node.nodeType !== 1) return;
|
if (!node || node.nodeType !== 1) return;
|
||||||
var tag = node.tagName.toLowerCase();
|
var tag = node.tagName.toLowerCase();
|
||||||
|
|
||||||
// 5.1 引用标签
|
// 5.1 引用标签
|
||||||
if (tag === 'mycite' || tag === 'autocite') {
|
if (tag === 'mycite' || tag === 'autocite') {
|
||||||
paintCiteNode(node, parseIds(node.getAttribute('data-id')));
|
paintCiteNode(node, parseIds(node.getAttribute('data-id')));
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 5.2 mytable 占位:在这里扫描对应表格
|
|
||||||
if (tag === 'mytable') {
|
|
||||||
var tid = String(node.getAttribute('data-id') || '').trim();
|
|
||||||
var tableNode = tid ? tableMap[tid] : null;
|
|
||||||
if (!tableNode) {
|
|
||||||
// 兜底:按属性再找一次
|
|
||||||
tableNode = el.querySelector(
|
|
||||||
'[data-table-id="' + tid + '"], [data-amt-id="' + tid + '"], [data-id="' + tid + '"], [main-id="' + tid + '"]'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (tableNode && !consumedTableNode.has(tableNode)) {
|
|
||||||
scanCitesInSubtree(tableNode); // 在 mytable 位置提前计入
|
// 5.2 mytable 占位:在这里扫描对应表格
|
||||||
consumedTableNode.add(tableNode); // 后续真实表格处不再重复
|
if (tag === 'mytable') {
|
||||||
|
var tid = String(node.getAttribute('data-id') || '').trim();
|
||||||
|
var tableNode = tid ? tableMap[tid] : null;
|
||||||
|
if (!tableNode) {
|
||||||
|
// 兜底:按属性再找一次
|
||||||
|
tableNode = el.querySelector(
|
||||||
|
'[data-table-id="' + tid + '"], [data-amt-id="' + tid + '"], [data-id="' + tid + '"], [main-id="' + tid + '"]'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (tableNode && !consumedTableNode.has(tableNode)) {
|
||||||
|
scanCitesInSubtree(tableNode); // 在 mytable 位置提前计入
|
||||||
|
consumedTableNode.add(tableNode); // 后续真实表格处不再重复
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5.3 若走到真实表格节点,且已在 mytable 处消费过,则跳过
|
// 5.3 若走到真实表格节点,且已在 mytable 处消费过,则跳过
|
||||||
if (consumedTableNode.has(node)) return;
|
if (consumedTableNode.has(node)) return;
|
||||||
|
|
||||||
// 5.4 正常递归
|
// 5.4 正常递归
|
||||||
for (var ch = node.firstElementChild; ch; ch = ch.nextElementSibling) {
|
for (var ch = node.firstElementChild; ch; ch = ch.nextElementSibling) {
|
||||||
walk(ch);
|
walk(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
walk(el);
|
walk(el);
|
||||||
|
|
||||||
return { idToNum: idToNum, order: order };
|
return { idToNum: idToNum, order: order };
|
||||||
}
|
}
|
||||||
|
|
||||||
function initArticleHtml(htmlData, refs, type) {
|
function initArticleHtml(htmlData, refs, type) {
|
||||||
document.querySelectorAll('wmath').forEach(el => {
|
document.querySelectorAll('wmath').forEach(el => {
|
||||||
|
|||||||
Reference in New Issue
Block a user