fix: stocks 字段支持对象格式 {code, name}
- investment.ts: stocks 类型改为 Array<{code, name} | string>
- EventFormModal: 编辑时兼容对象格式,保存时附带股票名称
This commit is contained in:
@@ -46,8 +46,8 @@ export interface InvestmentEvent {
|
||||
/** 重要度 (1-5) */
|
||||
importance?: number;
|
||||
|
||||
/** 相关股票代码列表 */
|
||||
stocks?: string[];
|
||||
/** 相关股票列表 */
|
||||
stocks?: Array<{ code: string; name: string } | string>;
|
||||
|
||||
/** 标签列表 */
|
||||
tags?: string[];
|
||||
@@ -85,8 +85,8 @@ export interface PlanFormData {
|
||||
/** 事件类型 */
|
||||
type: EventType;
|
||||
|
||||
/** 相关股票代码列表 */
|
||||
stocks: string[];
|
||||
/** 相关股票列表 */
|
||||
stocks: Array<{ code: string; name: string } | string>;
|
||||
|
||||
/** 标签列表 */
|
||||
tags: string[];
|
||||
|
||||
@@ -231,11 +231,15 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
if (mode === 'edit' && editingEvent) {
|
||||
// 将 stocks 转换为代码数组(兼容对象和字符串格式)
|
||||
const stockCodes = (editingEvent.stocks || []).map(stock =>
|
||||
typeof stock === 'string' ? stock : stock.code
|
||||
);
|
||||
form.setFieldsValue({
|
||||
title: editingEvent.title,
|
||||
date: dayjs(editingEvent.event_date || editingEvent.date),
|
||||
content: editingEvent.description || editingEvent.content || '',
|
||||
stocks: editingEvent.stocks || [],
|
||||
stocks: stockCodes,
|
||||
});
|
||||
} else {
|
||||
// 新建模式,重置表单并预填充模板内容
|
||||
@@ -279,13 +283,23 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
||||
|
||||
const base = getApiBase();
|
||||
|
||||
// 将选中的股票代码转换为包含名称的对象数组
|
||||
const stocksWithNames = (values.stocks || []).map((code: string) => {
|
||||
const stockInfo = allStocks.find(s => s.code === code);
|
||||
const watchlistInfo = watchlist.find(s => s.stock_code === code);
|
||||
return {
|
||||
code,
|
||||
name: stockInfo?.name || watchlistInfo?.stock_name || code,
|
||||
};
|
||||
});
|
||||
|
||||
// 构建请求数据
|
||||
const requestData: Record<string, unknown> = {
|
||||
title: values.title,
|
||||
content: values.content,
|
||||
date: values.date.format('YYYY-MM-DD'),
|
||||
type: eventType,
|
||||
stocks: values.stocks || [],
|
||||
stocks: stocksWithNames,
|
||||
status: 'active',
|
||||
};
|
||||
|
||||
@@ -336,7 +350,7 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}, [form, eventType, apiEndpoint, mode, editingEvent, label, onClose, onSuccess, loadAllData]);
|
||||
}, [form, eventType, apiEndpoint, mode, editingEvent, label, onClose, onSuccess, loadAllData, allStocks, watchlist]);
|
||||
|
||||
// 监听键盘快捷键 Ctrl + Enter
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user