0fc180637c
通过 display:none 模式实现轻量 KeepAlive,电商页面首次访问后保持挂载, 切换到其他页面再切回时所有右侧面板状态(上传图片、生成进度、结果)完整保留。 同时清理项目中的临时文件和本地冗余图片。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
export const ECOMMERCE_SUPPORTED_IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp", "image/gif"]);
|
|
export const ECOMMERCE_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
|
|
export interface EcommerceImageValidationResult {
|
|
accepted: File[];
|
|
rejected: Array<{ name: string; reason: string }>;
|
|
}
|
|
|
|
export function validateEcommerceImageFiles(files: File[]): EcommerceImageValidationResult {
|
|
const accepted: File[] = [];
|
|
const rejected: EcommerceImageValidationResult["rejected"] = [];
|
|
|
|
files.forEach((file) => {
|
|
if (!ECOMMERCE_SUPPORTED_IMAGE_TYPES.has(file.type)) {
|
|
rejected.push({ name: file.name, reason: "不支持的图片格式" });
|
|
return;
|
|
}
|
|
if (file.size > ECOMMERCE_MAX_IMAGE_BYTES) {
|
|
rejected.push({ name: file.name, reason: "图片超过 10MB" });
|
|
return;
|
|
}
|
|
accepted.push(file);
|
|
});
|
|
|
|
return { accepted, rejected };
|
|
}
|
|
|
|
export function summarizeRejectedImages(rejected: EcommerceImageValidationResult["rejected"]): string {
|
|
if (!rejected.length) return "";
|
|
const first = rejected[0];
|
|
const suffix = rejected.length > 1 ? ` 等 ${rejected.length} 个文件` : "";
|
|
return `${first.name}${suffix} 已跳过:${first.reason}`;
|
|
}
|
|
|
|
export function normalizeEcommerceImageMime(type: string): string {
|
|
return ECOMMERCE_SUPPORTED_IMAGE_TYPES.has(type) ? type : "image/png";
|
|
}
|