2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{p as H,d as R,q as b,a as C,s as F,by as q,o as J,E as $,b as x,j as B,e as D,H as j,w as A,k as I,x as w,m as K,u as E,v as Q,f as L,A as P,t as G,z as V,B as M,g as T,bz as U,bA as W,y as X,G as Y,I as Z,c as O,bB as ee,F as te,D as _}from"./index-7b3f5fdc.js";const le=["size"],ae=["name","value"],ie=["lay-skin"],ne={class:"layui-checkbox-label"},se=R({name:"LayCheckboxV2",__name:"index",props:{name:{},skin:{},label:{default:""},value:{},modelValue:{type:[Boolean,Array],default:!1},isIndeterminate:{type:Boolean,default:!1},size:{},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","change"],setup(m,{expose:i,emit:l}){const t=m,{size:o}=function(a){return{size:b(()=>{const r=E("LayForm",{});return a.size||r.size||"md"})}}(t),c=E("checkboxGroup",{}),d=b(()=>c!=null&&(c==null?void 0:c.name)==="LayCheckboxGroup"),n=l,h=Q(),u=b({get:()=>d.value?c.modelValue.value.includes(t.value):Array.isArray(t.modelValue)?t.modelValue.includes(t.value):t.modelValue,set(a){d.value?v(a):Array.isArray(t.modelValue)?e(a):(n("update:modelValue",a),n("change",a))}}),g=b(()=>Array.isArray(t.modelValue)?[...t.modelValue]:[]),v=function(a){let r=[...c.modelValue.value];a?r.push(t.value):r.splice(r.indexOf(t.value),1),c.modelValue.value=r},e=function(a){let r=[...g.value];a?r.push(t.value):r.splice(r.indexOf(t.value),1),n("update:modelValue",r),n("change",r)},y=function(){f.value||(u.value=!u.value)},f=b(()=>!!t.disabled||!(!c.hasOwnProperty("disabled")||!c.disabled.value));return i({toggle:y}),(a,r)=>(x(),B("span",{onClick:T(y,["stop"]),class:"layui-checkbox",size:w(o)},[L("input",{type:"checkbox",name:a.name,value:a.value},null,8,ae),L("div",{class:K(["layui-form-checkbox",{"layui-form-checked":u.value,"layui-checkbox-indeterminate":t.isIndeterminate,"layui-checkbox-disabled layui-disabled":f.value}]),"lay-skin":a.skin},[L("span",ne,[w(h).default||a.label?I(a.$slots,"default",{key:0},()=>[P(G(a.label),1)]):V("",!0)]),D(w(M),{type:u.value?"layui-icon-ok":t.isIndeterminate?"layui-icon-subtraction":""},null,8,["type"])],10,ie)],8,le))}}),oe=["onClick"],ce={class:"layui-tree-main"},de=["onClick"],re={key:0,class:"layui-tree-pack layui-tree-showLine",style:{display:"block"}},ue=R({name:"TreeNode",__name:"TreeNode",props:{tree:{},nodeList:{},showCheckbox:{type:Boolean},showLine:{type:Boolean},selectedKey:{},checkStrictly:{type:[Boolean,String]},collapseTransition:{type:Boolean},onlyIconControl:{type:Boolean},tailNodeIcon:{type:[String,Boolean]},replaceFields:{},load:{type:Function}},emits:["node-click","check-change"],setup(m,{emit:i}){const l=m,t=i;function o(e){const{children:y}=l.replaceFields;return!e.hasNextSibling&&e.parentNode&&(!e.parentNode.hasNextSibling||e.parentNode.hasNextSibling&&!e.parentNode[y])}const c=e=>{var y,f;const{children:a}=l.replaceFields;return l.showLine?((y=e[a])==null?void 0:y.length)>0||e.isLazy?e.isLeaf?"layui-icon-subtraction":"layui-icon-addition":l.tailNodeIcon?l.tailNodeIcon:"":((f=e[a])==null?void 0:f.length)>0||e.isLazy?e.isLeaf?"layui-icon-triangle-d":"layui-icon-triangle-r":""};function d(e){t("node-click",e)}const n=(e,y)=>{t("check-change",e,y)},h=U();function u(e){const{id:y,children:f}=l.replaceFields,a=e[y],r=l.tree.getOriginData(a),s=e[f]&&e[f].length>0;l.load&&e.isLazy&&!s?(e.isLoading=!0,l.load(r,p=>{const k=l.tree.createTree(p,a);Reflect.set(e,f,k),e.isLoading=!1,e.isLazy=!1,$(()=>{e.isLeaf=!e.isLeaf})})):s&&(e.isLeaf=!e.isLeaf)}function g(e){l.onlyIconControl||u(e),e.isDisabled||t("node-click",e)}const v=b(()=>{function e(y){var f;const{children:a}=l.replaceFields;let r=!1;for(const s of y[a]||[])s.isChecked&&(r=!0);if(!r&&(f=y[a])!=null&&f.length){for(const s of y[a]||[])if(r=e(s),r)break}return r}return y=>l.checkStrictly||!l.showCheckbox?!1:e(y)});return(e,y)=>{const f=W("tree-node",!0);return x(!0),B(te,null,X(e.nodeList,(a,r)=>{var s,p;return Y((x(),B("div",{key:r,class:K({"layui-tree-set":!0,"layui-tree-setLineShort":o(a),"layui-tree-setHide":a.isRoot})},[L("div",{class:K(["layui-tree-entry",{"layui-this":e.selectedKey===a[e.replaceFields.id]}]),onClick:k=>function(N){l.showLine||g(N)}(a)},[L("div",ce,[L("span",{class:K([e.showLine&&(((s=a[e.replaceFields.children])==null?void 0:s.length)>0||a.isLazy)?"layui-tree-icon":"",{"layui-tree-iconClick":!0},{"layui-tree-icon-standalone":c(a).length&&a.isLeaf&&!((p=a[e.replaceFields.children])!=null&&p.length)}])},[D(w(M),{type:c(a),onClick:T(k=>u(a),["stop"])},null,8,["type","onClick"])],2),e.showCheckbox?(x(),O(se,{key:0,value:"",skin:"primary",modelValue:a.isChecked,disabled:a.isDisabled,isIndeterminate:v.value(a),onChange:k=>function(N,S){var z;l.tree.setCheckedKeys(N,l.checkStrictly,S),t("check-change",S,N),h&&h!=null&&h.inputEl&&((z=h==null?void 0:h.inputEl.value)==null||z.focus())}(k,a)},null,8,["modelValue","disabled","isIndeterminate","onChange"])):V("",!0),a.isLoading?(x(),O(w(M),{key:1,class:"layui-tree-loading layui-anim layui-anim-rotate layui-anim-loop",type:"layui-icon-loading"})):V("",!0),L("span",{class:K({"layui-tree-txt":!0,"layui-disabled":a.isDisabled}),onClick:T(k=>g(a),["stop"])},[I(e.$slots,"title",{data:a},()=>[P(G(a[l.replaceFields.title]),1)])],10,de)])],10,oe),D(ee,{enable:e.collapseTransition},{default:A(()=>[a.isLeaf?(x(),B("div",re,[D(f,{tree:e.tree,"node-list":a[e.replaceFields.children]||[],"show-checkbox":e.showCheckbox,"show-line":e.showLine,"selected-key":e.selectedKey,"collapse-transition":e.collapseTransition,checkStrictly:e.checkStrictly,"only-icon-control":e.onlyIconControl,"tail-node-icon":e.tailNodeIcon,"replace-fields":e.replaceFields,load:e.load,onNodeClick:d,onCheckChange:n},j({_:2},[e.$slots.title?{name:"title",fn:A(k=>[I(e.$slots,"title",{data:k.data})]),key:"0"}:void 0]),1032,["tree","node-list","show-checkbox","show-line","selected-key","collapse-transition","checkStrictly","only-icon-control","tail-node-icon","replace-fields","load"])])):V("",!0)]),_:2},1032,["enable"])],2)),[[Z,a.visible]])}),128)}}});class he{constructor(i,l){this.config=i,this.treeData=[],this.init(l)}init(i){const l=this.createTree(i);this.treeData=l}createTree(i,l=""){let t;t=Array.isArray(i)?i:Array.of(Object.assign({},i));const o=[],{children:c,id:d}=this.config.replaceFields,n=t.length;for(let h=0;h<n;h++){const u=this.getNode(t[h],l,h<n-1),g=Reflect.get(u,c);Reflect.get(u,c)&&Reflect.set(u,c,this.createTree(g,u[d])),o.push(u)}return o}getNode(i,l,t){const{nodeMap:o,originMap:c,checkedKeys:d,expandKeys:n,replaceFields:{children:h,id:u,title:g},lazy:v}=this.config,e=Reflect.get(i,u),y=Reflect.get(i,g),f=Reflect.get(i,h),a=!!Reflect.get(i,"disabled"),r=!!Reflect.get(i,"spread")||n.includes(e),s=o.get(l),p=Object.assign({},i,{id:e,title:y,children:f||[],parentKey:l,isRoot:l==="",isDisabled:!1,isChecked:!1,isLeaf:!1,isLazy:!Reflect.get(i,"spread")&&v,isLoading:!1,hasNextSibling:t,parentNode:s||null,visible:!0});return p.isDisabled=a,p.isChecked=d.includes(e),p.isLeaf=s?s.isLeaf:n.includes(e),p.isLeaf=r||this.config.defaultExpandAll&&!v,o.has(e)||o.set(e,p),c.has(e)||c.set(e,i),p}treeForeach(i,l){const{children:t}=this.config.replaceFields;i.forEach(o=>{o[t]&&this.treeForeach(o[t],l),l(o)})}setCheckedKeys(i,l,t){const{children:o}=this.config.replaceFields;if(l)t.isChecked=i;else{if(_(t[o])){let c=0,d=0;this.treeForeach(t[o],n=>{n.isDisabled||(c++,n.isChecked&&d++)}),i=d<c,i=this.setChildrenChecked(i,t[o])}t.isChecked=i,t.parentNode&&this.setParentChecked(t.parentNode)}}setParentChecked(i){const{children:l}=this.config.replaceFields;if(!i)return;const t=i[l].every(o=>o.isChecked);i.isChecked=t,i.parentNode&&this.setParentChecked(i.parentNode)}setChildrenChecked(i,l){const{children:t}=this.config.replaceFields,o=l.length;let c=i;for(let d=0;d<o;d++)if(_(l[d][t])){const n=this.setChildrenChecked(i,l[d][t]);n||(c=!1),l[d].isChecked=n}else l[d].isDisabled?l[d].isChecked=c=!1:l[d].isChecked=i;return c}getData(){return this.treeData}getKeys(){const i=[],l=[],t=this.config.nodeMap[Symbol.iterator](),{id:o,children:c}=this.config.replaceFields;let d=t.next();for(;!d.done;){const[,n]=d.value,h=Reflect.get(n,o);n.isChecked&&l.push(h),!this.config.checkStrictly&&n.isChecked&&n[c]&&this.treeForeach(n[c],u=>{if(!u.isChecked){const g=l.findIndex(v=>v===u.parentKey);g>=0&&l.splice(g,1)}}),n.isLeaf&&i.push(h),d=t.next()}return{checkedKeys:l,expandKeys:i}}getOriginData(i){return this.config.originMap.get(i)}_filter(i){const{replaceFields:{children:l},searchNodeMethod:t,lazy:o}=this.config,c=function(d){d.forEach(n=>{const h=n[l];if(n.visible=t(n,i),c(h),!n.visible&&h.length){let u=!0;u=!h.some(g=>g.visible),n.visible=u===!1}i&&(!n.visible||n.isLeaf||o||(n.isLeaf=!0))})};c(this.treeData)}}const ye=m=>{const{id:i,title:l,children:t}=m||{};return{id:i||"id",title:l||"title",children:t||"children"}},pe=R({name:"LayTree",__name:"index",props:{data:{},treeOriginData:{},disabled:{type:Boolean,default:!1},edit:{type:[Boolean,String],default:!1},checkedKeys:{default:()=>[]},expandKeys:{},checkStrictly:{type:[Boolean,String],default:!1},collapseTransition:{type:Boolean,default:!0},onlyIconControl:{type:Boolean,default:!1},selectedKey:{},showLine:{type:Boolean,default:!0},showCheckbox:{type:Boolean,default:!1},replaceFields:{},tailNodeIcon:{type:[String,Boolean],default:"layui-icon-file"},isSelect:{type:Boolean,default:!0},defaultExpandAll:{type:Boolean,default:!1},lazy:{type:Boolean,default:!1},load:{},searchNodeMethod:{}},emits:["update:expandKeys","update:checkedKeys","node-click","update:selectedKey","update:treeOriginData","check-change"],setup(m,{expose:i,emit:l}){const t=m,o=l,c=b(()=>({"layui-tree":!0,"layui-form":t.showCheckbox,"layui-tree-line":t.showLine,"layui-tree-unline":!t.showLine})),d=b(()=>ye(t.replaceFields));let n=C(),h=C();const u=C(!1),g=C(!1),v=()=>{let{tree:s,nodeList:p}=((k,N)=>{const S=new he({nodeMap:new Map,originMap:new Map,replaceFields:k.replaceFields,showCheckbox:k.showCheckbox??!1,checkedKeys:k.checkedKeys??[],expandKeys:k.expandKeys??[],checkStrictly:k.checkStrictly??!1,defaultExpandAll:k.defaultExpandAll??!1,lazy:k.lazy??!1,searchNodeMethod:k.searchNodeMethod},k.data),z=b(()=>S.getData());return{tree:S,nodeList:z}})(Object.assign({},t,{replaceFields:d.value}));n.value=s,h.value=p.value};F(()=>t.data,()=>{u.value||v()},{deep:!0,immediate:!0}),F(()=>t.checkedKeys,()=>{u.value||v()}),F(()=>t.expandKeys,()=>{u.value||v()});const e=C([]),y=C([]);function f(s){const p=n.value.getOriginData(s[d.value.id]);t.isSelect&&o("update:selectedKey",s[d.value.id]),o("node-click",p)}F(n,()=>{if(g.value){const{checkedKeys:s,expandKeys:p}=n.value.getKeys();u.value=!0,String(y.value)!=String(s)&&(y.value=s,o("update:checkedKeys",s)),String(e.value)!=String(p)&&(e.value=p,o("update:expandKeys",p)),setTimeout(()=>{u.value=!1},0)}},{deep:!0}),q(()=>{o("update:treeOriginData",n.value.treeData)}),J(()=>{$(()=>{g.value=!0})});const a=(s,p)=>{o("check-change",s,p)},r=C(t.selectedKey);return F(()=>t.selectedKey,()=>{r.value=t.selectedKey}),i({filter:s=>{if(!t.searchNodeMethod)throw new Error("[Layui-vue/Tree] filterNodeMethod为空");n.value._filter(s)}}),(s,p)=>(x(),B("div",{class:K(c.value)},[D(ue,{tree:w(n),"node-list":w(h),"show-checkbox":s.showCheckbox,"show-line":s.showLine,selectedKey:r.value,"check-strictly":s.checkStrictly,"collapse-transition":s.collapseTransition,"only-icon-control":s.onlyIconControl,"tail-node-icon":s.tailNodeIcon,"replace-fields":d.value,load:s.load,onNodeClick:f,onCheckChange:a},j({_:2},[s.$slots.title?{name:"title",fn:A(({data:k})=>[I(s.$slots,"title",{data:k})]),key:"0"}:void 0]),1032,["tree","node-list","show-checkbox","show-line","selectedKey","check-strictly","collapse-transition","only-icon-control","tail-node-icon","replace-fields","load"])],2))}}),fe=H(pe);export{fe as b,se as n};
|