mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-26 12:38:13 +00:00
fix(file): 修复日期格式文件名被误转换导致创建失败的问题
newDateString 函数在处理请求参数时会将所有符合日期格式的字符串 (如 "2026-01-15")转换为完整日期时间格式("2026-01-15 00:00:00"), 导致文件名中出现冒号,触发后端文件名校验错误。 修复方案: - 直接调用时(key=null),保持原有行为用于显示格式化 - 递归处理对象属性时,仅对白名单字段(times、*_at)进行转换 - 其他字段(如 name)保持原值不转换 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9097369b0c
commit
3482e4b1a8
29
resources/assets/js/functions/common.js
vendored
29
resources/assets/js/functions/common.js
vendored
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user