feat: Features架构迁移 - P0和P1部分完成

## 完成的工作

### P0: 基础设施准备
- 创建 features/ 和 shared/ 目录结构
- 迁移共享资源:API基础设施、工具函数、类型定义
- 迁移通用composables:useMoney, useSmsCountdown, usePricingCalculator
- 迁移全局样式文件
- 建立模块化导出系统

### P1.1: 钱包模块 (wallet)
- 迁移 API: wallet.ts
- 迁移 Views: WalletView.vue
- 新增 Composable: useWallet.ts (封装钱包状态管理)
- 更新导入路径到 shared/

### P1.2: 聊天模块 (chats)
- 迁移 API: chats.ts
- 迁移 Views: ChatView, MessagesView (桌面+移动)
- 迁移 Composables: useChatSSE.ts
- 迁移 Components: ChatAttachmentImage.vue
- 更新导入路径到 shared/

## 技术改进
- 修复 shared/composables 导出问题 (default → 命名导出)
- 修复 shared/api/client.ts 类型导入路径
- 建立清晰的模块边界和导出规范

## 文档
- 添加完整的迁移计划文档
- 添加进度跟踪文档

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
yml2213
2026-06-04 08:38:36 +08:00
co-authored by Claude Opus 4.7
parent 10acca637e
commit b5903a169f
42 changed files with 7957 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
const IMAGE_UPLOAD_MAX_SIDE: Record<string, number> = {
avatar: 512,
chat: 1280,
"home-banner": 1920,
listing: 1920,
dispute: 1920,
handoff: 1920,
realname: 1920,
};
const IMAGE_UPLOAD_QUALITY: Record<string, number> = {
avatar: 0.82,
chat: 0.8,
"home-banner": 0.84,
listing: 0.84,
dispute: 0.86,
handoff: 0.86,
realname: 0.86,
};
export async function optimizeImageForUpload(file: File, scene: string) {
if (!file.type.startsWith("image/")) return file;
if (!["image/jpeg", "image/png", "image/webp"].includes(file.type)) return file;
if (typeof document === "undefined") return file;
try {
const image = await loadImage(file);
const maxSide = IMAGE_UPLOAD_MAX_SIDE[scene] || 1600;
const quality = IMAGE_UPLOAD_QUALITY[scene] || 0.82;
const { width, height } = fitSize(image.naturalWidth, image.naturalHeight, maxSide);
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
if (!context) return file;
context.fillStyle = "#ffffff";
context.fillRect(0, 0, width, height);
context.drawImage(image, 0, 0, width, height);
const blob = await canvasToBlob(canvas, "image/webp", quality);
if (!blob || blob.size >= file.size) return file;
return new File([blob], replaceFileExt(file.name, "webp"), {
type: "image/webp",
lastModified: Date.now(),
});
} catch {
return file;
}
}
function loadImage(file: File) {
return new Promise<HTMLImageElement>((resolve, reject) => {
const url = URL.createObjectURL(file);
const image = new Image();
image.onload = () => {
URL.revokeObjectURL(url);
resolve(image);
};
image.onerror = () => {
URL.revokeObjectURL(url);
reject(new Error("图片读取失败"));
};
image.src = url;
});
}
function fitSize(width: number, height: number, maxSide: number) {
if (width <= 0 || height <= 0) return { width: 1, height: 1 };
const scale = Math.min(1, maxSide / Math.max(width, height));
return {
width: Math.max(1, Math.round(width * scale)),
height: Math.max(1, Math.round(height * scale)),
};
}
function canvasToBlob(canvas: HTMLCanvasElement, type: string, quality: number) {
return new Promise<Blob | null>((resolve) => {
canvas.toBlob(resolve, type, quality);
});
}
function replaceFileExt(filename: string, ext: string) {
const base = filename.replace(/\.[^.]+$/, "");
return `${base || "image"}.${ext}`;
}