UNPKG

@jecloud/func

Version:

JECloud 功能库

1 lines 2.8 kB
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},e.apply(this,arguments)};import{computed as n,toRaw as t,isRef as i}from"vue";import{Modal as o}from"@jecloud/ui";import{doFormFieldExp4Sync as l}from"../actions/base-action/exps-action";import{isNotEmpty as r,isEmpty as c,encode as a,findDDAsyncNodes as s,isString as u,isFunction as f,forEach as d}from"@jecloud/utils";import v from"../../field";import{parseTreeSearchItem as p}from"../utils";import{onTreeSelectChange as g}from"./func-data-events";export function useFuncSelectEvents(e){var t,o=e.type,l=e.$func,r=e.modal,c=e.selectOptions,a=c.configInfo,s=null!==(t=v.parseConfigInfo({type:o,configInfo:a,options:c}))&&void 0!==t?t:{},u=n((function(){return i(r)?r.value:r}));return Object.assign(l,{selectConfig:s,selectOptions:c,$modal:u}),{selectConfig:s,onTreeSelectChange:g.bind(this,l),onGridCellDblclick:m.bind(this,l),onTreeCellDblclick:h.bind(this,l),onTreeRendered:b.bind(this,l)}}function m(n,t){var i=n.getFuncGrid().getPlugin();y(e({$plugin:i},n),t)}function h(n,t){y(e({$plugin:n.$tree.value.getPlugin()},n),t)}function b(e){var n,t=e.selectOptions,i=e.selectConfig,o=e.$tree,l=e.getDictionarys,r=t.value,u=t.name,f=t.idProperty,v=t.model,g=void 0===v?{}:v;if(!c(r)){var m=o.value.getPlugin(),h=null!=f?f:"code",b=u;d(["code","id","text"],(function(e){var n=i.sourceFields.indexOf(e);if(n>-1)return h=e,b=i.targetFields[n],!1}));var y=null!==(n=g[b])&&void 0!==n?n:r,$=y?y.split(","):[],x=function(e){var n=e.map((function(e){return m.setTreeExpand4Path({path:p(e).nodePath,async:i.async})}));Promise.all(n).then((function(){m.setSelectRow(e.map((function(e){return m.getRowById(e.id)})))}))};if(i.async)s({type:h,value:$.join(","),strData:a(l())}).then(x);else{var O=[];$.forEach((function(e){var n=m.findRecords((function(n){return e==n[h]}));O=O.concat(n)})),x(O)}}}function y(e,n){var i,c,a,s;void 0===n&&(n={});var d=n.row,v=e.$plugin,p=e.selectOptions,g=e.selectConfig,m=e.$modal,h=p.selectExp,b=p.callback;if(!p.disableDblclick){var y=null!==(c=null===(i=e.getResultRecords)||void 0===i?void 0:i.call(e))&&void 0!==c?c:v.getSelectedRecords();if(d&&!y.includes(d)&&y.push(d),h){var $="选中的数据无效,请重新选择...";u(h)?h={exp:h,message:$}:f(h)?h={fn:h,message:$}:h.message=h.message||$;var x=y.filter((function(n){return!l({$func:e,model:n,exp:h})}));if(r(x))return void o.confirm(h.message,{text:"智能剔除无效数据",handler:function(){v.setSelectRow(x,!1)}})}var O=y.map((function(e){return t(e)}));!1!==(null==b?void 0:b({rows:O,$modal:m.value,config:g}))&&(null===(s=null===(a=m.value)||void 0===a?void 0:a.close)||void 0===s||s.call(a))}}