From 682124f3e573a24523dd643f23d16bb7d3c7e08d Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 29 九月 2026 18:22:17 +0800
Subject: [PATCH] fix(inventory): 移除不合格库存相关字段并修复日期时间处理
---
src/utils/index.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/src/utils/index.js b/src/utils/index.js
index 809593f..aee9fa7 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -12,14 +12,58 @@
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
- var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
- var minutes =
- date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
- var seconds =
- date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
- return (
- year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds
- );
+ return year + "-" + month + "-" + day;
+}
+
+/**
+ * 浠呬繚鐣欐棩鏈熼儴鍒嗭紝鍘绘帀鏃跺垎绉掞紝杈撳嚭 YYYY-MM-DD銆�
+ * 鍏煎 Date 瀵硅薄銆�"YYYY-MM-DD HH:mm:ss"銆�"YYYY-MM-DDTHH:mm:ss" 绛夋牸寮忥紱
+ * 宸叉槸绾棩鏈熸垨闈炴棩鏈熷瓧绗︿覆鏃跺師鏍疯繑鍥炪��
+ */
+export function dateOnly(value) {
+ if (value == null || value === "") return "";
+ if (value instanceof Date) {
+ if (Number.isNaN(value.getTime())) return "";
+ const pad = (num) => String(num).padStart(2, "0");
+ return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(
+ value.getDate()
+ )}`;
+ }
+ const str = String(value).trim();
+ return str.split(/[ T]/)[0] || str;
+}
+
+/**
+ * el-table-column 鏃ユ湡鍒楁牸寮忓寲锛氫粎淇濈暀鏃ユ湡閮ㄥ垎锛屽幓鎺夋椂鍒嗙銆�
+ */
+export function formatDateColumn(row, column, cellValue) {
+ return dateOnly(cellValue);
+}
+
+/**
+ * 琛ュ叏鏃跺垎绉掞紝杈撳嚭 YYYY-MM-DD HH:mm:ss锛岀敤浜庡悗绔� LocalDateTime 瀛楁銆�
+ * 鍏煎 Date 瀵硅薄銆�"YYYY-MM-DD"銆�"YYYY-MM-DD HH:mm"銆�"YYYY-MM-DDTHH:mm:ss" 绛夎緭鍏ワ紱
+ * 绌哄�煎師鏍疯繑鍥炪��
+ */
+export function toDateTimeString(value) {
+ if (value == null || value === "") return value;
+ if (value instanceof Date) {
+ if (Number.isNaN(value.getTime())) return "";
+ const pad = (num) => String(num).padStart(2, "0");
+ return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(
+ value.getDate()
+ )} ${pad(value.getHours())}:${pad(value.getMinutes())}:${pad(
+ value.getSeconds()
+ )}`;
+ }
+ const [datePart, timePart = ""] = String(value)
+ .trim()
+ .replace("T", " ")
+ .split(/\s+/);
+ const timeUnits = timePart.split(":").filter((unit) => unit !== "");
+ while (timeUnits.length < 3) timeUnits.push("00");
+ const time = timeUnits.map((unit) => unit.padStart(2, "0")).join(":");
+ return `${datePart} ${time}`;
}
/**
--
Gitblit v1.9.3