Browse Source

修复点位管理列表渲染字段

pm 3 months ago
parent
commit
9fd552cdbf
1 changed files with 46 additions and 5 deletions
  1. 46 5
      src/components/SegregationPointManagement.tsx

+ 46 - 5
src/components/SegregationPointManagement.tsx

@@ -2,11 +2,12 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';
 import { Plus, Search, RefreshCw, Edit2, Trash2 } from 'lucide-react';
 import { segregationPointApi, SegregationPointVO, PageParam } from '../api/spm/index';
 import { dictDataApi } from '../api/DictData';
+import { postApi, PostVO } from '../api/Post';
 import { toast } from 'sonner';
 import { Modal, Table, Input, Button, Select, TreeSelect, Space, Image, Switch } from 'antd';
 import { ExclamationCircleOutlined } from '@ant-design/icons';
 import type { ColumnsType } from 'antd/es/table';
-import { getStrDictOptions, setDictOptions, DICT_TYPE } from '../utils/dict';
+import { getStrDictOptions, setDictOptions, getDictLabel, DICT_TYPE } from '../utils/dict';
 import SegregationPointForm, { SegregationPointFormRef } from './SegregationPointForm';
 import { Button as UIButton } from './ui/button';
 import PermissionWrapper from './PermissionWrapper';
@@ -39,6 +40,8 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
   const [machineryOptions, setMachineryOptions] = useState<any[]>([]);
   const [lotoOptions, setLotoOptions] = useState<Array<{ label: string; value: number }>>([]);
   const [powerTypeOptions, setPowerTypeOptions] = useState<Array<{ label: string; value: string }>>([]);
+  /** 岗位 id -> name,用于列表岗位列回显 */
+  const [postNameMap, setPostNameMap] = useState<Map<number, string>>(new Map());
 
   const formRef = useRef<SegregationPointFormRef>(null);
 
@@ -86,13 +89,44 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
   useEffect(() => {
     const initData = async () => {
       try {
-        // 获取岗位数据 - 接口已废弃,保留空数组
+        // 页面初始化即调用岗位接口,存储 id -> name,供列表岗位列回显
+        try {
+          const postRes = await postApi.getPostPage({ pageNo: 1, pageSize: -1 });
+          const raw = (postRes as any)?.data ?? postRes;
+          const postList: PostVO[] = Array.isArray(raw?.list) ? raw.list : Array.isArray(raw?.records) ? raw.records : Array.isArray(raw) ? raw : [];
+          const map = new Map<number, string>();
+          postList.forEach((item: any) => {
+            const id = item.id != null ? Number(item.id) : NaN;
+            const name = item.name != null ? String(item.name) : '';
+            if (!Number.isNaN(id) && name) map.set(id, name);
+          });
+          setPostNameMap(map);
+        } catch (postError) {
+          console.error('获取岗位列表失败:', postError);
+          setPostNameMap(new Map());
+        }
         setDeptOptions([]);
 
         // 锁定站和设备/工艺接口已废弃,设置为空数组
         setLotoOptions([]);
         setMachineryOptions([]);
 
+        // 获取点位分组数据(从字典 point_group,用于列表列回显)
+        try {
+          const pointGroupRes = await dictDataApi.getDictDataPage({ pageNo: 1, pageSize: -1, dictType: DICT_TYPE.POINT_GROUP });
+          const pgData = (pointGroupRes as any)?.list ?? (pointGroupRes as any)?.data?.list ?? (Array.isArray(pointGroupRes) ? pointGroupRes : []);
+          const pgList = Array.isArray(pgData) ? pgData : [];
+          setDictOptions(DICT_TYPE.POINT_GROUP, pgList.map((item: any) => ({
+            dictType: DICT_TYPE.POINT_GROUP,
+            label: item.label,
+            value: item.value,
+            colorType: item.colorType || '',
+            cssClass: item.cssClass || '',
+          })));
+        } catch (pgError) {
+          console.error('获取点位分组字典失败:', pgError);
+        }
+
         // 获取能量源数据(从字典 power_source)
         try {
           const powerRes = await dictDataApi.getDictDataPage({ pageNo: 1, pageSize: -1, dictType: DICT_TYPE.POWER_SOURCE });
@@ -236,14 +270,21 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
     },
     {
       title: t('table.position'),
-      dataIndex: 'workstationName',
+      dataIndex: 'workstationId',
       align: 'center',
+      render: (value: number | string | undefined) => {
+        if (value == null || value === '') return '-';
+        const id = Number(value);
+        if (Number.isNaN(id)) return '-';
+        return postNameMap.get(id) ?? '-';
+      },
     },
     {
       title: t('form.pointGroup'),
-      dataIndex: 'lotoName',
+      dataIndex: 'lotoId',
       width: 120,
       align: 'center',
+      render: (value: number | null | undefined) => (value != null ? getDictLabel(DICT_TYPE.POINT_GROUP, value) : null) || '-',
     },
     {
       title: t('table.segregationPointSerial'),
@@ -344,7 +385,7 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
         </div>
       ),
     },
-  ], [t, i18n.language, powerTypeOptions]);
+  ], [t, i18n.language, powerTypeOptions, postNameMap]);
 
   return (
     <div className="p-6 space-y-4">