2020-10-09 15:13:32 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2020-12-30 18:38:35 +08:00
|
|
|
|
public partial class TreeNodeTitle<TItem>
|
2020-10-09 15:13:32 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 树控件本身
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CascadingParameter(Name = "Tree")]
|
2020-12-30 18:38:35 +08:00
|
|
|
|
public Tree<TItem> TreeComponent { get; set; }
|
2020-10-09 15:13:32 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前节点
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CascadingParameter(Name = "SelfNode")]
|
2020-12-30 18:38:35 +08:00
|
|
|
|
public TreeNode<TItem> SelfNode { get; set; }
|
2020-10-09 15:13:32 +08:00
|
|
|
|
|
|
|
|
|
private bool CanDraggable => TreeComponent.Draggable && !SelfNode.IsDisabled;
|
|
|
|
|
|
|
|
|
|
private bool IsSwitcherOpen => SelfNode.IsExpanded && !SelfNode.IsLeaf;
|
|
|
|
|
|
|
|
|
|
private bool IsSwitcherClose => !SelfNode.IsExpanded && !SelfNode.IsLeaf;
|
|
|
|
|
|
|
|
|
|
protected ClassMapper TitleClassMapper { get; } = new ClassMapper();
|
|
|
|
|
|
|
|
|
|
private void SetTitleClassMapper()
|
|
|
|
|
{
|
|
|
|
|
TitleClassMapper.Clear().Add("ant-tree-node-content-wrapper")
|
|
|
|
|
.If("draggable", () => CanDraggable)
|
|
|
|
|
.If("ant-tree-node-content-wrapper-open", () => IsSwitcherOpen)
|
|
|
|
|
.If("ant-tree-node-content-wrapper-close", () => IsSwitcherClose)
|
|
|
|
|
.If("ant-tree-node-selected", () => SelfNode.IsSelected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
SetTitleClassMapper();
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
SetTitleClassMapper();
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnClick(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SelfNode.SetSelected(!SelfNode.IsSelected);
|
|
|
|
|
if (TreeComponent.OnClick.HasDelegate && args.Button == 0)
|
2020-12-30 18:38:35 +08:00
|
|
|
|
await TreeComponent.OnClick.InvokeAsync(new TreeEventArgs<TItem>(TreeComponent, SelfNode, args));
|
2020-10-09 15:13:32 +08:00
|
|
|
|
else if (TreeComponent.OnContextMenu.HasDelegate && args.Button == 2)
|
2020-12-30 18:38:35 +08:00
|
|
|
|
await TreeComponent.OnContextMenu.InvokeAsync(new TreeEventArgs<TItem>(TreeComponent, SelfNode, args));
|
2020-10-09 15:13:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnDblClick(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (TreeComponent.OnDblClick.HasDelegate && args.Button == 0)
|
2020-12-30 18:38:35 +08:00
|
|
|
|
await TreeComponent.OnDblClick.InvokeAsync(new TreeEventArgs<TItem>(TreeComponent, SelfNode, args));
|
2020-10-09 15:13:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|