2021-02-14 20:15:53 +08:00
|
|
|
|
using System;
|
2021-10-22 15:26:08 +08:00
|
|
|
|
using System.ComponentModel;
|
2021-02-14 20:15:53 +08:00
|
|
|
|
using System.Linq;
|
2020-11-09 22:17:27 +08:00
|
|
|
|
using AntDesign.TableModels;
|
2020-06-19 23:06:33 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public class ColumnBase : AntDomComponentBase, IColumn
|
|
|
|
|
{
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public ITable Table { get; set; }
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
[CascadingParameter(Name = "IsInitialize")]
|
|
|
|
|
public bool IsInitialize { get; set; }
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[CascadingParameter(Name = "IsHeader")]
|
|
|
|
|
public bool IsHeader { get; set; }
|
|
|
|
|
|
|
|
|
|
[CascadingParameter(Name = "IsColGroup")]
|
|
|
|
|
public bool IsColGroup { get; set; }
|
|
|
|
|
|
|
|
|
|
[CascadingParameter(Name = "IsPlaceholder")]
|
|
|
|
|
public bool IsPlaceholder { get; set; }
|
|
|
|
|
|
2021-01-20 23:35:57 +08:00
|
|
|
|
[CascadingParameter(Name = "IsBody")]
|
|
|
|
|
public bool IsBody { get; set; }
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public ColumnContext Context { get; set; }
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
[CascadingParameter(Name = "RowData")]
|
|
|
|
|
public RowData RowData { get; set; }
|
2020-08-01 23:45:48 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
[CascadingParameter(Name = "IsMeasure")]
|
|
|
|
|
public bool IsMeasure { get; set; }
|
|
|
|
|
|
2021-03-08 19:18:56 +08:00
|
|
|
|
[CascadingParameter(Name = "IsSummary")]
|
|
|
|
|
public bool IsSummary { get; set; }
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter]
|
2021-08-01 21:18:50 +08:00
|
|
|
|
public virtual string Title { get; set; }
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2020-12-05 18:44:38 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment TitleTemplate { get; set; }
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter]
|
2020-11-09 22:17:27 +08:00
|
|
|
|
public string Width { get; set; }
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2020-12-23 00:47:35 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string HeaderStyle { get; set; }
|
|
|
|
|
|
2020-09-28 16:06:02 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int RowSpan { get; set; } = 1;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int ColSpan { get; set; } = 1;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int HeaderColSpan { get; set; } = 1;
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Fixed { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
2021-01-10 21:44:25 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Ellipsis { get; set; }
|
|
|
|
|
|
2021-04-26 17:35:01 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Hidden { get; set; }
|
|
|
|
|
|
2021-10-22 15:26:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public ColumnAlign Align
|
|
|
|
|
{
|
|
|
|
|
get => _align;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_align = value;
|
|
|
|
|
_fixedStyle = CalcFixedStyle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 23:45:48 +08:00
|
|
|
|
public int ColIndex { get; set; }
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2021-01-21 14:56:20 +08:00
|
|
|
|
protected bool AppendExpandColumn => Table.HasExpandTemplate && ColIndex == (Table.TreeMode ? Table.TreeExpandIconColumnIndex : Table.ExpandIconColumnIndex);
|
|
|
|
|
|
2021-02-14 20:15:53 +08:00
|
|
|
|
private string _fixedStyle;
|
2021-01-10 21:44:25 +08:00
|
|
|
|
|
2022-03-04 17:59:13 +08:00
|
|
|
|
private ColumnAlign _align = ColumnAlign.Left;
|
|
|
|
|
|
2021-02-14 20:15:53 +08:00
|
|
|
|
protected string FixedStyle => _fixedStyle;
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
|
|
|
|
private void SetClass()
|
|
|
|
|
{
|
|
|
|
|
ClassMapper
|
|
|
|
|
.Add("ant-table-cell")
|
2021-01-09 23:57:31 +08:00
|
|
|
|
.GetIf(() => $"ant-table-cell-fix-{Fixed}", () => Fixed.IsIn("right", "left"))
|
2020-08-01 23:45:48 +08:00
|
|
|
|
.If($"ant-table-cell-fix-right-first", () => Fixed == "right" && Context?.Columns.FirstOrDefault(x => x.Fixed == "right")?.ColIndex == this.ColIndex)
|
|
|
|
|
.If($"ant-table-cell-fix-left-last", () => Fixed == "left" && Context?.Columns.LastOrDefault(x => x.Fixed == "left")?.ColIndex == this.ColIndex)
|
2021-01-21 14:56:20 +08:00
|
|
|
|
.If($"ant-table-cell-with-append", () => ColIndex == Table.TreeExpandIconColumnIndex && Table.TreeMode)
|
2021-01-10 21:44:25 +08:00
|
|
|
|
.If($"ant-table-cell-ellipsis", () => Ellipsis)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
2021-01-11 13:39:02 +08:00
|
|
|
|
|
|
|
|
|
// Render Pipeline: Initialize -> ColGroup -> Header ...
|
2021-01-09 23:57:31 +08:00
|
|
|
|
if (IsInitialize)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
2021-01-11 13:39:02 +08:00
|
|
|
|
Context?.AddColumn(this);
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
if (Fixed == "left")
|
|
|
|
|
{
|
2021-01-10 21:44:25 +08:00
|
|
|
|
Table?.HasFixLeft();
|
2021-01-09 23:57:31 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Fixed == "right")
|
|
|
|
|
{
|
2021-01-10 21:44:25 +08:00
|
|
|
|
Table?.HasFixRight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Ellipsis)
|
|
|
|
|
{
|
|
|
|
|
Table?.TableLayoutIsFixed();
|
2021-01-09 23:57:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (IsColGroup && Width == null)
|
|
|
|
|
{
|
|
|
|
|
Context?.AddColGroup(this);
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
2021-01-11 13:39:02 +08:00
|
|
|
|
else if (IsHeader)
|
|
|
|
|
{
|
|
|
|
|
Context?.AddHeaderColumn(this);
|
|
|
|
|
}
|
2020-06-19 23:06:33 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Context?.AddRowColumn(this);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 19:18:56 +08:00
|
|
|
|
if (IsHeader || IsBody || IsSummary)
|
2021-02-14 20:15:53 +08:00
|
|
|
|
{
|
|
|
|
|
_fixedStyle = CalcFixedStyle();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
SetClass();
|
|
|
|
|
}
|
2020-07-21 23:48:43 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
2021-10-22 15:26:08 +08:00
|
|
|
|
Context?.Columns.Remove(this);
|
2020-07-21 23:48:43 +08:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
2021-02-14 20:15:53 +08:00
|
|
|
|
|
|
|
|
|
private string CalcFixedStyle()
|
|
|
|
|
{
|
2021-10-22 15:26:08 +08:00
|
|
|
|
CssStyleBuilder cssStyleBuilder = new CssStyleBuilder();
|
|
|
|
|
if (Align != ColumnAlign.Left)
|
|
|
|
|
{
|
|
|
|
|
string alignment = Align switch
|
|
|
|
|
{
|
|
|
|
|
ColumnAlign.Center => "center",
|
|
|
|
|
ColumnAlign.Right => "right",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(alignment))
|
|
|
|
|
cssStyleBuilder.AddStyle("text-align", alignment);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-14 20:15:53 +08:00
|
|
|
|
if (Fixed == null || Context == null)
|
|
|
|
|
{
|
2021-10-22 15:26:08 +08:00
|
|
|
|
return cssStyleBuilder.Build();
|
2021-02-14 20:15:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fixedWidths = Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
if (Fixed == "left" && Context?.Columns.Count >= ColIndex)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < ColIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
fixedWidths = fixedWidths.Append($"{(CssSizeLength)Context?.Columns[i].Width}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Fixed == "right")
|
|
|
|
|
{
|
|
|
|
|
for (int i = (Context?.Columns.Count ?? 1) - 1; i > ColIndex; i--)
|
|
|
|
|
{
|
|
|
|
|
fixedWidths = fixedWidths.Append($"{(CssSizeLength)Context?.Columns[i].Width}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsHeader && Table.ScrollY != null && Table.ScrollX != null && Fixed == "right")
|
|
|
|
|
{
|
|
|
|
|
fixedWidths = fixedWidths.Append($"{(CssSizeLength)Table.ScrollBarWidth}");
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 15:26:08 +08:00
|
|
|
|
cssStyleBuilder.AddStyle("position", "sticky");
|
|
|
|
|
cssStyleBuilder.AddStyle(Fixed, $"{(fixedWidths.Any() ? $"calc({string.Join(" + ", fixedWidths) })" : "0px")}");
|
|
|
|
|
|
|
|
|
|
return cssStyleBuilder.Build();
|
2021-02-14 20:15:53 +08:00
|
|
|
|
}
|
2021-04-01 12:50:30 +08:00
|
|
|
|
|
|
|
|
|
protected void ToggleTreeNode()
|
|
|
|
|
{
|
|
|
|
|
RowData.Expanded = !RowData.Expanded;
|
2022-01-10 15:55:00 +08:00
|
|
|
|
Table?.OnExpandChange(RowData);
|
2021-04-01 12:50:30 +08:00
|
|
|
|
}
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|