Skip to content

Commit

Permalink
feat:1.0 正式版来啦
Browse files Browse the repository at this point in the history
本次更新内容较多,相对于0.9版本改动如下:
1.增加友链可见性的修改
2.增加自助申请页面
3.增加文章接口和过滤器
4.修复大量BUG和性能问题
5.使用Logger代替输出
6.移除无用功能(GatherLog)
7.增加toast提示框
8.首页可以预览博主最近动态
9.优化各种细节问题
10.优化代码风格
...
  • Loading branch information
Drizzle committed May 29, 2023
1 parent 9238469 commit e70229d
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 171 deletions.
24 changes: 7 additions & 17 deletions Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ public class ApiController : ControllerBase
{
private readonly IFreeSql _db;
private readonly FriendService _friendService;
private readonly ArticleService _articleService;

public ApiController(IFreeSql db, FriendService friendService)

public ApiController(IFreeSql db, FriendService friendService, ArticleService articleService)
{
_db = db;
_friendService = friendService;
_articleService = articleService;
}

/// <summary>
Expand All @@ -24,8 +27,7 @@ public ApiController(IFreeSql db, FriendService friendService)
[HttpGet("friends")]
public async Task<ActionResult<List<Friend>>> Friends()
{
var temp = await _db.Select<Friend>().Where(x => x.Visible == true)
.ToListAsync();
var temp = await _friendService.ListAsync(true);
var random = new Random();
var friends = new List<Friend>();
foreach (var item in temp)
Expand All @@ -41,20 +43,8 @@ public async Task<ActionResult<List<Friend>>> Friends()
/// </summary>
/// <returns></returns>
[HttpGet("articles")]
public async Task<ActionResult<List<Article>>> Articles()
{
return await _db.Select<Article>()
.ToListAsync();
}

/// <summary>
/// 申请友链
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public ActionResult<bool> Apply(Friend self)
public async Task<ActionResult<List<Article>>> Articles(int? friendId = null, int page = 1, int size = 10)
{
_friendService.Add(self);
return true;
return await _articleService.ListAsync(friendId, page, size);
}
}
1 change: 1 addition & 0 deletions Moments.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dearain/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lantin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Typecho/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
35 changes: 16 additions & 19 deletions Pages/Admin/RssManage.razor → Pages/Admin/FeedManage.razor
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
@page "/Admin/Rss"
@page "/Admin/Feed"
@using Moments.Model
@using Moments.Service
@inject IFreeSql Db
@inject IJSRuntime JsRuntime
@inject GatherService GatherService
<div class="m-1">
<button class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#rss-info" @onclick="DelAll">清空数据</button>
<button class="btn btn-danger" @onclick="DelAll">清空数据</button>
<button class="btn btn-success" @onclick="Gather">一件采集</button>

</div>

<!-- Info Modal -->
<div class="modal fade" id="rss-info" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">信息</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
清空成功,请手动刷新页面
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
<div>
<div class="list-group list-group-flush border-bottom scrollarea">
@foreach (var item in _nodeList)
Expand Down Expand Up @@ -106,6 +94,15 @@
await Db.Delete<Article>()
.Where("1=1")
.ExecuteAffrowsAsync();
await JsRuntime.InvokeVoidAsync("toast", "提示:", "清空成功");
_nodeList.Clear();
}

async Task Gather()
{
GatherService.GatherRssAll();

await JsRuntime.InvokeVoidAsync("toast", "提示:", "采集任务启动成功,请稍等一会刷新本页面!");
}

}
54 changes: 24 additions & 30 deletions Pages/Admin/FriendsManage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
@inject IFreeSql Db
@inject FriendService FriendService
@inject GatherService GatherService
@inject IJSRuntime JsRuntime
<div class="m-1">
<button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#add">添加新朋友</button>
<button class="btn btn-danger" @onclick="Check" data-bs-toggle="modal" data-bs-target="#verify-info">验证状态</button>
<button class="btn btn-danger" @onclick="Check">验证状态</button>
<button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="">订阅中心</button>
</div>
<table class="table" style="margin-top: 10px">
Expand All @@ -25,6 +26,18 @@
<a target="_blank" href="@item.Link">@item.Name</a>
</td>
<td>
<span style="margin-right: 10px;cursor: pointer" @onclick="(() => SwitchVis(item))">
<span class="badge rounded-pill text-bg-primary">
@if (item.Visible)
{
<span>可见</span>
}
else
{
<span>隐藏</span>
}
</span>
</span>
@switch (item.Verify)
{
case FriendState.正常:
Expand All @@ -40,6 +53,7 @@
<span class="badge text-bg-danger">@item.Verify</span>
break;
}

</td>
<td style="text-align: center">
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#friend-info" @onclick="() => { _info = item; }">查看</button>
Expand Down Expand Up @@ -252,42 +266,17 @@
</div>
</div>
</div>
<!-- Verify Modal -->
<div class="modal fade" id="verify-info" data-bs-backdrop="static" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">正在检查(@_cnt / @_friendCount):</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="progress" role="progressbar" aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width: @((int)_cnt * 1.0 / (_friendCount == 0 ? 1 : _friendCount) * 100)%"></div>
</div>
</div>
@if (_cnt == _friendCount)
{
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">完成</button>
</div>
}
</div>
</div>
</div>

