AuditDetailed.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import DDComponents from '@/components/DDComponents';
  2. import React, { useMemo, useState } from 'react';
  3. import { Button, Form } from 'antd';
  4. const AuditDetailed = (props) => {
  5. // const [form] = Form.useForm();
  6. const { items, form, onValuesChange } = props;
  7. const data = useMemo(() => {
  8. let linkedData = {};
  9. items.forEach((d) => {
  10. const item = d.props;
  11. if (item.linked) {
  12. linkedData = { ...linkedData, [item.id]: item.linked };
  13. }
  14. });
  15. const linkedList =
  16. items
  17. ?.map((item) => {
  18. const linked = item.props.linked;
  19. return linked ? Object.values(linked).flat() : [];
  20. })
  21. .flat() || [];
  22. return { linkedData, linkedList };
  23. }, [items]);
  24. const onFinish = (values) => {
  25. console.log(values);
  26. };
  27. const GetComponent = (item) => {
  28. const { id, label, bizAlias, required, notUpper } = item.props;
  29. //判断是否关联项
  30. if (data.linkedList.findIndex((curId) => curId == id) !== -1) {
  31. let control = null; //当前空间是否显示的条件 当id为control.id的组件选择的选项值为control.value 时显示
  32. Object.keys(data.linkedData).forEach((ctlIs) => {
  33. const linked = data.linkedData[ctlIs];
  34. Object.keys(linked).forEach((value) => {
  35. const ids = linked[value];
  36. if (ids.findIndex((curId) => curId == id) !== -1) {
  37. control = { id: ctlIs, value };
  38. }
  39. });
  40. });
  41. let currentValue = form.getFieldValue(control?.id);
  42. if (currentValue != control?.value) return null;
  43. }
  44. let formLabel;
  45. if (bizAlias !== undefined) {
  46. formLabel = bizAlias;
  47. } else {
  48. try {
  49. // 判断label是否为JSON数组
  50. formLabel = JSON.parse(label).join(',');
  51. } catch (error) {
  52. formLabel = label;
  53. }
  54. }
  55. // const component = DDComponents({ item });
  56. // if (!component) return null;
  57. return (
  58. <Form.Item
  59. key={id}
  60. name={id}
  61. label={formLabel}
  62. rules={[{ required: required }]}
  63. >
  64. <DDComponents item={item} />
  65. </Form.Item>
  66. );
  67. };
  68. return (
  69. <Form
  70. form={form}
  71. style={{ minHeight: '80vh', overflowY: 'auto', paddingRight: 20 }}
  72. layout="vertical"
  73. autoComplete="off"
  74. onValuesChange={onValuesChange}
  75. onFinish={onFinish}
  76. >
  77. {items.map((item) => GetComponent(item))}
  78. </Form>
  79. );
  80. };
  81. export default AuditDetailed;