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,54 @@
import { ref, computed } from 'vue'
import { fetchWalletBalance, fetchWalletLedger } from '../api/wallet'
import type { WalletAccount, WalletLedger } from '../api/wallet'
export function useWallet() {
const balance = ref<WalletAccount | null>(null)
const ledgers = ref<WalletLedger[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
const availableBalance = computed(() => balance.value?.available_balance ?? 0)
const frozenBalance = computed(() => balance.value?.frozen_balance ?? 0)
const totalBalance = computed(() => availableBalance.value + frozenBalance.value)
async function loadBalance() {
loading.value = true
error.value = null
try {
balance.value = await fetchWalletBalance()
} catch (err) {
error.value = err instanceof Error ? err.message : '加载余额失败'
throw err
} finally {
loading.value = false
}
}
async function loadLedger(page = 1, pageSize = 20) {
loading.value = true
error.value = null
try {
const result = await fetchWalletLedger(page, pageSize)
ledgers.value = result.items
return result
} catch (err) {
error.value = err instanceof Error ? err.message : '加载账单失败'
throw err
} finally {
loading.value = false
}
}
return {
balance,
ledgers,
loading,
error,
availableBalance,
frozenBalance,
totalBalance,
loadBalance,
loadLedger,
}
}