FormAndFilesNode.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { Card, Col, Input, Row, Table } from 'antd';
  2. import { Form } from '@ant-design/compatible';
  3. import { useForm } from 'antd/lib/form/Form';
  4. import PreviewFile from '@/components/PreviewFile';
  5. import FileViewerModal from '@/components/FileViewer';
  6. import { useState } from 'react';
  7. const renderFrom = data => {
  8. if (!data) return;
  9. try {
  10. const ding_schema = JSON.parse(data)[0];
  11. const formData = JSON.parse(ding_schema)?.formComponentValues;
  12. return (
  13. <>
  14. {formData.map((item, idx) => {
  15. const value = item.value[0];
  16. return (
  17. <Form.Item
  18. key={`FormAndFilesNode_${idx}`}
  19. labelCol={{ span: 6 }}
  20. wrapperCol={{ span: 18 }}
  21. label={item.name}
  22. >
  23. <div
  24. style={{
  25. width: '100%',
  26. paddingLeft: '20px',
  27. backgroundColor: '#ececef',
  28. border: '1px solid #bcb9b9',
  29. borderRadius: '4px',
  30. }}
  31. >
  32. {value}
  33. </div>
  34. </Form.Item>
  35. );
  36. })}
  37. </>
  38. );
  39. } catch {
  40. return;
  41. }
  42. };
  43. const FormAndFilesNode = ({
  44. title,
  45. formData,
  46. excelFileData,
  47. loading,
  48. // setExportData,
  49. // setExcelFileVisible,
  50. }) => {
  51. const [exportData, setExportData] = useState({});
  52. const [excelFileVisible, setExcelFileVisible] = useState(false);
  53. const columns = [
  54. {
  55. title: '附件',
  56. dataIndex: 'name',
  57. render: (text, item) => {
  58. return <PreviewFile name={item.name} src={item.url} />;
  59. },
  60. },
  61. {
  62. title: '预览',
  63. render: record => (
  64. <a
  65. style={{ marginLeft: 10 }}
  66. onClick={() => {
  67. setExportData(record);
  68. setExcelFileVisible(true);
  69. }}
  70. >
  71. 预览
  72. </a>
  73. ),
  74. },
  75. ];
  76. return (
  77. <>
  78. {excelFileData && formData && (
  79. <Card title={title} type="inner" style={{ marginTop: 20 }} loading={loading}>
  80. <Row style={{ marginTop: '20px' }}>
  81. <Col span={12}>{renderFrom(formData)}</Col>
  82. <Col span={11} offset={1}>
  83. <Table rowKey="id" columns={columns} dataSource={excelFileData} />
  84. </Col>
  85. </Row>
  86. </Card>
  87. )}
  88. <FileViewerModal
  89. data={exportData}
  90. visible={excelFileVisible}
  91. onCancel={() => {
  92. setExcelFileVisible(false);
  93. }}
  94. />
  95. </>
  96. );
  97. };
  98. export default FormAndFilesNode;