import{$ as e,M as t,G as d,Q as o,R as n,o as s,d as a,w as i,e as r,H as h,L as l,X as c,x as y,I as p,K as u,f as k,t as f,J as C,h as N,a0 as x,i as g,N as b,bZ as m}from"./index-8nyjtlby.js";import{l as K,g as w,T as E}from"./ly-checkbox.-ni42YSS.js";import{_ as I}from"./_plugin-vue_export-helper.BCo6x5W8.js";let _;const L=I({components:{LyTrees:I({name:"LyTree",componentName:"LyTree",components:{LyTreeNode:I({name:"LyTreeNode",componentName:"LyTreeNode",components:{lyCheckbox:K},props:{nodeId:[Number,String],renderAfterExpand:{type:Boolean,default:!0},checkOnlyLeaf:{type:Boolean,default:!1},showCheckbox:{type:Boolean,default:!1},showRadio:{type:Boolean,default:!1},indent:Number,iconClass:String},data:()=>({node:{indeterminate:!1,checked:!1,expanded:!1},expanded:!1,childNodeRendered:!1,oldChecked:null,oldIndeterminate:null,highlightCurrent:!1}),inject:["tree"],computed:{checkboxVisible(){return this.checkOnlyLeaf?this.showCheckbox&&this.node.isLeaf:this.showCheckbox},radioVisible(){return this.checkOnlyLeaf?this.showRadio&&this.node.isLeaf:this.showRadio}},watch:{"node.indeterminate"(e){this.handleSelectChange(this.node.checked,e)},"node.checked"(e){this.handleSelectChange(e,this.node.indeterminate)},"node.expanded"(e){this.$nextTick((()=>this.expanded=e)),e&&(this.childNodeRendered=!0)}},methods:{getNodeKey(e){let t=this.tree.store.root.getChildNodes([e])[0];return w(this.tree.nodeKey,t.data)},handleSelectChange(e,t){if(this.oldChecked!==e&&this.oldIndeterminate!==t){if(this.checkOnlyLeaf&&!this.node.isLeaf)return;if(this.checkboxVisible){const d=this.tree.store._getAllNodes();this.tree.$emit("check-change",{checked:e,indeterminate:t,node:this.node,data:this.node.data,checkedall:d.every((e=>e.checked))})}else this.tree.$emit("radio-change",{checked:e,node:this.node,data:this.node.data,checkedall:!1})}!this.expanded&&this.tree.expandOnCheckNode&&e&&this.handleExpandIconClick(),this.oldChecked=e,this.indeterminate=t},handleClick(){this.tree.store.setCurrentNode(this.node),this.tree.$emit("current-change",{node:this.node,data:this.tree.store.currentNode?this.tree.store.currentNode.data:null,currentNode:this.tree.store.currentNode}),this.tree.currentNode=this.node,this.tree.expandOnClickNode&&this.handleExpandIconClick(),this.tree.checkOnClickNode&&!this.node.disabled&&(this.checkboxVisible||this.radioVisible)&&this.handleCheckChange(!this.node.checked),this.tree.$emit("node-click",this.node)},handleExpandIconClick(){this.node.isLeaf||(this.expanded?(this.tree.$emit("node-collapse",this.node),this.node.collapse()):(this.node.expand(),this.tree.$emit("node-expand",this.node),this.tree.accordion&&e(`${this.tree.elId}-tree-node-expand`,this.node)))},handleCheckChange(t){this.node.disabled||(this.checkboxVisible?this.node.setChecked(t,!(this.tree.checkStrictly||this.checkOnlyLeaf)):this.node.setRadioChecked(t),this.$nextTick((()=>{this.tree.$emit("check",{node:this.node,data:this.node.data,checkedNodes:this.tree.store.getCheckedNodes(),checkedKeys:this.tree.store.getCheckedKeys(),halfCheckedNodes:this.tree.store.getHalfCheckedNodes(),halfCheckedKeys:this.tree.store.getHalfCheckedKeys()})})),e("updateKey"))},handleImageError(){this.node.icon=this.tree.defaultNodeIcon}},created(){if(!this.tree)throw new Error("Can not find node's tree.");this.node=this.tree.store.nodesMap[this.nodeId],this.highlightCurrent=this.tree.highlightCurrent,this.node.expanded&&(this.expanded=!0,this.childNodeRendered=!0);const e=(this.tree.props||{}).children||"children";this.$watch(`node.data.${e}`,(()=>{this.node.updateChildren()})),this.tree.accordion&&t(`${this.tree.elId}-tree-node-expand`,(e=>{this.node.id!==e.id&&this.node.level===e.level&&this.node.collapse()}))},beforeDestroy(){this.$parent=null}},[["render",function(e,t,b,m,K,w){const E=N,I=d("ly-checkbox"),_=x,L=g,v=d("ly-tree-node");return o((s(),a(L,{ref:"node",name:"LyTreeNode",class:h(["ly-tree-node",{"is-expanded":K.expanded,"is-hidden":!K.node.visible,"is-checked":!K.node.disabled&&K.node.checked}]),role:"treeitem",onClick:c(w.handleClick,["stop"])},{default:i((()=>[r(L,{class:h(["ly-tree-node__content",{"is-current":K.node.isCurrent&&K.highlightCurrent}]),style:l({"padding-left":(K.node.level-1)*b.indent+"px"})},{default:i((()=>[r(E,{onClick:c(w.handleExpandIconClick,["stop"]),class:h([{"is-leaf":K.node.isLeaf,expanded:!K.node.isLeaf&&K.node.expanded},"ly-tree-node__expand-icon",b.iconClass?b.iconClass:"ly-iconfont ly-icon-caret-right"])},null,8,["onClick","class"]),w.checkboxVisible||w.radioVisible?(s(),a(I,{key:0,type:w.checkboxVisible?"checkbox":"radio",checked:K.node.checked,indeterminate:K.node.indeterminate,disabled:!!K.node.disabled,onCheck:t[0]||(t[0]=e=>w.handleCheckChange(!K.node.checked))},null,8,["type","checked","indeterminate","disabled"])):y("",!0),K.node.loading?(s(),a(E,{key:1,class:"ly-tree-node__loading-icon ly-iconfont ly-icon-loading"})):y("",!0),K.node.icon&&K.node.icon.length>0?(s(),p(u,{key:2},[-1!==K.node.icon.indexOf("/")?(s(),a(_,{key:0,class:"ly-tree-node__icon",mode:"widthFix",src:K.node.icon,onError:w.handleImageError},null,8,["src","onError"])):(s(),a(E,{key:1,class:h(["ly-tree-node__icon",K.node.icon])},null,8,["class"]))],64)):y("",!0),r(L,{class:"ly-tree-node__label_box"},{default:i((()=>[r(E,{class:"ly-tree-node__label u-line-1"},{default:i((()=>[k(f(K.node.data.userName),1)])),_:1}),r(E,{style:{color:"#c6c6c6"},class:"ly-tree-node__label u-line-1"},{default:i((()=>[k(f(K.node.data.position?K.node.data.department+"/"+K.node.data.position:K.node.data.department),1)])),_:1})])),_:1})])),_:1},8,["class","style"]),!b.renderAfterExpand||K.childNodeRendered?o((s(),a(L,{key:0,class:"ly-tree-node__children",role:"group"},{default:i((()=>[(s(!0),p(u,null,C(K.node.childNodesId,(e=>(s(),a(v,{nodeId:e,"render-after-expand":b.renderAfterExpand,"show-checkbox":b.showCheckbox,"show-radio":b.showRadio,"check-only-leaf":b.checkOnlyLeaf,key:w.getNodeKey(e),indent:b.indent,"icon-class":b.iconClass},null,8,["nodeId","render-after-expand","show-checkbox","show-radio","check-only-leaf","indent","icon-class"])))),128))])),_:1},512)),[[n,K.expanded]]):y("",!0)])),_:1},8,["class","onClick"])),[[n,K.node.visible]])}],["__scopeId","data-v-851657fb"]])},data:()=>({updateKey:(new Date).getTime(),elId:`ly_${Math.ceil(1e6*Math.random()).toString(36)}`,visible:!0,store:{ready:!1},currentNode:null,childNodesId:[],mathKey:1}),provide(){return{tree:this}},props:{treeData:Array,ready:{type:Boolean,default:!0},emptyText:{type:String,default:"暂无数据"},renderAfterExpand:{type:Boolean,default:!0},nodeKey:String,checkStrictly:Boolean,defaultExpandAll:{type:Boolean,default:!0},toggleExpendAll:Boolean,expandOnClickNode:{type:Boolean,default:!0},expandOnCheckNode:{type:Boolean,default:!0},checkOnClickNode:Boolean,checkDescendants:{type:Boolean,default:!1},autoExpandParent:{type:Boolean,default:!0},defaultCheckedKeys:Array,defaultExpandedKeys:Array,expandCurrentNodeParent:Boolean,currentNodeKey:[String,Number],checkOnlyLeaf:{type:Boolean,default:!1},showCheckbox:{type:Boolean,default:!1},showRadio:{type:Boolean,default:!1},props:{type:[Object,Function],default:()=>({children:"children",label:"label",disabled:"disabled"})},lazy:{type:Boolean,default:!1},highlightCurrent:Boolean,load:Function,filterNodeMethod:Function,childVisibleForFilterNode:{type:Boolean,default:!1},accordion:Boolean,indent:{type:Number,default:18},iconClass:String,showNodeIcon:{type:Boolean,default:!1},defaultNodeIcon:{type:String,default:""},isInjectParentInNode:{type:Boolean,default:!1}},computed:{isEmpty(){if(this.store.root){const e=this.store.root.getChildNodes(this.childNodesId);return!e||0===e.length||e.every((({visible:e})=>!e))}return!0},showLoading(){return this.mathKey,!(this.store.getReady()&&this.ready)}},watch:{toggleExpendAll(e){this.store.toggleExpendAll(e)},defaultCheckedKeys(e){this.store.setDefaultCheckedKey(e)},defaultExpandedKeys(e){this.store.defaultExpandedKeys=e,this.store.setDefaultExpandedKeys(e)},checkStrictly(e){this.store.checkStrictly=e||this.checkOnlyLeaf},"store.root.childNodesId"(e){this.childNodesId=e},"store.root.visible"(e){this.visible=e},childNodesId(){this.$nextTick((()=>{this.$emit("ly-tree-render-completed")}))},treeData:{handler(e){this.updateKey=(new Date).getTime(),this.store.setData(e)},deep:!0}},methods:{filter(e,t){if(!this.filterNodeMethod)throw new Error("[Tree] filterNodeMethod is required when filter");this.store.filter(e,t),this.handleUpdateKey()},handleUpdateKey(){this.updateKey=(new Date).getTime()},getNodeKey(e){let t=this.store.root.getChildNodes([e])[0];return w(this.nodeKey,t.data)},getNodePath(e){return this.store.getNodePath(e)},getCheckedNodes(e,t){return this.store.getCheckedNodes(e,t)},getCheckedKeys(e,t){return this.store.getCheckedKeys(e,t)},getCurrentNode(){const e=this.store.getCurrentNode();return e?e.data:null},getCurrentKey(){const e=this.getCurrentNode();return e?e[this.nodeKey]:null},setCheckAll(e=!0){if(this.showRadio)throw new Error('You set the "show-radio" property, so you cannot select all nodes');this.showCheckbox||console.warn('You have not set the property "show-checkbox". Please check your settings'),this.store.setCheckAll(e)},setCheckedNodes(e,t){this.store.setCheckedNodes(e,t)},setCheckedKeys(e,t){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedKeys");this.store.setCheckedKeys(e,t),this.handleUpdateKey()},setChecked(e,t,d){this.store.setChecked(e,t,d)},getHalfCheckedNodes(){return this.store.getHalfCheckedNodes()},getHalfCheckedKeys(){return this.store.getHalfCheckedKeys()},setCurrentNode(e){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");this.store.setUserCurrentNode(e)},setCurrentKey(e){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");this.store.setCurrentNodeKey(e)},getNode(e){return this.store.getNode(e)},remove(e){this.store.remove(e)},append(e,t){this.store.append(e,t)},insertBefore(e,t){this.store.insertBefore(e,t)},insertAfter(e,t){this.store.insertAfter(e,t)},updateKeyChildren(e,t){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in updateKeyChild");this.store.updateChildren(e,t)}},created(){this.isTree=!0;let e=this.props;if("function"==typeof this.props&&(e=this.props()),"object"!=typeof e)throw new Error("props must be of object type.");this.store=new E({key:this.nodeKey,data:this.treeData,lazy:this.lazy,props:e,load:this.load,showCheckbox:this.showCheckbox,showRadio:this.showRadio,currentNodeKey:this.currentNodeKey,checkStrictly:this.checkStrictly||this.checkOnlyLeaf,checkDescendants:this.checkDescendants,expandOnCheckNode:this.expandOnCheckNode,defaultCheckedKeys:this.defaultCheckedKeys,defaultExpandedKeys:this.defaultExpandedKeys,expandCurrentNodeParent:this.expandCurrentNodeParent,autoExpandParent:this.autoExpandParent,defaultExpandAll:this.defaultExpandAll,filterNodeMethod:this.filterNodeMethod,childVisibleForFilterNode:this.childVisibleForFilterNode,showNodeIcon:this.showNodeIcon,isInjectParentInNode:this.isInjectParentInNode}),this.childNodesId=this.store.root.childNodesId,t("updateKey",(()=>{this.handleUpdateKey(),this.mathKey++}))},beforeDestroy(){this.accordion&&b(`${this.elId}-tree-node-expand`),b("updateKey")}},[["render",function(e,t,o,n,l,c){const N=g,x=d("ly-tree-node");return s(),a(N,null,{default:i((()=>[c.showLoading?(s(),a(N,{key:0,class:"ly-loader ly-flex-center"},{default:i((()=>[r(N,{class:"ly-loader-inner"},{default:i((()=>[k("加载中...")])),_:1})])),_:1})):(s(),p(u,{key:1},[c.isEmpty||!l.visible?(s(),a(N,{key:0,class:"ly-empty"},{default:i((()=>[k(f(o.emptyText),1)])),_:1})):y("",!0),(s(),a(N,{key:l.updateKey,class:h(["ly-tree",{"is-empty":c.isEmpty||!l.visible}]),role:"tree",name:"LyTreeExpand"},{default:i((()=>[(s(!0),p(u,null,C(l.childNodesId,(e=>(s(),a(x,{nodeId:e,"render-after-expand":o.renderAfterExpand,"show-checkbox":o.showCheckbox,"show-radio":o.showRadio,"check-only-leaf":o.checkOnlyLeaf,key:c.getNodeKey(e),indent:o.indent,"icon-class":o.iconClass,updateKey:"hanldeUpdateKey"},null,8,["nodeId","render-after-expand","show-checkbox","show-radio","check-only-leaf","indent","icon-class"])))),128))])),_:1},8,["class"]))],64))])),_:1})}],["__scopeId","data-v-aaf3f44f"]])},data:()=>({isReady:!1,props:{label:"userName",isLeaf:"isLeaf",value:"id",icon:"avatar"},treeData:[]}),onLoad(){_=this,this.isReady=!0},computed:{baseURL(){return this.define.baseURL}},methods:{loadNode(e,t){0===e.level?m(e.level).then((e=>{let d=JSON.parse(JSON.stringify(e.data));d.map((e=>(e.avatar=_.baseURL+e.avatar,d))),t(d)})):m(e.key).then((e=>{let d=JSON.parse(JSON.stringify(e.data));d.map((e=>(e.avatar=_.baseURL+e.avatar,d))),t(d)}))}}},[["render",function(e,t,o,n,r,h){const l=d("ly-trees"),c=g;return s(),a(c,{class:"tree-main"},{default:i((()=>[r.isReady?(s(),a(l,{key:0,props:r.props,"node-key":r.props.value,load:h.loadNode,lazy:"","tree-data":r.treeData,"show-node-icon":"",defaultExpandAll:!1},null,8,["props","node-key","load","tree-data"])):y("",!0)])),_:1})}]]);export{L as default};
-
zuoliyuan authored90de0deb