feat: calendar plugin with optional settings to enable or disable quick event creation (#6391)

* feat: calendar plugin with optional settings to enable or disable quick event creation

* feat: remove useless code

* Update zh-CN.json

* feat: modify configuration name

* feat: use nullish coalescing operator
This commit is contained in:
chenyongxin 2025-03-19 17:15:51 +08:00 committed by GitHub
parent 18ab00bce1
commit ee728bd9bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 4 deletions

View File

@ -286,7 +286,15 @@ export const Calendar: any = withDynamicSchemaProps(
}, [reactBigCalendar]);
// 新版 UISchema1.0 之后)中已经废弃了 useProps这里之所以继续保留是为了兼容旧版的 UISchema
const { dataSource, fieldNames, showLunar, defaultView, getFontColor, getBackgroundColor } = useProps(props);
const {
dataSource,
fieldNames,
showLunar,
defaultView,
getFontColor,
getBackgroundColor,
enableQuickCreateEvent,
} = useProps(props);
const height = useCalenderHeight();
const [date, setDate] = useState<Date>(new Date());
const [view, setView] = useState<View>(props.defaultView || 'month');
@ -440,7 +448,7 @@ export const Calendar: any = withDynamicSchemaProps(
onView={setView}
onSelectSlot={(slotInfo) => {
setCurrentSelectDate(slotInfo);
if (canCreate) {
if (canCreate && enableQuickCreateEvent) {
insertAddNewer(addNew);
setVisibleAddNewer(true);
}

View File

@ -219,6 +219,30 @@ export const calendarBlockSettings = new SchemaSettings({
};
},
},
{
name: 'quickCreateEvent',
Component: SchemaSettingsSwitchItem,
useComponentProps() {
const { t } = useTranslation();
const fieldSchema = useFieldSchema();
const field = useField();
const { dn } = useDesignable();
return {
title: t('Quick create event'),
checked: field.decoratorProps?.enableQuickCreateEvent ?? true,
onChange: (v) => {
field.decoratorProps.enableQuickCreateEvent = v;
fieldSchema['x-decorator-props']['enableQuickCreateEvent'] = v;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-decorator-props': field.decoratorProps,
},
});
},
};
},
},
{
name: 'showLunar',
Component: ShowLunarDesignerItem,

View File

@ -17,7 +17,7 @@ export const CalendarBlockContext = createContext<any>({});
CalendarBlockContext.displayName = 'CalendarBlockContext';
const InternalCalendarBlockProvider = (props) => {
const { fieldNames, showLunar, defaultView } = props;
const { fieldNames, showLunar, defaultView, enableQuickCreateEvent } = props;
const field = useField();
const { resource, service } = useBlockRequestContext();
@ -30,6 +30,7 @@ const InternalCalendarBlockProvider = (props) => {
fieldNames,
showLunar,
defaultView,
enableQuickCreateEvent: enableQuickCreateEvent ?? true,
fixedBlock: field?.decoratorProps?.fixedBlock,
}}
>
@ -104,6 +105,7 @@ export const useCalendarBlockProps = () => {
fieldNames: ctx.fieldNames,
showLunar: ctx.showLunar,
defaultView: ctx.defaultView,
enableQuickCreateEvent: ctx.enableQuickCreateEvent,
fixedBlock: ctx.fixedBlock,
getFontColor,
getBackgroundColor,

View File

@ -50,5 +50,6 @@
"Color field": "颜色字段",
"Not selected": "未选择",
"Default view": "默认视图",
"Event open mode": "事项打开方式"
"Event open mode": "事项打开方式",
"Quick create event": "快速创建事项"
}