| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- using Abp.Localization;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Mvc;
- using System.Web.WebPages;
- using IwbZero;
- namespace WePlatform.Views.Shared.Modals
- {
- #region ModalBody
- public class Input
- {
- public Input(string id, string displayName = "", InputTypes inputType = InputTypes.Text, string placeholder = "", string name = null, string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "", string help = "")
- {
- Id = id;
- Name = string.IsNullOrEmpty(name) ? id : name;
- DisplayName = string.IsNullOrEmpty(displayName) ? L(id) : displayName;
- InputType = inputType;
- _placeholder = placeholder;
- Value = value;
- _class = @class;
- DataOptions = dataOptions;
- Events = events;
- Styles = styles;
- Other = other;
- IsHidden = hide;
- IsRequired = !hide;
- IsDisabled = false;
- IsReadOnly = false;
- _label = label;
- Help = help;
- IsSm = true;
- }
- #region 方法
- public Input SetDataOptions(string dataOptions)
- {
- DataOptions = dataOptions;
- return this;
- }
- public Input SetEvents(string events)
- {
- Events = events;
- return this;
- }
- public Input SetName(string name)
- {
- Name = name;
- return this;
- }
- public Input SetHelp(string help)
- {
- Help = help;
- return this;
- }
- public Input SetHidden()
- {
- IsHidden = true;
- return this;
- }
- public Input SetLabel(string label)
- {
- _label = label;
- return this;
- }
- public Input SetLabelName(string label)
- {
- _label = "<label class=\"iwb-label col-md-2 form-control-label\" for=\"" + Id + "\">" + label +
- "</label>";
- return this;
- }
- public Input SetLabelNameRequired(string label)
- {
- _label = "<label class=\"iwb-label col-md-2 form-control-label iwb-label-required\" for=\"" + Id + "\">" + label +
- "</label>";
- return this;
- }
- public Input SetNotRequired()
- {
- IsRequired = false;
- return this;
- }
- public Input SetDisabled()
- {
- IsDisabled = true;
- return this;
- }
- public Input SetReadonly()
- {
- IsReadOnly = true;
- return this;
- }
- public Input SetSelectOptions(List<SelectListItem> poSelectOptions, bool isMultiple = false, bool isAddBlank = false)
- {
- string lcRetval = isAddBlank ? "<option value=\"\" selected>请选择</option>" : "";
- IsMultiple = isMultiple;
- if (poSelectOptions != null && poSelectOptions.Any())
- {
- foreach (var s in poSelectOptions)
- {
- lcRetval += "<option value=\"" + s.Value + "\">" + s.Text + "</option>\r\n";
- }
- }
- SelectOptions = lcRetval;
- InputType = InputTypes.List;
- return this;
- }
- public Input SetSelectOptions(string poSelectOptions, bool isMultiple = false, bool isAddBlank = false)
- {
- string lcRetval = isAddBlank ? "<option value=\"\" selected>请选择</option>" : "";
- IsMultiple = isMultiple;
- if (!string.IsNullOrEmpty(poSelectOptions))
- {
- lcRetval += poSelectOptions;
- }
- SelectOptions = lcRetval;
- InputType = InputTypes.List;
- return this;
- }
- public Input SetLayout(string labelLayout, string inputLayout)
- {
- LabelLayoutClass = labelLayout;
- InputLayoutClass = inputLayout;
- return this;
- }
- //public Input SetLayout(int labelLayout, int? inputLayout = null, string layoutPrefix = "col-md-")
- //{
- // inputLayout = inputLayout ?? 12 - labelLayout;
- // LabelLayout = $"{layoutPrefix}{labelLayout}";
- // InputLayout = $"{layoutPrefix}{inputLayout}";
- // return this;
- //}
- public Input SetOuterDiv(string classStr, string other = "")
- {
- DivClass = classStr;
- DivOther = other;
- return this;
- }
- /// <summary>
- /// 外层上面其他标签
- /// </summary>
- /// <param name="beforeStr"></param>
- /// <returns></returns>
- public Input SetOuterBefore(string beforeStr)
- {
- DivOutBefore = beforeStr;
- return this;
- }
- /// <summary>
- /// 外层下面其他标签
- /// </summary>
- /// <param name="afterStr"></param>
- /// <returns></returns>
- public Input SetOuterAfter(string afterStr)
- {
- DivOutAfter = afterStr;
- return this;
- }
- /// <summary>
- /// 内层上面其他标签
- /// </summary>
- /// <param name="beforeStr"></param>
- /// <returns></returns>
- public Input SetInterBefore(string beforeStr)
- {
- DivInterBefore = beforeStr;
- return this;
- }
- /// <summary>
- /// 内层下面其他标签
- /// </summary>
- /// <param name="afterStr"></param>
- /// <returns></returns>
- public Input SetInterAfter(string afterStr)
- {
- DivInterAfter = afterStr;
- return this;
- }
- /// <summary>
- /// 添加搜索按钮
- /// </summary>
- /// <param name="searchModalId"></param>
- /// <param name="target"></param>
- /// <param name="clear"></param>
- /// <returns></returns>
- public Input SetSearchIcon(string searchModalId, string target = "",string clear="")
- {
- SearchModalId = searchModalId;
- _target = target;
- Clear = clear;
- return this;
- }
- /// <summary>
- /// 配置需要清空的INPUT Id
- /// </summary>
- /// <param name="clear"></param>
- /// <param name="isDefault"></param>
- /// <returns></returns>
- public Input SetSearchClear(string clear,bool isDefault=true)
- {
- Clear = isDefault ? $"{clear}No,{clear}Name" : clear;
- return this;
- }
- /// <summary>
- /// 输入提示
- /// </summary>
- /// <param name="placeholder"></param>
- /// <returns></returns>
- public Input SetPlaceholder(string placeholder)
- {
- _placeholder = placeholder;
- return this;
- }
- public Input SetNotSmall()
- {
- IsSm = false;
- return this;
- }
- #endregion
- #region 字段属性
- public string Id { get; set; }
- public string Name { get; set; }
- public string DisplayName { get; set; }
- public string Help { get; set; }
- private string PlaceholderPrefix => InputType == InputTypes.List ? L("PlaceholderSelectHeader") : L("PlaceholderHeader");
- private string _placeholder;
- public string Placeholder => string.IsNullOrEmpty(_placeholder) ? $"{PlaceholderPrefix}{DisplayName}..." : _placeholder;
- public InputTypes InputType { get; set; }
- public string TypeStr
- {
- get
- {
- switch (InputType)
- {
- case InputTypes.Text:
- return "text";
- case InputTypes.Password:
- return "password";
- case InputTypes.Checkbox:
- return "checkbox";
- case InputTypes.Radio:
- return "radio";
- case InputTypes.File:
- return "file";
- case InputTypes.Number:
- return "number";
- default:
- return "text";
- }
- }
- }
- public DateTypes DateType { get; set; }
- public bool IsSm { get; set; }
- public string Number { get; set; }
- public int? Min { get; set; }
- public int? Max { get; set; }
- public string Value { get; set; }
- public string SelectOptions { get; private set; }
- private string _class;
- public string Class
- {
- get
- {
- var classStr = $"form-control {_class}";
- if (IsDisabled)
- {
- classStr += " disabled ";
- }
- if (IsReadOnly)
- {
- classStr += " readonly ";
- }
- if (InputType == InputTypes.Number)
- {
- classStr += $" {Number} ";
- }
- if (InputType == InputTypes.Date)
- {
- classStr += DateType == DateTypes.DateTime ? " iwb-date-time " : " iwb-date ";
- }
- return classStr;
- }
- set => _class = value;
- }
- public string DataOptions { get; set; }
- public string Events { get; set; }
- public string Styles { get; set; }
- private string _other;
- public string Other
- {
- get
- {
- if (Min != null)
- {
- _other += $" min={Min}";
- }
- if (Max != null)
- {
- _other += $" max={Max}";
- }
- return _other;
- }
- set => _other = value;
- }
- public bool IsHidden { get; set; }
- public bool IsRequired { get; set; }
- public bool IsDisabled { get; set; }
- public bool IsReadOnly { get; set; }
- public bool IsMultiple { get; private set; }
- public string Required => IsHidden ? "" : (IsRequired ? " required" : "");
- public string DivClass { get; set; }
- public string DivOther { get; set; }
- public string DivOutBefore { get; set; }
- public string DivOutAfter { get; set; }
- public string DivInterBefore { get; set; }
- public string DivInterAfter { get; set; }
- public string SearchModalId { get; set; }
- public string LabelLayoutClass { get; set; }
- public string InputLayoutClass { get; set; }
- private string _label;
- public string Label => IsHidden
- ? ""
- : string.IsNullOrEmpty(_label)
- ? (IsRequired
- ? $"<label class=\"{LabelLayoutClass} iwb-label {(IsSm ? "iwb-label-sm" : "col-form-label")} iwb-label-required\" for=\"{Id}\">{DisplayName}</label>"
- : $"<label class=\"{LabelLayoutClass} iwb-label {(IsSm ? "iwb-label-sm" : "col-form-label")} \" for=\"{Id}\">{DisplayName}</label>")
- : _label;
- public string Disabled => IsDisabled ? "disabled=\"disabled\"" : "";
- public string ReadOnly => IsReadOnly ? "readonly=\"readonly\"" : "";
- public FileInputOption FileOption { get; set; }
- private 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; }
- #endregion
- private static string L(string name)
- {
- var str = LocalizationHelper.GetSource(IwbZeroConsts.LocalizationSourceName).GetString(name);
- return str;
- }
- }
- public class InputHide : Input
- {
- public InputHide(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", string label = "")
- : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, true, label)
- {
- }
- }
- public class InputTextarea : Input
- {
- public InputTextarea(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, InputTypes.Textarea, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
- {
- }
- }
- public class InputKindeditor : InputTextarea
- {
- public InputKindeditor(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, placeholder, name, value, "kindeditor", dataOptions, events, styles, other, hide, label)
- {
- }
- }
- public class InputDate : Input
- {
- public InputDate(string id, string displayName = "", DateTypes date = DateTypes.Date, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
- {
- DateType = date;
- }
- public InputDate SetDateType(DateTypes date)
- {
- DateType = date;
- return this;
- }
- }
- public class InputDateTime : Input
- {
- public InputDateTime(string id, string displayName = "", DateTypes date = DateTypes.DateTime, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, InputTypes.Date, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
- {
- DateType = date;
- }
- public InputDateTime SetDateType(DateTypes date)
- {
- DateType = date;
- return this;
- }
- }
- public class InputNumber : Input
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="id"></param>
- /// <param name="displayName"></param>
- /// <param name="numberType">0是整数,其他是小数</param>
- /// <param name="min"></param>
- /// <param name="max"></param>
- /// <param name="placeholder"></param>
- /// <param name="name"></param>
- /// <param name="value"></param>
- /// <param name="class"></param>
- /// <param name="dataOptions"></param>
- /// <param name="events"></param>
- /// <param name="styles"></param>
- /// <param name="other"></param>
- /// <param name="hide"></param>
- /// <param name="label"></param>
- public InputNumber(string id, string displayName = "", int numberType = 0, int? min = null, int? max = null, string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, InputTypes.Number, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
- {
- Number = numberType == 0 ? "number" : "digits";
- Min = min;
- Max = max;
-
- }
- public InputNumber SetRange(int? min = null, int? max = null, int numberType = 1)
- {
- Min = min;
- Max = max;
- Number = numberType == 0 ? "number" : "digits";
- Other = Other ?? "";
- if (Min != null)
- {
- Other += $" min={Min}";
- }
- if (Max != null)
- {
- Other += $" max={Max}";
- }
- return this;
- }
- public InputNumber SetNumberType(int numberType = 1, int? min = null, int? max = null)
- {
- Number = numberType == 0 ? "number" : "digits";
- Min = min;
- Max = max;
- return this;
- }
- public InputNumber SetMin(int min)
- {
- Min = min;
- return this;
- }
- public InputNumber SetMax(int max)
- {
- Max = max;
- return this;
- }
- }
- public class InputFile : Input
- {
- public InputFile(string id, string displayName = "", string placeholder = "", string name = "", string value = "", string @class = "", string dataOptions = "", string events = "", string styles = "", string other = "", bool hide = false, string label = "")
- : base(id, displayName, InputTypes.File, placeholder, name, value, @class, dataOptions, events, styles, other, hide, label)
- {
- }
- /// <summary>
- /// 文件选择框设置信息
- /// </summary>
- /// <param name="opt"></param>
- /// <returns></returns>
- public InputFile SetFileOption(FileInputOption opt)
- {
- opt.FileInfoField = string.IsNullOrEmpty(opt.FileInfoField) ? Id : opt.FileInfoField;
- FileOption = opt;
- InputType = InputTypes.File;
- return this;
- }
- /// <summary>
- /// 文件选择框设置信息
- /// </summary>
- /// <returns></returns>
- public InputFile SetFileOption(string fileInfoField = "", string fileNameField = "", string fileExtField = "", int maxSize = 5)
- {
- fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField;
- FileOption = new FileInputOption(fileInfoField, fileNameField, fileExtField, false, maxSize);
- return this;
- }
- /// <summary>
- /// 图片选择框设置信息
- /// </summary>
- /// <returns></returns>
- public InputFile SetImageOption(string fileInfoField = "", string fileNameField = "", string fileExtField = "", int maxSize = 5)
- {
- fileInfoField = string.IsNullOrEmpty(fileInfoField) ? Id : fileInfoField;
- FileOption = new FileInputOption(fileInfoField, fileNameField, fileExtField, true, maxSize);
- return this;
- }
- }
- public class SpecialInputModel
- {
- public string Id { get; set; }
- public string InputStr { get; set; }
- }
- public class FileInputOption
- {
- public FileInputOption(string fileInfoField, string fileNameField = "", string fileExtField = "", bool isImage = true, int maxSize = 5, string fileIdField = null)
- {
- FileInfoField = fileInfoField;
- FileNameField = fileNameField;
- FileExtField = fileExtField;
- IsImage = isImage;
- MaxSize = maxSize;
- FileIdField = fileIdField;
- }
- public string FileIdField { get; set; }
- public string FileInfoField { get; set; }
- public string FileNameField { get; set; }
- public string FileExtField { get; set; }
- public bool IsImage { get; set; }
- /// <summary>
- /// 文件最大M(默认5M)
- /// </summary>
- public int MaxSize { get; set; } = 5;
- }
- //public class SelectOption
- //{
- // public SelectOption(string text, string value = "")
- // {
- // Text = text;
- // Value = value;
- // }
- // public string Value { get; set; }
- // public string Text { get; set; }
- //}
- public enum InputTypes
- {
- Text, List, Checkbox, Radio, Password, Textarea, File, Number, Date
- }
- public enum DateTypes
- {
- Date, DateTime
- }
- #endregion
- }
|