diff --git a/src/api/equipInfo/index.js b/src/api/equipInfo/index.js index 2bf0871..4382475 100644 --- a/src/api/equipInfo/index.js +++ b/src/api/equipInfo/index.js @@ -1,54 +1,33 @@ import { declareRequest } from "@cqsjjb/jjb-dva-runtime"; -import { - fromEquipForm, - fromPageResponse, - fromSingleResponse, - mapEquipEnableFlag, - toEquipForm, - toPageQuery, -} from "../enterpriseInfo/adapter"; -import { apiGet, apiPost, apiPostDelete, safeAction, safePageResult } from "../enterpriseInfo/http"; -export const equipInfoList = declareRequest("equipInfoLoading", safePageResult(async (params) => { - const query = toPageQuery(params, { - likeDeviceName: "deviceName", - instrumentType: "instrumentType", - deviceType: "deviceType", - enableStatus: "enableFlag", - }); - if (query.enableFlag !== undefined && query.enableFlag !== "") { - query.enableFlag = mapEquipEnableFlag(query.enableFlag); - } - const res = await apiGet("/safetyEval/org-equipment/page", query); - return fromPageResponse(res, toEquipForm); -})); +export const equipInfoList = declareRequest( + "equipInfoLoading", + "Get > /safetyEval/org-equipment/page", + "equipInfoList: [] | res.data || [] & equipInfoTotal: 0 | res.data?.total || 0", +); -export const equipInfoGet = declareRequest("equipInfoLoading", safeAction(async (params) => { - const res = await apiGet("/safetyEval/org-equipment/get", { id: params.id }); - return fromSingleResponse(res, toEquipForm); -})); +export const equipInfoGet = declareRequest( + "equipInfoLoading", + "Get > /safetyEval/org-equipment/get", + "equipInfoDetail: {} | res.data || {}", +); -export const equipInfoAdd = declareRequest("equipInfoLoading", safeAction(async (values) => { - const res = await apiPost("/safetyEval/org-equipment/save", fromEquipForm(values)); - return fromSingleResponse(res, toEquipForm); -})); +export const equipInfoAdd = declareRequest( + "equipInfoLoading", + "Post > @/safetyEval/org-equipment/save", +); -export const equipInfoEdit = declareRequest("equipInfoLoading", safeAction(async (values) => { - const res = await apiPost("/safetyEval/org-equipment/modify", fromEquipForm(values)); - return fromSingleResponse(res, toEquipForm); -})); +export const equipInfoEdit = declareRequest( + "equipInfoLoading", + "Post > @/safetyEval/org-equipment/modify", +); -export const equipInfoRemove = declareRequest("equipInfoLoading", safeAction(async ({ id }) => { - return apiPostDelete("/safetyEval/org-equipment/delete", id); -})); +export const equipInfoRemove = declareRequest( + "equipInfoLoading", + "Post > @/safetyEval/org-equipment/delete", +); -export const equipInfoToggleStatus = declareRequest("equipInfoLoading", safeAction(async ({ id }) => { - const res = await apiGet("/safetyEval/org-equipment/get", { id }); - const data = res?.data || {}; - const nextFlag = Number(data.enableFlag) === 1 ? 2 : 1; - return apiPost("/safetyEval/org-equipment/modify", { - ...data, - id, - enableFlag: nextFlag, - }); -})); +export const equipInfoToggleStatus = declareRequest( + "equipInfoLoading", + "Get > /safetyEval/org-equipment/modify", +); \ No newline at end of file diff --git a/src/components/FilePreviewModal/index.js b/src/components/FilePreviewModal/index.js index 55198a4..beaab0f 100644 --- a/src/components/FilePreviewModal/index.js +++ b/src/components/FilePreviewModal/index.js @@ -70,7 +70,7 @@ export default function FilePreviewModal({ return ( { + props.equipInfoList({ + ...router.query, + }); + }; useEffect(() => { - getData(); + searchForm.setFieldsValue(router.query); + handleSearch(); }, []); const onDelete = (id) => { @@ -36,26 +42,26 @@ function EquipInfoPage(props) { const res = await props.equipInfoRemove({ id }); if (res?.success !== false) { message.success("删除成功"); - getData(); + handleSearch(); } }, }); }; const onToggleStatus = (id, record) => { - const enabled = isEquipEnabled(record); + const enabled = record.enableFlag === 1; Modal.confirm({ title: "提示", content: enabled ? "是否停用" : "是否启用", okText: "是", cancelText: "否", onOk: async () => { - const res = await props.equipInfoToggleStatus({ id }); + const nextFlag = enabled ? 2 : 1; + const res = await props.equipInfoToggleStatus({ id, enableFlag: nextFlag }); if (res?.success !== false) { message.success("操作成功"); - await getData(); - } - else { + handleSearch(); + } else { message.error(res?.message || "操作失败"); } }, @@ -63,98 +69,110 @@ function EquipInfoPage(props) { }; return ( - - 装备信息管理 -
- 实现对评价机构内装备信息的维护管理。 -
- - } - > - + + + , + + + , + + + , + + + 启用 + 禁用 + + , ]} - onFinish={getData} + onReset={() => { + router.query = { ...router.query, current: 1, size: 10 }; + handleSearch(); + }} + onFinish={() => { + router.query = { ...router.query, current: 1, size: 10 }; + handleSearch(); + }} /> ( - - )} + rowKey="id" columns={[ - { title: "设备名称", dataIndex: "deviceName" }, - { title: "设备型号", dataIndex: "model" }, + { title: "设备名称", dataIndex: "deviceName", width: 200, ellipsis: true }, + { title: "设备型号", dataIndex: "deviceModel" }, { title: "仪器类型", dataIndex: "instrumentType" }, { title: "设备类型", dataIndex: "deviceType" }, - { title: "厂家", dataIndex: "manufacturer" }, + { title: "厂家", dataIndex: "manufacturer", ellipsis: true, width: 180 }, { title: "校准单位", dataIndex: "calibrationUnit" }, - { title: "校准初值", dataIndex: "calibrationInitialValue" }, + { title: "校准初值", dataIndex: "calibrationInitValue", width: 100, }, { title: "设备状态", width: 90, - render: (_, record) => (isEquipEnabled(record) ? "启用" : "禁用"), + render: (_, record) => { + const enabled = record.enableFlag === 1; + return {enabled ? "启用" : "禁用"}; + }, }, { title: "操作", - width: 260, + width: 180, render: (_, record) => ( - - - - - - + + ), }, ]} + dataSource={dataSource} + scroll={{ y: props.scrollY }} + loading={loading} + pagination={{ + total, + showSizeChanger: true, + showQuickJumper: true, + showTotal: (t) => `共 ${t} 条`, + current: router.query.current || 1, + pageSize: router.query.size || 10, + onChange: (page, pageSize) => { + router.query = { ...router.query, current: page, size: pageSize }; + handleSearch(); + }, + }} /> {formModalOpen && ( { setFormModalOpen(false); setCurrentId(""); }} - onSuccess={getData} + onSuccess={handleSearch} /> )} {viewModalOpen && ( { setViewModalOpen(false); setCurrentId(""); @@ -166,34 +184,28 @@ function EquipInfoPage(props) { } function EquipFormModal({ - open, currentId, requestAdd, requestEdit, requestDetails, onCancel, onSuccess, + open, currentId, equipInfoGet, equipInfoAdd, equipInfoEdit, onCancel, onSuccess, }) { const [form] = Form.useForm(); const [submitting, setSubmitting] = useState(false); const [detailLoading, setDetailLoading] = useState(false); useEffect(() => { - if (!open) { - return; - } + if (!open) return; if (!currentId) { form.resetFields(); return; } let cancelled = false; setDetailLoading(true); - safeRequest(requestDetails, { id: currentId }).then((res) => { - if (!cancelled && res?.data) { - form.setFieldsValue(res.data); - } + equipInfoGet({ id: currentId }).then((res) => { + if (cancelled) return; + const data = res?.data || {}; + form.setFieldsValue(data); }).finally(() => { - if (!cancelled) { - setDetailLoading(false); - } + if (!cancelled) setDetailLoading(false); }); - return () => { - cancelled = true; - }; + return () => { cancelled = true; }; }, [open, currentId]); const handleCancel = () => { @@ -204,21 +216,16 @@ function EquipFormModal({ const handleSubmit = async (values) => { try { setSubmitting(true); - const request = currentId ? requestEdit : requestAdd; - if (currentId) { - values.id = currentId; - } - const res = await request(values); + if (currentId) values.id = currentId; + const res = await (currentId ? equipInfoEdit(values) : equipInfoAdd(values)); if (res?.success !== false) { message.success(currentId ? "编辑成功" : "添加成功"); handleCancel(); onSuccess(); - } - else { + } else { message.error(res?.message || "操作失败"); } - } - finally { + } finally { setSubmitting(false); } }; @@ -226,7 +233,7 @@ function EquipFormModal({ return ( - + + + + + + + + + + + @@ -247,13 +264,8 @@ function EquipFormModal({ - - - - - - - + + @@ -261,11 +273,6 @@ function EquipFormModal({ - - - - - @@ -282,17 +289,17 @@ function EquipFormModal({ - + - + - +