|
| 1 | +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | +// Website: https://www.blazor.zone or https://argozhang.github.io/ |
| 4 | + |
| 5 | +using Microsoft.AspNetCore.Components; |
| 6 | +using Microsoft.AspNetCore.Components.Rendering; |
| 7 | +using System.Text.Json.Serialization; |
| 8 | + |
| 9 | +namespace BootstrapBlazor.Components; |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// <para lang="zh">DockContentItem 配置项子项对标 content 配置项内部 content 配置</para> |
| 13 | +/// <para lang="en">DockContentItem configuration item sub-item corresponds to the content configuration item inside the content configuration item</para> |
| 14 | +/// </summary> |
| 15 | +public class DockViewComponent : DockViewComponentBase |
| 16 | +{ |
| 17 | + /// <summary> |
| 18 | + /// <para lang="zh">获得/设置 组件是否显示 Header 默认 true 显示</para> |
| 19 | + /// <para lang="en">Gets or sets whether the component header is displayed. Default is true.</para> |
| 20 | + /// </summary> |
| 21 | + [Parameter] |
| 22 | + public bool ShowHeader { get; set; } = true; |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// <para lang="zh">获得/设置 组件 Title</para> |
| 26 | + /// <para lang="en">Gets or sets the component title.</para> |
| 27 | + /// </summary> |
| 28 | + [Parameter] |
| 29 | + public string? Title { get; set; } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// <para lang="zh">获得/设置 组件 Title 宽度 默认 null 未设置</para> |
| 33 | + /// <para lang="en">Gets or sets the component title width. Default is null (not set).</para> |
| 34 | + /// </summary> |
| 35 | + [Parameter] |
| 36 | + public int? TitleWidth { get; set; } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// <para lang="zh">获得/设置 组件 Title 样式 默认 null 未设置</para> |
| 40 | + /// <para lang="en">Gets or sets the component title style. Default is null (not set).</para> |
| 41 | + /// </summary> |
| 42 | + [Parameter] |
| 43 | + public string? TitleClass { get; set; } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// <para lang="zh">获得/设置 Title 模板 默认 null 未设置</para> |
| 47 | + /// <para lang="en">Gets or sets the title template. Default is null (not set).</para> |
| 48 | + /// </summary> |
| 49 | + [Parameter] |
| 50 | + [JsonIgnore] |
| 51 | + public RenderFragment? TitleTemplate { get; set; } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// <para lang="zh">获得/设置 组件 Class 默认 null 未设置</para> |
| 55 | + /// <para lang="en">Gets or sets the component class. Default is null (not set).</para> |
| 56 | + /// </summary> |
| 57 | + [Parameter] |
| 58 | + public string? Class { get; set; } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// <para lang="zh">获得/设置 组件是否可见 默认 true 可见</para> |
| 62 | + /// <para lang="en">Gets or sets whether the component is visible. Default is true.</para> |
| 63 | + /// </summary> |
| 64 | + [Parameter] |
| 65 | + public bool Visible { get; set; } = true; |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// <para lang="zh">获得/设置 组件是否允许关闭 默认 null 使用 DockView 的配置</para> |
| 69 | + /// <para lang="en">Gets or sets whether the component is allowed to be closed. Default is null (uses DockView configuration).</para> |
| 70 | + /// </summary> |
| 71 | + [Parameter] |
| 72 | + public bool? ShowClose { get; set; } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// <para lang="zh">获得/设置 组件唯一标识值 默认 null 未设置时取 Title 作为唯一标识</para> |
| 76 | + /// <para lang="en">Gets or sets the unique identifier for the component. Default is null, uses Title as the identifier if not set.</para> |
| 77 | + /// </summary> |
| 78 | + [Parameter] |
| 79 | + public string? Key { get; set; } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// <para lang="zh">获得/设置 是否锁定 默认 null 未设置时取 DockView 的配置</para> |
| 83 | + /// <para lang="en">Gets or sets whether the component is locked. Default is null (uses DockView configuration).</para> |
| 84 | + /// </summary> |
| 85 | + /// <remarks>锁定后无法拖动</remarks> |
| 86 | + [Parameter] |
| 87 | + public bool? IsLock { get; set; } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// <para lang="zh">获得/设置 是否显示锁定按钮 默认 null 未设置时取 DockView 的配置</para> |
| 91 | + /// <para lang="en">Gets or sets whether the lock button is displayed. Default is null (uses DockView configuration).</para> |
| 92 | + /// </summary> |
| 93 | + [Parameter] |
| 94 | + public bool? ShowLock { get; set; } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// <para lang="zh">获得/设置 是否悬浮 默认 null 未设置时取 DockView 的配置</para> |
| 98 | + /// <para lang="en">Gets or sets whether the component is floating. Default is null (uses DockView configuration).</para> |
| 99 | + /// </summary> |
| 100 | + [Parameter] |
| 101 | + public bool? IsFloating { get; set; } |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// <para lang="zh">获得/设置 是否显示可悬浮按钮 默认 null 未设置时取 DockView 的配置</para> |
| 105 | + /// <para lang="en">Gets or sets whether the float button is displayed. Default is null (uses DockView configuration).</para> |
| 106 | + /// </summary> |
| 107 | + [Parameter] |
| 108 | + public bool? ShowFloat { get; set; } |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// <para lang="zh">获得/设置 是否显示最大化按钮 默认 null 未设置时取 DockView 的配置</para> |
| 112 | + /// <para lang="en">Gets or sets whether the maximize button is displayed. Default is null (uses DockView configuration).</para> |
| 113 | + /// </summary> |
| 114 | + [Parameter] |
| 115 | + public bool? ShowMaximize { get; set; } |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// <para lang="zh">获得/设置 是否一直显示 默认 null 未设置时取 DockView 的配置</para> |
| 119 | + /// <para lang="en">Gets or sets whether the component is always displayed. Default is null (uses DockView configuration).</para> |
| 120 | + /// </summary> |
| 121 | + [Parameter] |
| 122 | + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] |
| 123 | + public string? Renderer { get; set; } |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// <para lang="zh">获得/设置 是否显示标题前置图标 默认 false 不显示</para> |
| 127 | + /// <para lang="en">Gets or sets whether the title bar icon is displayed. Default is false.</para> |
| 128 | + /// </summary> |
| 129 | + [Parameter] |
| 130 | + [JsonIgnore] |
| 131 | + public bool ShowTitleBar { get; set; } |
| 132 | + |
| 133 | + /// <summary> |
| 134 | + /// <para lang="zh">获得/设置 标题前置图标 默认 null 未设置使用默认图标</para> |
| 135 | + /// <para lang="en">Gets or sets the title bar icon. Default is null, uses the default icon if not set.</para> |
| 136 | + /// </summary> |
| 137 | + [Parameter] |
| 138 | + [JsonIgnore] |
| 139 | + public string? TitleBarIcon { get; set; } |
| 140 | + |
| 141 | + /// <summary> |
| 142 | + /// <para lang="zh">获得/设置 标题前置图标 Url 默认 null 未设置使用默认图标</para> |
| 143 | + /// <para lang="en">Gets or sets the title bar icon URL. Default is null, uses the default icon if not set.</para> |
| 144 | + /// </summary> |
| 145 | + [Parameter] |
| 146 | + [JsonIgnore] |
| 147 | + public string? TitleBarIconUrl { get; set; } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// <para lang="zh">获得/设置 标题前置图标点击回调方法 默认 null</para> |
| 151 | + /// <para lang="en">Gets or sets the callback method for clicking the title bar icon. Default is null.</para> |
| 152 | + /// </summary> |
| 153 | + [Parameter] |
| 154 | + [JsonIgnore] |
| 155 | + public Func<Task>? OnClickTitleBarCallback { get; set; } |
| 156 | + |
| 157 | + [CascadingParameter] |
| 158 | + [NotNull] |
| 159 | + private DockViewV2? DockView { get; set; } |
| 160 | + |
| 161 | + /// <summary> |
| 162 | + /// <inheritdoc/> |
| 163 | + /// </summary> |
| 164 | + protected override void OnInitialized() |
| 165 | + { |
| 166 | + base.OnInitialized(); |
| 167 | + |
| 168 | + Type = DockViewContentType.Component; |
| 169 | + } |
| 170 | + |
| 171 | + /// <summary> |
| 172 | + /// <inheritdoc/> |
| 173 | + /// </summary> |
| 174 | + /// <param name="builder"></param> |
| 175 | + protected override void BuildRenderTree(RenderTreeBuilder builder) |
| 176 | + { |
| 177 | + builder.OpenElement(0, "div"); |
| 178 | + builder.AddAttribute(10, "id", Id); |
| 179 | + builder.AddAttribute(20, "class", "bb-dockview-panel"); |
| 180 | + builder.AddAttribute(30, "data-bb-key", Key); |
| 181 | + builder.AddAttribute(40, "data-bb-title", Title); |
| 182 | + |
| 183 | + if (TitleTemplate != null) |
| 184 | + { |
| 185 | + builder.OpenElement(50, "div"); |
| 186 | + builder.AddAttribute(51, "class", "bb-dockview-item-title"); |
| 187 | + builder.AddContent(53, TitleTemplate); |
| 188 | + builder.CloseElement(); |
| 189 | + } |
| 190 | + else if (ShowTitleBar) |
| 191 | + { |
| 192 | + builder.OpenComponent<DockViewTitleBar>(60); |
| 193 | + builder.AddAttribute(61, nameof(DockViewTitleBar.BarIcon), TitleBarIcon); |
| 194 | + builder.AddAttribute(62, nameof(DockViewTitleBar.BarIconUrl), TitleBarIconUrl); |
| 195 | + builder.AddAttribute(63, nameof(DockViewTitleBar.OnClickBarCallback), OnClickBar); |
| 196 | + builder.CloseComponent(); |
| 197 | + } |
| 198 | + |
| 199 | + if (DockView.ShowTab(Key)) |
| 200 | + { |
| 201 | + builder.AddContent(70, ChildContent); |
| 202 | + } |
| 203 | + builder.CloseElement(); |
| 204 | + } |
| 205 | + |
| 206 | + private async Task OnClickBar() |
| 207 | + { |
| 208 | + if (OnClickTitleBarCallback != null) |
| 209 | + { |
| 210 | + await OnClickTitleBarCallback(); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + /// <summary> |
| 215 | + /// <para lang="zh">设置 Visible 参数方法</para> |
| 216 | + /// <para lang="en">Sets the Visible parameter.</para> |
| 217 | + /// </summary> |
| 218 | + /// <param name="visible"></param> |
| 219 | + public void SetVisible(bool visible) |
| 220 | + { |
| 221 | + Visible = visible; |
| 222 | + } |
| 223 | +} |
0 commit comments