完善推荐页显示

This commit is contained in:
橙子
2022-10-16 22:51:53 +08:00
parent 6d99539730
commit 50d43a2fc5
8 changed files with 33 additions and 26 deletions

View File

@@ -50,7 +50,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public override Task<Result> Add(ArticleEntity entity)
{
//如果标题为空默认为内容的前20个字符
entity.Title = string.IsNullOrEmpty(entity.Title) ? entity.Content.Substring(0, 20): entity.Title;
entity.Title = string.IsNullOrEmpty(entity.Title) ?
(entity.Content.Length > 20 ? entity.Content.Substring(0, 20) : entity.Content) :
entity.Title;
entity.UserId = HttpContext.GetUserIdInfo();
return base.Add(entity);
}

View File

@@ -56,10 +56,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
try
{
//路径为: 文件路径/文件id+文件扩展名
var path = Path.Combine($"{PathConst.wwwroot}/{file.FilePath}", file.Id.ToString()+ Path.GetExtension(file.FileName));
var path = Path.Combine($"{PathConst.wwwroot}/{file.FilePath}", file.Id.ToString() + Path.GetExtension(file.FileName));
var stream = System.IO.File.OpenRead(path);
var MimeType = Common.Helper.MimeHelper.GetMimeMapping(file.FileName);
return File(stream, MimeType, file.FileName);
return File(stream, MimeType, file.FileName);
}
catch
{
@@ -76,22 +76,18 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns>
[Route("/api/file/Upload/{type?}")]
[HttpPost]
public async Task<Result> Upload([FromRoute] string? type, [FromForm] IFormFileCollection file,[FromQuery] string? remark)
public async Task<Result> Upload([FromRoute] string? type, [FromForm] IFormFileCollection file, [FromQuery] string? remark)
{
if (type is null)
type = type ?? PathEnum.File.ToString();
type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type.ToLower());
if (!Enum.IsDefined(typeof(PathEnum), type))
{
type = PathEnum.File.ToString();
}
else
{
type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(type!.ToLower());
if (!Enum.IsDefined(typeof(PathEnum), type))
{
//后续类型可从字典表中获取
return Result.Error("上传失败!文件类型不支持!");
}
//后续类型可从字典表中获取
return Result.Error("上传失败!文件类型不支持!");
}
if (file.Count() == 0)
{
return Result.Error("未选择文件");
@@ -118,7 +114,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
string filename = data.Id.ToString() + Path.GetExtension(f.FileName);
string typePath = $"{PathConst.wwwroot}/{type}";
if (!Directory.Exists(typePath))
{
{
Directory.CreateDirectory(typePath);
}
using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.CreateNew, FileAccess.Write))

View File

@@ -11,14 +11,14 @@ namespace Yi.Framework.Common.Helper
{
public static List<T> SetTree<T>(List<T> list, Action<T> action = null)
{
if (list != null && list.Count > 0)
if (list is not null && list.Count > 0)
{
IList<T> result = new List<T>();
long pid = list.Min(m => (m as ITreeModel<T>).ParentId);
IList<T> t = list.Where(m => (m as ITreeModel<T>).ParentId == pid).ToList();
foreach (T model in t)
{
if (action != null)
if (action is not null)
{
action(model);
}
@@ -40,7 +40,7 @@ namespace Yi.Framework.Common.Helper
mm.Children = new List<T>();
foreach (T item in children)
{
if (action != null)
if (action is not null)
{
action(item);
}