| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- using VberZero.Tools.StringModel;
- namespace VberAdmin.Web.Models.Input;
- public class VmInputDate : VmInputBase
- {
- public VmInputDate(string name, string displayName) : base(name, displayName, VmInputType.Date)
- {
- DefaultClass = "form-control form-control-sm form-control-solid ps-12 flatpickr-input";
- DateType = VmDateType.Date;
- //IsNoCalendar = false;
- Format = "Y-m-d";
- IsOnlyTime = false;
- }
- public VmInputDate(string name, string displayName, VmDateType dateType) : this(name, displayName)
- {
- DateType = dateType;
- }
- public VmDateType DateType { get; set; }
- public bool IsOnlyTime { get; set; }
- public bool EnableSeconds { get; set; }
- public int ShowMonths { get; set; } = 1;
- public int HourIncrement { get; set; } = 1;
- public int MinuteIncrement { get; set; } = 5;
- public string DefaultDate { get; protected set; }
- public string DefaultHour { get; protected set; }
- public string DefaultMinute { get; protected set; }
- public string MinDate { get; protected set; }
- public string MaxDate { get; protected set; }
- public string MinTime { get; protected set; }
- public string MaxTime { get; protected set; }
- public string Format { get; protected set; }
- /// <summary>
- /// 禁用的日期
- /// 数组 单个日期: ["2025-01-10", "22025-01-11"] ||
- /// 日期范围 [{ from: "2025-01-05", to: "2025-01-25" },{...}]
- /// 函数 [function(date) { return (date.getDay() === 0 || date.getDay() === 6);} ] 返回true禁用
- /// </summary>
- public string Disable { get; protected set; }
- /// <summary>
- /// 启用日期(其余禁用)
- /// </summary>
- public string Enable { get; protected set; }
- public string ControlDataStr
- => $"data-date-show-months=\"{ShowMonths}\"" +
- $"data-date-hour-increment=\"{HourIncrement}\"" +
- $"data-date-minute-increment=\"{MinuteIncrement}\"" +
- $"{(EnableSeconds ? "data-date-enable-seconds=\"true\"" : "")} " +
- $"{(IsOnlyTime ? "data-date-no-Calendar=\"true\"" : "")} " +
- $"{(DefaultDate.Empty() ? "" : $"data-date-default-date=\"{DefaultDate}\"")} " +
- $"{(DefaultHour.Empty() ? "" : $"data-date-default-hour=\"{DefaultHour}\"")} " +
- $"{(DefaultMinute.Empty() ? "" : $"data-date-default-minute=\"{DefaultMinute}\"")} " +
- $"{(MinDate.Empty() ? "" : $"data-date-min-date=\"{MinDate}\"")} " +
- $"{(MaxDate.Empty() ? "" : $"data-date-max-date=\"{MaxDate}\"")} " +
- $"{(MinTime.Empty() ? "" : $"data-date-min-time=\"{MinTime}\"")} " +
- $"{(MaxTime.Empty() ? "" : $"data-date-max-time=\"{MaxTime}\"")} " +
- $"{(Disable.Empty() ? "" : $"data-date-disable=\"{Disable}\"")} " +
- $"{(Enable.Empty() ? "" : $"data-date-enable=\"{Enable}\"")} " +
- $"{(Format.Empty() ? "" : $"data-date-format=\"{Format}\"")} ";
- public override string Other
- {
- get
- {
- string str;
- switch (DateType)
- {
- case VmDateType.DateTime:
- str = "date-time";
- break;
- case VmDateType.DateRange:
- str = "r_date";
- break;
- case VmDateType.DateTimeRange:
- str = "r_date-time";
- break;
- default:
- str = "date";
- break;
- }
- return $"{base.Other ?? ""} data-vb-date=\"{str}\" {ControlDataStr}";
- }
- set => _other = value;
- }
- public VmInputDate WithFormat(string format)
- {
- Format = format;
- return this;
- }
- public VmInputDate WithDefaultDate(string date)
- {
- DefaultDate = date;
- return this;
- }
- public VmInputDate WithMinDate(string date)
- {
- MinDate = date;
- return this;
- }
- public VmInputDate WithMaxDate(string date)
- {
- MaxDate = date;
- return this;
- }
- public VmInputDate WithShowMonths(int months)
- {
- ShowMonths = months < 1 ? 1 : months;
- return this;
- }
- /// <summary>
- /// 禁用的日期
- /// </summary>
- /// <param name="disable"> 数组 eg:
- /// 单个日期: ["2025-01-10", "22025-01-11"] ;
- /// 日期范围 [{ from: "2025-01-05", to: "2025-01-25" },{...}];
- /// 函数 [function(date) { return (date.getDay() === 0 || date.getDay() === 6);} ] 返回true禁用
- /// </param>
- /// <returns></returns>
- public VmInputDate WithDisable(string disable)
- {
- Disable = disable;
- return this;
- }
- /// <summary>
- /// 禁用的日期
- /// </summary>
- /// <param name="enable"> 数组 eg:
- /// 单个日期: ["2025-01-10", "22025-01-11"] ;
- /// 日期范围 [{ from: "2025-01-05", to: "2025-01-25" },{...}];
- /// 函数 [function(date) { return (date.getDay() === 0 || date.getDay() === 6);} ] 返回true启用
- /// </param>
- /// <returns></returns>
- public VmInputDate WithEnable(string enable)
- {
- Enable = enable;
- return this;
- }
- }
- public class VmInputDateTime : VmInputDate
- {
- public VmInputDateTime(string name, string displayName) : base(name, displayName, VmDateType.DateTime)
- {
- Format = "Y-m-d H:i";
- }
- public VmInputDateTime WithOnlyTime()
- {
- IsOnlyTime = true;
- Format = "H:i";
- return this;
- }
- public VmInputDateTime WithIncrement(int hour = 1, int minute = 5)
- {
- HourIncrement = hour;
- MinuteIncrement = minute;
- return this;
- }
- public VmInputDateTime WithSeconds()
- {
- EnableSeconds = true;
- return this;
- }
- public VmInputDateTime WithDefaultTime(string hour, string minute)
- {
- DefaultHour = hour;
- DefaultMinute = minute;
- return this;
- }
- public VmInputDateTime WithMinTime(string time)
- {
- MinTime = time;
- return this;
- }
- public VmInputDateTime WithMaxTime(string time)
- {
- MaxTime = time;
- return this;
- }
- }
- public class VmInputDateRange : VmInputDate
- {
- public VmInputDateRange(string name, string displayName) : base(name, displayName, VmDateType.DateRange)
- {
- DefaultClass += " vb-date-range";
- }
- /// <summary>
- /// 起始时间间隔
- /// </summary>
- /// <param name="interval">单位:天</param>
- /// <param name="value"></param>
- /// <returns></returns>
- public VmInputDateRange WithInterval(int interval, DateTime? value = null)
- {
- var date = value ?? DateTime.Today;
- DefaultDate = $"[{date.AddDays(0 - interval):yyyy-MM-dd},{date:yyyy-MM-dd}]";
- return this;
- }
- }
- public class VmInputDateTimeRange : VmInputDate
- {
- public VmInputDateTimeRange(string name, string displayName) : base(name, displayName, VmDateType.DateTimeRange)
- {
- DefaultClass += " vb-date-range";
- Format = "Y-m-d H:i";
- }
- public VmInputDateTimeRange WithIncrement(int hour = 1, int minute = 5)
- {
- HourIncrement = hour;
- MinuteIncrement = minute;
- return this;
- }
- public VmInputDateTimeRange WithSeconds()
- {
- EnableSeconds = true;
- return this;
- }
- public VmInputDateTimeRange WithDefaultTime(string hour, string minute)
- {
- DefaultHour = hour;
- DefaultMinute = minute;
- return this;
- }
- public VmInputDateTimeRange WithMinTime(string time)
- {
- MinTime = time;
- return this;
- }
- public VmInputDateTimeRange WithMaxTime(string time)
- {
- MaxTime = time;
- return this;
- }
- public VmInputDateTimeRange WithOnlyTime()
- {
- Format = "H:i";
- IsOnlyTime = true;
- return this;
- }
- /// <summary>
- /// 起始时间间隔
- /// </summary>
- /// <param name="interval">单位:天</param>
- /// <param name="value"></param>
- /// <returns></returns>
- public VmInputDateTimeRange WithInterval(int interval, DateTime? value = null)
- {
- var date = value ?? DateTime.Today;
- DefaultDate = $"[{date.AddDays(0 - interval):yyyy-MM-dd},{date:yyyy-MM-dd}]";
- return this;
- }
- }
|