ly-tree.DZ8MU_HY.js 25 KB

1
  1. import{$ as e,t,p as s,w as i,v as d,H as o,R as n,I as h,a2 as r,X as a,z as l,A as c,Q as u,B as f,D as p,F as y,x as k,y as C,E as N,G as g,q as x,a5 as b,o as m}from"./index-P0fyQ2Em.js";import{_ as I}from"./index.BuZ8YmVY.js";import{r as w}from"./uni-app.es.DOtS5Ldl.js";import{_ as K}from"./_plugin-vue_export-helper.BCo6x5W8.js";const v="$treeNodeId",E=function(e,t){t&&!t[v]&&Object.defineProperty(t,v,{value:e.id,enumerable:!1,configurable:!1,writable:!1})},_=function(e,t){return t?e?t[e]:t[v]:null},L=function(e){for(let t=1,s=arguments.length;t<s;t++){let s=arguments[t]||{};for(let t in s)if(s.hasOwnProperty(t)){let i=s[t];void 0!==i&&(e[t]=i)}}return e},A=function(e){let t=!0,s=!0,i=!0;for(let d=0,o=e.length;d<o;d++){const o=e[d];(!0!==o.checked||o.indeterminate)&&(t=!1,o.disabled||(i=!1)),(!1!==o.checked||o.indeterminate)&&(s=!1)}return{all:t,none:s,allWithoutDisable:i,half:!t&&!s}},O=function(e){if(!e||0===e.childNodesId.length)return;let t=e.getChildNodes(e.childNodesId);const{all:s,none:i,half:d}=A(t);s?(e.checked=!0,e.indeterminate=!1):d?(e.checked=!1,e.indeterminate=!0):i&&(e.checked=!1,e.indeterminate=!1);let o=e.getParent(e.parentId);o&&0!==o.level&&(e.store().checkStrictly||O(o))},D=function(e,t){const s=e.store().props,i=e.data||{},d=s[t];if("function"==typeof d)return d(i,e);if("string"==typeof d)return i[d];if(void 0===d){const e=i[t];return void 0===e?"":e}},P=function(e){let t=e;return function(){return t}};let B=0;class S{constructor(e){this.time=(new Date).getTime(),this.id=B++,this.text=null,this.checked=!1,this.indeterminate=!1,this.data=null,this.expanded=!1,this.parentId=null,this.visible=!0,this.isCurrent=!1;for(let t in e)e.hasOwnProperty(t)&&("store"===t?this.store=P(e[t]):this[t]=e[t]);if(!this.store())throw new Error("[Node]store is required!");this.level=0,this.loaded=!1,this.childNodesId=[],this.loading=!1,this.label=D(this,"label"),this.key=this._getKey(),this.disabled=D(this,"disabled"),this.nextSibling=null,this.previousSibling=null,this.icon="",this._handleParentAndLevel(),this._handleProps(),this._handleExpand(),this._handleCurrent(),this.store().lazy&&this.store()._initDefaultCheckedNode(this),this.updateLeafState()}_getKey(){if(!this.data||Array.isArray(this.data))return null;if("object"==typeof this.data){const e=this.store().key,t=this.data[e];if(void 0===t)throw new Error(`您配置的node-key为"${e}",但数据中并未找到对应"${e}"属性的值,请检查node-key的配置是否合理`);return t}throw new Error("不合法的data数据")}_handleParentAndLevel(){if(null!==this.parentId){let e=this.getParent(this.parentId);if(this.store().isInjectParentInNode&&(this.parent=e),e){const t=e.getChildNodes(e.childNodesId),s=e.childNodesId.indexOf(this.key);this.nextSibling=s>-1?t[s+1]:null,this.previousSibling=s>0?t[s-1]:null}else e={level:0};this.level=e.level+1}}_handleProps(){const e=this.store().props;if(this.store().showNodeIcon&&(e&&void 0!==e.icon?this.icon=D(this,"icon"):console.warn('请配置props属性中的"icon"字段')),this.store().registerNode(this),e&&void 0!==e.isLeaf){const e=D(this,"isLeaf");"boolean"==typeof e&&(this.isLeafByUser=e)}}_handleExpand(){if(!0!==this.store().lazy&&this.data?(this.setData(this.data),this.store().defaultExpandAll&&(this.expanded=!0)):this.level>0&&this.store().lazy&&this.store().defaultExpandAll&&this.expand(),Array.isArray(this.data)||E(this,this.data),!this.data)return;const e=this.store().defaultExpandedKeys;this.store().key&&e&&-1!==e.indexOf(this.key)&&this.expand(null,this.store().autoExpandparent)}_handleCurrent(){this.store().key&&void 0!==this.store().currentNodeKey&&this.key===this.store().currentNodeKey&&(this.store().currentNode=this,this.store().currentNode.isCurrent=!0)}destroyStore(){}setData(e){let t;Array.isArray(e)||E(this,e),this.data=e,this.childNodesId=[],t=0===this.level&&Array.isArray(this.data)?this.data:D(this,"children")||[];for(let s=0,i=t.length;s<i;s++)this.insertChild({data:t[s]})}contains(e,t=!0){const s=function(i){const d=i.getChildNodes(i.childNodesId)||[];let o=!1;for(let n=0,h=d.length;n<h;n++){const i=d[n];if(i===e||t&&s(i)){o=!0;break}}return o};return s(this)}remove(){if(null!==this.parentId){this.getParent(this.parentId).removeChild(this)}}insertChild(e,t,s){if(!e)throw new Error("insertChild error: child is required.");if(!(e instanceof S)){if(!s){const s=this.getChildren(!0);-1===s.indexOf(e.data)&&(void 0===t||t<0?s.push(e.data):s.splice(t,0,e.data))}L(e,{parentId:(i=this.key,null==i||""===i?"":this.key),store:this.store()}),e=new S(e)}var i;e.level=this.level+1,void 0===t||t<0?this.childNodesId.push(e.key):this.childNodesId.splice(t,0,e.key),this.updateLeafState()}insertBefore(e,t){let s;t&&(s=this.childNodesId.indexOf(t.id)),this.insertChild(e,s)}insertAfter(e,t){let s;t&&(s=this.childNodesId.indexOf(t.id),-1!==s&&(s+=1)),this.insertChild(e,s)}removeChild(e){const t=this.getChildren()||[],s=t.indexOf(e.data);s>-1&&t.splice(s,1);const i=this.childNodesId.indexOf(e.key);i>-1&&(this.store()&&this.store().deregisterNode(e),e.parentId=null,this.childNodesId.splice(i,1)),this.updateLeafState()}removeChildByData(e){let t=null;for(let s=0;s<this.childNodesId.length;s++){let i=this.getChildNodes(this.childNodesId);if(i[s].data===e){t=i[s];break}}t&&this.removeChild(t)}getParent(e){try{return e.toString()?this.store().nodesMap[e]:null}catch(t){return null}}getChildNodes(e){let t=[];return 0===e.length||e.forEach((e=>{t.push(this.store().nodesMap[e])})),t}expand(e,t){const s=()=>{if(t){let e=this.getParent(this.parentId);for(;e&&e.level>0;)e.expanded=!0,e=this.getParent(e.parentId)}this.expanded=!0,e&&e()};this.shouldLoadData()?this.loadData((function(e){Array.isArray(e)&&(this.checked?this.setChecked(!0,!0):this.store().checkStrictly||O(this),s())})):s()}doCreateChildren(e,t={}){e.forEach((e=>{this.insertChild(L({data:e},t),void 0,!0)}))}collapse(){this.expanded=!1}shouldLoadData(){return!0===this.store().lazy&&this.store().load&&!this.loaded}updateLeafState(){if(!0===this.store().lazy&&!0!==this.loaded&&void 0!==this.isLeafByUser)return void(this.isLeaf=this.isLeafByUser);const e=this.childNodesId;!this.store().lazy||!0===this.store().lazy&&!0===this.loaded?this.isLeaf=!e||0===e.length:this.isLeaf=!1}setChecked(e,t,s,i){if(this.indeterminate="half"===e,this.checked=!0===e,this.checked&&this.store().expandOnCheckNode&&this.expand(null,!0),this.store().checkStrictly)return;if(this.store().showRadio)return;if(!this.shouldLoadData()||this.store().checkDescendants){let s=this.getChildNodes(this.childNodesId),{all:d,allWithoutDisable:o}=A(s);this.isLeaf||d||!o||(this.checked=!1,e=!1);const n=()=>{if(t){let s=this.getChildNodes(this.childNodesId);for(let n=0,h=s.length;n<h;n++){const d=s[n];i=i||!1!==e;const o=d.disabled?d.checked:i;d.setChecked(o,t,!0,i)}const{half:d,all:o}=A(s);o||(this.checked=o,this.indeterminate=d)}};if(this.shouldLoadData())return void this.loadData((()=>{n(),O(this)}),{checked:!1!==e});n()}if(!this.parentId)return;let d=this.getParent(this.parentId);d&&0===d.level||s||O(d)}setRadioChecked(e){this.store()._getAllNodes().sort(((e,t)=>t.level-e.level)).forEach((e=>e.setChecked(!1,!1))),this.checked=!0===e}getChildren(e=!1){if(0===this.level)return this.data;const t=this.data;if(!t)return null;const s=this.store().props;let i="children";return s&&(i=s.children||"children"),void 0===t[i]&&(t[i]=null),e&&!t[i]&&(t[i]=[]),t[i]}updateChildren(){let e=this.getChildNodes(this.childNodesId);const t=this.getChildren()||[],s=e.map((e=>e.data)),i={},d=[];t.forEach(((e,t)=>{const o=e[v];!!o&&function(e,t){for(let s=0;s!==e.length;++s)if(t(e[s]))return s;return-1}(s,(e=>e[v]===o))>=0?i[o]={index:t,data:e}:d.push({index:t,data:e})})),this.store().lazy||s.forEach((e=>{i[e[v]]||this.removeChildByData(e)})),d.forEach((({index:e,data:t})=>{this.insertChild({data:t},e)})),this.updateLeafState()}loadData(e,t={}){if(!0!==this.store().lazy||!this.store().load||this.loaded||this.loading&&!Object.keys(t).length)e&&e.call(this);else{this.loading=!0;const s=s=>{this.loaded=!0,this.loading=!1,this.childNodesId=[],this.doCreateChildren(s,t),this.updateLeafState(),e&&e.call(this,s)};this.store().load(this,s)}}}class ${constructor(t){if(this.ready=!1,this.currentNode=null,this.currentNodeKey=null,Object.assign(this,t),!this.key)throw new Error("[Tree] nodeKey is required");if(this.nodesMap={},this.root=new S({data:this.data,store:this}),this.lazy&&this.load){(0,this.load)(this.root,(t=>{this.root.doCreateChildren(t),this._initDefaultCheckedNodes(),this.ready=!0,e("updateKey")}))}else this._initDefaultCheckedNodes(),this.ready=!0}getReady(){return this.ready}filter(e,t){const s=this.filterNodeMethod,i=this.lazy,d=this,o=function(n){const h=n.root?n.root.getChildNodes(n.root.childNodesId):n.getChildNodes(n.childNodesId);if(h.forEach((i=>{if(t&&"object"==typeof t){if(!d.getNodePath(i.data).some((e=>e[d.key]===t[d.key])))return i.visible=!1,void o(i)}if(d.childVisibleForFilterNode){let t=i.getParent(i.parentId);i.visible=s.call(i,e,i.data,i)||t&&t.visible}else i.visible=s.call(i,e,i.data,i);o(i)})),!n.visible&&h.length){let e=!0;e=!h.some((e=>e.visible)),n.root?n.root.visible=!1===e:n.visible=!1===e}e&&(!n.visible||n.isLeaf||i||n.expand())};o(this)}setData(e){e!==this.root.data?(this.root.setData(e),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(e){if(e instanceof S)return e;const t="object"!=typeof e?e:_(this.key,e);return t&&this.nodesMap[t]||null}insertBefore(e,t){const s=this.getNode(t);s.getParent(s.parentId).insertBefore({data:e},s)}insertAfter(e,t){const s=this.getNode(t);s.getParent(s.parentId).insertAfter({data:e},s)}remove(e){const t=this.getNode(e);if(t&&null!==t.parentId){let e=t.getParent(t.parentId);t===this.currentNode&&(this.currentNode=null),e.removeChild(t)}}append(e,t){const s=t?this.getNode(t):this.root;s&&s.insertChild({data:e})}_initDefaultCheckedNodes(){const e=this.defaultCheckedKeys||[],t=this.nodesMap;let s=[],i=[];for(let d in t){(D(t[d],"checked")||!1)&&s.push(d)}i=Array.from(new Set([...e,...s])),i.forEach((e=>{const s=t[e];s&&s.setChecked(!0,!this.checkStrictly)}))}_initDefaultCheckedNode(e){-1!==(this.defaultCheckedKeys||[]).indexOf(e.key)&&e.setChecked(!0,!this.checkStrictly)}toggleExpendAll(e){this._getAllNodes().forEach((t=>{const s=this.getNode(t.key);s&&(e?s.expand():s.collapse())}))}setCheckAll(e){this._getAllNodes().forEach((t=>{t.setChecked(e,!1)}))}setDefaultCheckedKey(e){e!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=e,this._initDefaultCheckedNodes())}registerNode(e){if(!this.key||!e||!e.data)return;void 0!==e.key&&(this.nodesMap[e.key]=e)}deregisterNode(e){if(!this.key||!e||!e.data)return;e.getChildNodes(e.childNodesId).forEach((e=>{this.deregisterNode(e)})),delete this.nodesMap[e.key]}getNodePath(e){if(!this.key)throw new Error("[Tree] nodeKey is required in getNodePath");const t=this.getNode(e);if(!t)return[];const s=[t.data];let i=t.getParent(t.parentId);for(;i&&i!==this.root;)s.push(i.data),i=i.getParent(i.parentId);return s.reverse()}getCheckedNodes(e=!1,t=!1){const s=[],i=function(d){(d.root?d.root.getChildNodes(d.root.childNodesId):d.getChildNodes(d.childNodesId)).forEach((d=>{(d.checked||t&&d.indeterminate)&&(!e||e&&d.isLeaf)&&s.push(d.data),i(d)}))};return i(this),s}getCheckedKeys(e=!1,t=!1){return this.getCheckedNodes(e,t).map((e=>(e||{})[this.key]))}getHalfCheckedNodes(){const e=[],t=function(s){(s.root?s.root.getChildNodes(s.root.childNodesId):s.getChildNodes(s.childNodesId)).forEach((s=>{s.indeterminate&&e.push(s.data),t(s)}))};return t(this),e}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map((e=>(e||{})[this.key]))}_getAllNodes(){const e=[],t=this.nodesMap;for(let s in t)t.hasOwnProperty(s)&&e.push(t[s]);return e}updateChildren(e,t){const s=this.nodesMap[e];if(!s)return;const i=s.getChildNodes(s.childNodesId);for(let d=i.length-1;d>=0;d--){const e=i[d];this.remove(e.data)}for(let d=0,o=t.length;d<o;d++){const e=t[d];this.append(e,s.data)}}_setCheckedKeys(e,t=!1,s){const i=this._getAllNodes().sort(((e,t)=>t.level-e.level)),d=Object.create(null),o=Object.keys(s);i.forEach((e=>e.setChecked(!1,!1)));for(let n=0,h=i.length;n<h;n++){const s=i[n];let h=s.data[e];if(void 0===h)continue;if(h=h.toString(),!(o.indexOf(h)>-1)){s.checked&&!d[h]&&s.setChecked(!1,!1);continue}let r=s.getParent(s.parentId);for(;r&&r.level>0;)d[r.data[e]]=!0,r=r.getParent(r.parentId);if(s.isLeaf||this.checkStrictly)s.setChecked(!0,!1);else if(s.setChecked(!0,!0),t){s.setChecked(!1,!1);const e=function(t){t.getChildNodes(t.childNodesId).forEach((t=>{t.isLeaf||t.setChecked(!1,!1),e(t)}))};e(s)}}}setCheckedNodes(e,t=!1){const s=this.key,i={};e.forEach((e=>{i[(e||{})[s]]=!0})),this._setCheckedKeys(s,t,i)}setCheckedKeys(e,t=!1){this.defaultCheckedKeys=e;const s=this.key,i={};e.forEach((e=>{i[e]=!0})),this._setCheckedKeys(s,t,i)}setDefaultExpandedKeys(e){e=e||[],this.defaultExpandedKeys=e,e.forEach((e=>{const t=this.getNode(e);t&&t.expand(null,this.autoExpandParent)}))}setChecked(e,t,s){const i=this.getNode(e);i&&i.setChecked(!!t,s)}getCurrentNode(){return this.currentNode}setCurrentNode(e){const t=this.currentNode;t&&(t.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0,this.expandCurrentNodeParent&&this.currentNode.expand(null,!0)}setUserCurrentNode(e){const t=e[this.key],s=this.nodesMap[t];this.setCurrentNode(s)}setCurrentNodeKey(e){if(null==e)return this.currentNode&&(this.currentNode.isCurrent=!1),void(this.currentNode=null);const t=this.getNode(e);t&&this.setCurrentNode(t)}}const j=K({data:()=>({classObj:{}}),props:{type:{type:String,validator:e=>"radio"===e||"checkbox"===e},checked:Boolean,disabled:Boolean,indeterminate:Boolean},created(){this.classObj={wrapper:`ly-${this.type}`,input:`ly-${this.type}__input`,inner:`ly-${this.type}__inner`}},methods:{handleClick(){this.$emit("check",this.checked)}}},[["render",function(e,r,a,l,c,u){const f=h;return t(),s(f,{class:o(c.classObj.wrapper),onClick:n(u.handleClick,["stop"])},{default:i((()=>[d(f,{class:o([c.classObj.input,{"is-indeterminate":a.indeterminate,"is-checked":a.checked,"is-disabled":a.disabled}])},{default:i((()=>[d(f,{class:o(c.classObj.inner)},null,8,["class"])])),_:1},8,["class"])])),_:1},8,["class","onClick"])}],["__scopeId","data-v-a02edbc1"]]);const T=K({name:"LyTree",componentName:"LyTree",components:{LyTreeNode:K({name:"LyTreeNode",componentName:"LyTreeNode",components:{lyCheckbox:j},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 _(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 s=this.tree.store._getAllNodes();this.tree.$emit("check-change",{checked:e,indeterminate:t,node:this.node,data:this.node.data,checkedall:s.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,!0),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,s=!1){if(!this.node.disabled){if(this.tree.checkOnClickNode&&!s)return this.handleClick();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&&r(`${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,r,b,m,I,w){const K=h,v=a("ly-checkbox"),E=g,_=x,L=a("ly-tree-node",!0);return l((t(),s(_,{ref:"node",name:"LyTreeNode",class:o(["ly-tree-node",{"is-expanded":I.expanded,"is-hidden":!I.node.visible,"is-checked":!I.node.disabled&&I.node.checked}]),role:"treeitem",onClick:n(w.handleClick,["stop"])},{default:i((()=>[d(_,{class:o(["ly-tree-node__content",{"is-current":I.node.isCurrent&&I.highlightCurrent}]),style:u({"padding-left":(I.node.level-1)*b.indent+"px"})},{default:i((()=>[d(K,{onClick:n(w.handleExpandIconClick,["stop"]),class:o([{"is-leaf":I.node.isLeaf,expanded:!I.node.isLeaf&&I.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?(t(),s(v,{key:0,type:w.checkboxVisible?"checkbox":"radio",checked:I.node.checked,indeterminate:I.node.indeterminate,disabled:!!I.node.disabled,onCheck:r[0]||(r[0]=e=>w.handleCheckChange(!I.node.checked))},null,8,["type","checked","indeterminate","disabled"])):f("",!0),I.node.loading?(t(),s(K,{key:1,class:"ly-tree-node__loading-icon ly-iconfont ly-icon-loading"})):f("",!0),I.node.icon&&I.node.icon.length>0?(t(),p(y,{key:2},[-1!==I.node.icon.indexOf("/")?(t(),s(E,{key:0,class:"ly-tree-node__icon",mode:"widthFix",src:I.node.icon,onError:w.handleImageError},null,8,["src","onError"])):(t(),s(K,{key:1,class:o(["ly-tree-node__icon",I.node.icon])},null,8,["class"]))],64)):f("",!0),d(K,{class:"ly-tree-node__label u-line-1"},{default:i((()=>[k(C(I.node.label),1)])),_:1})])),_:1},8,["class","style"]),!b.renderAfterExpand||I.childNodeRendered?l((t(),s(_,{key:0,class:"ly-tree-node__children",role:"group"},{default:i((()=>[(t(!0),p(y,null,N(I.node.childNodesId,(e=>(t(),s(L,{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)),[[c,I.expanded]]):f("",!0)])),_:1},8,["class","onClick"])),[[c,I.node.visible]])}],["__scopeId","data-v-dda5522c"]])},data:()=>({updateKey:(new Date).getTime(),elId:`ly_${Math.ceil(1e6*Math.random()).toString(36)}`,visible:!0,store:{ready:!1},currentNode:null,childNodesId:[],mathKey:1,show:!0}),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(){this.$nextTick((()=>{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 _(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,s){this.store.setChecked(e,t,s)},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 $({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,r("updateKey",(()=>{this.handleUpdateKey(),this.mathKey++}))},beforeDestroy(){this.accordion&&b(`${this.elId}-tree-node-expand`),b("updateKey")}},[["render",function(e,n,h,r,l,c){const u=x,g=w(m("JnpfEmpty"),I),b=a("ly-tree-node");return t(),s(u,null,{default:i((()=>[c.showLoading?(t(),s(u,{key:0,class:"ly-loader ly-flex-center"},{default:i((()=>[d(u,{class:"ly-loader-inner"},{default:i((()=>[k(C(e.$t("component.drawer.loadingText")),1)])),_:1})])),_:1})):(t(),p(y,{key:1},[c.isEmpty||!l.visible?(t(),s(g,{key:0})):f("",!0),l.show?(t(),s(u,{key:l.updateKey,class:o(["ly-tree",{"is-empty":c.isEmpty||!l.visible}]),role:"tree",name:"LyTreeExpand"},{default:i((()=>[(t(!0),p(y,null,N(l.childNodesId,(e=>(t(),s(b,{nodeId:e,"render-after-expand":h.renderAfterExpand,"show-checkbox":h.showCheckbox,"show-radio":h.showRadio,"check-only-leaf":h.checkOnlyLeaf,key:c.getNodeKey(e),indent:h.indent,"icon-class":h.iconClass},null,8,["nodeId","render-after-expand","show-checkbox","show-radio","check-only-leaf","indent","icon-class"])))),128))])),_:1},8,["class"])):f("",!0)],64))])),_:1})}],["__scopeId","data-v-a14a1894"]]);export{T as _,j as l};