@code {
List<Friend> _friends = new();
Friend _edit = new();
Friend _del = new();
Friend _add = new();
Friend _info = new();
long _friendCount;
long _cnt;

protected override async Task OnInitializedAsync()
{
_friends = await Db.Select<Friend>().ToListAsync();
_friendCount = _friends.Count;
}

async Task Add()
Expand Down Expand Up @@ -319,17 +308,22 @@
GatherService.GatherRssItem(item);
}

void Check()
async void Check()
{
_cnt = 0;
foreach (var item in _friends)
{
#pragma warning disable CS4014
FriendService.VerifyItem(item);
#pragma warning restore CS4014
_cnt++;
StateHasChanged();
}
await JsRuntime.InvokeVoidAsync("toast", "提示:", "状态检测中,请等待1分钟后刷新本页面");
}

async Task SwitchVis(Friend item)
{
await FriendService.SetVis(item.FriendId, !item.Visible);
item.Visible = !item.Visible;
await JsRuntime.InvokeVoidAsync("toast", "提示:", "状态变更成功!");
}

}
57 changes: 0 additions & 57 deletions Pages/Admin/GatherManage.razor

This file was deleted.

65 changes: 65 additions & 0 deletions Pages/Apply.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@page "/Apply"
@using Moments.Service
@using Moments.Model
@inject FriendService FriendService
@inject IJSRuntime JsRuntime
<div style="text-align: center;padding: 20px">
<div class="input-group mb-3">
<span class="input-group-text">标题*</span>
<input @bind="_item.Name" type="text" class="form-control">
</div>
<div class="input-group mb-3">
<span class="input-group-text">简介</span>
<input @bind="_item.Info" type="text" class="form-control">
</div>
<div class="input-group mb-3">
<span class="input-group-text">LOGO</span>
<input @bind="_item.Avatar" type="text" class="form-control">
</div>
<div class="input-group mb-3">
<span class="input-group-text">链接*</span>
<input @bind="_item.Link" type="text" class="form-control">
</div>
<div class="input-group mb-3">
<span class="input-group-text">Feed</span>
<input @bind="_item.Rss" type="text" class="form-control">

<select class="form-select" @bind="_item.Rule">
@foreach (var item in Enum.GetNames(typeof(Rule)))
{
<option value="@item">@item</option>
}
</select>

</div>

<div class="input-group mb-3">
<span class="input-group-text">验证链接</span>
<input @bind="_item.VerifyUrl" type="text" class="form-control">
</div>
<div class="form-text">验证链接可以填写您的站点的收录本站的内页地址</div>
<button class="mt-5 btn btn-primary" @onclick="Submit">申请</button>
</div>

@code
{
readonly Friend _item = new ();

async Task Submit()
{
if (_item.Link is null)
{
await JsRuntime.InvokeVoidAsync("alert", "请填写带*的必填项目!");
return;
}
var temp = FriendService.First(x => x.Link == _item.Link);
if (temp is not null)
{
await JsRuntime.InvokeVoidAsync("alert", "请勿重复提交!");
return;
}
_item.Visible = false;
FriendService.Add(_item);
await JsRuntime.InvokeVoidAsync("alert", "提交申请成功!");
}
}
4 changes: 2 additions & 2 deletions Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{
<div class="item">
<div class="left">
<img @onclick="async () => Select(item.FriendId)" data-bs-toggle="modal" data-bs-target="#friend-info-modal" src="@GetAvatar(item.FriendId)" alt="头像">
<img @onclick="() => Task.FromResult(Select(item.FriendId))" data-bs-toggle="modal" data-bs-target="#friend-info-modal" src="@GetAvatar(item.FriendId)" alt="头像">
</div>
<div class="right">
<div class="name">
Expand Down Expand Up @@ -169,7 +169,7 @@
{
var f = _friends.Find(x => x.FriendId == target);
_select = f;
_selectArticles = await ArticleService.List(target);
_selectArticles = await ArticleService.ListAsync(target);
}

}
2 changes: 1 addition & 1 deletion Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered"/>

<div id="toast-div"></div>
<div id="blazor-error-ui">
<environment include="Staging,Production">
发生错误。在重新加载之前,此应用程序可能不再响应。
Expand Down
4 changes: 3 additions & 1 deletion Service/ArticleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public ArticleService(IFreeSql db)
/// <param name="page">页数</param>
/// <param name="size">单页大小</param>
/// <returns></returns>
public async Task<List<Article>> List(int? friendId = null, int page = 1, int size = 10)
public async Task<List<Article>> ListAsync(int? friendId = null, int page = 1, int size = 10)
{
return friendId is not null
? await _db.Select<Article>()
.Where(x => x.FriendId == friendId)
.OrderBy("PubDate DESC")
.Offset((page - 1) * size)
.Limit(size)
.ToListAsync()
: await _db.Select<Article>()
.OrderBy("PubDate DESC")
.Offset((page - 1) * size)
.Limit(size)
.ToListAsync();
Expand Down
Loading

0 comments on commit e70229d

Please sign in to comment.