You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

7 months ago
import { isArray, isUndefined } from 'lodash-es';
import { dateUtil } from '/nerv-lib/util/date-util';
const DATE_TYPE = [
'NsDatePicker',
'NsMonthPicker',
'NsWeekPicker',
'NsTimePicker',
'NsRangePicker',
'ADatePicker',
'AMonthPicker',
'AWeekPicker',
'ATimePicker',
'ARangePicker',
];
const INPUT_TYPE = ['NsInput', 'AInput'];
/**
*
*/
export function isDateType(component: string | undefined) {
if (isUndefined(component)) return false;
return DATE_TYPE.includes(component);
}
/**
*
*/
export function isInputType(component: string | undefined) {
if (isUndefined(component)) return false;
return INPUT_TYPE.includes(component);
}
/**
*moment格式
* @param component
* @param value
*/
export const transformDate = (component: string, value: any, format?: any) => {
if (value && isDateType(component)) {
if (isArray(value)) {
return value.map((item) => validTime(item, format));
}
return validTime(value, format);
}
};
/**
*
* @param time
* @param format
*/
export function validTime(time: any, format: string) {
if (dateUtil(time, format, true).isValid()) {
return time;
} else {
return dateUtil(time).format(format);
}
}