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
@@ -0,0 +1,69 @@
import { onUnmounted, ref } from "vue";
import { showToast } from "vant";
import { sendSmsCode } from "@/api/auth";
export function useSmsCountdown() {
const countDown = ref(0);
const sending = ref(false);
let timer: ReturnType<typeof setInterval> | null = null;
function startCountDown() {
countDown.value = 60;
timer = setInterval(() => {
countDown.value--;
if (countDown.value <= 0) {
clearInterval(timer!);
timer = null;
}
}, 1000);
}
onUnmounted(() => {
if (timer) {
clearInterval(timer);
timer = null;
}
});
async function handleSendCode(phone: string) {
if (!phone.trim()) {
showToast({ message: "请输入手机号", icon: "warning-o" });
return false;
}
sending.value = true;
try {
await sendSmsCode(phone);
showToast({
message: "验证码已发送,请注意查收",
icon: "passed",
});
startCountDown();
return true;
} catch (error) {
showToast({
message: readError(error, "验证码发送失败,请稍后重试"),
icon: "cross",
});
return false;
} finally {
sending.value = false;
}
}
function readError(error: unknown, fallback: string) {
if (typeof error === "object" && error && "response" in error) {
const response = (error as { response?: { data?: { message?: string } } })
.response;
return response?.data?.message || fallback;
}
return fallback;
}
return {
countDown,
sending,
handleSendCode,
readError,
};
}