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
@@ -27,9 +27,17 @@ import { api } from "@/lib/api";
import { NETWORK_NAME, config } from "@config/config";
import { useControllableObjectState } from "@components/olmap/core/useControllableState";
import { useSessionRecoveryDraft } from "@/lib/sessionRecoveryDraft";
import { getApiErrorMessage } from "@/lib/apiError";
import { FLOW_DISPLAY_UNIT, toM3s } from "@utils/units";
import { BurstLocationResult } from "./types";
import { getBurstLocationErrorNotice } from "./burstLocationError";
import {
createSchemeName,
isSchemeNameValid,
normalizeSchemeName,
SCHEME_NAME_MAX_LENGTH,
SCHEME_NAME_PREFIXES,
} from "@utils/schemeName";
interface Props {
onResult: (result: BurstLocationResult) => void;
@@ -67,7 +75,7 @@ export interface BurstLocationAnalysisParametersState {
export const createBurstLocationAnalysisParametersState =
(): BurstLocationAnalysisParametersState => ({
schemeName: `Burst_Locate_${Date.now()}`,
schemeName: createSchemeName(SCHEME_NAME_PREFIXES.burstLocation),
dataSource: "monitoring",
schemes: [],
selectedSchemeId: "",
@@ -163,12 +171,14 @@ const AnalysisParameters: React.FC<Props> = ({
description: `当前可选爆管分析方案 ${burstSchemes.length}`,
});
}
} catch (error: any) {
} catch (error) {
open?.({
type: "error",
message: "刷新方案失败",
description:
error?.response?.data?.detail ?? error?.message ?? "无法获取爆管分析方案列表",
description: getApiErrorMessage(
error,
"无法获取爆管分析方案列表",
),
});
} finally {
setSchemeLoading(false);
@@ -193,6 +203,7 @@ const AnalysisParameters: React.FC<Props> = ({
};
const isValid = useMemo(() => {
if (!isSchemeNameValid(schemeName)) return false;
if (!Number.isFinite(burstLeakage) || burstLeakage <= 0) return false;
if (!burstStartTime || !burstEndTime) {
return false;
@@ -204,6 +215,7 @@ const AnalysisParameters: React.FC<Props> = ({
return burstStartTime.isBefore(burstEndTime);
}, [
burstLeakage,
schemeName,
burstStartTime,
burstEndTime,
dataSource,
@@ -234,7 +246,7 @@ const AnalysisParameters: React.FC<Props> = ({
`${config.BACKEND_URL}/api/v1/burst-locations`,
{
data_source: dataSource,
scheme_name: schemeName.trim() || undefined,
scheme_name: normalizeSchemeName(schemeName),
burst_leakage: toM3s(burstLeakage, FLOW_DISPLAY_UNIT),
min_dpressure: minDpressure,
basic_pressure: basicPressure,
@@ -270,7 +282,7 @@ const AnalysisParameters: React.FC<Props> = ({
message: "爆管定位成功",
description: `定位到管段: ${(response.data as BurstLocationResult).located_pipe}`,
});
} catch (error: any) {
} catch (error) {
const notice = getBurstLocationErrorNotice(error);
open?.({
key: "burst-location-analysis-error",
@@ -294,6 +306,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"
/>