fix(api): 统一处理接口返回数据的默认值为null或undefined时的兼容问题

- 调整多个接口调用中解构data时去掉默认空数组或空对象,改用逻辑或操作符进行兼容处理
- 防止data为null或undefined导致程序异常,保证数据显示和渲染安全
- 相关组件和业务逻辑中增加了对data字段的非空判断和安全访问
- 更新图表和列表渲染初始化逻辑,避免因数据缺失导致的异常
- 优化请求数据接收后赋值流程,提升代码的鲁棒性与稳定性
master
LiuJiaNan 2026-07-27 10:16:38 +08:00
parent fdeeb1e9a2
commit 1f8f47f946
38 changed files with 109 additions and 109 deletions

View File

@ -130,8 +130,8 @@ function BottomUtils(props) {
if (gateTypes.includes(item1.type)) {
requestParams.gateType = item1.type;
}
const { data = [] } = await props[item1.request](requestParams);
pointData = [...data];
const { data } = await props[item1.request](requestParams);
pointData = [...(data || [])];
if (dangerWorkTypes.includes(item1.type)) {
for (let i = 0; i < pointData.length; i++) {
pointData[i].latitude = pointData[i].info.latitude;

View File

@ -12,8 +12,8 @@ function RecordStatsPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getXgfStatisticsListRecordProjectStatistics();
setData(data);
const { data } = await props.getXgfStatisticsListRecordProjectStatistics();
setData(data || []);
};
loadData();

View File

@ -14,11 +14,11 @@ function VideoPatrolPanel(props) {
const [active, setActive] = useState("");
const [playUrl, setPlayUrl] = useState("");
const loadPlayUrl = async (cameraNumber) => {
const { data = {}, success } = await props.getFixedCameraPlayUrl({
const { data, success } = await props.getFixedCameraPlayUrl({
indexCode: cameraNumber,
});
if (success && data)
setPlayUrl(data.url);
setPlayUrl(data?.url || "");
};
const selectCorp = (item) => {
setActive(item.corpinfoName);
@ -35,9 +35,9 @@ function VideoPatrolPanel(props) {
};
useEffect(() => {
const loadVideoList = async () => {
const { data = [] } = await props.getFixedCameraVideoList();
setList(data);
if (data.length) {
const { data } = await props.getFixedCameraVideoList();
setList(data || []);
if (data?.length) {
selectCorp(data[0]);
}
};

View File

@ -13,11 +13,11 @@ function RectificationPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getHiddenStatisticsByPortArea({
const { data } = await props.getHiddenStatisticsByPortArea({
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();

View File

@ -24,11 +24,11 @@ function WeatherPanel(props) {
alertTitle: result.alerts?.[0]?.title || "当前暂无气象预警",
});
const { data = [] } = await props.getEventReportListUnfinished({
const { data } = await props.getEventReportListUnfinished({
pageIndex: 1,
pageSize: 9999,
});
setEmergencyList(data);
setEmergencyList(data || []);
};
loadData();
}, []);

View File

@ -137,8 +137,8 @@ function WorkStatusPanel(props) {
};
useMount(() => {
const loadData = async () => {
const { data = [] } = await props.getProjectTaskScoreCount();
initEcharts(chartRef, chartInstance, data);
const { data } = await props.getProjectTaskScoreCount();
initEcharts(chartRef, chartInstance, data || []);
};
loadData();

View File

@ -13,11 +13,11 @@ function AlarmPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
const { data } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();

View File

@ -13,11 +13,11 @@ function PartnerPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getXgfStatisticsListCorpStatistics({
const { data } = await props.getXgfStatisticsListCorpStatistics({
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();

View File

@ -29,22 +29,22 @@ function WorkPanel(props) {
]);
useEffect(() => {
const loadData = async () => {
const [{ data: eightWorkData = [] }, { data: keyProjectData = [] }] = await Promise.all([
const [{ data: eightWorkData }, { data: keyProjectData }] = await Promise.all([
props.getEightWorkInfoDangerWorkStatistics(),
props.getKeyProjectLargeScreenStatistics(),
]);
setData((prevState) => {
prevState[1].doingCount = eightWorkData.doingCount;
prevState[1].appliedCount = eightWorkData.appliedCount;
prevState[1].doingCount = eightWorkData?.doingCount;
prevState[1].appliedCount = eightWorkData?.appliedCount;
prevState[0].doingCount = keyProjectData.morePeopleStartCount;
prevState[0].appliedCount = keyProjectData.morePeopleApplyCount;
prevState[0].doingCount = keyProjectData?.morePeopleStartCount;
prevState[0].appliedCount = keyProjectData?.morePeopleApplyCount;
prevState[2].doingCount = keyProjectData.fourNewHomeworkStartCount;
prevState[2].appliedCount = keyProjectData.fourNewHomeworkApplyCount;
prevState[2].doingCount = keyProjectData?.fourNewHomeworkStartCount;
prevState[2].appliedCount = keyProjectData?.fourNewHomeworkApplyCount;
prevState[3].doingCount = keyProjectData.nightWorkStartCount;
prevState[3].appliedCount = keyProjectData.nightWorkApplyCount;
prevState[3].doingCount = keyProjectData?.nightWorkStartCount;
prevState[3].appliedCount = keyProjectData?.nightWorkApplyCount;
return [...prevState];
});

View File

@ -12,7 +12,7 @@ function VideoItem({ cameraNumber, videoName, getFixedCameraPlayUrl }) {
const loadPlayUrl = async () => {
setLoading(true);
setPlayUrl("");
const { data = {}, success } = await getFixedCameraPlayUrl({ indexCode: cameraNumber });
const { data, success } = await getFixedCameraPlayUrl({ indexCode: cameraNumber });
if (!isUnmounted && success)
setPlayUrl(data?.url || "");

View File

@ -26,7 +26,7 @@ function Camera(props) {
const [videoList, setVideoList] = useState([]);
const loadData = async () => {
const [dictionaryData, { data = [] }] = await Promise.all([
const [dictionaryData, { data }] = await Promise.all([
getDictionary({ dictValue: "videoLevel" }),
props.getFixedCameraVideoInfoPage({
portArea,
@ -36,7 +36,7 @@ function Camera(props) {
}),
]);
setLevelList(dictionaryData);
setVideoList(data);
setVideoList(data || []);
};
useEffect(() => {

View File

@ -16,13 +16,13 @@ function AreaAlarmPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
const { data } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
portArea,
corpinfoId: currentBranchOffice,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();
}, []);

View File

@ -14,7 +14,7 @@ function KeyWorkStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const [{ data: eightWorkData = [] }, { data: keyProjectData = [] }]
const [{ data: eightWorkData }, { data: keyProjectData }]
= await Promise.all([
props.getEightWorkInfoScreenDepartmentStatistics({
portArea,
@ -26,7 +26,7 @@ function KeyWorkStatsPanel(props) {
}),
]);
const departmentMap = new Map(
keyProjectData.map(item => [
(keyProjectData || []).map(item => [
item.departmentId,
{
departmentName: item.departmentName,
@ -36,7 +36,7 @@ function KeyWorkStatsPanel(props) {
},
]),
);
eightWorkData.forEach((item) => {
(eightWorkData || []).forEach((item) => {
const department = departmentMap.get(item.departmentId) || {
departmentName: item.departmentName,
fourNewHomeworkCount: 0,

View File

@ -27,11 +27,11 @@ function ClosedAreaStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getPrimeportClosedAreaCorpStat({ portArea, corpinfoId: currentBranchOffice });
const { data } = await props.getPrimeportClosedAreaCorpStat({ portArea, corpinfoId: currentBranchOffice });
setData(statistics.map(item => ({
...item,
count: item.field ? data[item.field] || 0 : item.count,
count: item.field ? (data || {})[item.field] || 0 : item.count,
})));
};

View File

@ -19,13 +19,13 @@ function GateApplicationPanel(props) {
const loadData = async (activeIndex) => {
setIsVisible(false);
const { data = [] } = await props[activeIndex === 1 ? "getPrimeportClosedAreaCarApplyScreenList" : "getPrimeportClosedAreaPersonApplyScreenList"]({
const { data } = await props[activeIndex === 1 ? "getPrimeportClosedAreaCarApplyScreenList" : "getPrimeportClosedAreaPersonApplyScreenList"]({
pageIndex: 1,
pageSize: 9999,
portArea,
corpinfoId: currentBranchOffice,
});
setData(data);
setData(data || []);
setIsVisible(true);
};

View File

@ -13,12 +13,12 @@ function DangerWorkDataPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const { data = [] }
const { data }
= await props.getEightWorkInfoScreenDangerWorkDataStatistics({
portArea,
corpinfoId: currentBranchOffice,
});
setData(data);
setData(data || []);
};
loadData();
}, []);

View File

@ -13,7 +13,7 @@ function DepartmentWorkPanel(props) {
const [data, setData] = useState([]);
useEffect(() => {
const loadData = async () => {
const [{ data: eightWorkData = [] }, { data: keyProjectData = [] }]
const [{ data: eightWorkData }, { data: keyProjectData }]
= await Promise.all([
props.getEightWorkInfoScreenDepartmentStatistics({
portArea,
@ -25,7 +25,7 @@ function DepartmentWorkPanel(props) {
}),
]);
const departmentMap = new Map(
keyProjectData.map(item => [
(keyProjectData || []).map(item => [
item.departmentId,
{
departmentName: item.departmentName,
@ -35,7 +35,7 @@ function DepartmentWorkPanel(props) {
},
]),
);
eightWorkData.forEach((item) => {
(eightWorkData || []).forEach((item) => {
const department = departmentMap.get(item.departmentId) || {
departmentName: item.departmentName,
fourNewHomeworkCount: 0,

View File

@ -54,7 +54,7 @@ function KeyWorkPanel(props) {
const [data, setData] = useState(defaultStatistics);
useEffect(() => {
const loadData = async () => {
const [{ data: eightWorkData = {} }, { data: keyProjectData = {} }]
const [{ data: eightWorkData }, { data: keyProjectData }]
= await Promise.all([
props.getEightWorkInfoDangerWorkStatistics({
portArea,
@ -68,21 +68,21 @@ function KeyWorkPanel(props) {
setData([
{
...defaultStatistics[0],
currentCount: keyProjectData.fourNewHomeworkStartCount,
doingCount: keyProjectData.fourNewHomeworkDoingCount,
archivedCount: keyProjectData.fourNewHomeworkArchiveCount,
currentCount: keyProjectData?.fourNewHomeworkStartCount,
doingCount: keyProjectData?.fourNewHomeworkDoingCount,
archivedCount: keyProjectData?.fourNewHomeworkArchiveCount,
},
{
...defaultStatistics[1],
currentCount: eightWorkData.doingCount,
doingCount: eightWorkData.workingCount,
archivedCount: eightWorkData.archivedCount,
currentCount: eightWorkData?.doingCount,
doingCount: eightWorkData?.workingCount,
archivedCount: eightWorkData?.archivedCount,
},
{
...defaultStatistics[2],
currentCount: keyProjectData.morePeopleStartCount,
doingCount: keyProjectData.morePeopleDoingCount,
archivedCount: keyProjectData.morePeopleArchiveCount,
currentCount: keyProjectData?.morePeopleStartCount,
doingCount: keyProjectData?.morePeopleDoingCount,
archivedCount: keyProjectData?.morePeopleArchiveCount,
},
]);
};

View File

@ -28,7 +28,7 @@ function KeyWorkStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const [{ data: eightWorkData = {} }, { data: keyProjectData = {} }]
const [{ data: eightWorkData }, { data: keyProjectData }]
= await Promise.all([
props.getEightWorkInfoDangerWorkStatistics({
portArea,
@ -42,18 +42,18 @@ function KeyWorkStatsPanel(props) {
setData([
{
...defaultStatistics[0],
currentCount: keyProjectData.fourNewHomeworkStartCount,
applyCount: keyProjectData.fourNewHomeworkApplyCount,
currentCount: keyProjectData?.fourNewHomeworkStartCount,
applyCount: keyProjectData?.fourNewHomeworkApplyCount,
},
{
...defaultStatistics[1],
currentCount: eightWorkData.workingCount,
applyCount: eightWorkData.appliedCount,
currentCount: eightWorkData?.workingCount,
applyCount: eightWorkData?.appliedCount,
},
{
...defaultStatistics[2],
currentCount: keyProjectData.morePeopleStartCount,
applyCount: keyProjectData.morePeopleApplyCount,
currentCount: keyProjectData?.morePeopleStartCount,
applyCount: keyProjectData?.morePeopleApplyCount,
},
]);
};

View File

@ -16,13 +16,13 @@ function FireAlarmRecordPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
const { data } = await props.getAlarmRecordScreenIotDeviceAlarmPage({
portArea,
corpinfoId: currentBranchOffice,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();
}, []);

View File

@ -17,13 +17,13 @@ function FireDeviceStatusPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getSensorDeviceFireSituation({
const { data } = await props.getSensorDeviceFireSituation({
portArea,
corpinfoId: currentBranchOffice,
});
setData({
totalCount: data.totalCount || 0,
statusList: data.statusList || [],
totalCount: data?.totalCount || 0,
statusList: data?.statusList || [],
});
};
loadData();

View File

@ -14,13 +14,13 @@ function VolunteerFireTeamPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getFireBrigadeMemberScreenList({
const { data } = await props.getFireBrigadeMemberScreenList({
portArea,
corpinfoId: currentBranchOffice,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();
}, []);

View File

@ -159,13 +159,13 @@ function ContractProjectPanel(props) {
useMount(() => {
const loadData = async () => {
const { data = [] } = await props.getProjectContractProjectStatistics({
const { data } = await props.getProjectContractProjectStatistics({
portArea,
corpinfoId: currentBranchOffice,
pageIndex: 1,
pageSize: 9999,
});
initEcharts(chartRef, chartInstance, data);
initEcharts(chartRef, chartInstance, data || []);
};
loadData();

View File

@ -15,21 +15,21 @@ function MobileMonitoringPanel(props) {
useEffect(() => {
const loadPlayUrl = async (cameraNumber) => {
const { data = {}, success } = await props.getFixedCameraPlayUrl({
const { data, success } = await props.getFixedCameraPlayUrl({
indexCode: cameraNumber,
});
if (success && data) {
setPlayUrl(data.url);
setPlayUrl(data?.url || "");
}
};
const loadCamera = async () => {
const { data = [] } = await props.getFixedCameraVideoInfoPage({
const { data } = await props.getFixedCameraVideoInfoPage({
portArea,
corpinfoId: currentBranchOffice,
pageIndex: 1,
pageSize: 9999,
});
if (data.length) {
if (data?.length) {
loadPlayUrl(data[Math.floor(randoms(0, data.length - 1))].cameraNumber);
}
};

View File

@ -14,11 +14,11 @@ function ProjectProgressPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getKeyProjectLargeScreenProjectProgress({
const { data } = await props.getKeyProjectLargeScreenProjectProgress({
portArea,
corpinfoId: currentBranchOffice,
});
setData(data);
setData(data || []);
};
loadData();
}, []);

View File

@ -21,14 +21,14 @@ function ProjectStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getProjectVisualProjectStatistics({
const { data } = await props.getProjectVisualProjectStatistics({
portArea,
corpinfoId: currentBranchOffice,
});
setData([
{ ...defaultStatistics[0], value: data.totalProjectCount },
{ ...defaultStatistics[1], value: data.pendingProjectCount },
{ ...defaultStatistics[2], value: data.executingProjectCount },
{ ...defaultStatistics[0], value: data?.totalProjectCount },
{ ...defaultStatistics[1], value: data?.pendingProjectCount },
{ ...defaultStatistics[2], value: data?.executingProjectCount },
]);
};
loadData();

View File

@ -54,8 +54,8 @@ const KeyProject = (props) => {
const [info, setInfo] = useState({});
const getData = async () => {
const { data = {} } = await props.keyProjectInfo({ id: props.id });
console.log(data);
const { data } = await props.keyProjectInfo({ id: props.id });
const files = await getFile({
eqType: UPLOAD_FILE_TYPE_ENUM["168"],
eqForeignKey: data.keyProjectId,

View File

@ -24,11 +24,11 @@ function BasicInfoPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getCorpInfoCorpUserSummary({ portArea });
const { data } = await props.getCorpInfoCorpUserSummary({ portArea });
const counts = [
data.branchCorpCount,
data.relatedCorpCount,
data.userCount,
data?.branchCorpCount,
data?.relatedCorpCount,
data?.userCount,
];
setData(

View File

@ -20,13 +20,13 @@ function PersonnelStatsPanel(props) {
const loadData = async (enterpriseType) => {
setIsVisible(false);
const { data = [] } = await props.getCorpInfoCorpUserStatisticPage({
const { data } = await props.getCorpInfoCorpUserStatisticPage({
portArea,
enterpriseType,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
setIsVisible(true);
};

View File

@ -51,9 +51,9 @@ function RiskStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getRiskPointCorpRiskLevel({ portArea });
const { data } = await props.getRiskPointCorpRiskLevel({ portArea });
const countByLevel = Object.fromEntries(
data.map(item => [item.level, item.count]),
(data || []).map(item => [item.level, item.count]),
);
setData(

View File

@ -21,11 +21,11 @@ function GateStatsPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getPrimeportMkmjStatistics({ portArea });
const { data } = await props.getPrimeportMkmjStatistics({ portArea });
// 根据固定区域模板重新生成状态,避免直接修改 React 保存的上一轮统计数据。
setData(statistics.map((item) => {
const currentStatistics = data.find(statisticsItem => statisticsItem.areaType === item.areaType) || {};
const currentStatistics = (data || []).find(statisticsItem => statisticsItem.areaType === item.areaType) || {};
return {
...item,

View File

@ -16,12 +16,12 @@ function WorkRecordPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = [] } = await props.getEightWorkInfoScreenWorkRecord({
const { data } = await props.getEightWorkInfoScreenWorkRecord({
portArea,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
};
loadData();

View File

@ -25,13 +25,13 @@ function WorkStatusPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getEightWorkInfoScreenStatusStatistics({
const { data } = await props.getEightWorkInfoScreenStatusStatistics({
portArea,
});
const counts = [
data.appliedCount,
data.approvingCount,
data.archivedCount,
data?.appliedCount,
data?.approvingCount,
data?.archivedCount,
];
setData(
defaultStatistics.map((item, index) => ({

View File

@ -115,10 +115,10 @@ function WorkTrendPanel(props) {
useMount(() => {
const loadData = async () => {
const { data = [] } = await props.getEightWorkInfoScreenWorkTrend({
const { data } = await props.getEightWorkInfoScreenWorkTrend({
portArea,
});
initEcharts(chartRef, chartInstance, formatWorkTrendData(data));
initEcharts(chartRef, chartInstance, formatWorkTrendData(data || []));
};
loadData();

View File

@ -17,13 +17,13 @@ function FireDeviceListPanel(props) {
useEffect(() => {
const loadData = async () => {
setIsVisible(false);
const { data = [] } = await props.getFirePointDeviceList({
const { data } = await props.getFirePointDeviceList({
portArea,
...queryParams,
pageIndex: 1,
pageSize: 9999,
});
setData(data);
setData(data || []);
setIsVisible(true);
};

View File

@ -23,10 +23,10 @@ function KeyProjectPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getKeyProjectLargeScreenProjectStatistics({
const { data } = await props.getKeyProjectLargeScreenProjectStatistics({
portArea,
});
const counts = [data.totalProjectCount, data.startCount];
const counts = [data?.totalProjectCount, data?.startCount];
setData(
defaultStatistics.map((item, index) => ({
...item,

View File

@ -21,10 +21,10 @@ function VideoLocationPanel(props) {
useEffect(() => {
const loadData = async () => {
const { data = {} } = await props.getFixedCameraVideoLocationStat({
const { data } = await props.getFixedCameraVideoLocationStat({
portArea,
});
const counts = [data.totalCount, data.onlineCount, data.offlineCount];
const counts = [data?.totalCount, data?.onlineCount, data?.offlineCount];
setData(
defaultStatistics.map((item, index) => ({
...item,

View File

@ -132,8 +132,8 @@ export default function useMapMethods(viewerRef, request) {
const addBranchOfficePoint = async (portArea = "", pointInfo = null) => {
let requestData = [];
if (!pointInfo) {
const { data = [] } = await request.getCorpInfoListAll({ eqPortArea: portArea, inType: [0, 1, 2, 6] });
requestData = data;
const { data } = await request.getCorpInfoListAll({ eqPortArea: portArea, inType: [0, 1, 2, 6] });
requestData = data || [];
}
mitt.emit(changeCoverMaskVisibleMittKey, true);
let branchOfficePoint = [];