import { useRef, useState } from "react"; import { App, Button, Space, Tag } from "antd"; import { PlusOutlined, UploadOutlined } from "@ant-design/icons"; import { ProTable, type ProColumns, type ActionType } from "@ant-design/pro-components"; import { useTranslation } from "react-i18next"; import { Access } from "@/components/Access"; import { getCodeMappingPage, deleteCodeMapping } from "@/api/mdm/coding-system"; import type { CodeMappingVO } from "@/types/mdm/coding-system"; import { CODE_MAPPING_STATUS, CODE_MAPPING_TRANSITION, CODING_SCOPE_OPTIONS } from "@/types/mdm/coding-system"; import CodeMappingDrawer from "./components/CodeMappingDrawer"; const CodeMappingPage: React.FC = () => { const { t } = useTranslation("mdm/coding-system"); const { t: tc } = useTranslation("common"); const { message, modal } = App.useApp(); const actionRef = useRef(null); const [drawerOpen, setDrawerOpen] = useState(false); const reload = () => actionRef.current?.reload(); const handleDelete = (record: CodeMappingVO) => { modal.confirm({ title: t("deleteConfirm"), okType: "danger", content: t("deleteMappingConfirmContent"), onOk: async () => { await deleteCodeMapping(record.id); message.success(tc("success")); reload(); }, }); }; const columns: ProColumns[] = [ { title: t("oldCode"), dataIndex: "oldCode", width: 180, ellipsis: true, }, { title: "", key: "arrow", width: 50, search: false, render: () => →, }, { title: t("newCode"), dataIndex: "newCode", width: 200, ellipsis: true, }, { title: t("entityType"), dataIndex: "entityType", valueType: "select", valueEnum: Object.fromEntries(CODING_SCOPE_OPTIONS.map((s) => [s, { text: s }])), width: 100, }, { title: t("effectDate"), dataIndex: "effectDate", search: false, width: 110, }, { title: t("expireDate"), dataIndex: "expireDate", search: false, width: 110, }, { title: t("reason"), dataIndex: "reason", search: false, ellipsis: true, width: 140, }, { title: t("status"), dataIndex: "status", valueType: "select", valueEnum: { 0: { text: t("enable"), status: "Success" }, 1: { text: t("expired"), status: "Default" }, }, width: 80, render: (_, record) => { const item = CODE_MAPPING_STATUS[record.status as keyof typeof CODE_MAPPING_STATUS]; return item ? {t(item.label as "enable" | "expired")} : "-"; }, }, { title: t("transition"), dataIndex: "transition", search: false, width: 90, render: (_, record) => { const item = CODE_MAPPING_TRANSITION[record.transition as keyof typeof CODE_MAPPING_TRANSITION]; return item ? {item.label} : "-"; }, }, { title: tc("operation"), key: "action", fixed: "right", search: false, width: 120, render: (_, record) => ( handleDelete(record)}> {tc("delete")} ), }, ]; return ( <> columns={columns} actionRef={actionRef} rowKey="id" headerTitle={t("mappingList")} scroll={{ x: 1200 }} // eslint-disable-next-line @typescript-eslint/no-explicit-any request={async (params: any) => { const { current, pageSize, ...rest } = params; const { data } = await getCodeMappingPage({ pageNo: current ?? 1, pageSize: pageSize ?? 10, ...rest, }); return { data: data.list, total: data.total, success: true }; }} pagination={{ defaultPageSize: 10, showSizeChanger: true }} search={{ labelWidth: "auto" }} toolBarRender={() => [ , , ]} /> { setDrawerOpen(false); reload(); }} onClose={() => setDrawerOpen(false)} /> ); }; export default CodeMappingPage;