zhaolei
2020-11-20 921de2254ff5712a44ed8575ee8efe34252f6603
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
using Microsoft.AspNetCore.Components;
using System;
using System.Linq;
 
namespace Bootstrap.Admin.Pages.Components
{
    /// <summary>
    /// LgbInputText 组件
    /// </summary>
    public class LgbInputBase<TItem> : ValidateInputBase<TItem>
    {
        /// <summary>
        /// 获得/设置 控件样式 默认为 col-sm-6
        /// </summary>
        [Parameter]
        public string ColumnClass { get; set; } = "col-sm-6";
 
        /// <summary>
        /// 获得/设置 控件 type 属性 默认为 text
        /// </summary>
        [Parameter]
        public string InputType { get; set; } = "text";
 
        /// <summary>
        /// 获取 最大长度属性
        /// </summary>
        protected int? MaxLength
        {
            get
            {
                if (Rules.Count == 0 &&
                    AdditionalAttributes != null &&
                    AdditionalAttributes.TryGetValue("maxlength", out var maxlength) &&
                    int.TryParse(Convert.ToString(maxlength), out int ml))
                {
                    return ml;
                }
                return (Rules.FirstOrDefault(r => r is StringLengthValidator) as StringLengthValidator)?.Length;
            }
        }
    }
}