Browse Source

个人中心布局完成

layui
yirenyishi 6 years ago
parent
commit
4136e780db
  1. 2
      controllers/NoteController.go
  2. 70
      controllers/UserController.go
  3. 6
      models/NoteColl.go
  4. 1
      routers/UserRouter.go
  5. 11
      service/NoteService.go
  6. 51
      static/css/me.css
  7. 34
      views/T.me.tpl
  8. 38
      views/ublogs.html
  9. 49
      views/uinfo.html
  10. 49
      views/ulike.html
  11. 37
      views/unote.html

2
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 {

70
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"

6
models/NoteColl.go

@ -1,11 +1,13 @@
package models
/**
文章
*/
type NoteColl struct {
Id int64
UserId int64
Title string
Title string
Notes []*Note `orm:"-"`
}
Count int64 `orm:"-"`
}

1
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")
}

11
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)

51
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%;
}

34
views/T.me.tpl

@ -0,0 +1,34 @@
{{define "memenu"}}
<div class="me-menu">
<div style="height: 50px;line-height: 50px">
<a href=""><img src="/static/img/2.png" alt="头像" class="img-circle"></a>
<a href="" style="margin-left: 15px;font-size: 18px;text-decoration: none">{{.User.NickName}}</a>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
<div style="display: flex;height: 30px;line-height: 30px;">
<div style="display: inline-block;width: 100px">
<span>文章: </span>
<span>{{.User.BlogCount}}</span>
</div>
<div style="display: inline-block;flex: 1">
<span>访问: </span>
<span>{{.User.BlogBrowes}}</span>
</div>
</div>
<div style="display: flex;height: 30px;line-height: 30px;">
<div style="display: inline-block;width: 100px">
<span>评论: </span>
<span>{{.User.BlogComment}}</span>
</div>
<div style="display: inline-block;flex: 1">
<span>喜欢: </span>
<span>{{.User.BlogLike}}</span>
</div>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
<p {{if .IsMeBlog}}class="active"{{end}}><span></span><a href="/me/blog">我的博客</a></p>
<p {{if .IsMeNote}}class="active"{{end}}><span></span><a href="/me/note">我的笔记</a></p>
<p {{if .IsMeLike}}class="active"{{end}}><span></span><a href="/me/like">我的收藏</a></p>
<p {{if .IsMeInfo}}class="active"{{end}}><span></span><a href="/me/info">我的资料</a></p>
</div>
{{end}}

38
views/ublogs.html

