UNPKG

@jecloud/ui

Version:

JECloud UI库,基于ant-design-vue封装

1 lines 2.22 kB
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var r,t=1,o=arguments.length;t<o;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e},e.apply(this,arguments)};import r from"sortablejs";import{nextTick as t,onMounted as o,onUnmounted as n}from"vue";import{hasClass as l,isEmpty as a}from"@jecloud/utils";import{dragClass as i}from"./index";export function useColumnDD(e){var r;o((function(){t((function(){r=setTimeout((function(){initColumnDD(e)}),500)}))})),n((function(){clearTimeout(r),destroyColumnDD(e)}))}export var destroyColumnDD=function(e){var r;null===(r=e.columnSortables)||void 0===r||r.forEach((function(e){null==e||e.destroy()}))};export var initColumnDD=function(r){var t=r.$plugin.value,o=[];return["refTableHeader","refTableLeftHeader","refTableRightHeader"].forEach((function(n){var l=t.getRefMaps()[n];(null==l?void 0:l.value)&&o.push.apply(o,u(e(e({},r),{header:l.value,group:n})))})),r.columnSortables=o,o};var u=function(e){var t=e.context,o=e.$plugin,n=e.header,u=e.group,c=t.emit,f=o.value,s=n.$el.querySelectorAll(".vxe-table--header .vxe-header--row");if(!a(s)){var v=f.getRefMaps(),d=v.refElem,p=v.refTableHeader,m=d.value.querySelector(".vxe-table--render-wrapper"),g=p.value.$el,h=[];return s.forEach((function(e){var t=r.create(e,{handle:"."+i,forceFallback:!0,dragClass:"je-sortable-drag",group:u,indicator:!0,indicatorRootEl:m,indicatorScrollEl:g,preventOnFilter:!1,filter:function(e,r){var t=e.target;return!l(r,i)||!(l(t,"vxe-header--column")||l(t,"vxe-cell")||l(t,"vxe-cell--title"))},onMove:function(e){var r=e.dragEl,t=e.target;return l(t,i)&&r!==t},onStart:function(e){var r=e.from.querySelector("."+t.options.dragClass);r.style.lineHeight=r.style.height},onEnd:function(){var e=this.indicator,r=e.dragEl,t=e.swapEl,o=e.actions,n=f.getColumnNode(r),l=f.getColumnNode(t);if(r!==t){var a=f.getTableColumn().collectColumn,i=n.index,u=l.index;n.parent!==l.parent&&o.next&&u++;var s=n.parent?n.items:a,v=l.parent?l.items:a,d=s.splice(i,1)[0];v.splice(u,0,d),f.loadColumn(a).then((function(){c("column-drop",{$table:f})}))}else console.log("没有改变")}});h.push(t)})),f.$el.removeAttribute("draggable"),h}};