惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
Latest news
Latest news
F
Full Disclosure
T
Tenable Blog
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
L
LangChain Blog
有赞技术团队
有赞技术团队
Project Zero
Project Zero
Cloudbric
Cloudbric
爱范儿
爱范儿
GbyAI
GbyAI
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
S
Security @ Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
C
Cisco Blogs
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V2EX - 技术
V2EX - 技术
Engineering at Meta
Engineering at Meta
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
The Hacker News
The Hacker News
V
V2EX
F
Fortinet All Blogs
L
LINUX DO - 最新话题
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News | PayPal Newsroom
博客园 - 三生石上(FineUI控件)
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - Gu

上位机开发人员真的需要物理 PLC 或博途吗?我们仅仅需要一个模拟 S7 通讯的工具 检查采集程序心跳的程序挂了。看来得套娃,再来一个检测检测程序的程序 Web.INI vue前端项目,默认request 30秒超时,如何设置某个导出动作1分钟才超时 提示coreclr.dll 出错?栈溢出? .Net 6使用轻量级任务调度Coravel实践 Blazor 循环的迷思 Grafana 可视化图表 mysqldump 导出批量忽略某些表的bat脚本 cron表达式的讲解 若依 自定义注解@Log,实现aop java 处理日期时间有多个类,用哪个比较好 文件同步工具 西门子PLC Modus TCP通讯 thingsboard 接口 圆度和径向跳动,直线度的区别 安装thingsboard 3.7 dotNET_Reactor 混淆net程序时, 一些全局变量要加上volatile 修饰符, 不然优化到不会改变 Ant Design Blazor Table 组件的 自定义分页样式, 显示全部记录数,ShowTotal 安全可靠测评结果公告(2023年第1号) 2023-12-26 来源: 中国信息安全测评中心
Blazor 和Known 框架学习
Gu · 2024-04-26 · via 博客园 - Gu
  • [框架后台首页在\Known.AntBlazor\Admin.razor

  •  <AntMenu Accordion="Context.UserSetting.Accordion" Items="UserMenus" OnClick="e=>Context.Navigate(e)" />

  • <PageTabs @ref="tabs" Menu="CurrentMenu" Items="TabMenus" />

  • Known\Blazor\AdminPage.cs 里定义

    protected override async Task OnInitAsync()

    {

    Info = await Platform.Auth.GetAdminAsync();
    
    UserMenus = GetUserMenus(Info?.UserMenus);
    

    }

    select * from SysModule where Enabled='True'

  • 自定义页面—编辑模块,选择目标为【自定义】,代码xxx, 对应的razor文件名也是xxx,razor文件放在PMS.Shared 项目里,@inherits BaseTabPage

  • razor更改后要点热重载才生效

  • @Language["App.SubTitle"] 多语言在哪里改— PMS.share 项目的locales\zh-CN.json里

  • razor 组件的属性 attribute 是这样定义的: @code { [Parameter] public LoginFormInfo Model { get; set; }}

  • 子组件的属性,这样子组件的html由父组件控制 public RenderFragment HeaderTemplate { get; set; }

  • razor 页面头部,可以指定路由类似 @page '/counter'

  • @bind指令比较智能,它大概可以知道你需要绑定标签的哪个属性,例如:将其绑定到input标签时,它会绑定value属性。而将其绑定到checkbox中,它则自动绑定checked属性。@bind:format="dd-MM-yyyy"

  • 若要处理来自组件的 UI 事件并使用数据绑定,该组件必须是交互式的。 默认情况下,Blazor 组件从服务器静态呈现,这意味着它们生成 HTML 以响应请求,否则无法处理 UI 事件。 可以通过使用 @rendermode 指令应用交互式呈现模式,使组件具有交互性。可以将 @rendermode 指令应用于组件定义:razor @rendermode InteractiveServer
  • Counter 组件是使用交互式服务器呈现。 交互式服务器呈现通过与浏览器的 WebSocket 连接处理来自服务器的 UI 事件。 Blazor 通过此连接将 UI 事件发送到服务器,以便应用组件可以处理这些事件。 然后,Blazor 会使用呈现的更新来更新浏览器 DOM。
  • 如何将字符串参数传递给 Blazor 中的 @onclick 事件 <Button Type="primary" Icon="plus" OnClick='()=>{ lineId="0"; ShowLineDialog();}'>新增</Button>

  • Home.razor 是在哪里调用?
  • //Known的config.cs
    
        internal static MenuItem GetHomeMenu()
        {
            return new("Home", "home", PageTypes.GetValueOrDefault("Home")) { Closable = false };
        }
  • 核心组件 TablePage, 里面有Model, 构建UI的查询框,工具栏,表格
using Known.Extensions;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace Known.Blazor;

class TablePage<TItem> : BaseComponent where TItem : class, new()
{
    [Parameter] public TableModel<TItem> Model { get; set; }

    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        if (Model.QueryColumns.Count > 0 || Model.Toolbar.HasItem)
        {
            builder.Div("kui-top", () =>
            {
                UI.BuildQuery(builder, Model);
                UI.BuildToolbar(builder, Model.Toolbar);
            });
        }
        builder.Div("kui-table", () => UI.BuildTable(builder, Model));
    }
}

