FormAndFilesNode.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Card, Col, Row, Empty } from 'antd';
  2. import { Form } from 'antd';
  3. import { useMemo, useState } from 'react';
  4. import { useModel } from 'umi';
  5. import AttachmentTable from '@/components/AttachmentTable';
  6. import InnerContactField from '@/components/DDComponents/InnerContactField';
  7. import DepartmentField from '@/components/DDComponents/DepartmentField';
  8. import ProjectField from '@/components/DDComponents/ProjectField';
  9. const FormAndFilesNode = (props) => {
  10. const { formData, fileList } = props;
  11. const renderFormItem = (type, value) => {
  12. switch (type) {
  13. case 'InnerContactField':
  14. return <InnerContactField value={value} disabled={true} />;
  15. case 'DepartmentField':
  16. return <DepartmentField value={value} disabled={true} />;
  17. case 'ProjectField':
  18. return <ProjectField value={value} disabled={true} />;
  19. default:
  20. return (
  21. <div
  22. style={{
  23. width: '100%',
  24. padding: '4px 12px',
  25. backgroundColor: 'rgb(0,0,0,0.04)',
  26. border: '1px solid #D9D9D9',
  27. borderRadius: '6px',
  28. color: 'rgb(0,0,0,0.25) ',
  29. }}
  30. >
  31. {value}
  32. </div>
  33. );
  34. }
  35. };
  36. const renderForm = (data) => {
  37. if (!data) return <Empty description="没有表单信息" />;
  38. try {
  39. const formData = JSON.parse(data);
  40. if (formData.length == 0) return <Empty description="没有表单信息" />;
  41. return (
  42. <>
  43. {formData.map((item, idx) => {
  44. const value = item.value.join(',');
  45. return (
  46. <Form.Item
  47. key={`FormAndFilesNode_${idx}`}
  48. labelCol={{ span: 4 }}
  49. wrapperCol={{ span: 14 }}
  50. label={item.name}
  51. >
  52. {renderFormItem(item.type, value)}
  53. </Form.Item>
  54. );
  55. })}
  56. </>
  57. );
  58. } catch {
  59. return <Empty description="没有表单信息" />;
  60. }
  61. };
  62. const FormContent = useMemo(() => {
  63. return renderForm(formData);
  64. }, [formData]);
  65. return (
  66. <Card title="审批信息">
  67. <Row gutter={20}>
  68. <Col span={12}>{FormContent}</Col>
  69. <Col span={12}>
  70. <AttachmentTable excelFileList={fileList} />
  71. </Col>
  72. </Row>
  73. </Card>
  74. );
  75. };
  76. export default FormAndFilesNode;