@@ -658,88 +658,79 @@ function ScriptList() {
658
658
} )
659
659
) ;
660
660
661
- useEffect ( ( ) => {
662
- if ( ! newColumns . length ) {
663
- return ;
664
- }
665
- const SortableWrapper = ( props : any , ref : any ) => {
666
- return (
667
- < DndContext
668
- sensors = { sensors }
669
- collisionDetection = { closestCenter }
670
- onDragEnd = { ( event : DragEndEvent ) => {
671
- const { active, over } = event ;
672
- if ( ! over ) {
673
- return ;
674
- }
675
- if ( active . id !== over . id ) {
676
- dispatch ( sortScript ( { active : active . id as string , over : over . id as string } ) ) ;
677
- }
678
- } }
661
+ const SortableWrapper = ( props : any , ref : any ) => {
662
+ return (
663
+ < DndContext
664
+ sensors = { sensors }
665
+ collisionDetection = { closestCenter }
666
+ onDragEnd = { ( event : DragEndEvent ) => {
667
+ const { active , over } = event ;
668
+ if ( ! over ) {
669
+ return ;
670
+ }
671
+ if ( active . id !== over . id ) {
672
+ dispatch ( sortScript ( { active : active . id as string , over : over . id as string } ) ) ;
673
+ }
674
+ } }
675
+ >
676
+ < SortableContext
677
+ items = { store . getState ( ) . script . scripts . map ( ( s ) => ( { ... s , id : s . uuid } ) ) }
678
+ strategy = { verticalListSortingStrategy }
679
679
>
680
- < SortableContext
681
- items = { store . getState ( ) . script . scripts . map ( ( s ) => ( { ...s , id : s . uuid } ) ) }
682
- strategy = { verticalListSortingStrategy }
683
- >
684
- < table ref = { ref } { ...props } />
685
- </ SortableContext >
686
- </ DndContext >
687
- ) ;
688
- } ;
689
- const dealColumns : ColumnProps [ ] = [ ] ;
680
+ < table ref = { ref } { ...props } />
681
+ </ SortableContext >
682
+ </ DndContext >
683
+ ) ;
684
+ } ;
690
685
691
- newColumns . forEach ( ( item ) => {
692
- switch ( item . width ) {
693
- case - 1 :
694
- break ;
695
- default :
696
- dealColumns . push ( item ) ;
697
- break ;
698
- }
699
- } ) ;
686
+ const [ sortIndexState , setSortIndexState ] = useState ( - 1 ) ;
700
687
701
- const sortIndex = dealColumns . findIndex ( ( item ) => item . key === "sort" ) ;
702
- let SortableItem ;
703
- if ( sortIndex !== - 1 ) {
704
- const SortableItemComponent = ( props : any ) => {
705
- const { attributes, listeners, setNodeRef, transform, transition } = useSortable ( { id : props ! . record . uuid } ) ;
688
+ const SortableItemComponent = ( props : any ) => {
689
+ const { attributes, listeners, setNodeRef, transform, transition } = useSortable ( { id : props ! . record . uuid } ) ;
706
690
707
- const style = {
708
- transform : CSS . Transform . toString ( transform ) ,
709
- transition,
710
- } ;
691
+ const style = {
692
+ transform : CSS . Transform . toString ( transform ) ,
693
+ transition,
694
+ } ;
711
695
712
- // 替换排序列,使其可以拖拽
713
- props . children [ sortIndex + 1 ] = (
714
- < td
715
- className = "arco-table-td"
696
+ // 替换排序列,使其可以拖拽
697
+ props . children [ sortIndexState + 1 ] = (
698
+ < td
699
+ className = "arco-table-td"
700
+ style = { {
701
+ textAlign : "center" ,
702
+ } }
703
+ key = "drag"
704
+ >
705
+ < div className = "arco-table-cell" >
706
+ < IconMenu
716
707
style = { {
717
- textAlign : "center " ,
708
+ cursor : "move " ,
718
709
} }
719
- key = "drag"
720
- >
721
- < div className = "arco-table-cell" >
722
- < IconMenu
723
- style = { {
724
- cursor : "move" ,
725
- } }
726
- { ...listeners }
727
- />
728
- </ div >
729
- </ td >
730
- ) ;
710
+ { ...listeners }
711
+ />
712
+ </ div >
713
+ </ td >
714
+ ) ;
715
+
716
+ return < tr ref = { setNodeRef } style = { style } { ...attributes } { ...props } /> ;
717
+ } ;
718
+ SortableItemComponent . displayName = "SortableItem" ;
731
719
732
- return < tr ref = { setNodeRef } style = { style } { ...attributes } { ...props } /> ;
733
- } ;
734
- SortableItemComponent . displayName = "SortableItem" ;
735
- SortableItem = SortableItemComponent ;
720
+ useEffect ( ( ) => {
721
+ if ( ! newColumns . length ) {
722
+ return ;
736
723
}
724
+ const dealColumns : ColumnProps [ ] = newColumns . filter ( ( item ) => item . width !== - 1 ) ;
725
+
726
+ const sortIndex = dealColumns . findIndex ( ( item ) => item . key === "sort" ) ;
727
+ setSortIndexState ( sortIndex ) ;
737
728
738
729
setComponents ( {
739
730
table : React . forwardRef ( SortableWrapper ) ,
740
731
body : {
741
732
// tbody: SortableWrapper,
742
- row : SortableItem ,
733
+ row : sortIndex !== - 1 ? SortableItemComponent : undefined ,
743
734
} ,
744
735
} ) ;
745
736
setDealColumns ( dealColumns ) ;
0 commit comments