diff --git a/controllers/NoteController.go b/controllers/NoteController.go index 2b7fd23..bb89916 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -139,7 +139,7 @@ func (this *NoteController) Delete() { func (this *NoteController) Note() { uid := this.GetSession("userid") if uid == nil { - this.Redirect("/login.html", 302) + this.Redirect("/login", 302) } noteColls, err := service.GetNoteColl(uid.(int64)) if err == nil { diff --git a/controllers/UserController.go b/controllers/UserController.go index d2d46c2..d4ed0c2 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -49,6 +49,76 @@ func (this *UserController) PersonBlog() { } } this.Data["Page"] = page + this.Data["IsMeBlog"] = true + this.Data["Flag"] = 0 + this.Data["User"] = user + this.TplName = "ublogs.html" +} + +func (this *UserController) PersonNote() { + uid := this.GetSession("userid") + if uid == nil { + this.Redirect("/login", 302) + return + } + notColl, err := service.GetNoteColl(uid.(int64)) + if err == nil { + if len(notColl) > 0 { + for i := 0; i < len(notColl); i++ { + count, _ := service.CountNote(notColl[i].Id) + notColl[i].Count = count + } + } + } else { + notColl = make([]*models.NoteColl, 0) + } + if err != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + user, uerr := service.GetUser(uid.(int64)) + if uerr != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + this.Data["Note"] = notColl + this.Data["IsMeNote"] = true + this.Data["User"] = user + this.TplName = "unote.html" +} + +func (this *UserController) PersonLike() { + uid := this.GetSession("userid") + if uid == nil { + this.Redirect("/login", 302) + return + } + size := 15 + num, _ := this.GetInt("num") + if num <= 0 { + num = 1 + } + flag, _ := this.GetInt("flag") + page, err := service.MeBlogs(num, size, flag, uid.(int64)) + if err != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + user, uerr := service.GetUser(uid.(int64)) + if uerr != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + this.Data["Page"] = page + this.Data["IsMeBlog"] = true this.Data["Flag"] = 0 this.Data["User"] = user this.TplName = "ublogs.html" diff --git a/models/NoteColl.go b/models/NoteColl.go index 9119abe..7f955a5 100644 --- a/models/NoteColl.go +++ b/models/NoteColl.go @@ -1,11 +1,13 @@ package models + /** 文章 */ type NoteColl struct { Id int64 UserId int64 - Title string + Title string Notes []*Note `orm:"-"` -} \ No newline at end of file + Count int64 `orm:"-"` +} diff --git a/routers/UserRouter.go b/routers/UserRouter.go index a41acfd..f114d08 100644 --- a/routers/UserRouter.go +++ b/routers/UserRouter.go @@ -15,5 +15,6 @@ func init() { beego.Router("/me/blog", &controllers.UserController{}, "get:PersonBlog") + beego.Router("/me/note", &controllers.UserController{}, "get:PersonNote") } diff --git a/service/NoteService.go b/service/NoteService.go index 65bfa7b..736f293 100644 --- a/service/NoteService.go +++ b/service/NoteService.go @@ -33,7 +33,7 @@ func GetNote(note *models.Note) error { func DelNote(note *models.Note) error { o := orm.NewOrm() - _,err := o.Delete(note) + _, err := o.Delete(note) return err } @@ -45,6 +45,15 @@ func GetNoteByPid(pid int64) ([]*models.Note, error) { return notes, err } +func CountNote(pid int64) (int64, error) { + o := orm.NewOrm() + totalCount, err := o.QueryTable(&models.Note{}).Filter("Pid", pid).Count() + if err != nil { + return 0,err + } + return totalCount, nil +} + func SaveNoteColl(note *models.NoteColl) error { o := orm.NewOrm() id, err := o.Insert(note) diff --git a/static/css/me.css b/static/css/me.css index 74afabb..e7746db 100644 --- a/static/css/me.css +++ b/static/css/me.css @@ -1,4 +1,4 @@ -.me-menu{ +.me-menu { position: fixed; top: 60px; left: 20px; @@ -7,18 +7,61 @@ background-color: #f9f9f9; } -.me-blog-root{ +.me-menu p { + cursor: pointer; + font-size: 18px; + color: #555; + margin: 0; + height: 32px; + line-height: 32px; +} + +.me-menu .active { + color: #3CBEF8 !important +} + +.me-menu p a { + margin-left: 5px; + color: #555; + text-decoration: none; +} + +.me-menu .active span { + display: inline-block; + height: 100%; + width: 2px; + background-color: #3CBEF8; +} + +.me-menu .active a { + color: #3CBEF8; + vertical-align: top; + height: 32px; + line-height: 32px; + display: inline-block; +} + +.me-blog-root { height: 100%; margin: 50px 4% 0 0; } -.me-blog-list{ +.me-blog-list { margin-left: 300px; } -.me-blog-list p{ +.me-blog-list p { height: 30px; line-height: 30px; margin: 0; font-size: 15px; +} + +.me-footer{ + position: absolute; + bottom: 0; + left: 0; + width: 100%; + height: 110px; + padding: 0 4%; } \ No newline at end of file diff --git a/views/T.me.tpl b/views/T.me.tpl new file mode 100644 index 0000000..d20ef6c --- /dev/null +++ b/views/T.me.tpl @@ -0,0 +1,34 @@ +{{define "memenu"}} +
+
+ 头像 + {{.User.NickName}} +
+
+
+
+ 文章: + {{.User.BlogCount}} +
+
+ 访问: + {{.User.BlogBrowes}} +
+
+
+
+ 评论: + {{.User.BlogComment}} +
+
+ 喜欢: + {{.User.BlogLike}} +
+
+
+

我的博客

+

我的笔记

+

我的收藏

+

我的资料

+
+{{end}} \ No newline at end of file diff --git a/views/ublogs.html b/views/ublogs.html index 646f1c1..33af7ab 100644 --- a/views/ublogs.html +++ b/views/ublogs.html @@ -5,42 +5,22 @@
{{template "nav" .}} -
-
- 头像 - {{.User.NickName}} -
-
-
-
- 文章: - {{.User.BlogCount}} -
-
- 访问: - {{.User.BlogBrowes}} -
-
-
-
- 评论: - {{.User.BlogComment}} -
-
- 喜欢: - {{.User.BlogLike}} -
-
-
-
+{{template "memenu" .}} +
+ {{range .Page.List}}

{{.Title}}

发布时间:{{.Ctime.Format "2006/01/02"}} 浏览量:{{.Browses}} - 删除 + 删除 + 编辑

{{end}} diff --git a/views/uinfo.html b/views/uinfo.html new file mode 100644 index 0000000..b8c2cb8 --- /dev/null +++ b/views/uinfo.html @@ -0,0 +1,49 @@ +{{template "header"}} +博客 - 个人随笔 + + + +
+{{template "nav" .}} +{{template "memenu" .}} + +
+
+ {{range .Page.List}} +

{{.Title}}

+
+ 发布时间:{{.Ctime.Format "2006/01/02"}} + 浏览量:{{.Browses}} + 删除 + 编辑 +
+
+ {{end}} +
+ +
+
+ {{template "footer"}} +
+
+
+ + \ No newline at end of file diff --git a/views/ulike.html b/views/ulike.html new file mode 100644 index 0000000..b8c2cb8 --- /dev/null +++ b/views/ulike.html @@ -0,0 +1,49 @@ +{{template "header"}} +博客 - 个人随笔 + + + +
+{{template "nav" .}} +{{template "memenu" .}} + +
+
+ {{range .Page.List}} +

{{.Title}}

+
+ 发布时间:{{.Ctime.Format "2006/01/02"}} + 浏览量:{{.Browses}} + 删除 + 编辑 +
+
+ {{end}} +
+ +
+
+ {{template "footer"}} +
+
+
+ + \ No newline at end of file diff --git a/views/unote.html b/views/unote.html new file mode 100644 index 0000000..4a3a3d6 --- /dev/null +++ b/views/unote.html @@ -0,0 +1,37 @@ +{{template "header"}} +博客 - 个人随笔 + + + +
+{{template "nav" .}} +{{template "memenu" .}} + +
+
+ +
+ + {{range .Note}} +
+
+

{{.Title}}{{.Count}}

+ 删除 + 编辑 +
+
+
+ + {{end}} + +
+
+
+ + \ No newline at end of file