2020-04-28 15:56:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AntBlazor.Internal;
|
|
|
|
|
using AntBlazor.JsInterop;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using OneOf;
|
|
|
|
|
|
|
|
|
|
namespace AntBlazor
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public partial class DatePicker : AntDomComponentBase
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string PrefixCls { get; set; } = "ant-picker";
|
|
|
|
|
|
|
|
|
|
private string _picker;
|
|
|
|
|
private bool _isSetPicker = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Picker
|
|
|
|
|
{
|
|
|
|
|
get => _picker;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isSetPicker = true;
|
|
|
|
|
_picker = value;
|
|
|
|
|
|
|
|
|
|
InitPicker(value, 0);
|
|
|
|
|
InitPicker(value, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 17:33:09 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string PopupContainerSelector { get; set; }
|
|
|
|
|
|
2020-04-28 15:56:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Bordered { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool AutoFocus { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-10 17:33:09 +08:00
|
|
|
|
public bool Open { get; set; }
|
2020-04-28 15:56:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool InputReadOnly { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool ShowToday { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
public bool IsShowTime { get; private set; } = false;
|
|
|
|
|
public string ShowTimeFormat { get; private set; } = "HH:mm:ss";
|
|
|
|
|
private OneOf<bool, string> _showTime = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<bool, string> ShowTime
|
|
|
|
|
{
|
|
|
|
|
get => _showTime;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_showTime = value;
|
|
|
|
|
|
|
|
|
|
value.Switch(booleanValue =>
|
|
|
|
|
{
|
|
|
|
|
IsShowTime = booleanValue;
|
|
|
|
|
}, strValue =>
|
|
|
|
|
{
|
|
|
|
|
IsShowTime = true;
|
|
|
|
|
ShowTimeFormat = strValue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool AllowClear { get; set; } = true; // TODO
|
|
|
|
|
|
|
|
|
|
private string[] _placeholders = new string[] { "", "" };
|
|
|
|
|
private OneOf<string, string[]> _placeholder;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<string, string[]> Placeholder
|
|
|
|
|
{
|
|
|
|
|
get => _placeholder;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_placeholder = value;
|
|
|
|
|
value.Switch(single =>
|
|
|
|
|
{
|
|
|
|
|
_placeholders[0] = single;
|
|
|
|
|
}, arr =>
|
|
|
|
|
{
|
|
|
|
|
_placeholders[0] = arr.Length > 0 ? arr[0] : _placeholders[0];
|
|
|
|
|
_placeholders[1] = arr.Length > 1 ? arr[1] : _placeholders[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string PopupStyle { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string ClassName { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string DropdownClassName { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public string Size { get; set; } = DatePickerSize.Default;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Format { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly DateTime?[] _defaultValues = new DateTime?[2];
|
|
|
|
|
private OneOf<DateTime, DateTime[]> _defaultValue;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<DateTime, DateTime[]> DefaultValue
|
|
|
|
|
{
|
|
|
|
|
get => _defaultValue;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_defaultValue = value;
|
|
|
|
|
value.Switch(single =>
|
|
|
|
|
{
|
|
|
|
|
_defaultValues[0] = single;
|
|
|
|
|
}, arr =>
|
|
|
|
|
{
|
|
|
|
|
_defaultValues[0] = arr.Length > 0 ? arr[0] : _defaultValues[0];
|
|
|
|
|
_defaultValues[1] = arr.Length > 1 ? arr[1] : _defaultValues[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly DateTime?[] _defaultPickerValues = new DateTime?[2];
|
|
|
|
|
private OneOf<DateTime, DateTime[]> _defaultPickerValue;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<DateTime, DateTime[]> DefaultPickerValue
|
|
|
|
|
{
|
|
|
|
|
get => _defaultPickerValue;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_defaultPickerValue = value;
|
|
|
|
|
value.Switch(single =>
|
|
|
|
|
{
|
|
|
|
|
_defaultPickerValues[0] = single;
|
|
|
|
|
}, arr =>
|
|
|
|
|
{
|
|
|
|
|
_defaultPickerValues[0] = arr.Length > 0 ? arr[0] : _defaultPickerValues[0];
|
|
|
|
|
_defaultPickerValues[1] = arr.Length > 1 ? arr[1] : _defaultPickerValues[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment SuffixIcon { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment RenderExtraFooter { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<bool> OnOpenChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Action<DateTime, string> OnPanelChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Action<DateTime, string> OnChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, bool> DisabledDate { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, int[]> DisabledHours { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, int[]> DisabledMinutes { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, int[]> DisabledSeconds { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-05-18 14:46:42 +08:00
|
|
|
|
public Func<DateTime, DatePickerDisabledTime> DisabledTime { get; set; } = null;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, DateTime, RenderFragment> DateRender { get; set; }
|
|
|
|
|
|
|
|
|
|
// TODO: need locale
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<DateTime, RenderFragment> MonthCellRender { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly DateTime[] _values = new DateTime[2];
|
|
|
|
|
private OneOf<DateTime, DateTime[]> _value;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<DateTime, DateTime[]> Value
|
|
|
|
|
{
|
|
|
|
|
get => _value;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_value = value;
|
|
|
|
|
value.Switch(single =>
|
|
|
|
|
{
|
|
|
|
|
_values[0] = single;
|
|
|
|
|
}, arr =>
|
|
|
|
|
{
|
|
|
|
|
_values[0] = arr.Length > 0 ? arr[0] : _values[0];
|
|
|
|
|
_values[1] = arr.Length > 1 ? arr[1] : _values[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTime CurrentDate { get; private set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
private readonly DateTime[] _pickerValues = new DateTime[] { DateTime.Now, DateTime.Now };
|
|
|
|
|
private OneOf<DateTime, DateTime[]> _pickerValue;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<DateTime, DateTime[]> PickerValue
|
|
|
|
|
{
|
|
|
|
|
get => _pickerValue;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_pickerValue = value;
|
|
|
|
|
value.Switch(single =>
|
|
|
|
|
{
|
|
|
|
|
_pickerValues[0] = single;
|
|
|
|
|
}, arr =>
|
|
|
|
|
{
|
|
|
|
|
_pickerValues[0] = arr.Length > 0 ? arr[0] : _pickerValues[0];
|
|
|
|
|
_pickerValues[1] = arr.Length > 1 ? arr[1] : _pickerValues[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _isRange = false;
|
|
|
|
|
|
|
|
|
|
public bool IsRange
|
|
|
|
|
{
|
|
|
|
|
get => _isRange;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isRange = value;
|
|
|
|
|
|
|
|
|
|
if (value == true)
|
|
|
|
|
{
|
|
|
|
|
DisabledDate = (date) =>
|
|
|
|
|
{
|
|
|
|
|
if (_pickerStatus[0]._hadSelectValue && _inputEnd.IsOnFocused)
|
|
|
|
|
{
|
|
|
|
|
return date.CompareTo(_values[0]) < 0;
|
|
|
|
|
}
|
|
|
|
|
if (_pickerStatus[1]._hadSelectValue && _inputStart.IsOnFocused)
|
|
|
|
|
{
|
|
|
|
|
return date.CompareTo(_values[1]) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
private DatePickerInput _inputStart;
|
|
|
|
|
private DatePickerInput _inputEnd;
|
2020-05-22 11:24:12 +08:00
|
|
|
|
private OverlayTrigger _dropDown;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
private string _activeBarStyle = "";
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
private DatePickerStatus[] _pickerStatus
|
|
|
|
|
= new DatePickerStatus[] { new DatePickerStatus(), new DatePickerStatus() };
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
private Stack<string> _prePickerStack = new Stack<string>();
|
|
|
|
|
private bool _isClose = true;
|
|
|
|
|
private bool _needRefresh;
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
// set default picker type
|
|
|
|
|
if (_isSetPicker == false)
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
Picker = DatePickerType.Date;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.SetClass();
|
|
|
|
|
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task SetParametersAsync(ParameterView parameters)
|
|
|
|
|
{
|
|
|
|
|
_needRefresh = true;
|
|
|
|
|
|
|
|
|
|
return base.SetParametersAsync(parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
this.SetClass();
|
|
|
|
|
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void SetClass()
|
|
|
|
|
{
|
|
|
|
|
this.ClassMapper.Clear()
|
|
|
|
|
.Add(PrefixCls)
|
2020-05-22 11:24:12 +08:00
|
|
|
|
.Add($"{PrefixCls}-{Size}")
|
2020-04-28 15:56:56 +08:00
|
|
|
|
.If($"{PrefixCls}-borderless", () => Bordered == false)
|
|
|
|
|
.If($"{PrefixCls}-disabled", () => Disabled == true)
|
|
|
|
|
.If($"{ClassName}", () => !string.IsNullOrEmpty(ClassName))
|
|
|
|
|
.If($"{PrefixCls}-range", () => IsRange == true)
|
|
|
|
|
.If($"{PrefixCls}-focused", () => AutoFocus == true)
|
2020-05-18 14:46:42 +08:00
|
|
|
|
//.If($"{PrefixCls}-normal", () => Image.IsT1 && Image.AsT1 == Empty.PRESENTED_IMAGE_SIMPLE)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
//.If($"{PrefixCls}-{Direction}", () => Direction.IsIn("ltr", "rlt"))
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async override Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
2020-04-30 08:07:37 +08:00
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
if (_needRefresh && IsRange)
|
|
|
|
|
{
|
|
|
|
|
if (_inputStart.IsOnFocused)
|
|
|
|
|
{
|
2020-04-30 08:07:37 +08:00
|
|
|
|
Element element = await JsInvokeAsync<Element>(JSInteropConstants.getDomInfo, _inputStart.Ref);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_activeBarStyle = $"width: {element.clientWidth - 10}px; position: absolute; transform: translate3d(0px, 0px, 0px);";
|
|
|
|
|
}
|
|
|
|
|
else if (_inputEnd.IsOnFocused)
|
|
|
|
|
{
|
2020-04-30 08:07:37 +08:00
|
|
|
|
Element element = await JsInvokeAsync<Element>(JSInteropConstants.getDomInfo, _inputStart.Ref);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_activeBarStyle = $"width: {element.clientWidth - 10}px; position: absolute; transform: translate3d({element.clientWidth + 16}px, 0px, 0px);";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-22 11:24:12 +08:00
|
|
|
|
_activeBarStyle = "display: none";
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_needRefresh = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string GetInputValue(int index = 0)
|
|
|
|
|
{
|
2020-05-10 17:33:09 +08:00
|
|
|
|
DateTime? tryGetValue = GetIndexValue(index);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
2020-05-10 17:33:09 +08:00
|
|
|
|
if (tryGetValue == null)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 17:33:09 +08:00
|
|
|
|
DateTime value = (DateTime)tryGetValue;
|
|
|
|
|
|
2020-04-28 15:56:56 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(Format))
|
|
|
|
|
{
|
|
|
|
|
// TODO:Locale
|
|
|
|
|
return value.ToString(Format, CultureInfo.CurrentCulture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO:Locale
|
|
|
|
|
string formater = _pickerStatus[index]._initPicker switch
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
DatePickerType.Date => IsShowTime ? $"yyyy-MM-dd {ShowTimeFormat}" : "yyyy-MM-dd",
|
|
|
|
|
DatePickerType.Week => $"{value.Year}-{DateHelper.GetWeekOfYear(value)}周",
|
|
|
|
|
DatePickerType.Month => "yyyy-MM",
|
|
|
|
|
DatePickerType.Quarter => $"{value.Year}-{DateHelper.GetDayOfQuarter(value)}",
|
|
|
|
|
DatePickerType.Year => "yyyy",
|
|
|
|
|
DatePickerType.Time => "HH:mm:dd",
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_ => "yyyy-MM-dd",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return value.ToString(formater, CultureInfo.CurrentCulture);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 17:33:09 +08:00
|
|
|
|
private void ChangeFocusTarget(bool inputStartFocus, bool inputEndFocus)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-05-10 17:33:09 +08:00
|
|
|
|
if (!IsRange)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_needRefresh = true;
|
2020-05-10 17:33:09 +08:00
|
|
|
|
_inputStart.IsOnFocused = inputStartFocus;
|
|
|
|
|
_inputEnd.IsOnFocused = inputEndFocus;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async Task OnSelect(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
|
|
// change focused picker
|
|
|
|
|
if (IsRange && _inputEnd.IsOnFocused)
|
|
|
|
|
{
|
|
|
|
|
index = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// InitPicker is the finally value
|
|
|
|
|
if (_picker == _pickerStatus[index]._initPicker)
|
|
|
|
|
{
|
|
|
|
|
ChangeValue(date, index);
|
|
|
|
|
|
|
|
|
|
OnChange?.Invoke(date, GetInputValue(index));
|
|
|
|
|
|
|
|
|
|
// auto focus the other input
|
2020-05-18 14:46:42 +08:00
|
|
|
|
if (IsRange && (!IsShowTime || Picker == DatePickerType.Time))
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
if (index == 0 && !_pickerStatus[1]._hadSelectValue && !_inputEnd.IsOnFocused)
|
|
|
|
|
{
|
2020-04-30 08:07:37 +08:00
|
|
|
|
await Blur(0);
|
|
|
|
|
await Focus(1);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
if (index == 1 && !_pickerStatus[0]._hadSelectValue && !_inputStart.IsOnFocused)
|
|
|
|
|
{
|
2020-04-30 08:07:37 +08:00
|
|
|
|
await Blur(1);
|
|
|
|
|
await Focus(0);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_picker = _prePickerStack.Pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangePickerValue(date, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnInput(ChangeEventArgs args, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
if (args == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(args.Value.ToString(), out DateTime changeValue))
|
|
|
|
|
{
|
|
|
|
|
_values[index] = changeValue;
|
|
|
|
|
_pickerValues[index] = changeValue;
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-30 08:07:37 +08:00
|
|
|
|
|
2020-04-28 15:56:56 +08:00
|
|
|
|
private void InitPicker(string picker, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(_pickerStatus[index]._initPicker))
|
|
|
|
|
{
|
|
|
|
|
// note first picker type
|
|
|
|
|
_pickerStatus[index]._initPicker = picker;
|
|
|
|
|
|
|
|
|
|
// set default placeholder
|
2020-05-18 14:46:42 +08:00
|
|
|
|
_placeholders[index] = DatePickerPlaceholder.GetPlaceholderByType(_pickerStatus[index]._initPicker);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
if (IsRange && index != 0)
|
|
|
|
|
{
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
_pickerValues[index] = picker switch
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
DatePickerType.Date => now.AddMonths(1),
|
|
|
|
|
DatePickerType.Week => now.AddMonths(1),
|
|
|
|
|
DatePickerType.Month => now.AddYears(1),
|
|
|
|
|
DatePickerType.Decade => now.AddYears(1),
|
|
|
|
|
DatePickerType.Quarter => now.AddYears(1),
|
|
|
|
|
DatePickerType.Year => now.AddYears(10),
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_ => now,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
2020-05-10 17:33:09 +08:00
|
|
|
|
_dropDown.Hide();
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeValue(DateTime date, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
_values[index] = date;
|
|
|
|
|
|
|
|
|
|
_pickerStatus[index]._hadSelectValue = true;
|
|
|
|
|
|
2020-05-18 14:46:42 +08:00
|
|
|
|
if (IsRange && !IsShowTime && Picker != DatePickerType.Time)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
if (_pickerStatus[0]._hadSelectValue && _pickerStatus[1]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-18 14:46:42 +08:00
|
|
|
|
else if (!IsShowTime && Picker != DatePickerType.Time)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Focus(int index = 0)
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
DatePickerInput input = null;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
input = _inputStart;
|
|
|
|
|
}
|
|
|
|
|
else if (index == 1 && IsRange)
|
|
|
|
|
{
|
|
|
|
|
input = _inputEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input != null)
|
|
|
|
|
{
|
|
|
|
|
input.IsOnFocused = true;
|
2020-04-30 08:07:37 +08:00
|
|
|
|
await JsInvokeAsync(JSInteropConstants.focus, input.Ref);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_needRefresh = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Blur(int index = 0)
|
|
|
|
|
{
|
2020-05-18 14:46:42 +08:00
|
|
|
|
DatePickerInput input = null;
|
2020-04-28 15:56:56 +08:00
|
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
input = _inputStart;
|
|
|
|
|
}
|
|
|
|
|
else if (index == 1 && IsRange)
|
|
|
|
|
{
|
|
|
|
|
input = _inputEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input != null)
|
|
|
|
|
{
|
|
|
|
|
input.IsOnFocused = false;
|
2020-04-30 08:07:37 +08:00
|
|
|
|
await JsInvokeAsync(JSInteropConstants.blur, input.Ref);
|
2020-04-28 15:56:56 +08:00
|
|
|
|
_needRefresh = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetOnFocusPickerIndex()
|
|
|
|
|
{
|
|
|
|
|
if (_inputStart != null && _inputStart.IsOnFocused)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_inputEnd != null && _inputEnd.IsOnFocused)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get pickerValue by picker index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DateTime GetIndexPickerValue(int index)
|
|
|
|
|
{
|
|
|
|
|
return _pickerValues[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get value by picker index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-05-10 17:33:09 +08:00
|
|
|
|
public DateTime? GetIndexValue(int index)
|
2020-04-28 15:56:56 +08:00
|
|
|
|
{
|
2020-05-10 17:33:09 +08:00
|
|
|
|
if (_pickerStatus[index]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
return _values[index];
|
|
|
|
|
}
|
|
|
|
|
else if (_defaultValues[index] != null)
|
|
|
|
|
{
|
|
|
|
|
return (DateTime)_defaultValues[index];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-04-28 15:56:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangePickerValue(DateTime date, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
TimeSpan interval = date - _pickerValues[index];
|
|
|
|
|
|
|
|
|
|
_pickerValues[index] = date;
|
|
|
|
|
|
|
|
|
|
if (IsRange)
|
|
|
|
|
{
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
_pickerValues[1] = _pickerValues[1].Add(interval);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_pickerValues[0] = _pickerValues[0].Add(interval);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnPanelChange?.Invoke(_pickerValues[index], _picker);
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangePickerType(string type, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
_prePickerStack.Push(_picker);
|
|
|
|
|
_picker = type;
|
|
|
|
|
|
|
|
|
|
OnPanelChange?.Invoke(_pickerValues[index], _picker);
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|