import { CardStepTitle, FileLink, FileUpload } from "@/components"; import ExamDataPublishController from "@/services/apis/ExamDataPublishController"; import { ExamStatus, PublishStatus, ResourceFileType } from "@/services/enums"; import { ActionType, ProTable } from "@ant-design/pro-components"; import { history, useModel } from "@umijs/max"; import { App, Button, Space, theme } from "antd"; import { useCallback, useRef, useState } from "react"; import ExamDataPublishEditModal from "./ExamDataPublishEditModal"; /** 监测发布内容管理 */ const ExamDataPublishList: React.FC<{ examPlanId: number, examPlanStatus?: ExamStatus }> = ({ examPlanId }) => { const { token } = theme.useToken(); const actionRef = useRef(); const dataRef = useRef(); const currentRef = useRef>(); const [editOpen, setEditOpen] = useState(false); const { getDictValueEnum } = useModel('useDict'); const { message, modal } = App.useApp(); // 移出 const handleRemove = useCallback(async (id: number) => { modal.confirm({ title: '警告', content: '确定立即移出吗', okText: '确定', cancelText: '取消', centered: true, onOk: async () => { await ExamDataPublishController.del({ id }); message.success('已移出'); actionRef.current?.reload(); }, }); }, []); // 发布 const handlePublish = useCallback(async (id: number) => { modal.confirm({ title: '提示', content: '确定立即发布吗', okText: '确定', cancelText: '取消', centered: true, onOk: async () => { await ExamDataPublishController.publish({ id }); message.success('已发布'); actionRef.current?.reload(); }, }); }, []); // 取消发布 const handleUnpublish = useCallback(async (id: number) => { modal.confirm({ title: '提示', content: '确定立即取消发布吗', okText: '确定', cancelText: '取消', centered: true, onOk: async () => { await ExamDataPublishController.unpublish({ id }); message.success('已取消'); actionRef.current?.reload(); }, }); }, []); // 删除附件 const handleDeleteAttachment = useCallback(async (id: number, fileId: string) => { modal.confirm({ title: '警告', content: '确定立即删除吗', okText: '确定', cancelText: '取消', centered: true, onOk: async () => { await ExamDataPublishController.delAttachment({ sourceId: id, fileId }) message.success('已删除'); actionRef.current?.reload(); }, }); }, []); return ( <> headerTitle={结果反馈} style={{ marginTop: token.margin }} search={false} size="small" bordered scroll={{ x: '100%' }} sticky={{ offsetHeader: 56 }} actionRef={actionRef} options={{ density: false, fullScreen: false, setting: false }} pagination={false} columns={[ { title: '序', valueType: 'option', fixed: 'left', width: 32, align: 'center', render: (_, r, index) => { return index + 1; }, }, { title: '发布类型', dataIndex: 'type', valueEnum: getDictValueEnum('data_publish_type'), width: 96, align: 'center', fixed: 'left', }, { title: '发布名称', dataIndex: 'name', width: 180, }, { title: '发布内容', valueType: 'option', width: 80, align: 'center', render: (_, r) => { return ( ); }, }, { title: '备注说明', dataIndex: 'remark', ellipsis: true, width: 400, }, { title: '发布状态', dataIndex: 'status', valueEnum: getDictValueEnum('publish_status', true), width: 88, align: 'center', }, { title: '发布时间', dataIndex: 'beginTime', width: 144, align: 'center', }, { title: '附件', valueType: 'option', hideInSearch: true, width: 280 + token.paddingXS * 2, render: (_, r) => { const li = r.attachmentList?.map((t, i) => { return ( handleDeleteAttachment(r.id, t.fileId)} /> ); }); return ( {li} {(li?.length ?? 0) < 9 && { const fsp = file.name.split('.'); let extName = ''; if (fsp.length > 1) { extName = fsp[fsp.length - 1].toLowerCase(); } if (extName === '' || !['jpg', 'jpeg', 'png', 'gif', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'zip'].includes(extName)) { message.error('文件类型错误,请重新选择!') return { success: false, errorType: 'fileTypeError', errorMessage: '文件类型错误' }; } try { const formData = new FormData(); formData.append('type', `${ResourceFileType.EXAM_DATA_PUBLISH_ATTACHMENT}`); formData.append('sourceId', `${r.id}`); formData.append('fileName', `${file.name}`); formData.append('file', file); await ExamDataPublishController.uploadAttachment(formData, { onUploadProgress: (p: any) => { const progress = parseFloat((p.loaded / p.total * 100).toFixed(1)); onUploadProgress?.(progress); } }); actionRef.current?.reload(); return { success: true }; } catch { return { success: false }; } }} /> } ); }, }, { title: '操作', valueType: 'option', width: 196, align: 'center', fixed: 'right', render: (_, r) => { return ( <> ); }, } ]} rowKey="id" toolbar={{ actions: [ , ], }} request={async () => { const res = await ExamDataPublishController.getListByExamPlanId({ examplanid: examPlanId }); dataRef.current = res ?? []; return { data: res, success: true, }; }} /> {editOpen && currentRef.current && setEditOpen(false)} onFinish={() => actionRef.current?.reload()} /> } ); } export default ExamDataPublishList;