UNPKG

@opensig/opendesign

Version:

<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>

49 lines (48 loc) 1.26 kB
"use strict"; const tree = require("../_utils/tree.js"); const is = require("../_utils/is.js"); class MenuTree extends tree.VTree { constructor(value, parent, children = []) { super(value, parent, children); } addChild(options) { const { value, parentVal } = options; const node = { value, parent: null, children: [] }; if (is.isUndefined(parentVal)) { if (!this.hasSameNode(this.root.children, node.value)) { node.parent = this.root; this.root.children.push(node); } } else { const parentNode = this.getNode(this.root, parentVal); if (parentNode && !this.hasSameNode(parentNode.children, node.value)) { node.parent = parentNode; parentNode.children.push(node); } } } selectNode(val) { const path = this.getPath(this.root, val, []) || []; return path.map((node) => { if (is.isString(node.value)) { return node.value; } }); } getSiblings(val) { const node = this.getNode(this.root, val); if (!node || !node.parent) { return []; } return node.parent.children.map((item) => { if (item.value !== val) { return item.value; } }); } } module.exports = MenuTree;