fix(calendar): events cannot support moment (#1017)
* fix(calendar): events cannot support moment * fix: avoid manipulating raw values
This commit is contained in:
parent
a411240f48
commit
acc9f1df10
@ -84,32 +84,32 @@ const useEvents = (dataSource: any, fieldNames: any, date: Date, view: typeof We
|
|||||||
startDate.startOf('week');
|
startDate.startOf('week');
|
||||||
endDate.endOf('week');
|
endDate.endOf('week');
|
||||||
}
|
}
|
||||||
const push = (fields?: Record<string, any>) => {
|
const push = (eventStart: moment.Moment = start) => {
|
||||||
// 必须在这个月的开始时间和结束时间,切在日程的开始时间之后
|
// 必须在这个月的开始时间和结束时间,切在日程的开始时间之后
|
||||||
const eventStart: moment.Moment = fields?.start || start;
|
|
||||||
if (eventStart.isBefore(start) || !eventStart.isBetween(startDate, endDate)) {
|
if (eventStart.isBefore(start) || !eventStart.isBetween(startDate, endDate)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const event = {
|
|
||||||
id: get(item, fieldNames.id || 'id'),
|
|
||||||
title: get(item, fieldNames.title) || t('Untitle'),
|
|
||||||
end: eventStart.add(intervalTime, 'millisecond'),
|
|
||||||
...fields,
|
|
||||||
start: eventStart,
|
|
||||||
};
|
|
||||||
|
|
||||||
let out = false;
|
let out = false;
|
||||||
const res = exclude?.some((d) => {
|
const res = exclude?.some((d) => {
|
||||||
if (d.endsWith('_after')) {
|
if (d.endsWith('_after')) {
|
||||||
d = d.replace(/_after$/, '');
|
d = d.replace(/_after$/, '');
|
||||||
out = true;
|
out = true;
|
||||||
return event.start.isSameOrAfter(d);
|
return eventStart.isSameOrAfter(d);
|
||||||
} else {
|
} else {
|
||||||
return event.start.isSame(d);
|
return eventStart.isSame(d);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) return out;
|
if (res) return out;
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
id: get(item, fieldNames.id || 'id'),
|
||||||
|
title: get(item, fieldNames.title) || t('Untitle'),
|
||||||
|
start: eventStart.toDate(),
|
||||||
|
end: eventStart.add(intervalTime, 'millisecond').toDate(),
|
||||||
|
};
|
||||||
|
|
||||||
events.push(event);
|
events.push(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,21 +121,15 @@ const useEvents = (dataSource: any, fieldNames: any, date: Date, view: typeof We
|
|||||||
.date(startDate.date())
|
.date(startDate.date())
|
||||||
.day(start.day());
|
.day(start.day());
|
||||||
while (nextStart.isBefore(endDate)) {
|
while (nextStart.isBefore(endDate)) {
|
||||||
if (
|
if (push(nextStart.clone())) {
|
||||||
push({
|
|
||||||
start: nextStart.clone(),
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nextStart.add(1, 'week');
|
nextStart.add(1, 'week');
|
||||||
}
|
}
|
||||||
} else if (cron === 'every_month') {
|
} else if (cron === 'every_month') {
|
||||||
push({
|
push(start.clone().year(dateM.year()).month(dateM.month()));
|
||||||
start: start.clone().year(dateM.year()).month(dateM.month()),
|
|
||||||
});
|
|
||||||
} else if (cron === 'every_year') {
|
} else if (cron === 'every_year') {
|
||||||
push({ start: start.clone().year(dateM.year()) });
|
push(start.clone().year(dateM.year()));
|
||||||
} else {
|
} else {
|
||||||
push();
|
push();
|
||||||
if (!cron) return;
|
if (!cron) return;
|
||||||
@ -149,12 +143,7 @@ const useEvents = (dataSource: any, fieldNames: any, date: Date, view: typeof We
|
|||||||
});
|
});
|
||||||
while (interval.hasNext()) {
|
while (interval.hasNext()) {
|
||||||
const { value } = interval.next();
|
const { value } = interval.next();
|
||||||
if (
|
if (push(moment(value.toDate()))) break;
|
||||||
push({
|
|
||||||
start: moment(value.toDate()),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { observer } from '@formily/react';
|
import { observer } from '@formily/react';
|
||||||
import { Modal, Radio, Space, Typography } from 'antd';
|
import { Modal, Radio, Space, Typography } from 'antd';
|
||||||
|
import moment from 'moment';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -11,7 +12,7 @@ const { Text } = Typography;
|
|||||||
export const DeleteEvent = observer(() => {
|
export const DeleteEvent = observer(() => {
|
||||||
const { visible, setVisible } = useActionContext();
|
const { visible, setVisible } = useActionContext();
|
||||||
const { exclude = [], cron, ...record } = useRecord();
|
const { exclude = [], cron, ...record } = useRecord();
|
||||||
const startDate = record.__parent.__event.start.format();
|
const startDate = moment(record.__parent.__event.start).format();
|
||||||
const filterByTk = useFilterByTk();
|
const filterByTk = useFilterByTk();
|
||||||
const { resource, service, __parent } = useBlockRequestContext();
|
const { resource, service, __parent } = useBlockRequestContext();
|
||||||
const [value, onChange] = useState(startDate);
|
const [value, onChange] = useState(startDate);
|
||||||
|
Loading…
Reference in New Issue
Block a user