feat: 改为服务端渲染解决数据库无法连线问题
parent
27b6ccedd2
commit
7e2ba5996f
|
|
@ -23,8 +23,8 @@
|
||||||
new MenuDataItem
|
new MenuDataItem
|
||||||
{
|
{
|
||||||
Path = "/",
|
Path = "/",
|
||||||
Name = "welcome",
|
Name = "用户管理",
|
||||||
Key = "welcome",
|
Key = "user",
|
||||||
Icon = "smile",
|
Icon = "smile",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
@page "/"
|
||||||
|
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
@using UserPointManagement.Web
|
||||||
|
@namespace MyAntDesignAppServer.Pages
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
@{
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>用户积分管理系统</title>
|
||||||
|
<base href="~/" />
|
||||||
|
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
|
||||||
|
<link href="_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css" rel="stylesheet" />
|
||||||
|
<link href="./css/site.css" rel="stylesheet" />
|
||||||
|
<link href="UserPointManagement.Web.styles.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<app>
|
||||||
|
<component type="typeof(App)" render-mode="Server" />
|
||||||
|
</app>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="@("https://unpkg.com/@antv/g2plot@2.4.17/dist/g2plot.min.js")"></script>
|
||||||
|
<script src="_content/AntDesign/js/ant-design-blazor.js"></script>
|
||||||
|
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script>
|
||||||
|
<script src="_framework/blazor.server.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,38 +1,28 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AntDesign.ProLayout;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Hosting;
|
||||||
using UserPointManagement.Application;
|
using Microsoft.Extensions.Logging;
|
||||||
using UserPointManagement.Persistence;
|
|
||||||
|
|
||||||
namespace UserPointManagement.Web
|
namespace UserPointManagement.Web
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static async Task Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
CreateHostBuilder(args).Build().Run();
|
||||||
builder.RootComponents.Add<App>("#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<ProSettings>(builder.Configuration.GetSection("ProSettings"));
|
|
||||||
|
|
||||||
builder.Services.AddDbContext<UserPointManagementDbContext>(option =>
|
|
||||||
{
|
|
||||||
option
|
|
||||||
.UseNpgsql(builder.Configuration["Connection:UserPointManagement"])
|
|
||||||
.UseSnakeCaseNamingConvention();
|
|
||||||
});
|
|
||||||
|
|
||||||
var host = builder.Build();
|
|
||||||
await host.RunAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
|
Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
|
{
|
||||||
|
webBuilder.UseStartup<Startup>();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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<UserPointManagementDbContext>(option =>
|
||||||
|
{
|
||||||
|
option.UseNpgsql(Configuration["Connection:UserPointManagement"])
|
||||||
|
.UseSnakeCaseNamingConvention();
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddServices();
|
||||||
|
services.AddRepositories();
|
||||||
|
services.AddScoped(sp => new HttpClient
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri(sp.GetService<NavigationManager>().BaseUri)
|
||||||
|
});
|
||||||
|
services.Configure<ProSettings>(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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6</TargetFramework>
|
<TargetFramework>net6</TargetFramework>
|
||||||
|
|
@ -8,9 +8,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AntDesign.Charts" Version="0.2.3" />
|
<PackageReference Include="AntDesign.Charts" Version="0.2.3" />
|
||||||
<PackageReference Include="AntDesign.ProLayout" Version="0.12.4" />
|
<PackageReference Include="AntDesign.ProLayout" Version="0.12.4" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0" PrivateAssets="all" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
|
|
||||||
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
|
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,5 @@
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using UserPointManagement.Web
|
@using UserPointManagement.Web
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue