1- /**
2- * FullCalendar 日历 官网: https://fullcalendar.io/
3- * dayGridPlugin 月视图
4- * timeGridPlugin 周视图
5- * interactionPlugin 交互
6- * multiMonthPlugin 多月视图
7- * zhLocale 语言
8- */
91import { ProCard } from '@ant-design/pro-components' ;
102import { DateSelectArg , EventApi , EventClickArg , EventContentArg , formatDate } from '@fullcalendar/core' ;
113import zhLocale from '@fullcalendar/core/locales/zh-cn' ;
12- import dayGridPlugin from '@fullcalendar/daygrid' ; // a plugin!
13- import interactionPlugin from '@fullcalendar/interaction' ; // needed for dayClick
4+ import dayGridPlugin from '@fullcalendar/daygrid' ;
5+ import interactionPlugin from '@fullcalendar/interaction' ;
146import multiMonthPlugin from '@fullcalendar/multimonth' ;
157import FullCalendar from '@fullcalendar/react' ;
168import timeGridPlugin from '@fullcalendar/timegrid' ;
@@ -59,14 +51,10 @@ export default () => {
5951 return (
6052 < div className = "demo-app-sidebar" >
6153 < div className = "demo-app-sidebar-section" >
62- { /* <h2>Instructions</h2> */ }
6354 < h2 > 说明: </ h2 >
6455 < ul >
65- { /* <li>Select dates and you will be prompted to create a new event</li> */ }
6656 < li > 选择日期,系统将提示您创建一个新事件</ li >
67- { /* <li>Drag, drop, and resize events</li> */ }
6857 < li > 拖放和调整事件大小</ li >
69- { /* <li>Click an event to delete it</li> */ }
7058 < li > 单击需要删除的事件</ li >
7159 </ ul >
7260 </ div >
@@ -85,11 +73,11 @@ export default () => {
8573 } ;
8674
8775 const handleDateSelect = ( selectInfo : DateSelectArg ) => {
88- // let title = prompt('Please enter a new title for your event');
8976 let title = prompt ( '请为您的活动输入一个新标题' ) ;
9077 let calendarApi = selectInfo . view . calendar ;
9178
92- calendarApi . unselect ( ) ; // clear date selection
79+ // 清除日期选中状态,避免多次触发选中高亮
80+ calendarApi . unselect ( ) ;
9381
9482 if ( title ) {
9583 calendarApi . addEvent ( {
@@ -103,12 +91,7 @@ export default () => {
10391 } ;
10492
10593 const handleEventClick = ( clickInfo : EventClickArg ) => {
106- if (
107- confirm (
108- // `Are you sure you want to delete the event '${clickInfo.event.title}'`,
109- `您确定要删除事件吗 '${ clickInfo . event . title } '` ,
110- )
111- ) {
94+ if ( confirm ( `您确定要删除事件吗 '${ clickInfo . event . title } '` ) ) {
11295 clickInfo . event . remove ( ) ;
11396 }
11497 } ;
@@ -124,43 +107,26 @@ export default () => {
124107 < ProCard className = "shadow-2xl" >
125108 < div className = "demo-app" >
126109 < FullCalendar
127- // 语言
128110 locale = { zhLocale }
129- // 插件
130111 plugins = { [ dayGridPlugin , timeGridPlugin , interactionPlugin , multiMonthPlugin ] }
131112 headerToolbar = { {
132113 left : 'prev,next today' ,
133114 center : 'title' ,
134115 right : 'multiMonthYear,dayGridMonth,timeGridWeek,timeGridDay' ,
135116 } }
136- // 初始视图
137117 initialView = "dayGridMonth"
138118 editable = { true }
139119 selectable = { true }
140120 selectMirror = { true }
141121 dayMaxEvents = { true }
142- // 日期
143- // weekends={false}
144122 weekends = { state . weekendsVisible }
145- initialEvents = { INITIAL_EVENTS } // 或者,使用' events '设置从提要中获取
123+ // 使用静态初始事件;也可改为 events 属性从远程接口拉取
124+ initialEvents = { INITIAL_EVENTS }
146125 select = { handleDateSelect }
147- eventContent = { renderEventContent } // 自定义渲染功能
126+ eventContent = { renderEventContent }
148127 eventClick = { handleEventClick }
149- eventsSet = { handleEvents } // 在事件初始化/添加/更改/删除后调用
150- // 事件
151- // events={[
152- // { title: 'event 1', date: '2023-08-15' },
153- // { title: 'event 2', date: '2019-04-02' },
154- // ]}
155- // 点击日期
156- dateClick = { ( arg ) => {
157- // alert(arg.dateStr)
158- } }
159- /* 你可以在这些触发时更新远程数据库:
160- eventAdd={function(){}}
161- eventChange={function(){}}
162- eventRemove={function(){}}
163- */
128+ // 事件初始化/添加/更改/删除后均会触发,用于同步侧边栏事件列表
129+ eventsSet = { handleEvents }
164130 />
165131 < div className = "shadow-2xl p-8 m-8" > { renderSidebar ( ) } </ div >
166132 </ div >
0 commit comments