访问本地存储LocalStorage,在项目 Known\wwwroot\script.js 定义js方法

export class KBlazor {

    //Storage
    static getLocalStorage(key) {
        return localStorage.getItem(key);
    }
    static setLocalStorage(key, value) {
        if (value)
            localStorage.setItem(key, JSON.stringify(value));
        else
            localStorage.removeItem(key);
    }
}

在 Known\Blazor\JSService.cs 定义类

    public async Task<T> GetLocalStorageAsync<T>(string key)
    {
        var value = await InvokeAsync<string>("KBlazor.getLocalStorage", key);
        return Utils.FromJson<T>(value);
    }

    public Task SetLocalStorageAsync(string key, object value) => InvokeVoidAsync("KBlazor.setLocalStorage", key, value);

 调用方法示例

   protected override async Task OnAfterRenderAsync(bool firstRender)
   {
       await JS.SetLocalStorageAsync("name", "jacky");
       var name = await JS.GetLocalStorageAsync<string>("name");

   }

把表格导出excel  

        // 使用 EPPlus 加载 Excel 文件
        using (ExcelPackage package = new ExcelPackage(new FileInfo(excelFilePath)))
        {

            // 获取所有visible的工作表
            ExcelWorksheet destSheet = package.Workbook.Worksheets[0];
            for (int i = 0; i < complains.Count; i++)
            {
                int RowIndex = i + 2;
                PmsComplain c = complains[i];
                destSheet.Cells["A" + RowIndex].Value = c.Customer;


                destSheet.Cells["B" + RowIndex].Value = c.ErrorDate; //异常发生时间
                destSheet.Cells["C" + RowIndex].Value = c.Process;//反馈工序
               


            var stream = new MemoryStream(package.GetAsByteArray());
            await base.JS.DownloadFileAsync("Export.xlsx", stream);

默认上传最大50MB,要修改的话

program.cs 里的

builder.Services.AddApp(info =>
{
    info.WebRoot = builder.Environment.WebRootPath;
    info.ContentRoot = builder.Environment.ContentRootPath;
    info.IsDevelopment = builder.Environment.IsDevelopment();
    info.Connections[0].ConnectionString = builder.Configuration.GetSection("ConnString").Get<string>();
    info.UploadMaxSize = 1024 * 1024 * 100;
});

known 的config.cs

   public long UploadMaxSize { get; set; } = 1024 * 1024 * 100;

4.27版本更新后, 加入module定义了url,则 class 或razor 页面要加上 [Route("/sys/roles")] 这样的url, 选page,custom 都会找,不会默认page/{pageId}

如何查找routeData里是否有url,没有自动找pageId

An unhandled exception occurred while processing the request.

AmbiguousMatchException: The request matched multiple endpoints. Matches:

在Web项目多了一个index.zaor
等于默认有2个首页了