修复日期格式异常的问题

This commit is contained in:
ChenYi 2025-07-17 09:26:50 +08:00
parent dafeaf3075
commit 27a71e1d5f

View File

@ -49,6 +49,22 @@ const getDeviceInfoById = (deviceId: string) => {
return deviceOptions.value.find((device) => device.id === deviceId);
};
// yyyy-MM-dd HH:mm:ss
const formatDate = (date: Date | string) => {
if (!date) return undefined;
const d = new Date(date);
if (isNaN(d.getTime())) return undefined;
const year = d.getFullYear();
const month = String(d.getMonth() +1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
const hours = String(d.getHours()).padStart(2, '0');
const minutes = String(d.getMinutes()).padStart(2, '0');
const seconds = String(d.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const route = useRoute();
@ -232,8 +248,8 @@ const gridOptions: VxeGridProps<any> = {
const ioTDataTypeValue = currentFormValues.IoTDataType;
//
const startCreationTime = currentFormValues.StartCreationTime;
const endCreationTime = currentFormValues.EndCreationTime;
const startCreationTime = currentFormValues.StartCreationTime ? formatDate(currentFormValues.StartCreationTime) : undefined;
const endCreationTime = currentFormValues.EndCreationTime ? formatDate(currentFormValues.EndCreationTime) : undefined;
// DeviceId(10)使focusId
let finalDeviceId = currentFormValues.DeviceId || DeviceId || '';