1.限制年月日
const disabledDate = current => {
if (current) {
if (extra?.activityTime && extra?.activityTime?.length !== 0) {
const currentDate = dayjs(current).format('YYYY-MM-DD')
const startDate = extra?.activityTime?.[0].slice(0, 10)
const endDate = extra?.activityTime?.[1].slice(0, 10)
return !dayjs(currentDate).isBetween(
dayjs(startDate).subtract(1, 'day'),
dayjs(endDate).add(1, 'day')
)
}
}
}
2.限制时分秒
const range = (start, end) => {
const result = []
for (let i = start; i < end; i++) {
result.push(i)
}
return result
}
const ymd = time => {
if (time) {
return [Number(time.slice(11, 13)), Number(time.slice(14, 16)), Number(time.slice(17, 19))]
}
}
const disabledSMS = (limitTime, selectTime) => {
if (limitTime?.[0] === selectTime?.[0] && limitTime?.[1] === selectTime?.[1]) {
return {
disabledHours: () => range(0, 24).splice(0, limitTime[0]),
disabledMinutes: () => range(0, 60).splice(0, limitTime[1]),
disabledSeconds: () => range(0, 60).splice(0, limitTime[2])
}
}
if (limitTime?.[0] === selectTime?.[0]) {
return {
disabledHours: () => range(0, 24).splice(0, limitTime[0]),
disabledMinutes: () => range(0, 60).splice(0, limitTime[1])
}
}
return {
disabledHours: () => range(0, 24).splice(0, limitTime[0])
}
}
const disabledTime = (current, loc) => {
if (extra?.activityTime && extra?.activityTime?.length !== 0) {
const start = extra?.activityTime?.[0].slice(0, 10)
const end = extra?.activityTime?.[1].slice(0, 10)
const date = current && dayjs(current)?.format('YYYY-MM-DD')
if (date) {
if (loc === 'start') {
if (start === date) {
const startymd = ymd(extra?.activityTime?.[0])
const dateymd = ymd(dayjs(current)?.format('YYYY-MM-DD HH:mm:ss'))
return disabledSMS(startymd, dateymd)
}
if (end === date) {
const endymd = ymd(extra?.activityTime?.[1])
const dateymd = ymd(dayjs(current)?.format('YYYY-MM-DD HH:mm:ss'))
return disabledSMS(endymd, dateymd)
}
}
}
}
return false
}