From fcf0c2bbfae0a82d516dfa8b71f97e6ea817e0b4 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期二, 03 二月 2026 09:16:29 +0800
Subject: [PATCH] 任务管理查询明细修正
---
rsf-admin/src/page/basicInfo/basStation/CrossZoneAreaField.jsx | 76 ++++++++++++++++++++++++++++----------
1 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/rsf-admin/src/page/basicInfo/basStation/CrossZoneAreaField.jsx b/rsf-admin/src/page/basicInfo/basStation/CrossZoneAreaField.jsx
index fc25ff4..f81d839 100644
--- a/rsf-admin/src/page/basicInfo/basStation/CrossZoneAreaField.jsx
+++ b/rsf-admin/src/page/basicInfo/basStation/CrossZoneAreaField.jsx
@@ -1,4 +1,4 @@
-import * as React from 'react';
+import { useState, useRef, useEffect, useMemo, useCallback } from 'react';
import { Stack, Chip, Dialog, DialogTitle, DialogContent, IconButton, CircularProgress } from '@mui/material';
import { useTranslate, useRecordContext } from 'react-admin';
import CloseIcon from '@mui/icons-material/Close';
@@ -7,9 +7,9 @@
const CrossZoneAreaField = () => {
const translate = useTranslate();
const record = useRecordContext();
- const [open, setOpen] = React.useState(false);
- const [areaNames, setAreaNames] = React.useState([]);
- const [loading, setLoading] = React.useState(false);
+ const [open, setOpen] = useState(false);
+ const [areaNames, setAreaNames] = useState([]);
+ const [loading, setLoading] = useState(false);
const handleOpen = () => {
setOpen(true);
@@ -20,13 +20,48 @@
};
const fetchAreaNames = async () => {
- if (!record?.areaIds || record.areaIds.length === 0) return;
-
+ const areasData = record?.areaIds || record?.areas;
+ if (!areasData || areasData.length === 0) return;
+
setLoading(true);
- try {
- const res = await request.post(`/warehouseAreas/many/${record.areaIds.join(',')}`);
+ try {
+ // 鎻愬彇鎺掑簭淇℃伅鍜孖D
+ // Old format: [1, 2, 3] (array of integers)
+ // New format: [{id: 1, sort: 1}, {id: 2, sort: 2}] (array of objects)
+ const isObjectArray = areasData.length > 0 &&
+ typeof areasData[0] === 'object' &&
+ areasData[0] !== null &&
+ 'id' in areasData[0];
+
+ let areaIds = [];
+ let sortMap = new Map(); // 瀛樺偍 id -> sort 鐨勬槧灏�
+
+ if (isObjectArray) {
+ // 瀵硅薄鏁扮粍鏍煎紡锛屾彁鍙朓D鍜屾帓搴忎俊鎭�
+ areaIds = areasData.map(area => {
+ const id = area.id;
+ sortMap.set(id, area.sort || 0);
+ return id;
+ });
+ } else {
+ // 绾疘D鏁扮粍鏍煎紡
+ areaIds = areasData.map(id => Number(id));
+ }
+
+ const res = await request.post(`/warehouseAreas/many/${areaIds.join(',')}`);
if (res?.data?.code === 200) {
- setAreaNames(res.data.data || []);
+ let areas = res.data.data || [];
+
+ // 濡傛灉鏈夋帓搴忎俊鎭紝鎸夋帓搴忓�兼帓搴�
+ if (sortMap.size > 0) {
+ areas = areas.sort((a, b) => {
+ const sortA = sortMap.get(a.id) || 0;
+ const sortB = sortMap.get(b.id) || 0;
+ return sortA - sortB;
+ });
+ }
+
+ setAreaNames(areas);
}
} catch (error) {
console.error('鑾峰彇鍖哄煙鍚嶇О澶辫触:', error);
@@ -35,11 +70,12 @@
}
};
- React.useEffect(() => {
- if (record?.areaIds && record.areaIds.length !== 0 && record.areaIds.length > 0) {
+ useEffect(() => {
+ const areasData = record?.areaIds || record?.areas;
+ if (areasData && areasData.length > 0) {
fetchAreaNames();
}
- }, [record]);
+ }, [record]);
if (loading) {
return <CircularProgress size={20} />;
@@ -47,10 +83,10 @@
return (
<>
- <Stack
- direction="row"
- gap={1}
- flexWrap="wrap"
+ <Stack
+ direction="row"
+ gap={1}
+ flexWrap="wrap"
onClick={handleOpen}
sx={{ cursor: 'pointer' }}
>
@@ -67,16 +103,16 @@
label={`+${areaNames.length - 1}`}
/>
)}
- {areaNames.length === 0 && record.areaIds && record.areaIds.length > 0 && (
+ {areaNames.length === 0 && (record?.areaIds || record?.areas) && (record?.areaIds || record?.areas).length > 0 && (
<Chip
size="small"
- label={`${record.areaIds.length} 涓尯鍩焋}
+ label={`${(record?.areaIds || record?.areas).length} 涓尯鍩焋}
/>
)}
</Stack>
- <Dialog
- open={open}
+ <Dialog
+ open={open}
onClose={handleClose}
maxWidth="md"
fullWidth
--
Gitblit v1.9.1