From 7e2ba5996f2291e053cac8624515f34a37927fe3 Mon Sep 17 00:00:00 2001 From: zhangyousheng Date: Sat, 29 Jul 2023 11:00:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E4=B8=BA=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E6=B8=B2=E6=9F=93=E8=A7=A3=E5=86=B3=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=97=A0=E6=B3=95=E8=BF=9E=E7=BA=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Layouts/BasicLayout.razor | 4 +- .../Pages/_Host.cshtml | 32 ++++++++ src/UserPointManagement.Web/Program.cs | 44 +++++------ src/UserPointManagement.Web/Startup.cs | 74 +++++++++++++++++++ .../UserPointManagement.Web.csproj | 5 +- src/UserPointManagement.Web/_Imports.razor | 1 - .../appsettings.Development.json | 26 +++++++ src/UserPointManagement.Web/appsettings.json | 27 +++++++ 8 files changed, 179 insertions(+), 34 deletions(-) create mode 100644 src/UserPointManagement.Web/Pages/_Host.cshtml create mode 100644 src/UserPointManagement.Web/Startup.cs create mode 100644 src/UserPointManagement.Web/appsettings.Development.json create mode 100644 src/UserPointManagement.Web/appsettings.json diff --git a/src/UserPointManagement.Web/Layouts/BasicLayout.razor b/src/UserPointManagement.Web/Layouts/BasicLayout.razor index 424db3d..2795645 100644 --- a/src/UserPointManagement.Web/Layouts/BasicLayout.razor +++ b/src/UserPointManagement.Web/Layouts/BasicLayout.razor @@ -23,8 +23,8 @@ new MenuDataItem { Path = "/", - Name = "welcome", - Key = "welcome", + Name = "用户管理", + Key = "user", Icon = "smile", } }; diff --git a/src/UserPointManagement.Web/Pages/_Host.cshtml b/src/UserPointManagement.Web/Pages/_Host.cshtml new file mode 100644 index 0000000..cc99eec --- /dev/null +++ b/src/UserPointManagement.Web/Pages/_Host.cshtml @@ -0,0 +1,32 @@ +@page "/" +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using UserPointManagement.Web +@namespace MyAntDesignAppServer.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = null; +} + + + + + + + 用户积分管理系统 + + + + + + + + + + + + + + + + + diff --git a/src/UserPointManagement.Web/Program.cs b/src/UserPointManagement.Web/Program.cs index dc9af71..4851bec 100644 --- a/src/UserPointManagement.Web/Program.cs +++ b/src/UserPointManagement.Web/Program.cs @@ -1,38 +1,28 @@ using System; -using System.Net.Http; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading.Tasks; -using AntDesign.ProLayout; -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using UserPointManagement.Application; -using UserPointManagement.Persistence; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; namespace UserPointManagement.Web { public class Program { - public static async Task Main(string[] args) + public static void Main(string[] args) { - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("#app"); - - builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddAntDesign(); - builder.Services.AddServices(); - builder.Services.AddRepositories(); - builder.Services.Configure(builder.Configuration.GetSection("ProSettings")); - - builder.Services.AddDbContext(option => - { - option - .UseNpgsql(builder.Configuration["Connection:UserPointManagement"]) - .UseSnakeCaseNamingConvention(); - }); - - var host = builder.Build(); - await host.RunAsync(); + CreateHostBuilder(args).Build().Run(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } -} \ No newline at end of file +} diff --git a/src/UserPointManagement.Web/Startup.cs b/src/UserPointManagement.Web/Startup.cs new file mode 100644 index 0000000..de23de9 --- /dev/null +++ b/src/UserPointManagement.Web/Startup.cs @@ -0,0 +1,74 @@ +using System; +using System.Net.Http; +using AntDesign.ProLayout; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using UserPointManagement.Application; +using UserPointManagement.Persistence; + +namespace UserPointManagement.Web +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddRazorPages(); + services.AddServerSideBlazor(); + services.AddAntDesign(); + + services.AddDbContext(option => + { + option.UseNpgsql(Configuration["Connection:UserPointManagement"]) + .UseSnakeCaseNamingConvention(); + }); + + services.AddServices(); + services.AddRepositories(); + services.AddScoped(sp => new HttpClient + { + BaseAddress = new Uri(sp.GetService().BaseUri) + }); + services.Configure(Configuration.GetSection("ProSettings")); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseStaticFiles(); + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapBlazorHub(); + endpoints.MapFallbackToPage("/_Host"); + }); + } + } +} diff --git a/src/UserPointManagement.Web/UserPointManagement.Web.csproj b/src/UserPointManagement.Web/UserPointManagement.Web.csproj index 7eeafa1..92e8682 100644 --- a/src/UserPointManagement.Web/UserPointManagement.Web.csproj +++ b/src/UserPointManagement.Web/UserPointManagement.Web.csproj @@ -1,4 +1,4 @@ - + net6 @@ -8,9 +8,6 @@ - - - diff --git a/src/UserPointManagement.Web/_Imports.razor b/src/UserPointManagement.Web/_Imports.razor index f35f054..37ec627 100644 --- a/src/UserPointManagement.Web/_Imports.razor +++ b/src/UserPointManagement.Web/_Imports.razor @@ -6,6 +6,5 @@ @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web -@using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop @using UserPointManagement.Web diff --git a/src/UserPointManagement.Web/appsettings.Development.json b/src/UserPointManagement.Web/appsettings.Development.json new file mode 100644 index 0000000..3071d03 --- /dev/null +++ b/src/UserPointManagement.Web/appsettings.Development.json @@ -0,0 +1,26 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "ProSettings": { + "NavTheme": "dark", + "Layout": "side", + "ContentWidth": "Fluid", + "FixedHeader": false, + "FixSiderbar": true, + "Title": "Ant Design Pro", + "PrimaryColor": "daybreak", + "ColorWeak": false, + "SplitMenus": false, + "HeaderRender": true, + "FooterRender": true, + "MenuRender": true, + "MenuHeaderRender": true, + "HeaderHeight": 48 + } +} diff --git a/src/UserPointManagement.Web/appsettings.json b/src/UserPointManagement.Web/appsettings.json new file mode 100644 index 0000000..283ee9b --- /dev/null +++ b/src/UserPointManagement.Web/appsettings.json @@ -0,0 +1,27 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "ProSettings": { + "NavTheme": "dark", + "Layout": "side", + "ContentWidth": "Fluid", + "FixedHeader": false, + "FixSiderbar": true, + "Title": "Ant Design Pro", + "PrimaryColor": "daybreak", + "ColorWeak": false, + "SplitMenus": false, + "HeaderRender": true, + "FooterRender": true, + "MenuRender": true, + "MenuHeaderRender": true, + "HeaderHeight": 48 + }, + "Connection:UserPointManagement": "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;" +}