javascript
复制代码
import dayjs from 'dayjs';
setup() {
const disabledDate = current => {
return current && current > dayjs().endOf('day');
};
const range = (start, end) => {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
};
function disabledTime(dates, partial) {
const hours = dayjs().hour();
const minutes = dayjs().minute();
const seconds = dayjs().second();
if (!dates) {
dates = dayjs();
}
if (partial == 'start') {
if (dates[0] && dayjs(dates[0]).date() === dayjs().date()) {
if (dayjs(dates[0]).hour() === dayjs().hour()) {
return {
disabledHours: () => range(hours + 1, 24),
disabledMinutes: () => range(minutes + 1, 60),
disabledSeconds: () => range(seconds + 1, 60)
};
} else {
return {
disabledHours: () => range(hours, 24),
disabledMinutes: () => [],
disabledSeconds: () => []
};
}
} else {
return {
disabledHours: () => [],
disabledMinutes: () => [],
disabledSeconds: () => []
};
}
} else if (partial == 'end') {
if (dates[1] && dayjs(dates[1]).date() === dayjs().date()) {
if (dayjs(dates[1]).hour() === dayjs().hour()) {
return {
disabledHours: () => range(hours + 1, 24),
disabledMinutes: () => range(minutes + 1, 60),
disabledSeconds: () => range(seconds + 1, 60)
};
} else {
return {
disabledHours: () => range(hours, 24),
disabledMinutes: () => [],
disabledSeconds: () => []
};
}
} else {
return {
disabledHours: () => [],
disabledMinutes: () => [],
disabledSeconds: () => []
};
}
}
}
return {
disabledDate,
disabledTime
};
}