コード例 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            host = new WebHost();
            host.Setting(o =>
            {
                o.SetDebug();
                o.Port         = 8082;
                o.LogLevel     = EventArgs.LogType.Error;
                o.WriteLog     = true;
                o.LogToConsole = true;
            })
            .UseEFCore <NorthwindContext>()
            .UseJWT()
            .Initialize(s =>
            {
                s.ActionFactory.Register(this);
                s.GetWebFamily().AddScript("echarts.js");
                s.GetWebFamily().AddCss("website.css");
                s.Vue().Debug();
                WebHost.LoginHandler = (user, pwd, context) =>
                {
                    context.SetJwtToken(user, "user", 60 * 60);
                    return(Task.CompletedTask);
                };
                WebHost.Title       = "Northwind";
                WebHost.HeaderModel = "myheader";
                WebHost.MustLogin   = true;
                WebHost.HomeModel   = "home";

                WebHost.GetMenus = (user, role, context) =>
                {
                    List <Menu> menus = new List <Menu>();
                    var item          = new Menu();
                    item.ID           = "home";
                    item.Name         = "主页";
                    item.Img          = "/images/home.png";
                    item.Model        = "home";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "product";
                    item.Name  = "产品";
                    item.Img   = "/images/product.png";
                    item.Model = "products";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "order";
                    item.Name  = "订单";
                    item.Img   = "/images/order.png";
                    item.Model = "orders";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "customer";
                    item.Name  = "客户";
                    item.Img   = "/images/customer.png";
                    item.Model = "customers";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "employee";
                    item.Name  = "雇员";
                    item.Img   = "/images/employee.png";
                    item.Model = "employees";
                    menus.Add(item);

                    return(Task.FromResult(menus));
                };
            }).Completed(s =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    if (webView != null && webView.CoreWebView2 != null)
                    {
                        webView.CoreWebView2.Navigate("http://localhost:8082/");
                    }
                });
            });
            host.Run(true);
        }
コード例 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            host = new WebHost();
            host.Setting(o =>
            {
                o.SetDebug();
                o.Port         = 8082;
                o.LogLevel     = EventArgs.LogType.Error;
                o.WriteLog     = true;
                o.LogToConsole = true;
            })
            .UseEFCore <NorthwindContext>()
            .UseJWT()
            .UseFontawesome()
            .UseElement(PageStyle.ElementDashboard)
            .Initialize((http, vue, rec) =>
            {
                rec.AddAssemblies(typeof(MainWindow).Assembly);
                http.ActionFactory.Register(this);
                rec.AddScript("echarts.js");
                rec.AddCss("website.css");
                vue.Debug();
                WebHost.LoginHandler = (user, pwd, context) =>
                {
                    object token = context.SetJwtToken(user, "user", 60 * 60);
                    return(Task.FromResult(token));
                };
                WebHost.Title       = "Northwind";
                WebHost.HeaderModel = "myheader";
                WebHost.Login       = true;
                WebHost.HomeModel   = "home";

                WebHost.GetMenus = (user, role, context) =>
                {
                    List <Menu> menus = new List <Menu>();
                    var item          = new Menu();
                    item.ID           = "home";
                    item.Name         = "主页";
                    item.Img          = "fas fa-home";
                    item.Model        = "home";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "product";
                    item.Name  = "产品";
                    item.Img   = "fas fa-box";
                    item.Model = "products";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "order";
                    item.Name  = "订单";
                    item.Img   = "fas fa-shopping-cart";
                    item.Model = "orders";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "customer";
                    item.Name  = "客户";
                    item.Img   = "fas fa-hospital-user";
                    item.Model = "customers";
                    menus.Add(item);

                    item       = new Menu();
                    item.ID    = "employee";
                    item.Name  = "雇员";
                    item.Img   = "fas fa-users";
                    item.Model = "employees";
                    menus.Add(item);

                    return(Task.FromResult(menus));
                };
            }).Completed(s =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    if (webView != null && webView.CoreWebView2 != null)
                    {
                        webView.CoreWebView2.Navigate("http://localhost:8082/");
                    }
                });
            });
            host.Run(true);
        }