当前位置:网站首页>Fullcalendar v5.3.2 makes a demo of flight calendar

Fullcalendar v5.3.2 makes a demo of flight calendar

2020-11-10 12:04:35 The night King

Today, a new requirement is to make a flight calendar to book flights . And then I look for all kinds of , Finally find FullCalendar, Most of the online examples are useless , Most of them don't have the full version . The official website tutorial is not very detailed . It took a few days to complete the flight calendar , And compatible with mobile phone (FullCalendar The mobile phone is not compatible with the month view , So here the mobile phone cancels the month view ), I record the code , For their own and netizens reference

Let's take a look at the shape :

 

 

I don't say much nonsense . Code up :

  The front-end code :

<!DOCTYPE html>
<meta charset='utf-8' />
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header(' New booking ')" />
    <!-- introduce FullCalendar css and js  Go by yourself FullCalendar Download from the official website -->
    <link href='/cargo/css/main.css' rel='stylesheet' />
    <script src="/cargo/js/main.js"/>

    <!-- Load the flight data in the calendar -->
    <script type="text/javascript">
        // <div id='Calendar'></div>  The official website is here , I can't put it here , So I put it down 
    </script>
    <style>
        body {
            margin: 40px 10px;
            padding: 0;
            font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
            font-size: 14px;
        }

        #Calendar {
            max-width: 1500px;
            margin: 0 auto;
        }

        /* Event  Parameters  className  Value  */
        .doing:before {
            content:"【  Hang in the air  】";
            background-color:yellow;
            color:red;
            text-align:center;
            font-weight:bold;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper animated fadeInRight ">
    <div hidden class="form-group" style="margin-left: 75px">
        <a  class="btn btn-success disabled" id="bookFlightAdd" name="bookFlightAdd" onclick="$.operate.add()" shiro:hasPermission="freight:bookFlight:add">
            <i class="fa fa-plus"></i>  Booking space 
        </a>
        <input type="hidden" id="flightData" value="">
        <a display  id="bookFlightHidden" name="bookFlightHidden" onclick="$.operate.addFlightData($('#flightData').val())" shiro:hasPermission="freight:bookFlight:add"></a>
    </div>

    <!-- Flight calendar -->
    <div id='Calendar'></div>
</div>

<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "freight/bookFlight";

    <!-- Load the flight data in the calendar -->
    document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('Calendar');
        var calendar = new FullCalendar.Calendar(calendarEl, {
            initialView: windowSize(), // The initial view when the calendar is loaded 
            timeZone: 'UTC',// The time zone 
            editable: false,// Whether the calendar event can be modified 
            eventStartEditable:false,// Allows the start time of an event to be edited by dragging 
            eventDurationEditable:false,// Allows you to change the duration of an event by resizing 
            themeSystem: 'bootstrap',// The theme 
            locale: 'zh',// Language 
            headerToolbar: {// Head toolbar 
                left: 'prev,next today',
                center: 'title',
                right: headerToolbarRight()
            },
            dateClick: function(info) {// Mouse click 
                info.dayEl.style.backgroundColor = '#00FF99';
            },
            buttonText:{// Button text 
                today:    ' today ',
                month:    ' month ',
                week:     ' Zhou ',
                day:      ' God ',
            },
            initialDate: new Date(),// Initialization time 
            navLinks: true, //  You can click days / The name of the week to browse the view 
            dayMaxEvents: true, //  allow  " more "  link   When too many events 
            dayMaxEventRows: true, //  For all non time grid views 
            moreLinkClick:"week",  // Click on more When you press the button , Jump to what view 
            // Mouse hover prompt  event.event.title
            eventMouseEnter : function( event ) {
                $(".fc-daygrid-event").attr("title",' Click booking ');
            },

            // Enter the calendar interface to load the added data 
            events: function( fetchInfo, successCallback, failureCallback ){
                var events = [];
                $.ajax({
                    type:"POST",
                    url:prefix+"/viewData",
                    dataType:"json",
                    success:function(result){
                        var jobScheduleList =  result;
                        if(jobScheduleList.length > 1){
                            $.each(jobScheduleList,function(i,j){
                                events.push({
                                    //id:j.id,
                                    title: j.name,
                                    //url: prefix+j.url,// Set link 
                                    content:'$.operate.add()',// Content ( I defined it myself , The frame doesn't have )
                                    imageUrl:'/profile/'+j.imgUrl,// Picture links ( I defined it myself , The frame doesn't have )
                                    color: 'pink',// Set the color 
                                    start: new Date(j.startDate).format('yyyy-MM-dd'), //  Parsing time 
                                    //end:new Date(j.endDate).format('yyyy-MM-dd')
                                    //className: 'doing',// Set class name 
                                    //backgroundColor: 'gray',// Set the background color 
                                });
                            })
                            // Callback render calendar 
                            successCallback(events);
                        }
                    },
                    error:function(){
                        // Error in callback 
                    },
                })
            },

            // Airline image Injection 
            eventContent: function(arg) {
                let italicEl = document.createElement('span')
                if (arg.event.extendedProps.isUrgent) {
                    italicEl.onclick(setTimeout());
                    italicEl.innerHTML = '<img src="'+arg.event.extendedProps.imageUrl+'" width="30px" height="30px" style="border-radius: 15px;">'+' '+'<span>'+arg.event.title+'</span>';
                } else {
                    function abc() {
                        $('#flightData').val(arg.event.title);
                        // IE browser 
                        if(document.all) {
                            document.getElementById("bookFlightHidden").click();
                        }
                        //  Other browsers 
                        else {
                            var e = document.createEvent("MouseEvents");
                            e.initEvent("click", true, true);
                            document.getElementById("bookFlightHidden").dispatchEvent(e);
                        }
                    }
                    italicEl.onclick=abc;
                    italicEl.innerHTML = '<img src="'+arg.event.extendedProps.imageUrl+'" width="30px" height="30px" style="border-radius: 15px;">'+' '+'<span>'+arg.event.title+'</span>';
                }
                let arrayOfDomNodes = [ italicEl ]
                return { domNodes: arrayOfDomNodes }
            },
        });
        calendar.render();
    });

    // Determine the size of the window to display different views ( The mobile phone does not support month view )
    function windowSize(){
        if(window. innerWidth< 800){
            return 'dayGridWeek';
        } else {
            return 'dayGridMonth';
        }
    }
    // To determine the size of the window ( The mobile phone does not support month view )
    function headerToolbarRight(){
        if(window. innerWidth< 800){
            return 'dayGridWeek,dayGridDay';
        } else {
            return 'dayGridMonth,dayGridWeek,dayGridDay';
        }
    }

    // Convert the timestamp of the database to   character string 
    Date.prototype.format = function(format) {
        var o = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
        }
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }

        $(function () {
        var options = {
            createUrl: prefix + "/add",
            createCustomUrl: prefix + "/customAdd/{data}",
            modalName: " Booking space ",
        };
        $.table.init(options);
    });
