fullcalendar.io 可以在 .net core Blazor 中使用吗?

2024-01-29

我尝试在 Blazor WebAssembly 页面中使用 FullCalendar。 任何人都知道如何在 Blazor 中使用 FullCalendar ??? 任何人都可以帮助我吗?

我将 FullCalendar 包含在 libman.json 中

   {
      "library": "@fullcalendar/core",
      "provider": "unpkg",
      "destination": "wwwroot/lib/fullCalendar"
    }

在 wwwroot/index.html 中

   <script src="_framework/blazor.webassembly.js"></script>
   <script src="exampleJsInterop.js"></script>

我的 js 文件“exampleJsInterop.js”位于 wwwroot 文件夹中

window.exampleJsFunctions = {

    showPrompt: function (text) {
        return prompt(text, 'Type your name here');
    },
    displayWelcome: function (welcomeMessage) {
        document.getElementById('welcome').innerText = welcomeMessage;
    },

    calendar: function () {
        document.getElementById("#calendar").fullCalendar({
            schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
            editable: false,
            allDaySlot: true,
            eventLimit: true,
            axisFormat: 'HH:mm',
            slotLabelFormat: 'HH:mm',
            aspectRatio: 2,
            header: {
                left: 'today prev,next',
                center: 'title',
                right: 'month '
            },
            //defaultView: 'timelineDay',
            selectable: true,
        });
    }
    
};

剃刀页面

@page "/fullCalendar"
@inject IJSRuntime JsRuntime;

<h1>FullCalendar</h1>

<button type="button" class="btn btn-primary" @onclick="test">
    Bouton test
</button>

<div class="container">
    <div id='calendar'></div>
</div>

@code {
      private async void test() {
        await JsRuntime.InvokeVoidAsync("exampleJsFunctions.calendar");
    }
}

代码有什么问题吗?

错误 :

