treedata-vue
Version:
TreeNewBee
81 lines (80 loc) • 2.14 kB
JavaScript
import { resolveComponent as y, openBlock as a, createElementBlock as s, Fragment as _, renderList as u, createElementVNode as r, normalizeClass as K, toDisplayString as f, withDirectives as v, createBlock as b, createCommentVNode as g, vShow as k } from "vue";
const C = (e, l) => {
const t = e.__vccOpts || e;
for (const [i, d] of l)
t[i] = d;
return t;
}, m = {
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(e) {
const l = this.ids.indexOf(e[this.nodeKey]);
l >= 0 ? this.ids.splice(l, 1) : this.ids.push(e[this.nodeKey]), this.$emit("select", e);
},
hasChild(e) {
return e[this.childrenKey] && e[this.childrenKey].length;
}
}
}, x = { class: "tree" }, S = ["onClick"], D = { class: "tree-child" };
function p(e, l, t, i, d, c) {
const h = y("tree-data", !0);
return a(), s("div", x, [
(a(!0), s(_, null, u(t.data, (n) => (a(), s("div", {
class: "tree-item",
key: n[t.nodeKey]
}, [
r("div", {
class: K(["tree-title", {
"tree-title-child": c.hasChild(n),
"tree-title-child-open": d.ids.includes(n[t.nodeKey])
}]),
onClick: (B) => c.select(n)
}, [
r("span", null, f(n[t.labelKey]), 1)
], 10, S),
v(r("div", D, [
c.hasChild(n) ? (a(), b(h, {
key: 0,
onSelect: c.select,
nodeKey: t.nodeKey,
labelKey: t.labelKey,
childrenKey: t.childrenKey,
data: n[t.childrenKey]
}, null, 8, ["onSelect", "nodeKey", "labelKey", "childrenKey", "data"])) : g("", !0)
], 512), [
[k, d.ids.includes(n[t.nodeKey])]
])
]))), 128))
]);
}
const o = /* @__PURE__ */ C(m, [["render", p], ["__scopeId", "data-v-fb75ca65"]]), E = {
install(e) {
e.component(o.name, o);
}
};
export {
E as default
};