</script>
</body>
</html>

 

Back end code :

/**
 *  Flight calendar 
 * @author  The night Lord 
 * @create 2020-11-03 10:19
 */
public class FlightCalendar {
    public FlightCalendar() {
    }

    public FlightCalendar(int id, String name, String content, String url, String imgUrl, Date startDate, Date endDate) {
        this.id = id;
        this.name = name;
        this.url = url;
        this.imgUrl = imgUrl;
        this.content = content;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public int id ;
    /** name */
    public String name ;
    /** Content */
    public String content ;
    /** link */
    public String url ;
    /** Picture links */
    public String imgUrl ;
    /** Starting time */
    public Date startDate ;
    /** End time */
    public Date endDate ;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}
    /**
     *  Load flight calendar 
     * @param
     * @return
     */
    @RequiresPermissions({"freight:bookFlight:list"})
    @PostMapping({"/viewData"})
    @ResponseBody
    public List<FlightCalendar> ViewData() {

        // Check the flight plan 
        CargoFlightSchedule cargoFlightSchedule=new CargoFlightSchedule();
        cargoFlightSchedule.setStatue("1");
        cargoFlightSchedule.setBookStatue("3");
        cargoFlightSchedule.setFlightTime(new Date());
        List<CargoFlightSchedule> list = cargoFlightScheduleService.selectCargoFlightScheduleANDAirlinesCompanyList(cargoFlightSchedule);

        List<FlightCalendar> flightCalendars=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String title = list.get(i).getFlightNumber()+" "+list.get(i).getDeparturePort()+"-"+list.get(i).getDestination()+" "+DateUtil.format(list.get(i).getFlightTime(),"yyyy-MM-dd");
            flightCalendars.add(new FlightCalendar(i,
                            title,
                    "cargoFlightSchedules.get(i).getFlightNumber()",
                        "/add",
                            list.get(i).getaCimgUrl(),
                            list.get(i).getFlightTime(),
                            list.get(i).getFlightTime()));
        }

        return flightCalendars;
    }

You can leave a message if you have any questions or suggestions .

If I can help you , Could you make a recommendation ? thank you

版权声明
本文为[The night King]所创,转载请带上原文链接,感谢