fix(analysis): 统一方案名与接口错误提示
Generic Container CI/CD / test-build-publish (push) Successful in 1m2s
Frontend CI/CD v2 / build-test-publish-and-deploy (push) Successful in 1m2s

This commit is contained in:
2026-08-17 18:54:29 +08:00
parent 9e79d52dc8
commit 45def5bba3
12 changed files with 720 additions and 55 deletions
@@ -21,8 +21,16 @@ import { api } from "@/lib/api";
import { config } from "@config/config";
import { useControllableObjectState } from "@components/olmap/core/useControllableState";
import { useSessionRecoveryDraft } from "@/lib/sessionRecoveryDraft";
import { getApiErrorMessage } from "@/lib/apiError";
import { LeakageResultDetail } from "./types";
import { FLOW_DISPLAY_UNIT, toM3s } from "@utils/units";
import {
createSchemeName,
isSchemeNameValid,
normalizeSchemeName,
SCHEME_NAME_MAX_LENGTH,
SCHEME_NAME_PREFIXES,
} from "@utils/schemeName";
interface Props {
onResult: (result: LeakageResultDetail) => void;
@@ -43,7 +51,7 @@ export interface DMALeakAnalysisParametersState {
export const createDMALeakAnalysisParametersState =
(): DMALeakAnalysisParametersState => ({
schemeName: `DMA_Leak_${Date.now()}`,
schemeName: createSchemeName(SCHEME_NAME_PREFIXES.dmaLeakIdentification),
dmaCount: 5,
startTime: dayjs().subtract(2, "hour"),
endTime: dayjs(),
@@ -93,7 +101,7 @@ const AnalysisParameters: React.FC<Props> = ({
qSumInput.trim() !== "" && Number.isFinite(parsedQSum) && parsedQSum >= 0;
const isValid = useMemo(() => {
if (!schemeName.trim() || !startTime || !endTime) return false;
if (!isSchemeNameValid(schemeName) || !startTime || !endTime) return false;
return startTime.isBefore(endTime) && qSumIsValid;
}, [schemeName, startTime, endTime, qSumIsValid]);
@@ -118,7 +126,7 @@ const AnalysisParameters: React.FC<Props> = ({
const response = await api.post(
`${config.BACKEND_URL}/api/v1/leakage-identifications`,
{
scheme_name: schemeName.trim(),
scheme_name: normalizeSchemeName(schemeName),
dma_count: dmaCount,
scada_start: startTime.toISOString(),
scada_end: endTime.toISOString(),
@@ -136,12 +144,12 @@ const AnalysisParameters: React.FC<Props> = ({
message: "方案分析成功",
description: "DMA 漏损识别完成,请在方案查询中查看结果。",
});
} catch (error: any) {
} catch (error) {
open?.({
key: "dma-leak-analysis-error",
type: "error",
message: "提交分析失败",
description: error?.response?.data?.detail ?? "请求失败",
description: getApiErrorMessage(error, "DMA 漏损识别请求失败"),
});
} finally {
setRunning(false);
@@ -163,6 +171,13 @@ const AnalysisParameters: React.FC<Props> = ({
value={schemeName}
onChange={(e) => setFormField("schemeName", e.target.value)}
placeholder="请输入方案名称"
error={schemeName.trim().length > SCHEME_NAME_MAX_LENGTH}
helperText={
schemeName.trim().length > SCHEME_NAME_MAX_LENGTH
? `方案名称不能超过 ${SCHEME_NAME_MAX_LENGTH} 个字符`
: undefined
}
inputProps={{ maxLength: SCHEME_NAME_MAX_LENGTH }}
fullWidth
size="small"
/>