(Microsoft.JSInterop.JSException: $ is not** defined)   
>main.js:1 
Failed to load resource: the server responded with a status of 404 (Not Found)
    blazor.webassembly.js:1 Debugging hotkey: Shift+Alt+D (when application has focus)
    favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
    blazor.webassembly.js:1 WASM: 
    d.printErr @ blazor.webassembly.js:1
    put_char @ mono.js:1
    write @ mono.js:1
    write @ mono.js:1
    doWritev @ mono.js:1
    ___syscall146 @ mono.js:1
    Module._mono_background_exec @ mono.js:1
    pump_message @ mono.js:1
    setTimeout (async)
    _schedule_background_exec @ mono.js:1
    Module._mono_wasm_invoke_method @ mono.js:1
    callMethod @ blazor.webassembly.js:1
    beginInvokeDotNetFromJS @ blazor.webassembly.js:1
    l @ blazor.webassembly.js:1
    e.invokeMethodAsync @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    t.dispatchEvent @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    e.onGlobalEvent @ blazor.webassembly.js:1
    Show 26 more frames
    blazor.webassembly.js:1 WASM: Unhandled Exception:
    d.printErr @ blazor.webassembly.js:1
    put_char @ mono.js:1
    write @ mono.js:1
    write @ mono.js:1
    doWritev @ mono.js:1
    ___syscall146 @ mono.js:1
    Module._mono_background_exec @ mono.js:1
    pump_message @ mono.js:1
    setTimeout (async)
    _schedule_background_exec @ mono.js:1
    Module._mono_wasm_invoke_method @ mono.js:1
    callMethod @ blazor.webassembly.js:1
    beginInvokeDotNetFromJS @ blazor.webassembly.js:1
    l @ blazor.webassembly.js:1
    e.invokeMethodAsync @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    t.dispatchEvent @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    e.onGlobalEvent @ blazor.webassembly.js:1
    Show 26 more frames
    **blazor.webassembly.js:1 WASM: Microsoft.JSInterop.JSException: $ is not** defined
    d.printErr @ blazor.webassembly.js:1
    put_char @ mono.js:1
    write @ mono.js:1
    write @ mono.js:1
    doWritev @ mono.js:1
    ___syscall146 @ mono.js:1
    Module._mono_background_exec @ mono.js:1
    pump_message @ mono.js:1
    setTimeout (async)
    _schedule_background_exec @ mono.js:1
    Module._mono_wasm_invoke_method @ mono.js:1
    callMethod @ blazor.webassembly.js:1
    beginInvokeDotNetFromJS @ blazor.webassembly.js:1
    l @ blazor.webassembly.js:1
    e.invokeMethodAsync @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    t.dispatchEvent @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    e.onGlobalEvent @ blazor.webassembly.js:1
    Show 26 more frames
    blazor.webassembly.js:1 WASM: ReferenceError: $ is not defined
    d.printErr @ blazor.webassembly.js:1
    put_char @ mono.js:1
    write @ mono.js:1
    write @ mono.js:1
    doWritev @ mono.js:1
    ___syscall146 @ mono.js:1
    Module._mono_background_exec @ mono.js:1
    pump_message @ mono.js:1
    setTimeout (async)
    _schedule_background_exec @ mono.js:1
    Module._mono_wasm_invoke_method @ mono.js:1
    callMethod @ blazor.webassembly.js:1
    beginInvokeDotNetFromJS @ blazor.webassembly.js:1
    l @ blazor.webassembly.js:1
    e.invokeMethodAsync @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    t.dispatchEvent @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    (anonymous) @ blazor.webassembly.js:1
    e.onGlobalEvent @ blazor.webassembly.js:1
    Show 26 more frames
    blazor.webassembly.js:1 WASM:     at testDan (http://localhost:53863/:30:17)
    d.printErr @ blazor.webassembly.js:1
    put_char @ mono.js:1
    write @ mono.js:1
    write @ mono.js:1
    doWritev @ mono.js:1
    ___syscall146 @ mono.js:1
    Module._mono_background_exec @ mono.js:1
    pump_message @ mono.js:1
    setTimeout (async)
    _schedule_background_exec @ mono.js:1

经过一周的工作,我设法得到了全日历版本 4在 blazor net5 中运行。

日历选项.cs

using System;
using System.Collections.Generic;

namespace SmartApp.Components
{
    public class CalendarOptions
    {
        public string Id { get; set; }
        public string DefaultView { get; set; } = CalendarView.ListWeek;
        public DateTime DefaultDate { get; set; } = DateTime.Now;
        public List<CalendarEvent> CalendarEvents { get; set; } = new List<CalendarEvent>();
    }

    public class CalendarEvent
    {
        public string Identifier { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime Start { get; set; }
        public DateTime? End { get; set; }
        public string Url { get; set; } = string.Empty;
        public string SolidColor { get; set; }
        public string DotColor { get; set; }

        public string ClassName => $"{(string.IsNullOrEmpty(SolidColor) ? "" : $"fc-event-solid-{SolidColor}")} " +
                                   $"{(string.IsNullOrEmpty(DotColor) ? "" : $"fc-event-{DotColor}")}";

        public CalendarEventStatus Status { get; set; }
    }

    public class CalendarView
    {
        public static string DayGridMonth = "dayGridMonth";
        public static string TimeGridWeek = "timeGridWeek";
        public static string TimeGridDay = "timeGridDay";
        public static string ListWeek = "listWeek";
    }

    public class CalendarEventSolidColor
    {
        public static string Primary = "primary";
        public static string Warning = "warning";
        public static string Error = "error";
        public static string Success = "success";
        public static string Info = "info";
    }

    public class CalendarEventDotColor
    {
        public static string Primary = "primary";
        public static string Warning = "warning";
        public static string Error = "error";
        public static string Success = "success";
        public static string Info = "info";
        public static string Light = "light";
    }

    public enum CalendarEventStatus
    {
        Deleted = 0,
        Active = 1,
        Changed = 2
    }
}

输入日历.razor这是一个可重复使用的组件

@namespace SmartApp.Components

@inject IJSRuntime JSRuntime

<div id="@Id"></div>

@code {
    string _id;
    [Parameter]
    public string Id
    {
        get => _id ?? $"Calendar_{_uid}";
        set => _id = value;
    }

    [Parameter]
    public List<CalendarEvent> Events { get; set; }

    [Parameter]
    public string View { get; set; } = CalendarView.ListWeek;

    [Parameter]
    public EventCallback<List<CalendarEvent>> EventsChanged { get; set; }


    readonly string _uid = Guid.NewGuid().ToString().ToLower().Replace("-", "");

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await JSRuntime.InvokeVoidAsync("removeContent", $"#{Id}");

        var options = new CalendarOptions
        {
            Id = Id,
            DefaultView = View,
            CalendarEvents = Events.Where(r => r.Status == CalendarEventStatus.Active).ToList()
        };

        await JSRuntime.InvokeVoidAsync("FullCalendarInterop.init", options, DotNetObjectReference.Create(this));

        await base.OnAfterRenderAsync(firstRender);
    }

    [JSInvokable]
    public async Task CalendarEventDeleted(string identifier)
    {
        var calendarEvent = Events.FirstOrDefault(x => x.Identifier == identifier);

        if (calendarEvent != null)
            calendarEvent.Status = CalendarEventStatus.Deleted;

        await EventsChanged.InvokeAsync(Events);
    }

    [JSInvokable]
    public Task SetDefaultView(string defaultView)
    {
        View = defaultView ?? CalendarView.ListWeek;

        return Task.CompletedTask;
    }

}

互操作js

    FullCalendarInterop = (() => {
        return {
            //main function to initiate the module
            init: function (options, dotNetReference) {
                var calendarEl = document.getElementById(options.id);
                var calendar = new window.FullCalendar.Calendar(calendarEl, {
                    plugins: ['interaction', 'dayGrid', 'timeGrid', 'list'],
    
                    isRTL: window.KTUtil.isRTL(),
                    header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
                    },
    
                    height: 800,
                    contentHeight: 750,
                    aspectRatio: 3,  // see: https://fullcalendar.io/docs/aspectRatio
    
                    views: {
                        dayGridMonth: { buttonText: 'month' },
                        timeGridWeek: { buttonText: 'week' },
                        timeGridDay: { buttonText: 'day' },
                        listWeek: { buttonText: 'list' }
                    },
    
                    defaultView: options.defaultView,
                    defaultDate: options.defaultDate,
    
                    editable: true,
                    eventLimit: true, // allow "more" link when too many events
                    navLinks: true,
                    events: options.calendarEvents,
    
                    eventRender: function (info) {
                        var event = $(info.event);
                        var element = $(info.el);
                        var view = $(info.view);
    
                        if (info.event.extendedProps && info.event.extendedProps.description) {
                            if (element.hasClass('fc-day-grid-event')) {
                                element.data('content', info.event.extendedProps.description);
                                element.data('placement', 'top');
                                window.KTApp.initPopover(element);
                            } else if (element.hasClass('fc-time-grid-event')) {
                                element.find('.fc-title').append('<div class="fc-description">' + info.event.extendedProps.description + '</div>');
                            } else if (element.find('.fc-list-item-title').lenght !== 0) {
                                element.find('.fc-list-item-title').append('<div class="fc-description">' + info.event.extendedProps.description + '</div>');
                            }
                        }
    
                        element.find(".fc-bg").css("pointer-events", "none");
                        element.find(".fc-list-item-title.fc-widget-content").prepend(
                            "<span style='position: absolute; right: 5px;'>" +
                            "<button class='btn btn-icon btn-xs btn-circle btn-light' " +
                            "style='height: 16px; width: 16px;' id='calendar_del_" + event.id + "'>" +
                            "<i class='icon-xs text-dark-50 flaticon2-cross'></i></button></span>");
                        element.find(".fc-content").append("<span style='position: absolute; top: 5px; right: 5px;'>" +
                            "<button class='btn btn-icon btn-xs btn-circle btn-light' " +
                            "style='height: 16px; width: 16px;' id='calendar_del_" + event.id + "'>" +
                            "<i class='icon-xs text-dark-50 flaticon2-cross'></i></button></span>");
                        element.find("#calendar_del_" + event.id).click(function () {
                            var eventId = event[0]._def.defId;
                            var eventIdentifier = event[0]._def.extendedProps.identifier;
    
                            //Remove popover
                            removeContent(".popover.fade.show.bs-popover-top");
                            //$(".popover.fade.show.bs-popover-top").remove();
    
                            dotNetReference.invokeMethodAsync('CalendarEventDeleted', eventIdentifier);
                            //$("#candidate_calendar").fullCalendar('removeEvents', eventId);
                        });
                    },
                    viewSkeletonRender: function(info) {
                        var view = $(info.view);
                        var defaultView = view[0].type !== null ? view[0].type : "";
    
                        dotNetReference.invokeMethodAsync('SetDefaultView', defaultView);
                        //alert(defaultView);
                    }
                });
    
                calendar.render();
            }
        };
    })();

