完善监测点优化前端请求和回报状态
This commit is contained in:
@@ -11,15 +11,22 @@ import {
|
||||
} from "@mui/material";
|
||||
import { PlayArrow as PlayArrowIcon } from "@mui/icons-material";
|
||||
import { useNotification } from "@refinedev/core";
|
||||
import { useGetIdentity } from "@refinedev/core";
|
||||
import axios from "axios";
|
||||
import { config, NETWORK_NAME } from "@/config/config";
|
||||
|
||||
type IUser = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
const OptimizationParameters: React.FC = () => {
|
||||
const { open } = useNotification();
|
||||
const { data: user } = useGetIdentity<IUser>();
|
||||
|
||||
// 表单状态
|
||||
const [sensorType, setSensorType] = useState<string>("压力");
|
||||
const [method, setMethod] = useState<string>("聚类分析");
|
||||
const [sensorType, setSensorType] = useState<string>("pressure");
|
||||
const [method, setMethod] = useState<string>("kmeans");
|
||||
const [sensorCount, setSensorCount] = useState<number>(5);
|
||||
const [minDiameter, setMinDiameter] = useState<number>(5);
|
||||
const [schemeName, setSchemeName] = useState<string>(
|
||||
@@ -30,16 +37,23 @@ const OptimizationParameters: React.FC = () => {
|
||||
|
||||
// 传感器类型选项
|
||||
const sensorTypeOptions = [
|
||||
{ value: "压力", label: "压力" },
|
||||
{ value: "流量", label: "流量" },
|
||||
{ value: "pressure", label: "压力" },
|
||||
{ value: "flow", label: "流量" },
|
||||
];
|
||||
|
||||
// 方法选项
|
||||
const methodOptions = [
|
||||
{ value: "聚类分析", label: "聚类分析" },
|
||||
{ value: "灵敏度分析", label: "灵敏度分析" },
|
||||
{ value: "kmeans", label: "聚类分析" },
|
||||
{ value: "sensitivity", label: "灵敏度分析" },
|
||||
];
|
||||
|
||||
// 获取传感器类型的中文标签
|
||||
const getSensorTypeLabel = (value: string) => {
|
||||
return (
|
||||
sensorTypeOptions.find((option) => option.value === value)?.label || value
|
||||
);
|
||||
};
|
||||
|
||||
// 创建方案
|
||||
const handleCreateScheme = async () => {
|
||||
// 验证输入
|
||||
@@ -69,28 +83,40 @@ const OptimizationParameters: React.FC = () => {
|
||||
|
||||
setAnalyzing(true);
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
const requestData = {
|
||||
network: network,
|
||||
scheme_name: schemeName,
|
||||
sensor_type: sensorType,
|
||||
method: method,
|
||||
sensor_count: sensorCount,
|
||||
min_diameter: minDiameter,
|
||||
};
|
||||
if (!user || !user.name) {
|
||||
open?.({
|
||||
type: "error",
|
||||
message: "用户信息无效",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 发送优化请求
|
||||
const response = await axios.post(
|
||||
`${config.backendUrl}/monitoring-optimization/create`,
|
||||
requestData
|
||||
`${config.backendUrl}/sensorplacementscheme/create`,
|
||||
null,
|
||||
{
|
||||
params: {
|
||||
network: network,
|
||||
scheme_name: schemeName,
|
||||
sensor_type: sensorType,
|
||||
method: method,
|
||||
sensor_count: sensorCount,
|
||||
min_diameter: minDiameter,
|
||||
user_name: user.name,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data && response.data.success) {
|
||||
console.log("响应数据:", response.data); // 添加日志以便调试
|
||||
|
||||
// 兼容后端返回字符串 "success" 或对象 { success: true }
|
||||
if (response.data.success === true || response.data === "success") {
|
||||
open?.({
|
||||
type: "success",
|
||||
message: "方案创建成功",
|
||||
description: `方案 "${schemeName}" 已提交优化分析`,
|
||||
description: `方案 "${schemeName}" 已完成优化分析`,
|
||||
});
|
||||
|
||||
// 重置方案名称
|
||||
@@ -193,7 +219,9 @@ const OptimizationParameters: React.FC = () => {
|
||||
type="number"
|
||||
value={sensorCount}
|
||||
onChange={(e) => setSensorCount(parseInt(e.target.value) || 0)}
|
||||
inputProps={{ min: 1 }}
|
||||
slotProps={{
|
||||
htmlInput: { min: 1 },
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiOutlinedInput-root": {
|
||||
"&:hover fieldset": {
|
||||
@@ -213,7 +241,7 @@ const OptimizationParameters: React.FC = () => {
|
||||
variant="subtitle2"
|
||||
className="mb-2 font-semibold text-gray-700"
|
||||
>
|
||||
{sensorType}监测点安装最小管径(可选)
|
||||
{getSensorTypeLabel(sensorType)}监测点安装最小管径(可选)
|
||||
</Typography>
|
||||
<TextField
|
||||
fullWidth
|
||||
@@ -221,7 +249,9 @@ const OptimizationParameters: React.FC = () => {
|
||||
type="number"
|
||||
value={minDiameter}
|
||||
onChange={(e) => setMinDiameter(parseInt(e.target.value) || 0)}
|
||||
inputProps={{ min: 0 }}
|
||||
slotProps={{
|
||||
htmlInput: { min: 0 },
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiOutlinedInput-root": {
|
||||
"&:hover fieldset": {
|
||||
|
||||
Reference in New Issue
Block a user