Enterprise-level component library based on Bootstrap and Blazor

star nuget license download repo commit master coverage

AutoFill 自动填充组件

通过智能感应提示选项,选中后自动填充表单

填充表单

Demo
录入 Name 姓名智能提示,选择提示项后自动填充下方表单 目前支持键盘 Enter Spance
Loading...

通过设置自定义过滤条件回调委托 OnCustomFilter 过滤数据

Demo
录入 Name 姓名智能提示,通过设置自定义过滤条件回调委托 OnCustomFilter 过滤数据,当前过滤条件为 Name 包含输入字符串 并且 Count 值大于 50
Loading...

Attributes

Loading...
@page "/autofills"

<h3>AutoFill 自动填充组件</h3>

<h4>通过智能感应提示选项,选中后自动填充表单</h4>

<DemoBlock Title="基本用法" Introduction="填充表单" Name="Normal">
    <div class="mb-3">录入 <code>Name</code> 姓名智能提示,选择提示项后自动填充下方表单 目前支持键盘 <kbd>Enter</kbd> <kbd>Spance</kbd> <kbd><i class="fa fa-arrow-up"></i></kbd> <kbd><i class="fa fa-arrow-down"></i></kbd></div>
    <AutoFill TValue="Foo" Value="Model" Items="Items" IsLikeMatch="true" OnSelectedItemChanged="OnSelectedItemChanged" OnGetDisplayText="OnGetDisplayText" class="mb-3" IsSelectAllTextOnFocus="true">
        <Template>
            <div class="d-flex">
                <div>
                    <img src="@Foo.GetAvatarUrl(context.Id)" class="bb-avatar" />
                </div>
                <div class="ps-2">
                    <div>@context.Name</div>
                    <div class="bb-sub">@Foo.GetTitle(context.Id)</div>
                </div>
            </div>
        </Template>
    </AutoFill>
    <img src="@Foo.GetAvatarUrl(Model.Id)" class="shadow" style="width: 140px; margin-bottom: 1rem; border-radius: 6px;" />
    <EditorForm Model="@Model" RowType="RowType.Inline" ItemsPerRow="2" />
</DemoBlock>

<DemoBlock Title="自定义过滤条件" Introduction="通过设置自定义过滤条件回调委托 <code>OnCustomFilter</code> 过滤数据" Name="CustomFilter">
    <div class="mb-3">录入 <code>Name</code> 姓名智能提示,通过设置自定义过滤条件回调委托 <code>OnCustomFilter</code> 过滤数据,当前过滤条件为 <code>Name</code> 包含输入字符串 <b>并且</b> <code>Count</code> 值大于 50</div>
    <AutoFill TValue="Foo" Value="Model" Items="Items" OnCustomFilter="OnCustomFilter"  OnSelectedItemChanged="OnSelectedItemChanged" OnGetDisplayText="OnGetDisplayText" class="mb-3">
        <Template>
            <div class="d-flex">
                <div>
                    <img src="@Foo.GetAvatarUrl(context.Id)" class="bb-avatar" />
                </div>
                <div class="ps-2">
                    <div>@context.Name</div>
                    <div class="bb-sub">@Foo.GetTitle(context.Id)</div>
                </div>
            </div>
        </Template>
    </AutoFill>
    <EditorForm Model="@Model" RowType="RowType.Inline" ItemsPerRow="2" />
</DemoBlock>

<AttributeTable Items="@GetAttributes()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using BootstrapBlazor.Components;
using BootstrapBlazor.Shared.Common;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace BootstrapBlazor.Shared.Samples;

/// <summary>
/// 
/// </summary>
partial class AutoFills
{
    [NotNull]
    private Foo Model { get; set; } = new();

    [NotNull]
    private IEnumerable<Foo>? Items { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? LocalizerFoo { get; set; }

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Items = Foo.GenerateFoo(LocalizerFoo);
    }

    private Task OnSelectedItemChanged(Foo foo)
    {
        Model = Utility.Clone(foo);
        StateHasChanged();
        return Task.CompletedTask;
    }

    private string OnGetDisplayText(Foo foo) => foo.Name ?? "";

    private Task<IEnumerable<Foo>> OnCustomFilter(string searchText)
    {
        var items = string.IsNullOrEmpty(searchText) ? Items : Items.Where(i => i.Count > 50 && i.Name!.Contains(searchText));
        return Task.FromResult(items);
    }

    /// <summary>
    /// 获得属性方法
    /// </summary>
    /// <returns></returns>
    private IEnumerable<AttributeItem> GetAttributes() => new[]
    {
            // TODO: 移动到数据库中
            new AttributeItem() {
                Name = "DisplayCount",
                Description = "匹配数据时显示的数量",
                Type = "int",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "NoDataTip",
                Description = "无匹配数据时显示提示信息",
                Type = "string",
                ValueList = " — ",
                DefaultValue = "无匹配数据"
            },
            new AttributeItem() {
                Name = "IgnoreCase",
                Description = "匹配时是否忽略大小写",
                Type = "bool",
                ValueList = "true/false",
                DefaultValue = "true"
            },
            new AttributeItem() {
                Name = "IsLikeMatch",
                Description = "是否开启模糊查询",
                Type = "bool",
                ValueList = "true/false",
                DefaultValue = "false"
            },
            new AttributeItem() {
                Name = "Items",
                Description = "组件数据集合",
                Type = "IEnumerable<TValue>",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "OnCustomFilter",
                Description = "自定义集合过滤规则",
                Type = "Func<string, Task<IEnumerable<TValue>>>",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "OnGetDisplayText",
                Description = "通过模型获得显示文本方法",
                Type = "Func<TValue, string>",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "OnSelectedItemChanged",
                Description = "选项改变回调方法",
                Type = "Func<TValue, Task>",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "Template",
                Description = "候选项模板",
                Type = "RenderFragment<TValue>",
                ValueList = " — ",
                DefaultValue = " — "
            }
        };
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
Themes
Bootstrap
Motronic
Ant Design (完善中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload