1
0

index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { Spin } from 'antd';
  3. import Sortable from 'sortablejs';
  4. import './index.less';
  5. import { generateUUID } from '../../services/Tools';
  6. export default class DragSortingTable extends React.Component {
  7. // sortableContainersDecorator = (componentBackingInstance) => {
  8. // // check if backing instance not null
  9. // if (componentBackingInstance) {
  10. // const options = {
  11. // handle: '.group-title-proxy', // Restricts sort start click/touch to the specified element
  12. // };
  13. // Sortable.create(componentBackingInstance, options);
  14. // }
  15. // }
  16. sortableDecorator(componentBackingInstance) {
  17. // check if backing instance not null
  18. if (componentBackingInstance) {
  19. const options = Object.assign({
  20. // draggable: 'div.drag', // Specifies which items inside the element should be sortable
  21. handle: this.props.handle || '.drag', // this.props.handle, // Restricts sort start click/touch to the specified element
  22. group: this.props.group || generateUUID(),
  23. ghostClass: 'ghost',
  24. onEnd: (event) => {
  25. this.props.onMove(event.oldIndex, event.newIndex);
  26. },
  27. }, this.props.sortable || {});
  28. Sortable.create(componentBackingInstance, options);
  29. }
  30. }
  31. // sortableCategoryDecorator = (componentBackingInstance) => {
  32. // if (componentBackingInstance) {
  33. // const options = {
  34. // // draggable: 'div', // Specifies which items inside the element should be sortable
  35. // handle: '.cross_hair', // Restricts sort start click/touch to the specified element
  36. // group: 'category',
  37. // chosenClass: 'dangefeilei_choose',
  38. // onEnd: (event) => {
  39. // const id = event.item.getAttribute('data-id');
  40. // this.moveCategory(id, event.newIndex + 1);
  41. // },
  42. // };
  43. // Sortable.create(componentBackingInstance, options);
  44. // }
  45. // }
  46. render() {
  47. return (
  48. <Spin spinning={this.props.loading}>
  49. <div className='drag-container'
  50. ref={(ref) => {
  51. if (ref) this.sortableDecorator(ref);
  52. }}>
  53. {this.props.dataSource.map((item, index) => {
  54. return <div className={`drag ${this.props.type}`}>{this.props.renderItem(item, index)}</div>;
  55. })}
  56. </div></Spin>
  57. );
  58. }
  59. }