Browse Source

文章分类列表

懒得勤快 5 years ago
parent
commit
eeb967f617

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

@@ -599,10 +599,20 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// </summary>
         /// </summary>
         /// <returns></returns>
         /// <returns></returns>
         [Authority]
         [Authority]
-        public ActionResult GetPageData([Range(1, int.MaxValue, ErrorMessage = "页数必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 10, OrderBy orderby = OrderBy.ModifyDate, string kw = "")
+        public ActionResult GetPageData([Range(1, int.MaxValue, ErrorMessage = "页数必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 10, OrderBy orderby = OrderBy.ModifyDate, string kw = "", int? cid = null)
         {
         {
-            IOrderedQueryable<Post> temp;
-            var query = string.IsNullOrEmpty(kw) ? PostService.GetAll() : PostService.GetQuery(p => p.Title.Contains(kw) || p.Author.Contains(kw) || p.Email.Contains(kw) || p.Label.Contains(kw) || p.Content.Contains(kw));
+            Expression<Func<Post, bool>> where = p => true;
+            if (cid.HasValue)
+            {
+                where = where.And(p => p.CategoryId == cid.Value);
+            }
+
+            if (!string.IsNullOrEmpty(kw))
+            {
+                where = where.And(p => p.Title.Contains(kw) || p.Author.Contains(kw) || p.Email.Contains(kw) || p.Label.Contains(kw) || p.Content.Contains(kw));
+            }
+
+            var query = PostService.GetQuery(where);
             var total = query.Count();
             var total = query.Count();
             var list = query.OrderBy($"{nameof(Post.Status)} desc,{nameof(Post.IsFixedTop)} desc,{orderby.GetDisplay()} desc").Skip((page - 1) * size).Take(size).ProjectTo<PostDataModel>(MapperConfig).ToList();
             var list = query.OrderBy($"{nameof(Post.Status)} desc,{nameof(Post.IsFixedTop)} desc,{orderby.GetDisplay()} desc").Skip((page - 1) * size).Take(size).ProjectTo<PostDataModel>(MapperConfig).ToList();
             var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();
             var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();

+ 1 - 1
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -1408,7 +1408,7 @@
             <param name="id"></param>
             <param name="id"></param>
             <returns></returns>
             <returns></returns>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.PostController.GetPageData(System.Int32,System.Int32,Masuit.MyBlogs.Core.Models.Enum.OrderBy,System.String)">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.PostController.GetPageData(System.Int32,System.Int32,Masuit.MyBlogs.Core.Models.Enum.OrderBy,System.String,System.Nullable{System.Int32})">
             <summary>
             <summary>
             获取文章分页
             获取文章分页
             </summary>
             </summary>

+ 26 - 1
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.js

@@ -6,6 +6,7 @@
 	self.data = {};
 	self.data = {};
 	$scope.kw = "";
 	$scope.kw = "";
 	$scope.orderby = 1;
 	$scope.orderby = 1;
+	$scope.CategoryId = "";
 	$scope.paginationConf = {
 	$scope.paginationConf = {
 		currentPage:  1,
 		currentPage:  1,
 		//totalItems: $scope.total,
 		//totalItems: $scope.total,
@@ -25,13 +26,37 @@
 			self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
 			self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
 		}
 		}
 	});
 	});
+	$http.post("/category/getcategories", null).then(function (res) {
+		$scope.loadingDone();
+		var data = res.data;
+		if (data.Success) {
+			$scope.cat = data.Data;
+			$('.ui.dropdown.category').dropdown({
+				onChange: function (value) {
+					$scope.CategoryId = value;
+					self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
+				},
+				message: {
+					maxSelections: '最多选择 {maxCount} 项',
+					noResults: '无搜索结果!'
+				}
+			});
+		} else {
+			window.notie.alert({
+				type: 3,
+				text: '获取文章分类失败!',
+				time: 4
+			});
+		}
+	});
 	this.GetPageData = function (page, size) {
 	this.GetPageData = function (page, size) {
 		$scope.loading();
 		$scope.loading();
 		$http.post("/post/getpagedata", {
 		$http.post("/post/getpagedata", {
 			page,
 			page,
 			size,
 			size,
 			kw: $scope.kw,
 			kw: $scope.kw,
-			orderby:$scope.orderby
+			orderby:$scope.orderby,
+			cid:$scope.CategoryId
 		}).then(function(res) {
 		}).then(function(res) {
 			//$scope.paginationConf.currentPage = page;
 			//$scope.paginationConf.currentPage = page;
 			$scope.paginationConf.totalItems = res.data.TotalCount;
 			$scope.paginationConf.totalItems = res.data.TotalCount;

File diff suppressed because it is too large
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.min.js


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

@@ -9,6 +9,18 @@
                 <input type="text" class="form-control" ng-change="search(kw)" ng-model="kw" placeholder="全局搜索" />
                 <input type="text" class="form-control" ng-change="search(kw)" ng-model="kw" placeholder="全局搜索" />
             </div>
             </div>
         </div>
         </div>
+        <div class="input-group">
+            <span class="input-group-addon">分类:</span>
+            <div class="ui search selection dropdown category">
+                <input name="category" type="hidden" id="category">
+                <i class="dropdown icon"></i>
+                <div class="default text">请选择分类</div>
+                <div class="menu">
+                    <div class="item"data-value="">无</div>
+                    <div class="item" ng-repeat="item in cat track by $index" data-value="{{item.Id}}">{{item.Name}}</div>
+                </div>
+            </div>
+        </div>
         <div class="input-group">
         <div class="input-group">
             <span class="input-group-addon">服务端排序方式:</span>
             <span class="input-group-addon">服务端排序方式:</span>
             <div class="ui selection dropdown orderby">
             <div class="ui selection dropdown orderby">

Some files were not shown because too many files changed in this diff