打包最新的前端,升级.NET7.0

This commit is contained in:
igeekfan
2022-11-11 00:01:00 +08:00
parent 6bfc2dd266
commit 6fd0364356
20 changed files with 84 additions and 213 deletions

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\IGeekFan.AspNetCore.Knife4jUI\IGeekFan.AspNetCore.Knife4jUI.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,95 @@
using Knife4jUIDemo;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AspNetCore6Api.Controllers
{
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Get<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Get<65><74><EFBFBD><EFBFBD>
/// </summary>
[ApiController]
[Route("api/WeatherForecast/[action]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
/// <summary>
/// <20>õ<EFBFBD>һ<EFBFBD><D2BB>ErrorCode
/// </summary>
/// <returns></returns>
[HttpGet]
public ErrorCode GetErrorCode()
{
return ErrorCode.Success;
}
[HttpGet]
public ErrorCode GetErrorCode2(ErrorCode errorCode)
{
return errorCode;
}
[HttpGet]
public IActionResult GetErrorCode4(ErrorCode errorCode)
{
return new JsonResult(new PostErrorCodeDto() { Message = "a", ErrorCode = errorCode });
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Post
/// </summary>
/// <returns></returns>
[HttpPost]
public PostErrorCodeDto PostErrorCode([FromBody] PostErrorCodeDto PostErrorCodeDto)
{
return PostErrorCodeDto;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Get<65><74><EFBFBD><EFBFBD>
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
/// </summary>
public class PostErrorCodeDto
{
/// <summary>
/// <20><EFBFBD><ECB3A3>Ϣ
/// </summary>
public string Message { get; set; }
public WeatherForecast WeatherForecast { get; set; }
/// <summary>
/// ״̬<D7B4><CCAC>
/// </summary>
public ErrorCode ErrorCode { get; set; }
}
}

View File

@ -0,0 +1,81 @@
using System.ComponentModel;
namespace Knife4jUIDemo
{
/// <summary>
/// 注释ErrorCode
/// </summary>
public enum ErrorCode
{
/// <summary>
/// 操作成功
/// </summary>
Success = 0,
/// <summary>
/// 未知错误
/// </summary>
UnknownError = 1007,
/// <summary>
/// 服务器未知错误
/// </summary>
ServerUnknownError = 999,
/// <summary>
/// 失败
/// </summary>
Error = 1000,
/// <summary>
/// 认证失败
/// </summary>
AuthenticationFailed = 10000,
/// <summary>
/// 无权限
/// </summary>
NoPermission = 10001,
/// <summary>
/// 失败
/// </summary>
Fail = 9999,
/// <summary>
/// refreshToken异常
/// </summary>
RefreshTokenError = 10100,
/// <summary>
/// 资源不存在
/// </summary>
NotFound = 10020,
/// <summary>
/// 参数错误
/// </summary>
[Description("参数错误")]
ParameterError = 10030,
/// <summary>
/// 令牌失效
/// </summary>
[Description("令牌失效")]
TokenInvalidation = 10040,
/// <summary>
/// 令牌过期
/// </summary>
TokenExpired = 10050,
/// <summary>
/// 字段重复
/// </summary>
RepeatField = 10060,
/// <summary>
/// 禁止操作
/// </summary>
Inoperable = 10070,
//10080 请求方法不允许
//10110 文件体积过大
//10120 文件数量过多
//10130 文件扩展名不符合规范
//10140 请求过于频繁,请稍后重试
ManyRequests = 10140
}
}

View File

@ -0,0 +1,43 @@
using IGeekFan.AspNetCore.Knife4jUI;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "API V1", Version = "v1" });
var filePath = Path.Combine(System.AppContext.BaseDirectory, "AspNetCore7Api.xml");
c.IncludeXmlComments(filePath, true);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseKnife4UI(c =>
{
c.RoutePrefix = "swagger"; // serve the UI at root
c.SwaggerEndpoint("/v1/swagger.json", "V1 Docs");
});
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapSwagger("/k4/{documentName}/swagger.json");
});
app.Run();

View File

@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"AspNetCore7Api": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7030;http://localhost:5030",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,13 @@
namespace AspNetCore6Api
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}