treedata-vue
Version:
TreeNewBee
2 lines (1 loc) • 1.79 kB
JavaScript
(function(e,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("vue")):typeof define=="function"&&define.amd?define(["vue"],c):(e=typeof globalThis<"u"?globalThis:e||self,e["tree-data"]=c(e.Vue))})(this,function(e){"use strict";const c="",o=(t,d)=>{const n=t.__vccOpts||t;for(const[a,i]of d)n[a]=i;return n},h={name:"treeData",props:{data:{required:!0,type:Array},nodeKey:{type:String,default:"id"},labelKey:{type:String,default:"label"},childrenKey:{type:String,default:"children"}},data(){return{ids:[]}},methods:{select(t){const d=this.ids.indexOf(t[this.nodeKey]);d>=0?this.ids.splice(d,1):this.ids.push(t[this.nodeKey]),this.$emit("select",t)},hasChild(t){return t[this.childrenKey]&&t[this.childrenKey].length}}},y={class:"tree"},_=["onClick"],f={class:"tree-child"};function K(t,d,n,a,i,s){const u=e.resolveComponent("tree-data",!0);return e.openBlock(),e.createElementBlock("div",y,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.data,l=>(e.openBlock(),e.createElementBlock("div",{class:"tree-item",key:l[n.nodeKey]},[e.createElementVNode("div",{class:e.normalizeClass(["tree-title",{"tree-title-child":s.hasChild(l),"tree-title-child-open":i.ids.includes(l[n.nodeKey])}]),onClick:m=>s.select(l)},[e.createElementVNode("span",null,e.toDisplayString(l[n.labelKey]),1)],10,_),e.withDirectives(e.createElementVNode("div",f,[s.hasChild(l)?(e.openBlock(),e.createBlock(u,{key:0,onSelect:s.select,nodeKey:n.nodeKey,labelKey:n.labelKey,childrenKey:n.childrenKey,data:l[n.childrenKey]},null,8,["onSelect","nodeKey","labelKey","childrenKey","data"])):e.createCommentVNode("",!0)],512),[[e.vShow,i.ids.includes(l[n.nodeKey])]])]))),128))])}const r=o(h,[["render",K],["__scopeId","data-v-fb75ca65"]]);return{install(t){t.component(r.name,r)}}});