From 3482e4b1a87c54265d1a3bd9616b3651c39cbbe0 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 20 Jan 2026 22:33:45 +0000 Subject: [PATCH] =?UTF-8?q?fix(file):=20=E4=BF=AE=E5=A4=8D=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=A0=BC=E5=BC=8F=E6=96=87=E4=BB=B6=E5=90=8D=E8=A2=AB?= =?UTF-8?q?=E8=AF=AF=E8=BD=AC=E6=8D=A2=E5=AF=BC=E8=87=B4=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit newDateString 函数在处理请求参数时会将所有符合日期格式的字符串 (如 "2026-01-15")转换为完整日期时间格式("2026-01-15 00:00:00"), 导致文件名中出现冒号,触发后端文件名校验错误。 修复方案: - 直接调用时(key=null),保持原有行为用于显示格式化 - 递归处理对象属性时,仅对白名单字段(times、*_at)进行转换 - 其他字段(如 name)保持原值不转换 Co-Authored-By: Claude Opus 4.5 --- resources/assets/js/functions/common.js | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index ca13f3fae..134f789c9 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -2409,24 +2409,37 @@ const timezone = require("dayjs/plugin/timezone"); * 对象中有Date格式的转成指定格式 * @param value 支持类型:dayjs、Date、string * @param format 默认格式:YYYY-MM-DD HH:mm:ss + * @param key 当前字段名(用于白名单判断) * @returns {*} */ - newDateString(value, format = "YYYY-MM-DD HH:mm:ss") { + newDateString(value, format = "YYYY-MM-DD HH:mm:ss", key = null) { if (value === null) { return value; } - if (value instanceof dayjs || value instanceof Date || $A.isDateString(value)) { - value = $A.dayjs(value).format(format); - } else if ($A.isJson(value)) { + // Date/dayjs 对象直接转换 + if (value instanceof dayjs || value instanceof Date) { + return $A.dayjs(value).format(format); + } + // 字符串日期处理: + // 1. 直接调用(key=null)时,始终转换(用于显示格式化) + // 2. 递归调用(key有值)时,仅白名单字段转换(避免文件名等被误转换) + if ($A.isDateString(value)) { + if (key === null || key === 'times' || /_at$/i.test(key)) { + return $A.dayjs(value).format(format); + } + return value; + } + // 对象:递归处理 + if ($A.isJson(value)) { value = Object.assign({}, value) - for (let key in value) { - if (!value.hasOwnProperty(key)) continue; - value[key] = $A.newDateString(value[key], format); + for (let k in value) { + if (!value.hasOwnProperty(k)) continue; + value[k] = $A.newDateString(value[k], format, k); } } else if ($A.isArray(value)) { value = Object.assign([], value) value.forEach((val, index) => { - value[index] = $A.newDateString(val, format); + value[index] = $A.newDateString(val, format, key); }); } return value;