/
BarcodeGenerators.razor
172 lines (156 loc) · 6.9 KB
/
BarcodeGenerators.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@page "/barcodeGenerators"
@attribute [TabItemOption(Text = "条码生成器", Icon = "fa fa-barcode")]
@inherits AppComponentBase
@using System.ComponentModel
@using BootstrapBlazor.Components
<a href="https://www.nuget.org/packages/BootstrapBlazor.BarcodeGenerator#readme-body-tab"><h3>条码生成器 Barcode Generator</h3></a>
<hr />
<a href="https://github.com/densen2014/Densen.Extensions/blob/master/Demo/DemoShared/Pages/BarcodeGenerators.razor"><h5>页面源码</h5></a>
<Tab IsLazyLoadTabItem>
<TabItem Text="条码生成器">
<div style="max-width: 554px;">
<div class="col-12" style="text-align: center; vertical-align: middle;">
<BarCodeGenerator Value="@value" Options="Options" OnResult="OnResult" />
</div>
<GroupBox Title="参数">
<div class="row g-3">
<div class="col-12 col-sm-6">
<InputOnKeyup @bind-Value="value" ShowLabel="true" OnInput="true" />
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Options.Type" OnValueChanged="OnValueChanged" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Slider @bind-Value="Options.Width" Min="1" Max="6" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Slider @bind-Value="Options.Height" Min="10" Max="300" Step="5" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Slider @bind-Value="Options.Margin" Min="-30" Max="100" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Switch @bind-Value="Options.Flat" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<ColorPicker @bind-Value="Options.Background" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<ColorPicker @bind-Value="Options.LineColor" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Switch @bind-Value="Options.DisplayValue" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<InputOnKeyup ShowLabel="true" @bind-Value="Options.Text" OnInput="true" />
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Options.TextAlign" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Options.TextPosition" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Options.Font" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Options.FontOptions" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Slider @bind-Value="Options.FontSize" Min="8" Max="52" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Slider @bind-Value="Options.TextMargin" Min="-30" Max="100" ShowLabel="true" />
</div>
<div class="col-12 col-sm-6">
<Textarea Value="@svg" DisplayText="SVG内容" ShowLabel="true" />
</div>
</div>
</GroupBox>
@*<Textarea @bind-Value="value" />*@
</div>
</TabItem>
<TabItem Text="批量">
<BarCodeGenerator Type="EnumBarcodeType.CODE128" Value="Hi!" />
<BarCodeGenerator Type="EnumBarcodeType.EAN13" Value="1234567890128" />
<BarCodeGenerator Type="EnumBarcodeType.EAN8" Value="12345670" />
<BarCodeGenerator Type="EnumBarcodeType.EAN5" Value="12345" />
<BarCodeGenerator Type="EnumBarcodeType.EAN2" Value="12" />
<BarCodeGenerator Type="EnumBarcodeType.UPC" Value="123456789012" />
<BarCodeGenerator Type="EnumBarcodeType.CODE39" Value="Hello" />
<BarCodeGenerator Type="EnumBarcodeType.ITF14" Value="1234567890123" />
<BarCodeGenerator Type="EnumBarcodeType.ITF14" Value="123456" />
<BarCodeGenerator Type="EnumBarcodeType.MSI" Value="12345" />
</TabItem>
<TabItem Text="简单配置">
<BarCodeGenerator Options="Options1" />
<BarCodeGenerator Options="Options2" />
<BarCodeGenerator Options="Options3" />
</TabItem>
</Tab>
@code{
private BarcodeGeneratorOption Options { get; set; } = new();
private BarcodeGeneratorOption Options1 { get; set; } = new()
{
Value = "Hi!",
FontSize = 40,
Background = "#4b8b7f",
LineColor = "#ffffff",
Margin = 40,
TextMargin = 80
};
private BarcodeGeneratorOption Options2 { get; set; } = new()
{
Value = "Hi!",
TextAlign = EnumBarcodeTextAlign.left,
TextPosition = EnumTextPosition.top,
Font = EnumBarcodeFont.Cursive,
FontOptions = EnumBarcodeFontOption.bold,
FontSize = 40,
TextMargin = 15,
Text = "Special"
};
private BarcodeGeneratorOption Options3 { get; set; } = new()
{
Value = "1234",
Type = EnumBarcodeType.pharmacode,
DisplayValue = false,
Height = 50,
Width = 6
};
private Dictionary<string, string> defaultValues = new Dictionary<string, string>()
{
{ "CODE128", "Example 1234"},
{ "CODE128A", "EXAMPLE"},
{ "CODE128B", "Example text"},
{ "CODE128C", "12345678"},
{ "EAN13", "1234567890128"},
{ "EAN8", "12345670"},
{ "EAN5", "12340"},
{ "EAN2", "10"},
{ "UPC", "123456789999"},
{ "CODE39", "EXAMPLE TEXT"},
{ "ITF14", "10012345000017"},
{ "ITF", "123456"},
{ "MSI", "123456"},
{ "MSI10", "123456"},
{ "MSI11", "123456"},
{ "MSI1010", "123456"},
{ "MSI1110", "123456"},
{ "pharmacode", "1234"}
};
[DisplayName("条码文字")]
private string? value { get; set; } = "12345";
[DisplayName("SVG内容")]
private string? svg { get; set; }
private Task OnResult(string value)
{
svg = value;
return Task.CompletedTask;
}
private Task OnValueChanged(EnumBarcodeType type)
{
value = defaultValues[type.ToString()];
return Task.CompletedTask;
}
}