Skip to content

Commit 20c20fc

Browse files
author
wangkaikai
committed
首页文章分类接口完成
1 parent 2903566 commit 20c20fc

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

controllers/index.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ func GetBlogInfo(this *gin.Context){
6969
"data" : data,
7070
})
7171
}
72+
//获取文章分类列表
7273
func GetCategorys(this *gin.Context){
7374
datas := GetCategoryList()
75+
num := len(datas)
76+
fmt.Println(num)
77+
var code int
78+
if num >0 {
79+
code = 200
80+
}else{
81+
code = 0
82+
}
83+
this.JSON(http.StatusOK, gin.H{
84+
"code" : code,
85+
"data" : datas,
86+
})
7487
}

models/Ali_category.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Ali_category struct {
1515
CatName string `json:"catName" form:"catName"`
1616
}
1717

18-
func GetCategoryList()(categorys[] *Ali_category){
19-
datas, err := db.SqlDB.Query("select * from ali_catogory")
18+
func GetCategoryList()(categorys []Ali_category){
19+
datas, err := db.SqlDB.Query("select * from ali_category")
2020
if err != nil{
2121
log.Println(err)
2222
}

static/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ $(function(){
1010
//获取文章分类列表
1111
getBlogsCategorys();
1212
//获取文章列表(默认第一页)
13-
getPageBlogs();
14-
//获取统计信息
15-
getSiteCounts();
16-
//获取站长信息、
17-
getUserInfo();
18-
//获取点击排行前5的文章
19-
getTopViewBlogs();
20-
//获取友链
21-
getFriendlyUrls();
22-
//获取底部备案信息
23-
getFooterInfo();
13+
// getPageBlogs();
14+
// //获取统计信息
15+
// getSiteCounts();
16+
// //获取站长信息、
17+
// getUserInfo();
18+
// //获取点击排行前5的文章
19+
// getTopViewBlogs();
20+
// //获取友链
21+
// getFriendlyUrls();
22+
// //获取底部备案信息
23+
// getFooterInfo();
2424
})
2525
//获取推荐文章
2626
function getTopBlogs(){
@@ -54,10 +54,12 @@ function getBlogsCategorys(){
5454
$.get(url, function(data){
5555
if(data.code == 200){
5656
var categoryObj = $("#categorys");
57-
datas = data.data;
57+
var datas = data.data;
58+
var category_html_str = '';
5859
for(i in datas){
59-
var category_html_str = '';
60-
category_html_str += '<a href="/home/getBlogList?cId='+datas[i].cId+'">'+datas[i].cName+'</a>'
60+
console.log(i);
61+
console.log(datas[i].catName);
62+
category_html_str += '<a href="/home/getBlogsList?catId='+datas[i].catId+'">'+datas[i].catName+'</a>';
6163
}
6264
categoryObj.append(category_html_str);
6365
}else{

views/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
<!--异步获取置顶文章-->
2828
</div>
2929
<div class="title">
30-
<h3>文章分类</h3>
30+
<h3>分类</h3>
3131
<div id="categorys" class="more">
3232
<!--文章分类 start-->
33-
<a href="#" title="MZ-NetBlog主题" >MZ-NetBlog主题</a>
33+
3434
<!--文章分类 end-->
3535
</div>
3636
</div>

0 commit comments

Comments
 (0)