RemoveData.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { DeleteOutlined } from '@ant-design/icons';
  2. import { ArrayItems } from '@formily/antd';
  3. import { Popconfirm } from 'antd';
  4. import { service } from '@/pages/system/DataSource';
  5. import _ from 'lodash';
  6. import { useField } from '@formily/react';
  7. import { Store } from 'jetlinks-store';
  8. interface Props {
  9. type: any;
  10. }
  11. const RemoveData = (props: Props) => {
  12. const { type } = props;
  13. const row = ArrayItems.useRecord!();
  14. const index = ArrayItems.useIndex!();
  15. const self = useField();
  16. const array = ArrayItems.useArray!();
  17. if (!array) return null;
  18. if (array.field?.pattern !== 'editable') return null;
  19. return (
  20. <div>
  21. <Popconfirm
  22. title={'确认删除'}
  23. onConfirm={() => {
  24. if (self?.disabled) return;
  25. if (_.map(Store.get('datasource-detail-list'), 'name').includes(type.table)) {
  26. service.rdbTables(type.id, type.table).then((resp) => {
  27. if (resp.status === 200) {
  28. if ([..._.map(resp.result.columns, 'name')].includes(row?.name)) {
  29. service.delRdbTablesColumn(type.id, type.table, [row?.name]).then((response) => {
  30. if (response.status === 200) {
  31. array.field?.remove?.(index);
  32. array.props?.onRemove?.(index);
  33. }
  34. });
  35. } else {
  36. array.field?.remove?.(index);
  37. array.props?.onRemove?.(index);
  38. }
  39. }
  40. });
  41. } else {
  42. array.field?.remove?.(index);
  43. array.props?.onRemove?.(index);
  44. }
  45. }}
  46. >
  47. <DeleteOutlined />
  48. </Popconfirm>
  49. </div>
  50. );
  51. };
  52. export default RemoveData;