feat: initialize new React application structure with TypeScript, ESLint, and Prettier configurations, while removing legacy files and adding new components and pages for enhanced functionality

This commit is contained in:
Supra4E8C
2025-12-07 11:32:31 +08:00
parent 8e4132200d
commit 450964fb1a
144 changed files with 14223 additions and 21647 deletions

56
src/utils/validation.ts Normal file
View File

@@ -0,0 +1,56 @@
/**
* 验证工具函数
*/
/**
* 验证 URL 格式
*/
export function isValidUrl(url: string): boolean {
try {
new URL(url);
return true;
} catch {
return false;
}
}
/**
* 验证 API Base URL
*/
export function isValidApiBase(apiBase: string): boolean {
if (!apiBase) return false;
// 允许 http/https 协议
const urlPattern = /^https?:\/\/.+/i;
return urlPattern.test(apiBase);
}
/**
* 验证 API Key 格式
*/
export function isValidApiKey(key: string): boolean {
if (!key || key.length < 8) return false;
// 基础验证:不包含空格
return !/\s/.test(key);
}
/**
* 验证 JSON 格式
*/
export function isValidJson(str: string): boolean {
try {
JSON.parse(str);
return true;
} catch {
return false;
}
}
/**
* 验证 Email 格式
*/
export function isValidEmail(email: string): boolean {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email);
}