2020-10-09 15:13:32 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2021-01-10 18:49:52 +08:00
|
|
|
|
public partial class TreeNodeSwitcher<TItem> : ComponentBase
|
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 IsShowLineIcon => !SelfNode.IsLeaf && TreeComponent.ShowLine;
|
|
|
|
|
|
|
|
|
|
private bool IsShowSwitchIcon => !SelfNode.IsLeaf && !TreeComponent.ShowLine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 节点是否处于展开状态
|
|
|
|
|
/// </summary>
|
2021-01-07 00:41:26 +08:00
|
|
|
|
private bool IsSwitcherOpen => SelfNode.Expanded && !SelfNode.IsLeaf;
|
2020-10-09 15:13:32 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 节点是否处于关闭状态
|
|
|
|
|
/// </summary>
|
2021-01-07 00:41:26 +08:00
|
|
|
|
private bool IsSwitcherClose => !SelfNode.Expanded && !SelfNode.IsLeaf;
|
2020-10-09 15:13:32 +08:00
|
|
|
|
|
|
|
|
|
protected ClassMapper ClassMapper { get; } = new ClassMapper();
|
|
|
|
|
|
|
|
|
|
private void SetClassMap()
|
|
|
|
|
{
|
|
|
|
|
ClassMapper.Clear().Add("ant-tree-switcher")
|
|
|
|
|
.If("ant-tree-switcher-noop", () => SelfNode.IsLeaf)
|
|
|
|
|
.If("ant-tree-switcher_open", () => IsSwitcherOpen)
|
|
|
|
|
.If("ant-tree-switcher_close", () => IsSwitcherClose);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
SetClassMap();
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
SetClassMap();
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<MouseEventArgs> OnSwitcherClick { get; set; }
|
|
|
|
|
|
|
|
|
|
private async Task OnClick(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (OnSwitcherClick.HasDelegate)
|
|
|
|
|
await OnSwitcherClick.InvokeAsync(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|