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
+4
View File
@@ -0,0 +1,4 @@
// 通用 Composables
export { useMoney } from './useMoney'
export { useSmsCountdown } from './useSmsCountdown'
export { usePricingCalculator } from './usePricingCalculator'
@@ -0,0 +1,3 @@
export function useMoney() {
return (value: number | undefined | null) => `¥${Math.round(Number(value || 0))}`
}
@@ -0,0 +1,195 @@
import { computed, type Ref } from 'vue'
import type { ChargeMode, ListingPublishOptions, PublishSalePriceConfig, QuantityKey, ScreenshotKey } from '@/api/listingOptions'
import type { PublishForm } from '@/types/publish'
import {
buildDepositBreakdownItems,
calculateConsumablePrice,
calculateDailyLossRatioAdjustment,
calculatePlatformPricing,
calculateRecommendedDeposit,
calculateSellerReferenceRatio,
formatNumber,
hasAcceleratedSaleRatioInput as hasAcceleratedSaleRatioValue,
isQuantityItemDisabledForInsurance,
readFinalSaleRatio,
roundMoney,
roundRatio,
} from '@/utils/pricing'
export function usePricingCalculator(options: {
publishOptions: Ref<ListingPublishOptions>
salePriceConfig: Ref<PublishSalePriceConfig>
form: PublishForm
quantityValues: Record<QuantityKey, number>
quantityModes: Record<QuantityKey, ChargeMode>
screenshotFiles: Record<ScreenshotKey, string>
selectedSkins: Ref<string[]>
}) {
const serverOptions = computed(() => options.publishOptions.value.server_options)
const faceOptions = computed(() => options.publishOptions.value.face_options)
const rankOptions = computed(() => options.publishOptions.value.rank_options)
const insuranceOptions = computed(() => options.publishOptions.value.insurance_options)
const levelOptions = computed(() => options.publishOptions.value.level_options)
const loginMethodOptions = computed(() => options.publishOptions.value.login_method_options)
const regionOptions = computed(() => options.publishOptions.value.region_options)
const banRecordOptions = computed(() => options.publishOptions.value.ban_record_options)
const banEvidenceOptions = computed(() => options.publishOptions.value.ban_evidence_options)
const skinGroups = computed(() => options.publishOptions.value.skin_groups)
const quantityItems = computed(() => options.publishOptions.value.quantity_items)
const screenshotSlots = computed(() => options.publishOptions.value.screenshot_slots)
const priceConfig = computed(() => options.publishOptions.value.price_config)
const depositRecommendConfig = computed(() => options.publishOptions.value.deposit_recommend_config)
const fireLevelMin = computed(() => options.publishOptions.value.fire_level_min || 38)
const fireLevelPlaceholder = computed(() => `等级低于${fireLevelMin.value}级的号无法发布`)
const coinMAmount = computed(() => Number(options.form.haf_coin_amount || 0))
const coinWanAmount = computed(() => coinMAmount.value * 100)
const dailyLossMAmount = computed(() => Number(options.form.daily_loss_m || 10))
const dailyLossRatioAdjustment = computed(() => calculateDailyLossRatioAdjustment(dailyLossMAmount.value))
const screenshotUrls = computed(() =>
screenshotSlots.value.map((item) => options.screenshotFiles?.[item.key]).filter((url): url is string => Boolean(url)),
)
function hasAcceleratedSaleRatioInput() {
return hasAcceleratedSaleRatioValue(options.form.accelerated_sale_ratio)
}
function isQuantityItemDisabled(item: { key: string; label: string }) {
return isQuantityItemDisabledForInsurance(item, options.form.season_insurance)
}
const calculatedSellerReferenceRatio = computed(() =>
calculateSellerReferenceRatio({
coinMAmount: coinMAmount.value,
form: options.form,
ratioConfig: options.publishOptions.value.ratio_config,
skinGroups: skinGroups.value,
selectedSkins: options.selectedSkins.value,
levelOptions: levelOptions.value,
dailyLossRatioAdjustment: dailyLossRatioAdjustment.value,
}),
)
const calculatedDefaultSaleRatio = computed(() => calculatedSellerReferenceRatio.value)
const maxAcceleratedSaleRatio = computed(() =>
calculatedDefaultSaleRatio.value > 0 ? roundRatio(calculatedDefaultSaleRatio.value + 10) : 0,
)
const calculatedRatio = computed(() =>
readFinalSaleRatio(
calculatedDefaultSaleRatio.value,
options.form.accelerated_sale_ratio,
maxAcceleratedSaleRatio.value,
),
)
const calculatedCoinBasePrice = computed(() => {
if (calculatedRatio.value <= 0) return 0
return roundMoney(coinWanAmount.value / calculatedRatio.value)
})
const calculatedConsumablePrice = computed(() =>
calculateConsumablePrice({
quantityItems: quantityItems.value,
quantityValues: options.quantityValues,
quantityModes: options.quantityModes,
seasonInsurance: options.form.season_insurance,
}),
)
const calculatedSellerPrice = computed(() =>
calculatedRatio.value > 0 ? roundMoney(calculatedCoinBasePrice.value + calculatedConsumablePrice.value) : 0,
)
const calculatedPlatformPricing = computed(() =>
calculatePlatformPricing({
coinMAmount: coinMAmount.value,
coinWanAmount: coinWanAmount.value,
sellerRatio: calculatedRatio.value,
sellerCoinBasePrice: calculatedCoinBasePrice.value,
sellerTotalPrice: calculatedSellerPrice.value,
consumablePrice: calculatedConsumablePrice.value,
salePriceConfig: options.salePriceConfig.value,
}),
)
const calculatedFinalPrice = computed(() => calculatedPlatformPricing.value.buyerTotalPrice)
const calculatedRatioText = computed(() => (calculatedRatio.value > 0 ? `1:${formatNumber(calculatedRatio.value)}` : '--'))
const calculatedDefaultSaleRatioText = computed(() =>
calculatedDefaultSaleRatio.value > 0 ? `1:${formatNumber(calculatedDefaultSaleRatio.value)}` : '--',
)
const saleRatioRangeText = computed(() => {
if (calculatedDefaultSaleRatio.value <= 0) return '完成基础信息后自动计算参考比例'
return `可设置 1:${formatNumber(calculatedDefaultSaleRatio.value)} ~ 1:${formatNumber(maxAcceleratedSaleRatio.value)}`
})
const acceleratedSaleRatioPlaceholder = computed(() => {
if (calculatedDefaultSaleRatio.value <= 0) return '填写资料后自动生成可设置范围'
return `默认 ${formatNumber(calculatedDefaultSaleRatio.value)},最高 ${formatNumber(maxAcceleratedSaleRatio.value)}`
})
const recommendedDepositAmount = computed(() =>
calculateRecommendedDeposit({
depositRecommendConfig: depositRecommendConfig.value,
skinGroups: skinGroups.value,
selectedSkins: options.selectedSkins.value,
}),
)
const depositBreakdownItems = computed(() =>
buildDepositBreakdownItems({
depositRecommendConfig: depositRecommendConfig.value,
skinGroups: skinGroups.value,
selectedSkins: options.selectedSkins.value,
}),
)
const platformRuleLabel = computed(() => {
const labels: Record<string, string> = {
fixed_markup: '固定加价',
ratio_subtract: '比例修正',
none: '无加价',
}
return labels[calculatedPlatformPricing.value.ruleType] || calculatedPlatformPricing.value.ruleType
})
const publishTitle = computed(() => {
const parts = [
options.form.server_region,
options.form.rank_level,
coinMAmount.value ? `${coinMAmount.value}M哈夫币` : '',
].filter(Boolean)
return parts.length ? parts.join(' ') : '待完善账号信息'
})
return {
serverOptions,
faceOptions,
rankOptions,
insuranceOptions,
levelOptions,
loginMethodOptions,
regionOptions,
banRecordOptions,
banEvidenceOptions,
skinGroups,
quantityItems,
screenshotSlots,
priceConfig,
depositRecommendConfig,
fireLevelMin,
fireLevelPlaceholder,
coinMAmount,
coinWanAmount,
dailyLossMAmount,
dailyLossRatioAdjustment,
screenshotUrls,
calculatedSellerReferenceRatio,
calculatedDefaultSaleRatio,
maxAcceleratedSaleRatio,
calculatedRatio,
calculatedCoinBasePrice,
calculatedConsumablePrice,
calculatedSellerPrice,
calculatedPlatformPricing,
calculatedFinalPrice,
calculatedRatioText,
calculatedDefaultSaleRatioText,
saleRatioRangeText,
acceleratedSaleRatioPlaceholder,
recommendedDepositAmount,
depositBreakdownItems,
platformRuleLabel,
publishTitle,
hasAcceleratedSaleRatioInput,
isQuantityItemDisabled,
}
}
@@ -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,
};
}