diff --git a/src/types/investment.ts b/src/types/investment.ts index 1c415f00..7b8854af 100644 --- a/src/types/investment.ts +++ b/src/types/investment.ts @@ -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[]; diff --git a/src/views/Dashboard/components/EventFormModal.tsx b/src/views/Dashboard/components/EventFormModal.tsx index a6cba50b..d9735fbb 100644 --- a/src/views/Dashboard/components/EventFormModal.tsx +++ b/src/views/Dashboard/components/EventFormModal.tsx @@ -231,11 +231,15 @@ export const EventFormModal: React.FC = ({ 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 = ({ 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 = { 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 = ({ } 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(() => {