UNPKG

@jecloud/ui

Version:

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

1 lines 4.18 kB
var e=this&&this.__spreadArrays||function(){for(var e=0,r=0,n=arguments.length;r<n;r++)e+=arguments[r].length;var t=Array(e),o=0;for(r=0;r<n;r++)for(var a=arguments[r],i=0,c=a.length;i<c;i++,o++)t[o]=a[i];return t};import{onMounted as r}from"vue";import{isEmpty as n,forEach as t,isArray as o,isNotEmpty as a}from"@jecloud/utils";import{useExtendMethods as i}from"../../../hooks";import{tableMethodKeys as c}from"./method-keys";import{useOverrides as u}from"./overrides";import{initColumnDD as l,destroyColumnDD as s}from"../plugins/sortablejs/column-dd";export function useMethods(e){var n=e.$panel,t=e.$plugin,o={};Object.assign(o,i({plugin:t,keys:c})),Object.assign(o,i({plugin:n,keys:["refreshLayout"]})),Object.assign(o,d(e)),Object.assign(e,o);var a=u(e);r((function(){Object.keys(a).forEach((function(e){t.value["_"+e]=t.value[e],t.value[e]=a[e]})),Object.keys(o).forEach((function(e){t.value[e]||(t.value[e]=o[e])}))}))}function d(r){var i=r.$plugin,c=r.context,u=r.selection,d={initColumnDD:function(){l(r)},destroyColumnDD:function(){s(r)},refreshColumnDD:function(){d.destroyColumnDD(),d.initColumnDD()},doAction:function(r){for(var n,t,o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];return null===(t=null===(n=null==i?void 0:i.value)||void 0===n?void 0:n[r])||void 0===t?void 0:t.call.apply(t,e([n],o))},setStore:function(e){var r;c.emit("update:store",e),e.autoLoad&&(null===(r=e.load)||void 0===r||r.call(e))},hasCheckboxColumn:function(){var e=i.value,r=!1;return t(e.getColumns(),(function(e){if("checkbox"===e.type)return r=!0,!1})),r},setTreeExpandDeep:function(e,r){void 0===e&&(e=[]);var n=i.value;o(e)||(e=[e]);var t=e.map((function(e){return n.getRowById(e.id)}));return n.setTreeExpand(t,r).then((function(){var t=[];return e.forEach((function(e){var r;t.push.apply(t,null!==(r=e.children)&&void 0!==r?r:[])})),t.length&&n.setTreeExpandDeep(t,r)}))},setTreeExpand4Path:function(e){var r,n,t=e.row,o=e.expand,a=void 0===o||o,c=e.path,u=e.async,l=i.value;if(u){for(var s=c.split("/"),d=s.shift(),f=l.getRowById(d);!f&&s.length;)d=s.shift(),f=l.getRowById(d);return s.length?l.isTreeExpandByRow(f)?l.setTreeExpand4Path({path:s.join("/"),async:u,expand:a}):l.setTreeExpand(f,a).then((function(){return l.setTreeExpand4Path({path:s.join("/"),async:u,expand:a})})):Promise.resolve([f])}var v=[];if(c)for(var h=c.split("/");h.length;){var p=l.getRowById(h.shift());p&&v.push(p)}else for(var g=null!==(n=null===(r=l.treeConfig)||void 0===r?void 0:r.parentField)&&void 0!==n?n:"parent";t;)v.unshift(t),t=l.getRowById(t[g]);return l.setTreeExpand(v,a).then((function(){return[v.pop()]}))},setSelectRow:function(e,r){void 0===r&&(r=!0);var n=i.value;return d.hasCheckboxColumn()?n.setCheckboxRow(e,r):r?n.setCurrentRow(o(e)?e[0]:e):n.clearCurrentRow()},triggerSelectChange:function(e){var t=i.value,o=t.props,l=o.treeConfig,s=o.checkboxConfig,d=e.records,f=e.checked,v=e.row,h=e.eventType,p=r.props.multiple,g=function(){"currentChange"===h&&p||(u.value=e.records),c.emit("select-change",e)},m=function(){if(!n(f)){if(s.checkStrictly&&s.cascadeChild)for(var r=v.children,o=function(){t.setCheckboxRow(r,f);var e=[];r.forEach((function(r){e=e.concat(r.children)})),r=e};a(r);)o();Object.assign(e,{records:t.getCheckboxRecords(),reserves:t.getCheckboxReserveRecords(),indeterminates:t.getCheckboxIndeterminateRecords()})}};if(l&&s)if(function(){if(!n(f)&&s.checkStrictly&&s.cascadeParent&&f)for(var e=t.getRowById(v.parent);e;)t.setCheckboxRow(e,f),e=t.getRowById(e.parent)}(),l.lazy){var C=d.map((function(e){return t.setTreeExpandDeep(e,!0)}));Promise.all(C).then((function(){m(),g()}))}else m(),g();else g()},getSelectedRecords:function(){var e=i.value;if(d.hasCheckboxColumn())return e.getCheckboxRecords();var r=e.getCurrentRecord();return r?[r]:[]},clearSelectedRecords:function(){var e=i.value;if(null==e?void 0:e.getSelectedRecords().length){return(d.hasCheckboxColumn()?e.clearCheckboxRow():e.clearCurrentRow()).then((function(){d.triggerSelectChange({records:[],$table:e})}))}return Promise.resolve()},findRecords:function(e){var r=i.value.internalData.fullDataRowIdData,n=[];for(var t in r){var o=r[t].row;(null==e?void 0:e(o))&&n.push(o)}return n}};return d}