和很多人一样,我正在尝试将Full Calendar与React一起使用。和许多人一样,试图获取它来注册外部事件下降。我包括全班同学。请帮忙,如果我们能使它正常工作,我可以更新示例,而没有人像我那样松散头发。 :)
我尝试了每种组合。我最后使用了包装器插件,因为日历一直在吹牛。
我确定这与我如何加载插件或如何传递拖动的数据有关。我只是在日历上方创建了一个简单的div,然后将其拖动,日历就会突出显示。.bt放下时,没有一个偶数寄存器。
有人有什么建议吗?
import React, { Component } from "react";
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/';
import '../styles/calendar.css'
import 'fullcalendar-reactwrapper/dist/css/fullcalendar.min.css'
import FullCalendar from 'fullcalendar-reactwrapper';
import { dayGrid } from '@fullcalendar/daygrid';
import interactionPlugin, { Draggable } from '@fullcalendar/interaction';
// import {Calendar } from '@fullcalendar/core';
import '@fullcalendar/core/main.css';
import '@fullcalendar/daygrid/main.css';
class MyCalendar extends Component {
constructor(props) {
super(props);
this.state = {
events: [
{
title: 'All Day Event',
start: '2017-05-01',
color: '#257e4a'
},
{
title: 'Long Event',
start: '2017-05-07',
end: '2017-05-10',
rendering: 'background'
},
{
id: 9,
title: 'Repeating Event background',
start: '2017-05-09T16:00:00',
color: '#ff9f89',
textColor: 'red'
},
{
id: 99,
title: 'Repeating inverse-Event',
start: '2017-05-16T16:00:00',
rendering: 'inverse-background',
},
{
title: 'Conference',
start: '2017-05-11',
end: '2017-05-13'
},
{
title: 'Meeting',
start: '2017-05-12T10:30:00',
end: '2017-05-12T12:30:00'
},
{
title: 'Birthday Party',
start: '2017-05-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2017-05-28'
}
],
}
}
handleSelect = ({ start, end }) => {
console.log('select', start, end);
// const title = window.prompt('New Event name')
// if (title)
// this.setState({
// events: [
// ...this.state.events,
// {
// start,
// end,
// title,
// },
// ],
// })
}
drop(args) {
console.log('drop', args);
}
eventRecieve(args) {
console.log('eventRecieve', args);
}
click(args) {
console.log('click', args);
}
select(args) {
console.log('select', args);
}
onDragStart = (ev, id) => {
console.log('drag start', ev, id);
ev.dataTransfer.setData("id", id);
}
onDragStop = (ev, id) => {
console.log('on drag stop', ev, id);
ev.dataTransfer.setData("id", id);
}
eventDragStart = (ev, id) => {
console.log('drag start', ev, id);
// ev.dataTransfer.setData("id", id);
}
eventDragResize = (ev, id) => {
console.log('drag start', ev, id);
// ev.dataTransfer.setData("id", id);
}
eventDragStop = (ev, id) => {
console.log('drag Stop', ev, id);
// ev.dataTransfer.setData("id", id);
}
render() {
return (<div >
<div>
<div
key={1}
draggable
onDragStart={(e) => this.onDragStart(e, 1)}
onDragStop={(e) => this.onDragStop(e, 1)}
data-event='{ title: "my event", duration: "02:00" }'
>
Drag Me
</div>
</div>
<div>
<FullCalendar
droppable={true}
plugins={[interactionPlugin, 'interaction', 'dayGrid', 'timeGrid', 'list']}
header={{
left: 'prev,next today myCustomButton',
center: 'title',
right: 'dayGridMonth,dayGridWeek,dayGridDay,timeGridWeek,timeGridDay'
}}
onDragStop={(e) => this.onDragStop(e, 1)}
defaultDate={'2017-05-12'}
navLinks={true} // can click day/week names to navigate views
editable={true}
nowIndicator={true}
selectable={true}
eventSelect={(args) => this.select(args)}
select={(args) => this.select(args)}
eventLimit={true} // allow "more" link when too many events
events={this.state.events}
eventClick={(args) => this.click(args)}
drop={(args) => this.drop(args)}
eventDragStart={(args) => this.eventDragStart(args)}
eventDragStop={(args) => this.eventDragStop(args)}
eventResize={(args) => this.eventDragResize(args)}
eventDrop={(args) => this.drop(args)}
eventReceive={(args) => this.eventRecieve(args)}
/>
</div>
</div>);
}
}
const styles = {
div: {
margin: 10
}
};
MyCalendar.propTypes = {
children: PropTypes.node,
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(MyCalendar);