Commit 450f13df28ecc471416e8273058a6b3a08a3fed6

Authored by boyang
1 parent 76787ee6

fix: 修改预警数据报错

Showing 1 changed file with 11 additions and 2 deletions
src/pages/Order/Order/index.tsx
... ... @@ -131,7 +131,7 @@ import './index.less';
131 131 import { OrderListItemType, OrderType } from './type.d';
132 132 // import { useNavigate } from 'react-router-dom';
133 133 import { history } from '@umijs/max';
134   -import { format } from 'fecha';
  134 +// import { format } from 'fecha';
135 135  
136 136 const OrderPage = () => {
137 137 const [orderDrawerVisible, setOrderDrawerVisible] = useState<boolean>(false);
... ... @@ -4590,10 +4590,19 @@ const OrderPage = () =&gt; {
4590 4590 }
4591 4591 function setOriginTime(value) {
4592 4592 const currentDate = new Date();
  4593 +
4593 4594 // 创建一个新的日期对象,并在当前日期的基础上加上 daysToAdd 天
4594 4595 const newDate = new Date(currentDate);
4595 4596 newDate.setDate(currentDate.getDate() - value);
4596   - const formattedDate = format(newDate, 'yyyy-MM-dd HH:mm:ss');
  4597 + // 检查日期是否有效,并格式化输出
  4598 + function formatDate(date) {
  4599 + const year = date.getFullYear();
  4600 + const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需加1
  4601 + const day = String(date.getDate()).padStart(2, '0'); // 确保是两位数
  4602 + return `${year}-${month}-${day} ${date.toTimeString().split(' ')[0]}`; // 获取时间部分
  4603 + }
  4604 + const formattedDate = formatDate(newDate);
  4605 + // const formattedDate = format(newDate, 'YYYY-MM-dd HH:mm:ss');
4597 4606 return formattedDate;
4598 4607 }
4599 4608 const [invoiceWarningNum, setInvoiceWarningNum] = useState(0);
... ...