|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +using Microsoft.AspNetCore.Components.Forms; |
| 7 | + |
| 8 | +namespace BootstrapBlazor.Server.Components.Samples.Tutorials; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// BarCodeGenerator 组件示例代码 |
| 12 | +/// </summary> |
| 13 | +public partial class BarCodeGenerator |
| 14 | +{ |
| 15 | + private string _activeContentType = "Text"; |
| 16 | + |
| 17 | + private readonly List<string> _contents = ["Text", "Url", "Wi-Fi", "Email"]; |
| 18 | + |
| 19 | + private readonly WiFiContent _wifiContent = new(); |
| 20 | + |
| 21 | + private readonly EmailContent _emailContent = new(); |
| 22 | + |
| 23 | + private readonly TextContent _textContent = new(); |
| 24 | + |
| 25 | + private readonly TextContent _urlContent = new(); |
| 26 | + |
| 27 | + private string? _content; |
| 28 | + |
| 29 | + private string _desc => _activeContentType switch |
| 30 | + { |
| 31 | + "Text" => Localizer["TextDesc"], |
| 32 | + "Url" => Localizer["UrlDesc"], |
| 33 | + "Wi-Fi" => Localizer["WiFiDesc"], |
| 34 | + "Email" => Localizer["EmailDesc"], |
| 35 | + _ => string.Empty |
| 36 | + }; |
| 37 | + |
| 38 | + private string? GetItemClassString(string item) => CssBuilder.Default("bc-type-item") |
| 39 | + .AddClass("active", _activeContentType == item) |
| 40 | + .Build(); |
| 41 | + |
| 42 | + private void OnActiveType(string item) |
| 43 | + { |
| 44 | + _activeContentType = item; |
| 45 | + } |
| 46 | + |
| 47 | + private Task OnTextSubmit(EditContext context) |
| 48 | + { |
| 49 | + _content = _textContent.ToString(); |
| 50 | + StateHasChanged(); |
| 51 | + return Task.CompletedTask; |
| 52 | + } |
| 53 | + |
| 54 | + private Task OnUrlSubmit(EditContext context) |
| 55 | + { |
| 56 | + _content = _urlContent.ToString(); |
| 57 | + StateHasChanged(); |
| 58 | + return Task.CompletedTask; |
| 59 | + } |
| 60 | + |
| 61 | + private Task OnWiFiSubmit(EditContext context) |
| 62 | + { |
| 63 | + _content = _wifiContent.ToString(); |
| 64 | + StateHasChanged(); |
| 65 | + return Task.CompletedTask; |
| 66 | + } |
| 67 | + |
| 68 | + private Task OnEmailSubmit(EditContext context) |
| 69 | + { |
| 70 | + _content = _emailContent.ToString(); |
| 71 | + StateHasChanged(); |
| 72 | + return Task.CompletedTask; |
| 73 | + } |
| 74 | +} |
0 commit comments