|
@@ -246,11 +246,12 @@ const getList = async () => {
|
|
|
// 如果maturityTime是字符串,转换为Date对象以便于比较
|
|
|
if (item.maturityTime) {
|
|
|
if (typeof item.maturityTime === 'string') {
|
|
|
- item.maturityTime = new Date(item.maturityTime);
|
|
|
+ item.maturityTime = new Date(item.maturityTime).getTime();
|
|
|
}
|
|
|
} else {
|
|
|
- // 默认7天后过期
|
|
|
- item.maturityTime = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
|
+ // 默认7天后过期 - 仅对新增用户设置默认值
|
|
|
+ const defaultDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
|
+ item.maturityTime = defaultDate.getTime();
|
|
|
}
|
|
|
|
|
|
// 如果createTime是字符串,转换为Date对象
|
|
@@ -275,7 +276,7 @@ const getList = async () => {
|
|
|
item.inspection = 1 // 关键:覆盖接口返回值
|
|
|
}
|
|
|
|
|
|
- // 更新过期状态和剩余天数
|
|
|
+ // 更新过期状态和剩余天数 - 使用后端返回的数据
|
|
|
updateExpirationStatus(item);
|
|
|
|
|
|
return item;
|
|
@@ -306,12 +307,12 @@ const handleUserChange = (row: UserRow) => {
|
|
|
row.inspection = 0; // 默认不可巡检
|
|
|
}
|
|
|
if (!row.maturityTime) {
|
|
|
- // 默认7天后过期
|
|
|
+ // 默认7天后过期 - 仅对新增用户设置默认值
|
|
|
const defaultDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
|
- // 格式化为字符串
|
|
|
- row.maturityTime = defaultDate.toISOString().substring(0, 19).replace('T', ' ');
|
|
|
+ row.maturityTime = defaultDate.getTime(); // 使用时间戳格式
|
|
|
// 更新过期状态
|
|
|
- updateExpirationStatus(row);
|
|
|
+ row.valid = true;
|
|
|
+ row.daysLeft = 7;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -337,15 +338,17 @@ const handleDateChange = (row: UserRow) => {
|
|
|
// 更新过期状态和剩余天数
|
|
|
const updateExpirationStatus = (row: UserRow) => {
|
|
|
if (row.maturityTime != null && row.maturityTime !== 0) {
|
|
|
- const maturityDate = typeof row.maturityTime === 'string'
|
|
|
- ? new Date(row.maturityTime)
|
|
|
- : row.maturityTime;
|
|
|
- const now = new Date();
|
|
|
- row.valid = maturityDate > now;
|
|
|
+ // 处理时间戳格式
|
|
|
+ const maturityTimestamp = typeof row.maturityTime === 'string'
|
|
|
+ ? new Date(row.maturityTime).getTime()
|
|
|
+ : Number(row.maturityTime);
|
|
|
+
|
|
|
+ const now = Date.now();
|
|
|
+ row.valid = maturityTimestamp > now;
|
|
|
|
|
|
if (row.valid) {
|
|
|
// 计算剩余天数
|
|
|
- const diffTime = maturityDate.getTime() - now.getTime();
|
|
|
+ const diffTime = maturityTimestamp - now;
|
|
|
row.daysLeft = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
|
} else {
|
|
|
row.daysLeft = 0;
|
|
@@ -357,11 +360,10 @@ const updateExpirationStatus = (row: UserRow) => {
|
|
|
const handleAddRow = () => {
|
|
|
// 默认7天后过期的日期
|
|
|
const defaultDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
|
- const formattedDate = defaultDate.toISOString().substring(0, 19).replace('T', ' ');
|
|
|
-
|
|
|
+
|
|
|
const newRow = {
|
|
|
userId: undefined,
|
|
|
- maturityTime: formattedDate,
|
|
|
+ maturityTime: defaultDate.getTime(), // 使用时间戳格式
|
|
|
onlyRead: 3, // 默认只读
|
|
|
valid: true,
|
|
|
daysLeft: 7,
|
|
@@ -389,7 +391,12 @@ const updateSubmitData = () => {
|
|
|
.map(row => {
|
|
|
// 确保maturityTime是正确的格式
|
|
|
let maturityTime = row.maturityTime;
|
|
|
- if (maturityTime instanceof Date) {
|
|
|
+
|
|
|
+ // 如果是时间戳,转换为日期字符串格式
|
|
|
+ if (typeof maturityTime === 'number') {
|
|
|
+ const date = new Date(maturityTime);
|
|
|
+ maturityTime = date.toISOString().substring(0, 19).replace('T', ' ');
|
|
|
+ } else if (maturityTime instanceof Date) {
|
|
|
maturityTime = maturityTime.toISOString().substring(0, 19).replace('T', ' ');
|
|
|
}
|
|
|
|