feat: 基础迁移完成了

This commit is contained in:
许永平
2025-07-03 18:09:07 +08:00
parent 47ff85bafa
commit 2564e3cfac
13 changed files with 989 additions and 20 deletions

46
nkebao/src/utils/index.ts Normal file
View File

@@ -0,0 +1,46 @@
// 通用工具函数
export const cn = (...classes: (string | undefined | null | false)[]) => {
return classes.filter(Boolean).join(' ');
};
// 格式化日期
export const formatDate = (date: string | Date) => {
return new Date(date).toLocaleDateString('zh-CN');
};
// 格式化时间
export const formatTime = (date: string | Date) => {
return new Date(date).toLocaleTimeString('zh-CN');
};
// 格式化日期时间
export const formatDateTime = (date: string | Date) => {
return new Date(date).toLocaleString('zh-CN');
};
// 防抖函数
export const debounce = <T extends (...args: any[]) => any>(
func: T,
wait: number
): ((...args: Parameters<T>) => void) => {
let timeout: NodeJS.Timeout;
return (...args: Parameters<T>) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
};
// 节流函数
export const throttle = <T extends (...args: any[]) => any>(
func: T,
wait: number
): ((...args: Parameters<T>) => void) => {
let inThrottle: boolean;
return (...args: Parameters<T>) => {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => (inThrottle = false), wait);
}
};
};