AssetManager.UniApp/types/portfolio.ts
claw_bot fa2fa98985 feat: TypeScript 迁移完成
- 新增 tsconfig.json 配置
- 新增 types/ 目录(7个类型定义文件,与后端 DTO 对齐)
- 迁移 vite.config.js → vite.config.ts
- 迁移 main.js → main.ts
- 迁移 utils/api.js → utils/api.ts(泛型化请求封装)
- 迁移 utils/currency.js → utils/currency.ts
- 迁移 6 个 Vue 页面组件(添加 lang="ts" 和类型注解)
- 新增 TYPESCRIPT_MIGRATION.md 迁移计划文档
- 更新 todo.md 进度

收益:完整类型提示、编译时错误检查、重构安全性提升
2026-03-24 05:53:29 +00:00

219 lines
4.1 KiB
TypeScript

/**
* 组合/持仓/交易类型定义(与后端 DTO 对齐)
*/
// 货币类型
export type CurrencyCode = 'CNY' | 'USD' | 'HKD' | 'EUR' | 'GBP' | 'JPY' | 'SGD' | 'AUD';
// 资产类型
export type AssetType = 'Stock' | 'Crypto' | 'Fund' | 'ETF';
// ===== 创建组合 =====
export interface StockItem {
name?: string;
code?: string;
price: number;
amount: number;
date?: string;
currency?: string;
assetType: AssetType;
}
export interface CreatePortfolioRequest {
name?: string;
strategyId?: string;
currency?: string;
stocks?: StockItem[];
}
export interface CreatePortfolioResponse {
id?: string;
totalValue: number;
returnRate: number;
currency?: string;
createdAt?: string;
}
// ===== 更新组合 =====
export interface UpdatePortfolioRequest {
name?: string;
strategyId?: string;
status?: string;
}
// ===== 组合列表 =====
export interface PortfolioListItem {
id?: string;
name?: string;
tags?: string;
status?: string;
statusType?: string;
iconChar?: string;
iconBgClass?: string;
iconTextClass?: string;
value: number;
currency?: string;
returnRate: number;
returnType?: string;
todayProfit: number;
todayProfitCurrency?: string;
}
export interface GetPortfoliosResponse {
items?: PortfolioListItem[];
}
// ===== 组合详情 =====
export interface StrategyInfo {
id?: string;
name?: string;
description?: string;
}
export interface PositionItem {
id?: string;
stockCode?: string;
stockName?: string;
symbol?: string;
amount: number;
averagePrice: number;
currentPrice: number;
totalValue: number;
profit: number;
profitRate: number;
changeAmount: number;
ratio: number;
deviationRatio: number;
currency?: string;
}
export interface PortfolioDetailResponse {
id?: string;
name?: string;
currency?: string;
status?: string;
strategy?: StrategyInfo;
portfolioValue: number;
totalReturn: number;
todayProfit: number;
historicalChange: number;
dailyVolatility: number;
todayProfitCurrency?: string;
logicModel?: string;
logicModelStatus?: string;
logicModelDescription?: string;
totalItems: number;
totalRatio: number;
positions?: PositionItem[];
}
// ===== 交易相关 =====
export interface TransactionItem {
id?: string;
portfolioId?: string;
date?: string;
time?: string;
type?: string;
title?: string;
stockCode?: string;
amount: number;
currency?: string;
status?: string;
remark?: string;
}
export interface GetTransactionsRequest {
portfolioId?: string;
limit: number;
offset: number;
}
export interface GetTransactionsResponse {
items?: TransactionItem[];
total: number;
page: number;
pageSize: number;
}
export interface CreateTransactionRequest {
portfolioId?: string;
type?: string;
stockCode?: string;
amount: number;
price: number;
currency?: string;
remark?: string;
assetType: AssetType;
transactionTime?: string;
transactionDate?: string;
}
export interface CreateTransactionResponse {
id?: string;
totalAmount: number;
status?: string;
createdAt?: string;
}
// ===== 总资产 =====
export interface TotalAssetsResponse {
totalValue: number;
currency?: string;
todayProfit: number;
todayProfitCurrency?: string;
totalReturnRate: number;
}
// ===== 净值历史 =====
export interface NavHistoryRequest {
startDate?: string;
endDate?: string;
interval?: string;
}
export interface NavHistoryItem {
date?: string;
nav: number;
totalValue: number;
totalCost: number;
dailyReturn: number;
cumulativeReturn: number;
}
export interface NavStatistics {
maxReturn: number;
minReturn: number;
maxDrawdown: number;
sharpeRatio: number;
volatility: number;
totalReturn: number;
tradingDays: number;
}
export interface NavHistoryResponse {
portfolioId?: string;
currency?: string;
navHistory?: NavHistoryItem[];
statistics?: NavStatistics;
}
export interface BackfillNavRequest {
portfolioId?: string;
force: boolean;
}
export interface BackfillNavResponse {
portfolioId?: string;
recordsCreated: number;
startDate?: string;
endDate?: string;
message?: string;
}