|
|
@@ -1,12 +1,11 @@
|
|
|
import React, { useState, useImperativeHandle, forwardRef, useEffect } from 'react';
|
|
|
-import { Modal, Form, Input, Select, TreeSelect, Upload, Image, Row, Col, message } from 'antd';
|
|
|
+import { Modal, Form, Input, Select, Upload, Image, Row, Col, message } from 'antd';
|
|
|
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
|
import type { UploadFile } from 'antd/es/upload/interface';
|
|
|
import { segregationPointApi, SegregationPointVO } from '../api/spm/index';
|
|
|
-import { marsDeptApi } from '../api/marsdept/index';
|
|
|
+import { postApi, PostVO } from '../api/Post';
|
|
|
import { lotoStationApi } from '../api/lotoStation/index';
|
|
|
import { loginApi } from '../api/Login';
|
|
|
-import { handleTree } from '../utils/tree';
|
|
|
import { getStrDictOptions, DICT_TYPE } from '../utils/dict';
|
|
|
import { toast } from 'sonner';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
@@ -31,7 +30,7 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
const [imageMap, setImageMap] = useState<Record<number, string>>({});
|
|
|
|
|
|
// 下拉选项数据
|
|
|
- const [deptOptions, setDeptOptions] = useState<any[]>([]);
|
|
|
+ const [postOptions, setPostOptions] = useState<Array<{ label: string; value: number }>>([]);
|
|
|
const [lotoOptions, setLotoOptions] = useState<Array<{ label: string; value: number }>>([]);
|
|
|
const powerTypeOptions = getStrDictOptions(DICT_TYPE.POWER_TYPE);
|
|
|
|
|
|
@@ -83,9 +82,16 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
const loadOptionsData = async () => {
|
|
|
try {
|
|
|
// 获取岗位数据
|
|
|
- const deptRes = await marsDeptApi.listMarsDept({ pageNo: 1, pageSize: -1 });
|
|
|
- const deptTreeData = handleTree(deptRes.list, 'id', 'parentId');
|
|
|
- setDeptOptions(convertToTreeSelectData(deptTreeData, 'workstationName'));
|
|
|
+ const postRes = await postApi.getPostPage({ pageNo: 1, pageSize: -1 });
|
|
|
+ const data = (postRes as any)?.data || postRes;
|
|
|
+ const postList = data?.list || [];
|
|
|
+ const options = postList
|
|
|
+ .filter((item: PostVO) => item.id !== undefined)
|
|
|
+ .map((item: PostVO) => ({
|
|
|
+ label: item.name,
|
|
|
+ value: item.id!,
|
|
|
+ }));
|
|
|
+ setPostOptions(options);
|
|
|
|
|
|
// 获取锁定站数据
|
|
|
const lotoRes = await lotoStationApi.listLoto({ pageNo: 1, pageSize: -1 });
|
|
|
@@ -95,6 +101,7 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
})));
|
|
|
} catch (error) {
|
|
|
console.error('加载选项数据失败:', error);
|
|
|
+ toast.error('加载选项数据失败');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -136,15 +143,6 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
return -1;
|
|
|
};
|
|
|
|
|
|
- // 转换树形数据为 TreeSelect 格式
|
|
|
- const convertToTreeSelectData = (treeData: any[], labelKey: string): any[] => {
|
|
|
- return treeData.map(item => ({
|
|
|
- title: item[labelKey],
|
|
|
- value: item.id,
|
|
|
- key: item.id,
|
|
|
- children: item.children ? convertToTreeSelectData(item.children, labelKey) : undefined,
|
|
|
- }));
|
|
|
- };
|
|
|
|
|
|
// 选择隔离点图标
|
|
|
const selectIcon = (imageUrl: string, index: number) => {
|
|
|
@@ -265,7 +263,6 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
<Form.Item
|
|
|
label={t('form.lotoStation')}
|
|
|
name="lotoId"
|
|
|
- rules={[{ required: true, message: t('form.lotoStationRequired') }]}
|
|
|
>
|
|
|
<Select placeholder={t('form.lotoStationPlaceholder')} options={lotoOptions} />
|
|
|
</Form.Item>
|
|
|
@@ -276,9 +273,10 @@ const SegregationPointForm = forwardRef<SegregationPointFormRef, SegregationPoin
|
|
|
name="workstationId"
|
|
|
rules={[{ required: true, message: t('form.workstationRequired') }]}
|
|
|
>
|
|
|
- <TreeSelect
|
|
|
- treeData={deptOptions}
|
|
|
+ <Select
|
|
|
placeholder={t('form.workstationPlaceholder')}
|
|
|
+ allowClear
|
|
|
+ options={postOptions}
|
|
|
style={{ width: '100%' }}
|
|
|
/>
|
|
|
</Form.Item>
|