From dd97328b2f132d185c0ce19be7856480109eb72e Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Sun, 30 Nov 2025 14:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=89=8D=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0HTML=E5=AE=9E=E4=BD=93=E8=A7=A3=E7=A0=81=E5=85=9C?= =?UTF-8?q?=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加decodeHtmlEntities方法解码文件名 - 添加getFileDisplayName统一获取显示名称 - 确保文件名正确显示,即使后端未解码 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.html | 8 ++++---- frontend/app.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/frontend/app.html b/frontend/app.html index 31818db..f48b5d4 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -1373,7 +1373,7 @@ -
{{ file.displayName || file.name }}
+
{{ getFileDisplayName(file) }}
{{ file.isDirectory ? '文件夹' : file.sizeFormatted }}
@@ -1419,9 +1419,9 @@ - {{ file.displayName || file.name }} - - + {{ getFileDisplayName(file) }} + + {{ file.isDirectory ? '-' : file.sizeFormatted }} {{ formatDate(file.modifiedTime) }} diff --git a/frontend/app.js b/frontend/app.js index 0eec044..02755a4 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -2015,6 +2015,48 @@ handleDragLeave(e) { return d.toLocaleString(); }, + // HTML实体解码(前端兜底,防止已实体化的文件名显示乱码) + decodeHtmlEntities(str) { + if (typeof str !== 'string') return str; + const entityMap = { + amp: '&', + lt: '<', + gt: '>', + quot: '"', + apos: "'", + '#x27': "'", + '#x2F': '/', + '#x60': '`' + }; + const decodeOnce = (input) => + input.replace(/&(#x[0-9a-fA-F]+|#\d+|[a-zA-Z]+);/g, (match, code) => { + if (code[0] === '#') { + const isHex = code[1]?.toLowerCase() === 'x'; + const num = isHex ? parseInt(code.slice(2), 16) : parseInt(code.slice(1), 10); + if (!Number.isNaN(num)) { + return String.fromCharCode(num); + } + return match; + } + const mapped = entityMap[code]; + return mapped !== undefined ? mapped : match; + }); + let output = str; + let decoded = decodeOnce(output); + while (decoded !== output) { + output = decoded; + decoded = decodeOnce(output); + } + return output; + }, + + getFileDisplayName(file) { + if (!file) return ''; + const base = file.displayName || file.name || ''; + const decoded = this.decodeHtmlEntities(base); + return decoded || base; + }, + openShare(url) { if (!url) return; const newWindow = window.open(url, '_blank', 'noopener');