提问人:Anonimo 提问时间:7/11/2023 最后编辑:Anonimo 更新时间:7/20/2023 访问量:101
我想在完整日历中有两个由 slotMinTime 和 slotMaxTime 定义的期间
I want to have two periods in the fullcalendar defined by slotMinTime and slotMaxTime
问:
我打算在同一日历中使用两个不同的时期。到目前为止,我发现的唯一方法是在两个不同的日历中执行此操作,如下所示:
$(".btn-show").click(function(e) {
e.preventDefault();
el = $(this).data('element');
$(el).show();
$("section > div").not(el).hide();
});
$(document).on('click', '.dad-visita', function(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
initialViews = 'timeGridWeek';
}else{
initialViews = 'timeGridWeek';
}
var calendarEl = document.getElementById('calendario');
var today = moment().day();
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: "pt-br",
buttonText:{
today: 'Hoje',
list: 'Lista'
},
navLinks: true,
firstDay: today,
hiddenDays: [ 0 ],
initialView: initialViews,
editable: true,
selectable: true,
unselectAuto:true,
eventOverlap: false,
eventColor: '#f16621',
slotDuration: '00:45',
allDaySlot : false,
eventStartEditable: false,
eventDurationEditable:false,
longPressDelay: 0,
nowIndicator: "true",
slotMinTime: '10:30',
slotMaxTime: '12:00',
contentHeight: 'auto',
});
calendar.render();
});
$(document).on('click', '.dad-visita', function(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
initialViews = 'timeGridWeek';
}else{
initialViews = 'timeGridWeek';
}
var calendarEl = document.getElementById('calendario1');
var today = moment().day();
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: "pt-br",
buttonText:{
today: 'Hoje',
list: 'Lista'
},
navLinks: true,
firstDay: today,
hiddenDays: [ 0 ],
initialView: initialViews,
editable: true,
selectable: true,
unselectAuto:true,
eventOverlap: false,
eventColor: '#f16621',
slotDuration: '00:45',
allDaySlot : false,
eventStartEditable: false,
eventDurationEditable:false,
longPressDelay: 0,
nowIndicator: "true",
slotMinTime: '14:30',
slotMaxTime: '19:00',
contentHeight: 'auto',
});
calendar.render();
});
<link href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/pt-br.js"></script>
<a href="s160" data-element="#minhaDiv160" class="btn-show dad-visita">
<i class="metismenu-icon pe-7s-info"></i>
Consultar Visitas
</a>
<section id="s160">
<div style="display:none;" id="minhaDiv160">
<div class="cal-wrapper"><div id='calendario'></div></div>
<div class="cal-wrapper"><div id='calendario1'></div></div>
</div>
</section>
但是这样我必须有两个日历,这不是正确的方法。我必须这样做的原因是我需要 slotDuration 为 45 分钟,并且在早上它正确地假设事件的时间。
但是,如果将 slotMinTime 设置为 10:30,将 slotMaxTime 设置为 19:00,则使用此 slotDuration,下午事件中的日历将从 14:15 开始,如以下示例所示:
$(".btn-show").click(function(e) {
e.preventDefault();
el = $(this).data('element');
$(el).show();
$("section > div").not(el).hide();
});
$(document).on('click', '.dad-visita', function(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
initialViews = 'timeGridWeek';
}else{
initialViews = 'timeGridWeek';
}
var calendarEl = document.getElementById('calendario');
var today = moment().day();
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: "pt-br",
buttonText:{
today: 'Hoje',
list: 'Lista'
},
navLinks: true,
firstDay: today,
hiddenDays: [ 0 ],
initialView: initialViews,
editable: true,
selectable: true,
unselectAuto:true,
eventOverlap: false,
eventColor: '#f16621',
slotDuration: '00:45',
allDaySlot : false,
eventStartEditable: false,
eventDurationEditable:false,
longPressDelay: 0,
nowIndicator: "true",
slotMinTime: '10:30',
slotMaxTime: '19:00',
contentHeight: 'auto',
});
calendar.render();
});
<link href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/pt-br.js"></script>
<a href="s160" data-element="#minhaDiv160" class="btn-show dad-visita">
<i class="metismenu-icon pe-7s-info"></i>
Consultar Visitas
</a>
<section id="s160">
<div style="display:none;" id="minhaDiv160">
<div class="cal-wrapper"><div id='calendario'></div></div>
<div class="cal-wrapper"><div id='calendario1'></div></div>
</div>
</section>
从 14:15 开始,它很快就会返回所有不同下午活动的时间以及我想要的内容。
我仍然找不到解决这个问题的方法。
使用 selectAllow 编写代码:
$(".btn-show").click(function(e) {
e.preventDefault();
el = $(this).data('element');
$(el).show();
$("section > div").not(el).hide();
});
$(document).on('click', '.dad-visita', function(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
initialViews = 'timeGridWeek';
}else{
initialViews = 'timeGridWeek';
}
var calendarEl = document.getElementById('calendario');
var today = moment().day();
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: "pt-br",
buttonText:{
today: 'Hoje',
list: 'Lista'
},
navLinks: true,
firstDay: today,
hiddenDays: [ 0 ],
initialView: initialViews,
editable: true,
selectable: true,
unselectAuto:true,
eventOverlap: false,
eventColor: '#f16621',
slotDuration: '00:15',
allDaySlot : false,
eventStartEditable: false,
eventDurationEditable:false,
longPressDelay: 0,
nowIndicator: "true",
slotMinTime: '10:30',
slotMaxTime: '19:00',
contentHeight: 'auto',
select: function(start, end) {
var start1 = moment((start.startStr)).format('HH:mm:ss');
if(start1 == '14:15:00'){
$('#ModalAddVisit #start').val(moment((start.startStr)).format('YYYY-MM-DD' + " " + '14:30:00'));
$('#ModalAddVisit #end').val(moment((start.startStr)).format('YYYY-MM-DD' + " " + '15:15:00'));
$("#ModalAddVisit").modal("show");
}
},
});
calendar.render();
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/pt-br.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<a href="s160" data-element="#minhaDiv160" class="btn-show dad-visita">
<i class="metismenu-icon pe-7s-info"></i>
Consultar Visitas
</a>
<section id="s160">
<div style="display:none;" id="minhaDiv160">
<div class="cal-wrapper"><div id='calendario'></div></div>
</div>
</section>
<div class="modal fade" tabindex="-1" id="ModalAddVisit" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">NOVA VISITA</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" class="row g-3 insvisit">
<div class="row">
<div class="col-6">
<label for="start"> <strong>DATA/HORA INICIAL</strong> <span style="color: red;">*</span></label>
<input type="text" name="start" id="start" required>
</div>
<div class="col-6">
<label for="end"> <strong>DATA/HORA FINAL</strong> <span style="color: red;">*</span></label>
<input type="text" name="end" id="end" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
<button type="button" class="btn btn-primary validatevisit" id="save-event">Gravar</button>
</div>
</form>
</div>
</div>
</div>
</div>
答:
1赞
ADyson
7/20/2023
#1
FullCalendar 不允许在同一日历上设置两个不同的最小值和最大值。
要解决这个问题,但仍然实现强制执行 45 分钟时段的目标,并在中午休息一下,无法创建任何事件,您可以
- 将 slotDuration 减少到 15 分钟,并且
- 使用 selectAllow 来限制用户可以实际选择的时间段长度,以及
- 使用 businessHours 标记不可用的时间段,并使用 selectConstraint 确保用户无法在该时间段内添加事件。
$(".btn-show").click(function(e) {
e.preventDefault();
el = $(this).data('element');
$(el).show();
$("section > div").not(el).hide();
});
$(document).on('click', '.dad-visita', function() {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
initialViews = 'timeGridWeek';
} else {
initialViews = 'timeGridWeek';
}
var calendarEl = document.getElementById('calendario');
var today = moment().day();
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: "pt-br",
buttonText: {
today: 'Hoje',
list: 'Lista'
},
navLinks: true,
firstDay: today,
hiddenDays: [0],
initialView: initialViews,
editable: true,
selectable: true,
unselectAuto: true,
eventOverlap: false,
eventColor: '#f16621',
slotDuration: '00:15',
allDaySlot: false,
eventStartEditable: false,
eventDurationEditable: false,
longPressDelay: 0,
nowIndicator: "true",
slotMinTime: '10:30',
slotMaxTime: '19:00',
contentHeight: 'auto',
selectConstraint: "businessHours",
selectAllow: function(info) {
var start = moment(info.start);
var end = moment(info.end);
var diff = end.diff(start, 'minutes');
return (diff == 45);
},
businessHours: [
{
daysOfWeek: [0, 1, 2, 3, 4, 5, 6],
startTime: '10:00',
endTime: '12:00'
},
{
daysOfWeek: [0, 1, 2, 3, 4, 5, 6],
startTime: '14:30',
endTime: '19:00'
}
],
select: function(info) {
var start1 = moment((info.startStr)).format('HH:mm:ss');
$('#ModalAddVisit #start').val(moment((info.startStr)).format('YYYY-MM-DD' + " " + '14:30:00'));
$('#ModalAddVisit #end').val(moment((info.startStr)).format('YYYY-MM-DD' + " " + '15:15:00'));
$("#ModalAddVisit").modal("show");
}
});
calendar.render();
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/pt-br.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<a href="s160" data-element="#minhaDiv160" class="btn-show dad-visita">
<i class="metismenu-icon pe-7s-info"></i> Consultar Visitas
</a>
<section id="s160">
<div style="display:none;" id="minhaDiv160">
<div class="cal-wrapper">
<div id='calendario'></div>
</div>
</div>
</section>
<div class="modal fade" tabindex="-1" id="ModalAddVisit" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">NOVA VISITA</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" class="row g-3 insvisit">
<div class="row">
<div class="col-6">
<label for="start"> <strong>DATA/HORA INICIAL</strong> <span style="color: red;">*</span></label>
<input type="text" name="start" id="start" required>
</div>
<div class="col-6">
<label for="end"> <strong>DATA/HORA FINAL</strong> <span style="color: red;">*</span></label>
<input type="text" name="end" id="end" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
<button type="button" class="btn btn-primary validatevisit" id="save-event">Gravar</button>
</div>
</form>
</div>
</div>
</div>
</div>
评论
I need the slotDuration to be 45 minutes
...究竟为什么呢?为什么不能有更短的插槽持续时间?如果您需要将用户限制为仅选择 45 分钟的时间块,还有其他方法可以实现这一点。