"use client"; /** * 策略说明的获取钩子(2026-09 重构后简化)。 * * 说明/公式由后端 `describe_strategy` 从 spec **真实推导**(不是前端拼字符串): * 「页面显示的公式」与「引擎实际执行的规则」只有一个来源,不会文案与实现漂移。 * * 重构后选股策略只含选股条件,说明走 `GET /strategies/{id}/describe`(需要已保存的 id); * 未保存参数的实时预览不再有意义(选股策略没有可即时预览的回测公式),故移除。 */ import { useEffect, useState } from "react"; import { apiGet } from "@/lib/api"; import type { StrategyDoc } from "@/lib/types"; export interface DocState { doc: StrategyDoc | null; loading: boolean; error: string; } const EMPTY: DocState = { doc: null, loading: false, error: "" }; /** 已保存选股策略 → 说明(后端按选股条件推导) */ export function useStrategyDocById(id: string | null): DocState { const [state, setState] = useState(EMPTY); useEffect(() => { if (!id) { setState(EMPTY); return; } let alive = true; setState({ doc: null, loading: true, error: "" }); apiGet(`/strategies/${encodeURIComponent(id)}/describe`) .then((doc) => alive && setState({ doc, loading: false, error: "" })) .catch((e: Error) => alive && setState({ doc: null, loading: false, error: e.message })); return () => { alive = false; }; }, [id]); return state; }