function removeContent(target) {
    $(target).html("");
}

这就是我们在页面中实现它的方式。

页面剃刀

@inject IJSRuntime JS

<EditForm Model="@_calendarEvents">
    <div class="card card-custom">
        <div class="card-header">
            <div class="card-title">
                <h3 class="card-label">
                    Calendar
                </h3>
            </div>
            <div class="card-toolbar">
                <a href="#" class="btn btn-light-primary font-weight-bold">
                    <i class="ki ki-plus "></i> Add Event
                </a>
            </div>
        </div>
        <div class="card-body">
            <InputCalendar Id="candidate_calendar" @bind-Events="_calendarEvents"></InputCalendar>
        </div>
    </div>
</EditForm>


@code {

    private List<CalendarEvent> _calendarEvents;

    protected override async Task OnInitializedAsync()
    {
        _calendarEvents =new List<CalendarEvent>
        {
            new CalendarEvent
            {
                Identifier = Guid.NewGuid().ToString(),
                Title = "Breakfast",
                Description = "Time to eat.",
                Start = DateTime.Now.AddHours(6),
                End = DateTime.Now.AddHours(7),
                SolidColor = CalendarEventSolidColor.Primary,
                DotColor = CalendarEventDotColor.Light,
                Status = CalendarEventStatus.Active
            },
            new CalendarEvent
            {
                Identifier = Guid.NewGuid().ToString(),
                Title = "Lunch",
                Description = "Time to eat.",
                Start = DateTime.Now.AddHours(10),
                End = DateTime.Now.AddHours(11),
                SolidColor = CalendarEventSolidColor.Warning,
                DotColor = CalendarEventDotColor.Light,
                Status = CalendarEventStatus.Active
            }
        };

        await base.OnInitializedAsync();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        // If the calendar changes, we make an action here.

        await base.OnAfterRenderAsync(firstRender);
    }

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

fullcalendar.io 可以在 .net core Blazor 中使用吗? 的相关文章

随机推荐

  • Maven archetype 插件不允许 archetype-resources 中的 .resources 通过

    我怎样才能制作这样的资源 gitignore成为最终项目的一部分 创建原型archetype resources gitignore mvn install mvn archetype generate 生成的项目不包含 gitignore
  • scrapy项目加载器返回列表不是单个值

    我正在使用 scrapy 0 20 我想使用项目加载器 这是我的代码 l XPathItemLoader item MyItemClass response response l add value url response url l a
  • 无法从我的协议类调用委托方法

    我在一类中有一个协议 protocol DataStorageManager void saveFile end interface DataManager NSObject id
  • Boot 3 升级后错误响应正文发生更改

    我的项目中有以下控制器端点 GetMapping value id public FooDto findOne PathVariable Long id Foo model fooService findById id orElseThro
  • ImageFont 检测丢失的字形(Python Pillow)[重复]

    这个问题在这里已经有答案了 这是一个简短的example http pillow readthedocs io en 3 1 x reference ImageFont html from PIL import ImageFont Imag
  • 如何处理 Node.js 中的“read ETIMEDOUT”?

    我有一个使用 Node js 的发布 订阅模型将数据从一个客户端传输到另一个客户端 此外 服务器还记录收到的所有内容并将其发送给新客户端 但是 某些数据在传输时损坏 并且出现如下错误 Error with socket Error writ
  • R中的快速并行二分距离计算

    使用并行 Rcpp 后端计算 R 中二分距离最快的方法是什么 parallelDist是一个很棒的包 带有 cpp 后端并支持多线程 但不支持二分距离计算 据我所知 Using parallelDist 用于二分距离矩阵计算 除了 m1 m
  • 从 C# 在现有 IE 窗口的选项卡中启动 URL

    当 browserExe 指向 Firefox Safari 或 Chrome 时 以下代码将在现有浏览器窗口中打开链接 当指向 IEXPLORE EXE IE7 时 将打开一个新窗口 ProcessStartInfo pi new Pro
  • 如何在 Visual Studio Code 中禁用 PHP 验证?

    在 Windows 版本的 Visual Studio Code 版本 0 10 1 中打开任何 PHP 文件时 我收到消息 无法验证 php 文件 没有找到php程序 使用 php validate executablePath 设置来配
  • 在 PHP7 中本机分析多个脚本

    自 PHP 7 发布以来 现在不可能使用以下命令来分析整个脚本选择declare ticks 1 在你的基本文件中 然后使用register tick function 监视每个刻度 因为它不再遵循包含路径 根据提交的 PHP 错误http
  • 如何解决.NET Core包版本冲突

    我正在从 NET MVC 5 Web 应用程序迁移到 NET Core 2 2 Web API 项目以及五个 NET Standard 2 0 项目 所有项目都托管在一个解决方案下 我现在收到 28 个关于包冲突的警告 MSB3277 这些
  • 如何更改geom_point中的颜色或ggplot中的线条[重复]

    这个问题在这里已经有答案了 我有一个这样的数据 data lt structure list sample structure c 1L 1L 1L 1L 1L 1L 1L 1L 1L 1L 2L 2L 2L 2L 2L 2L 2L 2L
  • 重载或可选参数之间的性能差异?

    我想知道是否应该在 C 中使用可选参数 到目前为止 我总是重载方法 但可选参数也很好 更干净 代码更少 我在其他语言中使用它们 所以我在某种程度上也习惯了它们 有什么反对使用它们的吗 性能对我来说是第一个关键点 会掉吗 Example co
  • 如何保存 raphael 生成的 svg

    有没有办法将 raphael 生成的 SVG 保存为 svg 文件 请注意 它只需要在 Chrome 中工作 我想出了一个解决方案拉斐尔导出 https github com ElbertF Raphael Export 它给了我一个有效的
  • 更新已部署的 SSIS 包

    我有一个已部署的 SSIS 包 其中包含时间表和所有内容 现在 我对这个包进行了更改 我是否必须重新部署它 并再次为其设置计划 或者是否有办法让已部署的 SSIS 包更新为最新版本 是的 您需要将包重新部署到调度程序期望找到包的任何位置 但
  • 在 Tensorflow 2 中将梯度可视化为热图

    我正在研究通过引导反向传播生成热图的任务 我重写了原来的Relu并获得了每个参数的梯度 但是 我不确定下一步应该做什么 感谢您的帮助 谢谢你 这是我的代码 我首先使用 tf RegisterGradient GuidedRelu like
  • Python urlparse——提取不带子域的域名

    需要一种使用 Python urlparse 从 url 中提取不带子域的域名的方法 例如我想提取 google com 来自完整的网址 例如 http www google com 我能想到的最接近的urlparse is the net
  • 如何在Python中将JSON字符串转换为整数?

    如何将此 json 中的年份和 isbn 转换为整数 title The Notebook author Nicholas Sparks year 1996 isbn 0553816713 您可以简单地用相应的 int 值更新这些值 dat
  • XStream:解析时 XML 层次结构崩溃

    我有一个 XML 文档 由 Adob e XFA 表单生成 其中包含如下数据
  • fullcalendar.io 可以在 .net core Blazor 中使用吗?

    我尝试在 Blazor WebAssembly 页面中使用 FullCalendar 任何人都知道如何在 Blazor 中使用 FullCalendar 任何人都可以帮助我吗 我将 FullCalendar 包含在 libman json