| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- using Abp.Localization;
- using VberZero;
- using VberZero.Tools.StringModel;
- namespace VberAdmin.Web.Models.Input;
- public abstract class VmInputBase
- {
- protected static string L(string name)
- {
- var str = LocalizationHelper.GetSource(VzConsts.LocalizationSourceName).GetString(name);
- return str;
- }
- #region 字段属性
- protected VmInputBase(string name, string displayName, VmInputType inputType)
- {
- Name = name;
- DisplayName = displayName;
- InputType = inputType;
- IsHidden = false;
- IsReadOnly = false;
- IsDisabled = false;
- IsRequired = false;
- Other = "";
- DefaultClass = "form-control form-control-sm form-control-solid";
- DefaultValue = "";
- LabelClass = "fs-6 fw-bolder mb-1";
- InputClass = "";
- }
- public string ModalId { get; set; }
- public bool UseId { get; set; }
- public string Name { get; set; }
- public string DisplayName { get; set; }
- public VmInputType InputType { get; set; }
- public string Style { get; set; }
- public string Class { get; set; }
- public virtual string DefaultClass { get; set; }
- protected string _other;
- public virtual string Other
- {
- get
- {
- if (MinLength != null) _other += $" minlength={MinLength}";
- if (MaxLength != null) _other += $" maxlength={MaxLength}";
- if (Min != null) _other += $" min={Min}";
- if (Max != null) _other += $" max={Max}";
- return _other;
- }
- set => _other = value;
- }
- public int? MinLength { get; set; }
- public int? MaxLength { get; set; }
- public int? Min { get; set; }
- public int? Max { get; set; }
- public string DefaultValue { get; set; }
- private string PlaceholderPrefix =>
- InputType == VmInputType.Select ? L("PlaceholderSelectHeader") : L("PlaceholderHeader");
- public string PlaceholderStr => Placeholder.Empty() ? $"{PlaceholderPrefix}{DisplayName}..." : Placeholder;
- public string Placeholder { get; set; }
- public bool IsHidden { get; set; }
- public bool IsRequired { get; set; }
- public bool IsDisabled { get; set; }
- public bool IsReadOnly { get; set; }
- public string Help { get; set; }
- protected virtual string ClassStr =>
- $"{(IsHidden ? "" : DefaultClass)} {Class} {(IsRequired ? "required" : "")} {(DefaultValue.Empty() ? "" : "default-value")} {(IsDisabled ? "disabled" : "")} {(IsReadOnly ? "readonly" : "")}";
- public string LabelClass { get; set; }
- public string InputClass { get; set; }
- public string LayoutClass { get; set; }
- public string Special { get; set; }
- public virtual string InputBaseString =>
- $" class=\"{ClassStr}\" {(UseId ? $"id =\"{Name}\"" : "")} name=\"{Name}\" {(DefaultValue.Empty() ? "" : $"value=\"{DefaultValue}\"")} placeholder=\"{PlaceholderStr}\" {(IsDisabled ? "disabled" : "")} {(IsReadOnly ? "readonly" : "")} {Other} {(Style.Empty() ? "" : $"style=\"{Style}\"")}";
- #endregion 字段属性
- #region 方法
- public virtual VmInputBase WithHide()
- {
- IsHidden = true;
- return this;
- }
- public virtual VmInputBase WithReadonly()
- {
- IsReadOnly = true;
- return this;
- }
- public virtual VmInputBase WithDisabled()
- {
- IsDisabled = true;
- return this;
- }
- public virtual VmInputBase WithRequired()
- {
- IsRequired = true;
- return this;
- }
- public virtual VmInputBase WithDefaultValue(string value)
- {
- DefaultValue = value;
- return this;
- }
- public virtual VmInputBase WithPlaceholder(string placeholder)
- {
- Placeholder = placeholder;
- return this;
- }
- public virtual VmInputBase WithStyle(string style)
- {
- Style = style;
- return this;
- }
- public virtual VmInputBase WithClass(string @class)
- {
- Class = @class;
- return this;
- }
- public virtual VmInputBase WithOther(string other)
- {
- Other += other;
- return this;
- }
- public virtual VmInputBase WithHelp(string help)
- {
- Help = help;
- return this;
- }
- public virtual VmInputBase WithSpecial(string special)
- {
- Special = special;
- return this;
- }
- public virtual VmInputBase WithMaxLength(int maxLength)
- {
- MaxLength = maxLength;
- return this;
- }
- public virtual VmInputBase WithMinLength(int minLength)
- {
- MinLength = minLength;
- return this;
- }
- public virtual VmInputBase WithHidden()
- {
- IsHidden = true;
- return this;
- }
- public virtual VmInputBase WithLayoutClass(string layout)
- {
- LayoutClass = layout;
- return this;
- }
- #endregion 方法
- #region 配合查询模态框使用
- /// <summary>
- /// 查询模态框ID
- /// </summary>
- public string QueryModalId { get; set; }
- public string DivSearchClass { get; set; }
- protected string _target;
- public string Target =>
- string.IsNullOrEmpty(_target) ? DefaultTarget ?? "" :
- _target.StartsWith(".") ? _target :
- _target.StartsWith("#") ? _target : $"#{_target}";
- public string DefaultTarget { get; set; }
- public string Clear { get; set; }
- /// <summary>
- /// 添加搜索按钮
- /// </summary>
- /// <param name="modalId"></param>
- /// <returns></returns>
- public virtual VmInputBase WithQueryIcon(string modalId)
- {
- QueryModalId = modalId;
- return this;
- }
- /// <summary>
- /// 添加搜索按钮
- /// </summary>
- /// <param name="modalId"></param>
- /// <param name="target"></param>
- /// <param name="clear"></param>
- /// <returns></returns>
- public virtual VmInputBase WithQueryIcon(string modalId, string target, string clear = "")
- {
- QueryModalId = modalId;
- _target = target;
- if (clear.NotEmpty()) WithQueryClear(clear, true);
- return this;
- }
- /// <summary>
- /// 添加搜索范围Class
- /// </summary>
- /// <param name="class"></param>
- /// <returns></returns>
- public virtual VmInputBase WithQueryClass(string @class)
- {
- DivSearchClass = @class;
- return this;
- }
- /// <summary>
- /// 添加搜索按钮
- /// </summary>
- /// <param name="modalId"></param>
- /// <param name="class"></param>
- /// <param name="clear"></param>
- /// <returns></returns>
- public virtual VmInputBase WithQueryIconWithClass(string modalId, string @class, string clear = "")
- {
- QueryModalId = modalId;
- _target = "." + @class;
- DivSearchClass = @class;
- if (clear.NotEmpty()) WithQueryClear(clear, true);
- return this;
- }
- /// <summary>
- /// 配置需要清空的INPUT name
- /// </summary>
- /// <param name="clear"></param>
- /// <param name="isDefault"></param>
- /// <returns></returns>
- public virtual VmInputBase WithQueryClear(string clear, bool isDefault = false)
- {
- Clear = isDefault ? $"{clear}No,{clear}Name" : clear;
- return this;
- }
- #endregion 配合查询模态框使用
- }
|