From db475501a4073d48f2fd804ca6428b0f86fe6332 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 08 五月 2025 18:14:59 +0800
Subject: [PATCH] 动态字段显示问题修复

---
 rsf-admin/src/page/locItem/LocItemList.jsx |  117 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 81 insertions(+), 36 deletions(-)

diff --git a/rsf-admin/src/page/locItem/LocItemList.jsx b/rsf-admin/src/page/locItem/LocItemList.jsx
index 8822317..6469f7e 100644
--- a/rsf-admin/src/page/locItem/LocItemList.jsx
+++ b/rsf-admin/src/page/locItem/LocItemList.jsx
@@ -29,10 +29,11 @@
     NumberInput,
     ReferenceInput,
     ReferenceArrayInput,
+    useRefresh,
     AutocompleteInput,
     DeleteButton,
 } from 'react-admin';
-import { Box, Typography, Card, Stack } from '@mui/material';
+import { Box, Typography, Card, Stack, LinearProgress } from '@mui/material';
 import { styled } from '@mui/material/styles';
 import LocItemCreate from "./LocItemCreate";
 import LocItemPanel from "./LocItemPanel";
@@ -43,6 +44,7 @@
 import MyField from "../components/MyField";
 import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting';
 import * as Common from '@/utils/common';
+import request from '@/utils/request';
 
 const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
     '& .css-1vooibu-MuiSvgIcon-root': {
@@ -95,7 +97,6 @@
 
 const LocItemList = () => {
     const translate = useTranslate();
-
     const [createDialog, setCreateDialog] = useState(false);
     const [drawerVal, setDrawerVal] = useState(false);
 
@@ -124,40 +125,7 @@
                 )}
                 perPage={DEFAULT_PAGE_SIZE}
             >
-                <StyledDatagrid
-                    preferenceKey='locItem'
-                    bulkActionButtons={false}
-                    rowClick={false}
-                    expand={false}
-                    expandSingle={true}
-                    omit={['id', 'createTime','locId','orderId', 'orderItemId', 'matnrId', 'splrBatch','workQty','qty', 'createBy', 'memo','fieldsIndex']}
-                   
-                >
-                    <NumberField source="id" />
-                    <NumberField source="locId" label="table.field.locItem.locId" />
-                    <TextField source="locCode" label="table.field.locItem.locCode" />
-                    <NumberField source="orderId" label="table.field.locItem.orderId" />
-                    <TextField source="type$" label="table.field.locItem.type" />
-                    <NumberField source="orderItemId" label="table.field.locItem.orderItemId" />
-                    <NumberField source="wkType$" label="table.field.locItem.wkType" />
-                    <NumberField source="matnrId" label="table.field.locItem.matnrId" />
-                    <TextField source="matnrCode" label="table.field.locItem.matnrCode" />
-                    <TextField source="maktx" label="table.field.locItem.maktx" />
-                    <TextField source="spec" label="table.field.locItem.spec" />
-                    <TextField source="model" label="table.field.locItem.model" />
-                    <TextField source="batch" label="table.field.locItem.batch" />
-                    <TextField source="trackCode" label="table.field.locItem.trackCode" />
-                    <TextField source="unit" label="table.field.locItem.unit" />
-                    <NumberField source="anfme" label="table.field.locItem.anfme" />
-                    <TextField source="splrBatch" label="table.field.locItem.splrBatch" />
-                    <TextField source="fieldsIndex" label="table.field.locItem.fieldsIndex" />
-                    <TextField source="updateBy$" label="common.field.updateBy"  />
-                    <DateField source="updateTime" label="common.field.updateTime" showTime />
-                    <TextField source="createBy$" label="common.field.createBy" />
-                    <DateField source="createTime" label="common.field.createTime" showTime />
-                    <BooleanField source="statusBool" label="common.field.status" sortable={false} />
-                    <TextField source="memo" label="common.field.memo" sortable={false} />
-                </StyledDatagrid>
+                <DynamicFields />
             </List>
             <LocItemCreate
                 open={createDialog}
@@ -174,3 +142,80 @@
 }
 
 export default LocItemList;
+
+
+const DynamicFields = (props) => {
+    const translate = useTranslate();
+    const notify = useNotify();
+    const [columns, setColumns] = useState([]);
+    const { isLoading } = useListContext();
+    const refresh = useRefresh();
+    useEffect(() => {
+        getDynamicFields();
+    }, []);
+
+    const getDynamicFields = async () => {
+        const { data: { code, data, msg }, } = await request.get("/fields/enable/list");
+        if (code == 200) {
+            const arr = [
+                <NumberField source="id" />,
+                <NumberField source="locId" label="table.field.locItem.locId" />,
+                <TextField source="locCode" label="table.field.locItem.locCode" />,
+                <NumberField source="orderId" label="table.field.locItem.orderId" />,
+                <TextField source="type$" label="table.field.locItem.type" />,
+                <NumberField source="orderItemId" label="table.field.locItem.orderItemId" />,
+                <NumberField source="wkType$" label="table.field.locItem.wkType" />,
+                <NumberField source="matnrId" label="table.field.locItem.matnrId" />,
+                <TextField source="matnrCode" label="table.field.locItem.matnrCode" />,
+                <TextField source="maktx" label="table.field.locItem.maktx" />,
+                <TextField source="spec" label="table.field.locItem.spec" />,
+                <TextField source="model" label="table.field.locItem.model" />,
+                <TextField source="batch" label="table.field.locItem.batch" />,
+                <TextField source="trackCode" label="table.field.locItem.trackCode" />,
+                <TextField source="unit" label="table.field.locItem.unit" />,
+                <NumberField source="anfme" label="table.field.locItem.anfme" />,
+                <TextField source="splrBatch" label="table.field.locItem.splrBatch" />,
+                <TextField source="fieldsIndex" label="table.field.locItem.fieldsIndex" />,
+            ]
+            const fields = data.map(el => <TextField key={el.fields} source={`extendFields.[${el.fields}]`} label={el.fieldsAlise} />)
+            const lastArr = [
+                <TextField source="updateBy$" label="common.field.updateBy" />,
+                <DateField source="updateTime" label="common.field.updateTime" showTime />,
+                <TextField source="createBy$" label="common.field.createBy" />,
+                <DateField source="createTime" label="common.field.createTime" showTime />,
+                <BooleanField source="statusBool" label="common.field.status" sortable={false} />,
+                <TextField source="memo" label="common.field.memo" sortable={false} />,
+            ]
+            setColumns([...arr, ...fields, ...lastArr]);
+        } else {
+            notify(msg);
+        }
+    }
+
+    return (
+        <Box sx={{ position: 'relative', minHeight: "60vh", }}>
+            {isLoading && (
+                <LinearProgress
+                    sx={{
+                        height: "2px",
+                        position: 'absolute',
+                        top: 0,
+                        left: 0,
+                        right: 0,
+                    }}
+                />
+            )}
+            {columns.length > 0 &&
+                <StyledDatagrid
+                    preferenceKey='locItem'
+                    bulkActionButtons={false}
+                    rowClick={false}
+                    expand={false}
+                    expandSingle={true}
+                    omit={['id', 'createTime', 'locId', 'orderId', 'orderItemId', 'matnrId', 'splrBatch', 'workQty', 'qty', 'createBy', 'memo', 'fieldsIndex']}
+                >
+                    {columns.map((column) => column)}
+                </StyledDatagrid>}
+        </Box>
+    )
+}
\ No newline at end of file

--
Gitblit v1.9.1