|
@@ -1,11 +1,10 @@
|
|
|
import React, { useState, useImperativeHandle, forwardRef, useEffect } from 'react';
|
|
import React, { useState, useImperativeHandle, forwardRef, useEffect } from 'react';
|
|
|
-import { Modal, Form, Input, Select, Radio, Spin, Row, Col, TreeSelect } from 'antd';
|
|
|
|
|
|
|
+import { Modal, Form, Input, Select, Radio, Spin, Row, Col } from 'antd';
|
|
|
import { lockCabinetApi, LockCabinetVO } from '../../api/lockCabinet';
|
|
import { lockCabinetApi, LockCabinetVO } from '../../api/lockCabinet';
|
|
|
import { hardwareApi } from '../../api/Hardware';
|
|
import { hardwareApi } from '../../api/Hardware';
|
|
|
-import { workstationApi, WorkstationVO } from '../../api/workstation';
|
|
|
|
|
|
|
+import { postApi, PostVO } from '../../api/Post';
|
|
|
import { toast } from 'sonner';
|
|
import { toast } from 'sonner';
|
|
|
import { DICT_TYPE, getStrDictOptions } from '../../utils/dict';
|
|
import { DICT_TYPE, getStrDictOptions } from '../../utils/dict';
|
|
|
-import { handleTree, TreeNode } from '../../utils/tree';
|
|
|
|
|
import UploadImg from './UploadImg';
|
|
import UploadImg from './UploadImg';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
@@ -26,7 +25,7 @@ const LockCabinetForm = forwardRef<LockCabinetFormRef, LockCabinetFormProps>(({
|
|
|
const [currentId, setCurrentId] = useState<number | undefined>();
|
|
const [currentId, setCurrentId] = useState<number | undefined>();
|
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
|
const [hardwareOptions, setHardwareOptions] = useState<{ label: string; value: number }[]>([]);
|
|
const [hardwareOptions, setHardwareOptions] = useState<{ label: string; value: number }[]>([]);
|
|
|
- const [workstationOptions, setWorkstationOptions] = useState<TreeNode[]>([]);
|
|
|
|
|
|
|
+ const [postOptions, setPostOptions] = useState<{ label: string; value: number }[]>([]);
|
|
|
const [isOnlineOptions] = useState(() => getStrDictOptions(DICT_TYPE.ISONLINE_STATUS));
|
|
const [isOnlineOptions] = useState(() => getStrDictOptions(DICT_TYPE.ISONLINE_STATUS));
|
|
|
const [statusOptions] = useState(() => getStrDictOptions(DICT_TYPE.CANBINET_STATUS));
|
|
const [statusOptions] = useState(() => getStrDictOptions(DICT_TYPE.CANBINET_STATUS));
|
|
|
|
|
|
|
@@ -45,17 +44,22 @@ const LockCabinetForm = forwardRef<LockCabinetFormRef, LockCabinetFormProps>(({
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 获取岗位列表
|
|
// 获取岗位列表
|
|
|
- const getWorkstationList = async () => {
|
|
|
|
|
|
|
+ const getPostList = async () => {
|
|
|
try {
|
|
try {
|
|
|
- const response = await workstationApi.listMarsDept({ pageNo: 1, pageSize: -1 });
|
|
|
|
|
- // 过滤掉 id 为 undefined 的项,并转换为 TreeNode 类型
|
|
|
|
|
- const validList = response.list
|
|
|
|
|
- .filter(item => item.id !== undefined)
|
|
|
|
|
- .map(item => ({ ...item, id: item.id! })) as TreeNode[];
|
|
|
|
|
- const treeData = handleTree(validList, 'id', 'parentId');
|
|
|
|
|
- setWorkstationOptions(treeData);
|
|
|
|
|
|
|
+ const response = await postApi.getPostPage({ pageNo: 1, pageSize: -1 });
|
|
|
|
|
+ const data = (response as any)?.data || response;
|
|
|
|
|
+ const postList = data?.list || [];
|
|
|
|
|
+ // 转换为选项格式
|
|
|
|
|
+ const options = postList
|
|
|
|
|
+ .filter((item: PostVO) => item.id !== undefined)
|
|
|
|
|
+ .map((item: PostVO) => ({
|
|
|
|
|
+ label: item.name,
|
|
|
|
|
+ value: item.id!,
|
|
|
|
|
+ }));
|
|
|
|
|
+ setPostOptions(options);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('获取岗位列表失败:', error);
|
|
console.error('获取岗位列表失败:', error);
|
|
|
|
|
+ toast.error('获取岗位列表失败');
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -78,7 +82,7 @@ const LockCabinetForm = forwardRef<LockCabinetFormRef, LockCabinetFormProps>(({
|
|
|
setCurrentId(id);
|
|
setCurrentId(id);
|
|
|
|
|
|
|
|
// 加载选项数据
|
|
// 加载选项数据
|
|
|
- await Promise.all([getHardwareList(), getWorkstationList()]);
|
|
|
|
|
|
|
+ await Promise.all([getHardwareList(), getPostList()]);
|
|
|
|
|
|
|
|
// 修改时,先调详情接口获取数据详情
|
|
// 修改时,先调详情接口获取数据详情
|
|
|
if (id) {
|
|
if (id) {
|
|
@@ -178,15 +182,6 @@ const LockCabinetForm = forwardRef<LockCabinetFormRef, LockCabinetFormProps>(({
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 转换树形数据为TreeSelect格式
|
|
|
|
|
- const convertToTreeSelectData = (nodes: TreeNode[]): any[] => {
|
|
|
|
|
- return nodes.map(node => ({
|
|
|
|
|
- title: (node as any).workstationName || (node as any).name,
|
|
|
|
|
- value: node.id,
|
|
|
|
|
- key: node.id,
|
|
|
|
|
- children: node.children ? convertToTreeSelectData(node.children) : undefined,
|
|
|
|
|
- }));
|
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<Modal
|
|
<Modal
|
|
@@ -224,10 +219,10 @@ const LockCabinetForm = forwardRef<LockCabinetFormRef, LockCabinetFormProps>(({
|
|
|
name="workstationId"
|
|
name="workstationId"
|
|
|
rules={[{ required: true, message: t('form.workstationIdRequired') }]}
|
|
rules={[{ required: true, message: t('form.workstationIdRequired') }]}
|
|
|
>
|
|
>
|
|
|
- <TreeSelect
|
|
|
|
|
- treeData={convertToTreeSelectData(workstationOptions)}
|
|
|
|
|
|
|
+ <Select
|
|
|
placeholder={t('form.workstationPlaceholder')}
|
|
placeholder={t('form.workstationPlaceholder')}
|
|
|
- treeDefaultExpandAll
|
|
|
|
|
|
|
+ allowClear
|
|
|
|
|
+ options={postOptions}
|
|
|
/>
|
|
/>
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
|
|
|