fix(client): 出入库抽屉生产日期截取防空串崩溃

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-14 10:09:35 +08:00
parent 44c985e6b5
commit 782cf057a3
4 changed files with 45 additions and 6 deletions
+10
View File
@@ -12,6 +12,16 @@ DateTime? parseYmd(String? s) {
return DateTime.tryParse(t);
}
/// 安全截取日期字符串前 10 位(`yyyy-MM-dd`)。
///
/// null 或空串一律返回 null(视为「无值」,供上层「两值皆空不渲染」的逻辑判断);
/// 长度不足 10 原样返回。用于兜底后端 `Date` 零值序列化为 `""`(而非 null)、
/// 或历史导入数据缺失生产日期的场景,避免 `''.substring(0, 10)` 抛 RangeError。
String? shortDate(String? v) {
if (v == null || v.isEmpty) return null;
return v.length >= 10 ? v.substring(0, 10) : v;
}
/// 组合年/月/日为 `yyyy-MM-dd`,自动把超出当月的「日」clamp 回当月最大值
/// (如 2 月选 31 → 28/29)。任一为空返回 null。
String? composeYmd(int? year, int? month, int? day) {