This commit is contained in:
2026-04-16 10:54:08 +08:00
parent 2fe45fd693
commit 0b1bc06465
3 changed files with 18 additions and 25 deletions

View File

@@ -19,8 +19,8 @@ const service = axios.create({
// baseURL: 'https://submission.tmrjournals.com/', //正式 记得切换 // baseURL: 'https://submission.tmrjournals.com/', //正式 记得切换
// baseURL: 'http://www.tougao.com/', //测试本地 记得切换 // baseURL: 'http://www.tougao.com/', //测试本地 记得切换
// baseURL: 'http://192.168.110.110/tougao/public/index.php/', // baseURL: 'http://192.168.110.110/tougao/public/index.php/',
baseURL: '/api', //本地 // baseURL: '/api', //本地
// baseURL: '/', //正式 baseURL: '/', //正式
}); });

View File

@@ -1285,38 +1285,30 @@ str = str.replace(regex, function (match, content, offset, fullString) {
return html; return html;
}, },
getCleanTextForCount (html) {
getCleanTextForCount(html) {
if (!html) return ""; if (!html) return "";
// 创建临时容器解析 HTML
const tempDiv = document.createElement('div'); const tempDiv = document.createElement('div');
tempDiv.innerHTML = html; tempDiv.innerHTML = html;
// A. 特殊处理 wmath只拿它里面的公式文本扔掉里面生成的 mjx-container 等标签 // 1. 处理公式 (保留公式文本内容)
const wmaths = tempDiv.querySelectorAll('wmath'); const wmaths = tempDiv.querySelectorAll('wmath');
wmaths.forEach(wm => { wmaths.forEach(wm => {
// textContent 会拿到最原始的公式字符,忽略内部所有标签 const textNode = document.createTextNode(" " + wm.textContent + " ");
const textNode = document.createTextNode(wm.textContent);
wm.parentNode.replaceChild(textNode, wm); wm.parentNode.replaceChild(textNode, wm);
}); });
// B. 获取现在的 HTML 内容 // 2. 移除所有引用标签 [1], [2] (防止用户靠狂刷引用来凑字数)
let result = tempDiv.innerHTML; const refs = tempDiv.querySelectorAll('span.reference-link, a.ref'); // 根据你系统的 class 名调整
refs.forEach(r => r.remove());
// C. 去掉特定排版标签的“壳”(保留里面的文字) // 3. 获取纯文本 (textContent 是浏览器原生方法,能处理所有标签及其属性)
// 包含 b, strong, br, em, i, sup, sub 等 let text = tempDiv.textContent || tempDiv.innerText || "";
result = result.replace(/<(p|div|b|strong|br|em|i|sup|sub)[^>]*>/gi, "");
result = result.replace(/<\/(p|div|b|strong|br|em|i|sup|sub)>/gi, "");
// 4. 标准化空格:将 HTML 实体、换行、多个空格统一转为一个空格
return text.replace(/&nbsp;/ig, " ")
// E. 彻底“脱水”:去掉 HTML 实体、换行符、所有空格 .replace(/[\r\n\t]+/g, " ")
result = result.replace(/&nbsp;/ig, ""); .replace(/\s+/g, " ")
result = result.replace(/[\r\n\t]/g, ""); .trim();
result = result.replace(/\s+/g, "");
return result;
}, },

View File

@@ -390,6 +390,7 @@ export default {
this.questionform.comment this.questionform.comment
]; ];
Char_Cter = this.$commonJS.getCleanTextForCount(contents.join(' ')); Char_Cter = this.$commonJS.getCleanTextForCount(contents.join(' '));
console.log("🚀 ~ questionSubmit ~ Char_Cter:", Char_Cter);