import { shortcut, extend, VerticalAdaptLayout, Layout, compact, isKey } from "@/core"; import { NodeButton, Label, IconLabel } from "@/base"; @shortcut() export class BasicTreeItem extends NodeButton { static xtype = "bi.tree_item"; _defaultConfig() { const conf = super._defaultConfig(...arguments); return extend(conf, { baseCls: `${conf.baseCls || ""} bi-tree-item bi-list-item-active`, id: "", pId: "", height: 24, readonly: true, isFirstNode: false, isLastNode: false, layer: 0, iconWidth: 16, iconHeight: 16, iconCls: "", }); } render() { const { layer, height, hgap, textHgap, textVgap, textLgap, textRgap, text, value, py, keyword, iconWidth, iconHeight, iconCls, } = this.options; const icon = isKey(iconCls) ? { el: { type: IconLabel.xtype, iconWidth, iconHeight, cls: iconCls, }, width: 24, } : null; const indent = layer === 0 ? null : { el: { type: Layout.xtype, height, width: height, cls: this.getLineCls(), }, lgap: layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2, // 偏移公式为每一层的偏移量为节点高度的一半 width: "", }; return { type: VerticalAdaptLayout.xtype, items: compact([ icon, indent, { el: { type: Label.xtype, ref: _ref => { this.text = _ref; }, textAlign: "left", whiteSpace: "nowrap", textHeight: height, height, hgap: hgap || textHgap, vgap: textVgap, lgap: textLgap, rgap: textRgap, text, value, keyword, py, }, width: "fill", } ]), }; } getLineCls() { const options = this.options; if (options.layer === 0 && options.isFirstNode && options.isLastNode) { return ""; } else if (options.layer === 0 && options.isFirstNode) { return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? "tree-first-solid-line-conn-background" : "first-line-conn-background"; } else if (options.isLastNode) { return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? "tree-last-solid-line-conn-background" : "last-line-conn-background"; } else { return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? "tree-mid-solid-line-conn-background" : "mid-line-conn-background"; } } doRedMark() { this.text.doRedMark(...arguments); } unRedMark() { this.text.unRedMark(...arguments); } getId() { return this.options.id; } getPId() { return this.options.pId; } } export class FirstTreeLeafItem extends BasicTreeItem { static xtype = "bi.first_tree_leaf_item"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { extraCls: "bi-first-tree-leaf-item", isFirstNode: true, isLastNode: false, }); } } @shortcut() export class MidTreeLeafItem extends BasicTreeItem { static xtype = "bi.mid_tree_leaf_item"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { extraCls: "bi-mid-tree-leaf-item", isFirstNode: false, isLastNode: false, }); } } @shortcut() export class LastTreeLeafItem extends BasicTreeItem { static xtype = "bi.last_tree_leaf_item"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { extraCls: "bi-last-tree-leaf-item", isFirstNode: false, isLastNode: true, }); } } @shortcut() export class RootTreeLeafItem extends BasicTreeItem { static xtype = "bi.root_tree_leaf_item"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { extraCls: "bi-root-tree-leaf-item", isFirstNode: false, isLastNode: false, }); } }