Skip to content

Commit

Permalink
ng-zorro树形TagHelper添加CheckedKey等属性
Browse files Browse the repository at this point in the history
  • Loading branch information
UtilCore committed Jun 27, 2019
1 parent 5ff1092 commit 67d36d1
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,5 @@ BenchmarkDotNet.Artifacts/
/template/CodeSmith/.vs/CodeGenerator/v15
/sample/Util.Samples.Webs/node_modules
/sample/Util.Samples.Webs/wwwroot/dist
/template/CodeSmith/CodeGenerator/*.user
/template/CodeSmith/*.suo
2 changes: 1 addition & 1 deletion build/version.props
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>1</VersionMajor>
<VersionMinor>9</VersionMinor>
<VersionPatch>0.3</VersionPatch>
<VersionPatch>0.4</VersionPatch>
<VersionQuality></VersionQuality>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix></VersionSuffix>
Expand Down
Expand Up @@ -2,7 +2,7 @@
@model Util.Samples.Service.Dtos.Systems.RoleDto
<page-header [title]="'树形'"></page-header>
<nz-card [nzBordered]="false">
<util-tree url="/api/role" query-param="queryParam" show-checkbox="true"></util-tree>
<util-tree url="/api/role" multiple="true" query-param="queryParam" show-checkbox="true"></util-tree>

<util-tree-table id="t" base-url="RoleTable" query-param="queryParam" expand-all="true" >
<util-tree-table-column for="Code"></util-tree-table-column>
Expand Down
Expand Up @@ -64,15 +64,17 @@ export abstract class TableQueryComponentBase<TViewModel extends ViewModel, TQue
* 查询
* @param button 按钮
*/
query( button ) {
this.table.query( button );
query( button? ) {
this.table.query( {
button:button
} );
}

/**
* 延迟搜索
* @param button 按钮
*/
search( button ) {
search( button? ) {
this.table.search( {
button: button,
delay: this.getDelay()
Expand Down
Expand Up @@ -14,9 +14,9 @@ import { TreeQueryParameter } from "../core/tree-model";
selector: 'x-tree',
template: `
<nz-tree [nzData]="dataSource" [nzAsyncData]="async"
[nzCheckable]="showCheckbox" [nzBlockNode]="blockNode"
[nzShowExpand]="showExpand" [nzShowLine]="showLine" [nzExpandAll]="expandAll" [nzExpandedKeys]="expandedKeys"
[nzCheckedKeys]="checkedKeys" [nzSelectedKeys]="selectedKeys" [nzMultiple]="multiple" [nzShowIcon]="showIcon"
[nzCheckable]="showCheckbox" [nzBlockNode]="blockNode" [nzMultiple]="multiple"
[nzShowExpand]="showExpand" [nzShowLine]="showLine" [nzExpandAll]="expandAll" [nzShowIcon]="showIcon"
[nzExpandedKeys]="expandedKeys" [nzCheckedKeys]="checkedKeys" [nzSelectedKeys]="selectedKeys"
(nzClick)="click($event)" (nzDblClick)="dblClick($event)" (nzExpandChange)="expandChange($event)"
(nzCheckBoxChange)="checkBoxChange($event)">
</nz-tree>
Expand Down Expand Up @@ -70,15 +70,15 @@ export class Tree implements AfterContentInit {
/**
* 展开节点的标识列表
*/
@Input() expandedKeys: boolean;
@Input() expandedKeys: string[];
/**
* 复选框选中节点的标识列表
*/
@Input() checkedKeys: boolean;
@Input() checkedKeys: string[];
/**
* 选中节点的标识列表
*/
@Input() selectedKeys: boolean;
@Input() selectedKeys: string[];
/**
* 允许选中多个节点
*/
Expand Down Expand Up @@ -164,9 +164,9 @@ export class Tree implements AfterContentInit {
if ( !result )
return;
this.dataSource = result.nodes || [];
this.expandedKeys = result.expandedKeys || [];
this.checkedKeys = result.checkedKeys || [];
this.selectedKeys = result.selectedKeys || [];
this.expandedKeys = this.expandedKeys ? [...this.expandedKeys] : result.expandedKeys || [];
this.checkedKeys = this.checkedKeys ? [...this.checkedKeys] : result.checkedKeys || [];
this.selectedKeys = this.selectedKeys ? [...this.selectedKeys] : result.selectedKeys || [];
}

/**
Expand Down
Expand Up @@ -19,6 +19,10 @@ public class MenuItemTagHelper : AngularTagHelperBase {
/// [nzSelected],是否被选中,默认值:false
/// </summary>
public string Selected { get; set; }
/// <summary>
/// (click),单击事件处理函数
/// </summary>
public string OnClick { get; set; }

/// <summary>
/// 获取渲染器
Expand Down
Expand Up @@ -37,6 +37,7 @@ public class MenuItemRender : AngularRenderBase {
ConfigId( builder );
ConfigDisabled( builder );
ConfigSelected( builder );
ConfigEvents( builder );
ConfigContent( builder );
}

Expand All @@ -53,5 +54,12 @@ public class MenuItemRender : AngularRenderBase {
private void ConfigSelected( TagBuilder builder ) {
builder.AddAttribute( "[nzSelected]", _config.GetBoolValue( UiConst.Selected ) );
}

/// <summary>
/// 配置事件
/// </summary>
private void ConfigEvents( TagBuilder builder ) {
builder.AddAttribute( "(click)", _config.GetValue( UiConst.OnClick ) );
}
}
}
10 changes: 10 additions & 0 deletions src/Util.Ui.Angular.AntDesign/Zorro/Trees/Renders/TreeRender.cs
Expand Up @@ -38,6 +38,7 @@ public class TreeRender : AngularRenderBase {
ConfigId( builder );
ConfigData( builder );
ConfigNode( builder );
ConfigKeys( builder );
ConfigEvents( builder );
ConfigContent( builder );
}
Expand All @@ -64,6 +65,15 @@ public class TreeRender : AngularRenderBase {
builder.AddAttribute( "multiple", _config.GetBoolValue( UiConst.Multiple ) );
}

/// <summary>
/// 配置键列表
/// </summary>
private void ConfigKeys( TagBuilder builder ) {
builder.AddAttribute( "[checkedKeys]", _config.GetValue( UiConst.CheckedKeys ) );
builder.AddAttribute( "[expandedKeys]", _config.GetValue( UiConst.ExpandedKeys ) );
builder.AddAttribute( "[selectedKeys]", _config.GetValue( UiConst.SelectedKeys ) );
}

/// <summary>
/// 配置事件
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Util.Ui.Angular.AntDesign/Zorro/Trees/TreeTagHelper.cs
Expand Up @@ -52,6 +52,18 @@ public class TreeTagHelper : AngularTagHelperBase {
/// </summary>
public bool Multiple { get; set; }
/// <summary>
/// [nzCheckedKeys],选中复选框的标识数组,范例:['1','2']
/// </summary>
public string CheckedKeys { get; set; }
/// <summary>
/// [nzExpandedKeys],展开树节点的标识数组,范例:['1','2']
/// </summary>
public string ExpandedKeys { get; set; }
/// <summary>
/// [nzSelectedKeys],选中树节点的标识数组,范例:['1','2']
/// </summary>
public string SelectedKeys { get; set; }
/// <summary>
/// (nzClick),单击事件处理函数
/// </summary>
public string OnClick { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions src/Util.Ui.Core/Configs/UiConst.cs
Expand Up @@ -879,5 +879,17 @@ public static class UiConst {
/// 内联缩进
/// </summary>
public const string InlineIndent = "inline-indent";
/// <summary>
/// 勾选的键列表
/// </summary>
public const string CheckedKeys = "checked-keys";
/// <summary>
/// 展开的键列表
/// </summary>
public const string ExpandedKeys = "expanded-keys";
/// <summary>
/// 选中的键列表
/// </summary>
public const string SelectedKeys = "selected-keys";
}
}
Expand Up @@ -28,7 +28,7 @@ import { <%=SafeClassName%>ViewModel } from './model/<%=CamelClassName%>-view-mo
*/
@Component({
selector: '<%=CamelClassName%>-list',
templateUrl: !env.dev() ? './html/<%=CamelClassName%>-list.component.html' : '/view/<%=Namespace.ToCamelCase()%>/<%=CamelClassName%>'
templateUrl: !env.dev() ? './html/index.component.html' : '/view/<%=Namespace.ToCamelCase()%>/<%=CamelClassName%>'
})
export class <%=SafeClassName%>ListComponent extends TreeTableQueryComponentBase<<%=SafeClassName%>ViewModel, <%=SafeClassName%>Query> {
/**
Expand Down
Expand Up @@ -34,7 +34,7 @@ using Util.Applications.Dtos;

namespace <%= string.Format("{0}.Service.Dtos.{1}",Namespace,Entity.TableSchema) %> {
/// <summary>
/// <%= Description %>数据传输对象
/// <%= Description %>参数
/// </summary>
public class <%= SafeClassName %>Dto : DtoBase {
<% foreach(Property p in Entity.Properties) { %>
Expand Down
Expand Up @@ -77,5 +77,16 @@ public class MenuItemTagHelperTest {
result.Append( "<li nz-menu-item=\"\" [nzSelected]=\"true\"></li>" );
Assert.Equal( result.ToString(), GetResult( attributes ) );
}

/// <summary>
/// 测试单击事件
/// </summary>
[Fact]
public void TestOnClick() {
var attributes = new TagHelperAttributeList { { UiConst.OnClick, "a" } };
var result = new String();
result.Append( "<li (click)=\"a\" nz-menu-item=\"\"></li>" );
Assert.Equal( result.ToString(), GetResult( attributes ) );
}
}
}
Expand Up @@ -167,6 +167,39 @@ public class TreeTagHelperTest {
Assert.Equal( result.ToString(), GetResult( attributes ) );
}

/// <summary>
/// 测试勾选的键列表
/// </summary>
[Fact]
public void TestCheckedKeys() {
var attributes = new TagHelperAttributeList { { UiConst.CheckedKeys, "a" } };
var result = new String();
result.Append( "<x-tree [checkedKeys]=\"a\"></x-tree>" );
Assert.Equal( result.ToString(), GetResult( attributes ) );
}

/// <summary>
/// 测试展开的键列表
/// </summary>
[Fact]
public void TestExpandedKeys() {
var attributes = new TagHelperAttributeList { { UiConst.ExpandedKeys, "a" } };
var result = new String();
result.Append( "<x-tree [expandedKeys]=\"a\"></x-tree>" );
Assert.Equal( result.ToString(), GetResult( attributes ) );
}

/// <summary>
/// 测试选中的键列表
/// </summary>
[Fact]
public void TestSelectedKeys() {
var attributes = new TagHelperAttributeList { { UiConst.SelectedKeys, "a" } };
var result = new String();
result.Append( "<x-tree [selectedKeys]=\"a\"></x-tree>" );
Assert.Equal( result.ToString(), GetResult( attributes ) );
}

/// <summary>
/// 测试单击事件
/// </summary>
Expand Down

0 comments on commit 67d36d1

Please sign in to comment.