懒得勤快 8 months ago
parent
commit
79ac9392d9

+ 2 - 3
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -626,7 +626,7 @@ public sealed class PostController : BaseController
     /// </summary>
     /// <returns></returns>
     [MyAuthorize]
-    public async Task<ActionResult> GetPageData([FromServices] IRedisClient cacheManager, int page = 1, [Range(1, 200, ErrorMessage = "页大小必须介于{1}-{2}")] int size = 10, OrderBy orderby = OrderBy.ModifyDate, string kw = "", int? cid = null)
+    public async Task<ActionResult> GetPageData([FromServices] IRedisClient cacheManager, int page = 1, [Range(1, 200, ErrorMessage = "页大小必须介于{1}-{2}")] int size = 10, OrderBy orderby = OrderBy.ModifyDate, string kw = "", int? cid = null, bool useRegex = false)
     {
         Expression<Func<Post, bool>> where = p => true;
         if (cid.HasValue)
@@ -636,8 +636,7 @@ public sealed class PostController : BaseController
 
         if (!string.IsNullOrEmpty(kw))
         {
-            kw = kw.Split('|', StringSplitOptions.RemoveEmptyEntries).Select(Regex.Escape).Join("|");
-            where = where.And(p => Regex.IsMatch(p.Title + p.Author + p.Email + p.Content, kw, RegexOptions.IgnoreCase));
+            where = useRegex ? where.And(p => Regex.IsMatch(p.Title + p.Author + p.Email + p.Content + p.ProtectContent, kw, RegexOptions.IgnoreCase)) : where.And(p => (p.Title + p.Author + p.Email + p.Content + p.ProtectContent).Contains(kw));
         }
 
         var list = orderby switch

+ 3 - 2
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.js

@@ -3,6 +3,7 @@
     self.stats = [];
     self.data = {};
     $scope.kw = "";
+    $scope.useRegex = false;
     $scope.orderby = 1;
     $scope.CategoryId = "";
     $scope.paginationConf = {
@@ -113,8 +114,8 @@
     });
 
     this.GetPageData = function (page, size) {
-        let params = { page, size, kw: $scope.kw, orderby: $scope.orderby, cid: $scope.CategoryId };
-        $http.get(`/post/getpagedata?page=${page || 1}&size=${size}&kw=${$scope.kw}&orderby=${$scope.orderby}&cid=${$scope.CategoryId}`).then(function (res) {
+        let params = { page, size, kw: $scope.kw, useRegex: $scope.useRegex, orderby: $scope.orderby, cid: $scope.CategoryId };
+        $http.get(`/post/getpagedata?page=${page || 1}&size=${size}&kw=${$scope.kw}&useRegex=${$scope.useRegex}&orderby=${$scope.orderby}&cid=${$scope.CategoryId}`).then(function (res) {
             $scope.paginationConf.totalItems = res.data.TotalCount;
             $("div[ng-table-pagination]").remove();
             self.tableParams = new NgTableParams({ count: 50000 }, {

+ 4 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/post/postlist.html

@@ -24,6 +24,10 @@
                 <input type="text" class="form-control" ng-change="search(kw)" ng-model="kw" placeholder="全局搜索" />
             </div>
         </div>
+        <div class="input-group">
+                <input type="checkbox" ng-change="search(kw)" ng-model="useRegex" id="regex"/>
+                <label class="input-group-addon" for="regex">使用正则表达式</label>
+        </div>
         <div class="input-group">
             <span class="input-group-addon">分类:</span>
             <div class="form-control" id="category" style="width: 200px"></div>