chenlu
2024-05-16 6edc05acd8bb1de3bedbf093c618d429c62d446b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Sortable from 'sortablejs'
import {VXETable} from "vxe-table";
 
/*表格拖拽*/
let sortable2 = null
 function columnDrop2(xGrid){
    const $grid = xGrid
    sortable2 = Sortable.create($grid.$el.querySelector('.body--wrapper>.vxe-table--header .vxe-header--row'), {
        handle: '.vxe-header--column',
        onEnd: (sortableEvent) => {
            const targetThElem = sortableEvent.item
            const newIndex = sortableEvent.newIndex
            const oldIndex = sortableEvent.oldIndex
            const { fullColumn, tableColumn } = $grid.getTableColumn()
            const wrapperElem = targetThElem.parentNode
            const newColumn = fullColumn[newIndex]
            if (newColumn.fixed) {
                // 错误的移动
                const oldThElem = wrapperElem.children[oldIndex]
                if (newIndex > oldIndex) {
                    wrapperElem.insertBefore(targetThElem, oldThElem)
                } else {
                    wrapperElem.insertBefore(targetThElem, oldThElem ? oldThElem.nextElementSibling : oldThElem)
                }
                VXETable.modal.message({ content: '固定列不允许拖动!', status: 'error' })
                return
            }
            // 获取列索引 columnIndex > fullColumn
            const oldColumnIndex = $grid.getColumnIndex(tableColumn[oldIndex])
            const newColumnIndex = $grid.getColumnIndex(tableColumn[newIndex])
            // 移动到目标列
            const currRow = fullColumn.splice(oldColumnIndex, 1)[0]
            fullColumn.splice(newColumnIndex, 0, currRow)
            $grid.loadColumn(fullColumn)
        }
    })
}
export {
    columnDrop2,
    sortable2
}