调整环境变量参数,支持项目切换

This commit is contained in:
JIANG
2026-02-11 12:07:29 +08:00
parent 03e5f1456c
commit 8b6198a2ac
7 changed files with 106 additions and 44 deletions
@@ -7,6 +7,7 @@ import { Stroke } from "ol/style";
import GeoJson from "ol/format/GeoJSON";
import config from "@config/config";
import { useMap } from "@app/OlMap/MapComponent";
import { useProject } from "@/contexts/ProjectContext";
interface PropertyItem {
key: string;
@@ -26,6 +27,8 @@ const ZonePropsPanel: React.FC<ZonePropsPanelProps> = ({
onClose,
}) => {
const map = useMap();
const project = useProject();
const workspace = project?.workspace;
const [props, setProps] = React.useState<
PropertyItem[] | Record<string, any>
@@ -103,9 +106,10 @@ const ZonePropsPanel: React.FC<ZonePropsPanelProps> = ({
if (!map) {
return;
}
const workspaceValue = workspace || config.MAP_WORKSPACE;
const networkZoneLayer = new VectorLayer({
source: new VectorSource({
url: `${config.MAP_URL}/${config.MAP_WORKSPACE}/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${config.MAP_WORKSPACE}:network_zone&outputFormat=application/json`,
url: `${config.MAP_URL}/${workspaceValue}/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${workspaceValue}:network_zone&outputFormat=application/json`,
format: new GeoJson(),
}),
style: new Style({
@@ -155,7 +159,7 @@ const ZonePropsPanel: React.FC<ZonePropsPanelProps> = ({
map.removeLayer(highlightLayer);
map.un("click", clickListener);
};
}, [map, handleMapClickSelectFeatures]);
}, [map, handleMapClickSelectFeatures, workspace]);
// 获取中文标签
const getChineseLabel = (key: string): string => {
const labelMap: Record<string, string> = {
+9 -3
View File
@@ -50,9 +50,10 @@ import { FixedSizeList } from "react-window";
import { useNotification } from "@refinedev/core";
import axios from "axios";
import { useGetIdentity } from "@refinedev/core";
import config, { NETWORK_NAME } from "@/config/config";
import config from "@/config/config";
import { useMap } from "@app/OlMap/MapComponent";
import { useProject } from "@/contexts/ProjectContext";
import { GeoJSON } from "ol/format";
import { handleMapClickSelectFeatures as mapClickSelectFeatures } from "@/utils/mapQueryService";
import VectorLayer from "ol/layer/Vector";
@@ -180,12 +181,17 @@ const SCADADeviceList: React.FC<SCADADeviceListProps> = ({
}
}, [pendingSelection, onSelectionChange]);
// Get workspace from context
const project = useProject();
const workspace = project?.workspace;
// 初始化 SCADA 设备列表
useEffect(() => {
const fetchScadaDevices = async () => {
setLoading(true);
try {
const url = `${config.MAP_URL}/${config.MAP_WORKSPACE}/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${config.MAP_WORKSPACE}:geo_scada&outputFormat=application/json`;
const activeWorkspace = workspace || config.MAP_WORKSPACE;
const url = `${config.MAP_URL}/${activeWorkspace}/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${activeWorkspace}:geo_scada&outputFormat=application/json`;
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch SCADA devices");
const json = await response.json();
@@ -211,7 +217,7 @@ const SCADADeviceList: React.FC<SCADADeviceListProps> = ({
}
};
fetchScadaDevices();
}, []);
}, [workspace]);
const effectiveDevices = devices.length > 0 ? devices : internalDevices;
+38 -10
View File
@@ -19,14 +19,29 @@ import { useState } from "react";
interface ProjectSelectorProps {
open: boolean;
onSelect: (workspace: string, networkName: string) => void;
onSelect: (workspace: string, networkName: string, extent?: number[]) => void;
onClose?: () => void;
}
const PROJECTS = [
{ label: "TJWater (默认)", workspace: "TJWater", networkName: "tjwater" },
{ label: "苏州河", workspace: "szh", networkName: "szh" },
{ label: "测试项目", workspace: "test", networkName: "test" },
{
label: "默认",
workspace: "tjwater",
networkName: "tjwater",
extent: [13508802, 3608164, 13555651, 3633686],
},
{
label: "苏州河",
workspace: "szh",
networkName: "szh",
extent: [13490131, 3630016, 13525879, 3666969],
},
{
label: "测试项目",
workspace: "test",
networkName: "test",
extent: [13508849, 3608036, 13555781, 3633813],
},
];
export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
@@ -36,10 +51,13 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
}) => {
const [workspace, setWorkspace] = useState(PROJECTS[0].workspace);
const [networkName, setNetworkName] = useState(PROJECTS[0].networkName);
const [extent, setExtent] = useState<number[] | undefined>(
PROJECTS[0].extent,
);
const [customMode, setCustomMode] = useState(false);
const handleConfirm = () => {
onSelect(workspace, networkName);
onSelect(workspace, networkName, extent);
};
return (
@@ -56,8 +74,8 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
background: "rgba(255, 255, 255, 0.95)",
backdropFilter: "blur(10px)",
position: "relative",
}
}
},
},
}}
slots={{ transition: Fade }}
transitionDuration={500}
@@ -76,7 +94,14 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
<CloseIcon />
</IconButton>
)}
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", mb: 2 }}>
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
mb: 2,
}}
>
<Box sx={{ transform: "scale(1.5)", mb: 2, mt: 1 }}>
<Title />
</Box>
@@ -85,7 +110,9 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
</Typography>
</Box>
<DialogContent sx={{ display: "flex", flexDirection: "column", gap: 3, pt: 1 }}>
<DialogContent
sx={{ display: "flex", flexDirection: "column", gap: 3, pt: 1 }}
>
{!customMode ? (
<FormControl fullWidth variant="outlined">
<InputLabel></InputLabel>
@@ -101,6 +128,7 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
if (p) {
setWorkspace(p.workspace);
setNetworkName(p.networkName);
setExtent(p.extent);
}
}
}}
@@ -155,7 +183,7 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
sx={{
textTransform: "none",
borderRadius: 2,
fontWeight: "bold"
fontWeight: "bold",
}}
>