gerson
2025-02-20 a762b59c2c4b459f72ede19716d476bb3513f622
src/utils/util.ts
@@ -284,7 +284,7 @@
   callback: (value: T, index?, array?, parent?) => any,
   parent: any = null,
   markParent = false,
   childrenKey = 'Children'
   childrenKey = 'children'
) => {
   if (!treeData || treeData.length === 0) return;
   if (!parent) parent = treeData;
@@ -547,6 +547,7 @@
   const endDate = new Date();
   const startDate = new Date();
   startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates);
   endDate.setHours(23,59,59,59)
   startDate.setHours(0, 0, 0, 0);
   return [startDate, endDate];
};
@@ -627,6 +628,21 @@
      percent += '%';
   }
   return percent;
};
/**
 * 保留指定精度小数位,且不补零
 * @param num
 * @param precision
 * @returns
 */
export const toMyFixed = (num, precision) => {
   if (num == null) return '';
   if (!precision) return num + '';
   const factor = Math.pow(10, precision);
   return Math.round(Number(num) * factor) / factor + '';
};
/**
@@ -734,3 +750,15 @@
   }
   return decodedData;
}
/**
 * 休眠指定秒数
 * @param seconds 休眠秒数
 * @returns Promise
 */
export const sleep = (seconds: number): Promise<void> => {
   return new Promise((resolve) => {
      setTimeout(resolve, seconds * 1000);
   });
};