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) */
|
/** 重要度 (1-5) */
|
||||||
importance?: number;
|
importance?: number;
|
||||||
|
|
||||||
/** 相关股票代码列表 */
|
/** 相关股票列表 */
|
||||||
stocks?: string[];
|
stocks?: Array<{ code: string; name: string } | string>;
|
||||||
|
|
||||||
/** 标签列表 */
|
/** 标签列表 */
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
@@ -85,8 +85,8 @@ export interface PlanFormData {
|
|||||||
/** 事件类型 */
|
/** 事件类型 */
|
||||||
type: EventType;
|
type: EventType;
|
||||||
|
|
||||||
/** 相关股票代码列表 */
|
/** 相关股票列表 */
|
||||||
stocks: string[];
|
stocks: Array<{ code: string; name: string } | string>;
|
||||||
|
|
||||||
/** 标签列表 */
|
/** 标签列表 */
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
|||||||
@@ -231,11 +231,15 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
if (mode === 'edit' && editingEvent) {
|
if (mode === 'edit' && editingEvent) {
|
||||||
|
// 将 stocks 转换为代码数组(兼容对象和字符串格式)
|
||||||
|
const stockCodes = (editingEvent.stocks || []).map(stock =>
|
||||||
|
typeof stock === 'string' ? stock : stock.code
|
||||||
|
);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
title: editingEvent.title,
|
title: editingEvent.title,
|
||||||
date: dayjs(editingEvent.event_date || editingEvent.date),
|
date: dayjs(editingEvent.event_date || editingEvent.date),
|
||||||
content: editingEvent.description || editingEvent.content || '',
|
content: editingEvent.description || editingEvent.content || '',
|
||||||
stocks: editingEvent.stocks || [],
|
stocks: stockCodes,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 新建模式,重置表单并预填充模板内容
|
// 新建模式,重置表单并预填充模板内容
|
||||||
@@ -279,13 +283,23 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
|||||||
|
|
||||||
const base = getApiBase();
|
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> = {
|
const requestData: Record<string, unknown> = {
|
||||||
title: values.title,
|
title: values.title,
|
||||||
content: values.content,
|
content: values.content,
|
||||||
date: values.date.format('YYYY-MM-DD'),
|
date: values.date.format('YYYY-MM-DD'),
|
||||||
type: eventType,
|
type: eventType,
|
||||||
stocks: values.stocks || [],
|
stocks: stocksWithNames,
|
||||||
status: 'active',
|
status: 'active',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -336,7 +350,7 @@ export const EventFormModal: React.FC<EventFormModalProps> = ({
|
|||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
}
|
}
|
||||||
}, [form, eventType, apiEndpoint, mode, editingEvent, label, onClose, onSuccess, loadAllData]);
|
}, [form, eventType, apiEndpoint, mode, editingEvent, label, onClose, onSuccess, loadAllData, allStocks, watchlist]);
|
||||||
|
|
||||||
// 监听键盘快捷键 Ctrl + Enter
|
// 监听键盘快捷键 Ctrl + Enter
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user