| 1 |
- import{$ as e,p as t,m as s,w as d,q as i,E as o,N as n,G as r,Y as h,X as a,x as l,y as c,a1 as u,z as f,B as y,F as p,t as k,v as C,C as N,D as g,o as x,Z as b}from"./index-C9TJPork.js";import{r as m}from"./resources.DEPsJg7u.js";import{_ as I}from"./_plugin-vue_export-helper.BCo6x5W8.js";const w="$treeNodeId",K=function(e,t){t&&!t[w]&&Object.defineProperty(t,w,{value:e.id,enumerable:!1,configurable:!1,writable:!1})},v=function(e,t){return t?e?t[e]:t[w]:null},E=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 d=s[t];void 0!==d&&(e[t]=d)}}return e},_=function(e){let t=!0,s=!0,d=!0;for(let i=0,o=e.length;i<o;i++){const o=e[i];(!0!==o.checked||o.indeterminate)&&(t=!1,o.disabled||(d=!1)),(!1!==o.checked||o.indeterminate)&&(s=!1)}return{all:t,none:s,allWithoutDisable:d,half:!t&&!s}},L=function(e){if(!e||0===e.childNodesId.length)return;let t=e.getChildNodes(e.childNodesId);const{all:s,none:d,half:i}=_(t);s?(e.checked=!0,e.indeterminate=!1):i?(e.checked=!1,e.indeterminate=!0):d&&(e.checked=!1,e.indeterminate=!1);let o=e.getParent(e.parentId);o&&0!==o.level&&(e.store().checkStrictly||L(o))},D=function(e,t){const s=e.store().props,d=e.data||{},i=s[t];if("function"==typeof i)return i(d,e);if("string"==typeof i)return d[i];if(void 0===i){const e=d[t];return void 0===e?"":e}},A=function(e){let t=e;return function(){return t}};let O=0;class P{constructor(e){this.time=(new Date).getTime(),this.id=O++,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=A(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)||K(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)||K(this,e),this.data=e,this.childNodesId=[],t=0===this.level&&Array.isArray(this.data)?this.data:D(this,"children")||[];for(let s=0,d=t.length;s<d;s++)this.insertChild({data:t[s]})}contains(e,t=!0){const s=function(d){const i=d.getChildNodes(d.childNodesId)||[];let o=!1;for(let n=0,r=i.length;n<r;n++){const d=i[n];if(d===e||t&&s(d)){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 P)){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))}E(e,{parentId:(d=this.key,null==d||""===d?"":this.key),store:this.store()}),e=new P(e)}var d;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 d=this.childNodesId.indexOf(e.key);d>-1&&(this.store()&&this.store().deregisterNode(e),e.parentId=null,this.childNodesId.splice(d,1)),this.updateLeafState()}removeChildByData(e){let t=null;for(let s=0;s<this.childNodesId.length;s++){let d=this.getChildNodes(this.childNodesId);if(d[s].data===e){t=d[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||L(this),s())})):s()}doCreateChildren(e,t={}){e.forEach((e=>{this.insertChild(E({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,d){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:i,allWithoutDisable:o}=_(s);this.isLeaf||i||!o||(this.checked=!1,e=!1);const n=()=>{if(t){let s=this.getChildNodes(this.childNodesId);for(let n=0,r=s.length;n<r;n++){const i=s[n];d=d||!1!==e;const o=i.disabled?i.checked:d;i.setChecked(o,t,!0,d)}const{half:i,all:o}=_(s);o||(this.checked=o,this.indeterminate=i)}};if(this.shouldLoadData())return void this.loadData((()=>{n(),L(this)}),{checked:!1!==e});n()}if(!this.parentId)return;let i=this.getParent(this.parentId);i&&0===i.level||s||L(i)}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 d="children";return s&&(d=s.children||"children"),void 0===t[d]&&(t[d]=null),e&&!t[d]&&(t[d]=[]),t[d]}updateChildren(){let e=this.getChildNodes(this.childNodesId);const t=this.getChildren()||[],s=e.map((e=>e.data)),d={},i=[];t.forEach(((e,t)=>{const o=e[w];!!o&&function(e,t){for(let s=0;s!==e.length;++s)if(t(e[s]))return s;return-1}(s,(e=>e[w]===o))>=0?d[o]={index:t,data:e}:i.push({index:t,data:e})})),this.store().lazy||s.forEach((e=>{d[e[w]]||this.removeChildByData(e)})),i.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 B{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 P({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,d=this.lazy,i=this,o=function(n){const r=n.root?n.root.getChildNodes(n.root.childNodesId):n.getChildNodes(n.childNodesId);if(r.forEach((d=>{if(t&&"object"==typeof t){if(!i.getNodePath(d.data).some((e=>e[i.key]===t[i.key])))return d.visible=!1,void o(d)}if(i.childVisibleForFilterNode){let t=d.getParent(d.parentId);d.visible=s.call(d,e,d.data,d)||t&&t.visible}else d.visible=s.call(d,e,d.data,d);o(d)})),!n.visible&&r.length){let e=!0;e=!r.some((e=>e.visible)),n.root?n.root.visible=!1===e:n.visible=!1===e}e&&(!n.visible||n.isLeaf||d||n.expand())};o(this)}setData(e){e!==this.root.data?(this.root.setData(e),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(e){if(e instanceof P)return e;const t="object"!=typeof e?e:v(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=[],d=[];for(let i in t){(D(t[i],"checked")||!1)&&s.push(i)}d=Array.from(new Set([...e,...s])),d.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 d=t.getParent(t.parentId);for(;d&&d!==this.root;)s.push(d.data),d=d.getParent(d.parentId);return s.reverse()}getCheckedNodes(e=!1,t=!1){const s=[],d=function(i){(i.root?i.root.getChildNodes(i.root.childNodesId):i.getChildNodes(i.childNodesId)).forEach((i=>{(i.checked||t&&i.indeterminate)&&(!e||e&&i.isLeaf)&&s.push(i.data),d(i)}))};return d(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 d=s.getChildNodes(s.childNodesId);for(let i=d.length-1;i>=0;i--){const e=d[i];this.remove(e.data)}for(let i=0,o=t.length;i<o;i++){const e=t[i];this.append(e,s.data)}}_setCheckedKeys(e,t=!1,s){const d=this._getAllNodes().sort(((e,t)=>t.level-e.level)),i=Object.create(null),o=Object.keys(s);d.forEach((e=>e.setChecked(!1,!1)));for(let n=0,r=d.length;n<r;n++){const s=d[n];let r=s.data[e];if(void 0===r)continue;if(r=r.toString(),!(o.indexOf(r)>-1)){s.checked&&!i[r]&&s.setChecked(!1,!1);continue}let h=s.getParent(s.parentId);for(;h&&h.level>0;)i[h.data[e]]=!0,h=h.getParent(h.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,d={};e.forEach((e=>{d[(e||{})[s]]=!0})),this._setCheckedKeys(s,t,d)}setCheckedKeys(e,t=!1){this.defaultCheckedKeys=e;const s=this.key,d={};e.forEach((e=>{d[e]=!0})),this._setCheckedKeys(s,t,d)}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 d=this.getNode(e);d&&d.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 S=I({name:"LyTree",componentName:"LyTree",components:{LyTreeNode:I({name:"LyTreeNode",componentName:"LyTreeNode",components:{lyCheckbox:I({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,h,a,l,c,u){const f=r;return t(),s(f,{class:o(c.classObj.wrapper),onClick:n(u.handleClick,["stop"])},{default:d((()=>[i(f,{class:o([c.classObj.input,{"is-indeterminate":a.indeterminate,"is-checked":a.checked,"is-disabled":a.disabled}])},{default:d((()=>[i(f,{class:o(c.classObj.inner)},null,8,["class"])])),_:1},8,["class"])])),_:1},8,["class","onClick"])}],["__scopeId","data-v-f2b0401b"]])},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 v(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),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&&h(`${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,h,b,m,I,w){const K=r,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:d((()=>[i(_,{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:d((()=>[i(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:h[0]||(h[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(),y(p,{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),i(K,{class:"ly-tree-node__label u-line-1"},{default:d((()=>[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:d((()=>[(t(!0),y(p,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-b4d9e9cf"]])},data:()=>({updateKey:(new Date).getTime(),elId:`ly_${Math.ceil(1e6*Math.random()).toString(36)}`,visible:!0,store:{ready:!1},currentNode:null,childNodesId:[],mathKey:1,icon:m.message.nodata,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(){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 v(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 B({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,h("updateKey",(()=>{this.handleUpdateKey(),this.mathKey++}))},beforeDestroy(){this.accordion&&b(`${this.elId}-tree-node-expand`),b("updateKey")}},[["render",function(e,n,h,l,c,u){const b=x,m=g,I=r,w=a("ly-tree-node");return t(),s(b,null,{default:d((()=>[u.showLoading?(t(),s(b,{key:0,class:"ly-loader ly-flex-center"},{default:d((()=>[i(b,{class:"ly-loader-inner"},{default:d((()=>[k(C(e.$t("component.drawer.loadingText")),1)])),_:1})])),_:1})):(t(),y(p,{key:1},[u.isEmpty||!c.visible?(t(),s(b,{key:0,class:"notData-box u-flex-col"},{default:d((()=>[i(b,{class:"u-flex-col notData-inner"},{default:d((()=>[i(m,{src:c.icon,mode:"",class:"iconImg"},null,8,["src"])])),_:1}),i(I,{class:"notData-inner-text"},{default:d((()=>[k(C(e.$t("common.noData")),1)])),_:1})])),_:1})):f("",!0),c.show?(t(),s(b,{key:c.updateKey,class:o(["ly-tree",{"is-empty":u.isEmpty||!c.visible}]),role:"tree",name:"LyTreeExpand"},{default:d((()=>[(t(!0),y(p,null,N(c.childNodesId,(e=>(t(),s(w,{nodeId:e,"render-after-expand":h.renderAfterExpand,"show-checkbox":h.showCheckbox,"show-radio":h.showRadio,"check-only-leaf":h.checkOnlyLeaf,key:u.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-c6993145"]]);export{S as _};
|