@ -5,42 +5,22 @@
<body>
<div class="root-container">
{{template "nav" .}}
<div class="me-menu">
<div style="height: 50px;line-height: 50px">
<a href=""><img src="/static/img/2.png" alt="头像" class="img-circle"></a>
<a href="" style="margin-left: 15px;font-size: 18px;text-decoration: none">{{.User.NickName}}</a>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
<div style="display: flex;height: 30px;line-height: 30px;">
<div style="display: inline-block;width: 100px">
<span>文章: </span>
<span>{{.User.BlogCount}}</span>
</div>
<div style="display: inline-block;flex: 1">
<span>访问: </span>
<span>{{.User.BlogBrowes}}</span>
</div>
</div>
<div style="display: flex;height: 30px;line-height: 30px;">
<div style="display: inline-block;width: 100px">
<span>评论: </span>
<span>{{.User.BlogComment}}</span>
</div>
<div style="display: inline-block;flex: 1">
<span>喜欢: </span>
<span>{{.User.BlogLike}}</span>
</div>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
</div>
{{template "memenu" .}}
<div class="me-blog-root">
<div class="me-blog-list">
<ol class="breadcrumb">
<li>个人中心</li>
<li>博客列表</li>
<li class="active">管理博客</li>
</ol>
{{range .Page.List}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p>
<div>
<em>发布时间:{{.Ctime.Format "2006/01/02"}}</em>
<em>浏览量:{{.Browses}}</em>
<span style="width: 35px;margin-left: 30px"><a href="">删除</a></span>
<span style="width: 35px;margin-left: 30px;"><a href="" style="color: #F84822">删除</a></span>
<span style="width: 35px;margin-left: 10px;"><a href="" style="color: #F84822">编辑</a></span>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
{{end}}

49
views/uinfo.html

@ -0,0 +1,49 @@
{{template "header"}}
<title>博客 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/me.css"/>
</head>
<body>
<div class="root-container">
{{template "nav" .}}
{{template "memenu" .}}
<div class="me-blog-root">
<div class="me-blog-list">
{{range .Page.List}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p>
<div>
<em>发布时间:{{.Ctime.Format "2006/01/02"}}</em>
<em>浏览量:{{.Browses}}</em>
<span style="width: 35px;margin-left: 30px;"><a href="" style="color: #F84822">删除</a></span>
<span style="width: 35px;margin-left: 10px;"><a href="" style="color: #F84822">编辑</a></span>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
{{end}}
<div style="text-align: center">
<nav>
<div class="pagination pagination-lg">
<ul>
{{if .Page.FirstPage}}
{{else}}
<li class="prev">
<a href="/me/blog?num={{ .Page.PageNo | NAdd -1}}&flag={{.Flag}}">&laquo;</a>
</li>
{{end}}
<li class="active"><a href="javascript:void(0)">{{.Page.PageNo}}</a></li>
{{if .Page.LastPage}}
{{else}}
<li class="next">
<a href="/me/blog?num={{ .Page.PageNo | NAdd +1}}&flag={{.Flag}}">&raquo;</a>
</li>
{{end}}
</ul>
</div>
</nav>
</div>
</div>
{{template "footer"}}
</div>
</div>
</div>
</body>
</html>

49
views/ulike.html

@ -0,0 +1,49 @@
{{template "header"}}
<title>博客 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/me.css"/>
</head>
<body>
<div class="root-container">
{{template "nav" .}}
{{template "memenu" .}}
<div class="me-blog-root">
<div class="me-blog-list">
{{range .Page.List}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p>
<div>
<em>发布时间:{{.Ctime.Format "2006/01/02"}}</em>
<em>浏览量:{{.Browses}}</em>
<span style="width: 35px;margin-left: 30px;"><a href="" style="color: #F84822">删除</a></span>
<span style="width: 35px;margin-left: 10px;"><a href="" style="color: #F84822">编辑</a></span>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
{{end}}
<div style="text-align: center">
<nav>
<div class="pagination pagination-lg">
<ul>
{{if .Page.FirstPage}}
{{else}}
<li class="prev">
<a href="/me/blog?num={{ .Page.PageNo | NAdd -1}}&flag={{.Flag}}">&laquo;</a>
</li>
{{end}}
<li class="active"><a href="javascript:void(0)">{{.Page.PageNo}}</a></li>
{{if .Page.LastPage}}
{{else}}
<li class="next">
<a href="/me/blog?num={{ .Page.PageNo | NAdd +1}}&flag={{.Flag}}">&raquo;</a>
</li>
{{end}}
</ul>
</div>
</nav>
</div>
</div>
{{template "footer"}}
</div>
</div>
</div>
</body>
</html>

37
views/unote.html

@ -0,0 +1,37 @@
{{template "header"}}
<title>博客 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/me.css"/>
</head>
<body>
<div class="root-container">
{{template "nav" .}}
{{template "memenu" .}}
<div class="me-blog-root">
<div class="me-blog-list">
<ol class="breadcrumb">
<li>个人中心</li>
<li>笔记文件夹</li>
<li class="active">管理文件夹</li>
</ol>
</div>
{{range .Note}}
<div class="me-blog-list">
<div style="display: flex">
<p style="flex:1">{{.Title}}<span class="badge" style="margin-left: 3px">{{.Count}}</span></p>
<span style="width: 35px;"><a href="" style="color: #F84822">删除</a></span>
<span style="width: 35px;margin-left: 10px;"><a href="" style="color: #F84822">编辑</a></span>
</div>
<hr style="height:1px;border:none;border-top:1px solid #EEE;margin: 6px;"/>
</div>
{{end}}
<div class="me-footer">
{{template "footer"}}
</div>
</div>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save