From 7a87d539992f1d3a82d14fa8694fcd3f6d19ae72 Mon Sep 17 00:00:00 2001 From: yirenyishi Date: Mon, 26 Nov 2018 22:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/UserController.go | 26 ++++++++++++++++++++-- routers/UserRouter.go | 1 + static/css/u.css | 20 +++++++++++++++++ views/T.me.tpl | 4 ++-- views/uinfo.html | 2 +- views/user.html | 41 +++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 static/css/u.css create mode 100644 views/user.html diff --git a/controllers/UserController.go b/controllers/UserController.go index 72062a5..0bb55e5 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -22,6 +22,28 @@ func (u *UserController) RegistPage() { u.TplName = "regist.html" } +func (this *UserController) UserInfo() { + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + user, err := service.GetUser(id) + if err != nil { + this.Redirect("/500", 302) + return + } + size := 15 + num, _ := this.GetInt("num") + if num <= 0 { + num = 1 + } + flag, _ := this.GetInt("flag") + if page, err := service.MeBlogs(num, size, flag, id); err == nil { + this.Data["Page"] = page + } + this.Data["User"] = user + this.TplName = "user.html" + return +} + func (this *UserController) PersonBlog() { uid := this.GetSession("userid") if uid == nil { @@ -164,9 +186,9 @@ func (this *UserController) Edit() { user.QQ = this.GetString("qqnum") user.Sex, _ = this.GetInt("catory") user.DescInfo = this.GetString("mdesc") - if _,err :=service.EditUser(user); err !=nil{ + if _, err := service.EditUser(user); err != nil { this.Data["json"] = models.ReurnError(500, "") - }else{ + } else { this.Data["json"] = models.ReurnSuccess("") } this.ServeJSON() diff --git a/routers/UserRouter.go b/routers/UserRouter.go index 8b8d115..3fff668 100644 --- a/routers/UserRouter.go +++ b/routers/UserRouter.go @@ -12,6 +12,7 @@ func init() { beego.Router("/regist", &controllers.UserController{}, "post:Regist") beego.Router("/regist", &controllers.UserController{}, "get:RegistPage") beego.Router("/user/edit", &controllers.UserController{}, "post:Edit") + beego.Router("/u/:id([0-9]+)", &controllers.UserController{}, "get:UserInfo") diff --git a/static/css/u.css b/static/css/u.css new file mode 100644 index 0000000..c135152 --- /dev/null +++ b/static/css/u.css @@ -0,0 +1,20 @@ +.uinfo { + color: #515a6e; + margin: 5px; +} + +.udesc span { + margin-right: 8px; +} + +.blog-list { + display: flex; + font-size: 16px; + min-height: 35px; + line-height: 35px; +} + +a{ + color: #515a6e; + text-decoration: none !important; +} \ No newline at end of file diff --git a/views/T.me.tpl b/views/T.me.tpl index c5b39e8..05bb1c3 100644 --- a/views/T.me.tpl +++ b/views/T.me.tpl @@ -1,8 +1,8 @@ {{define "memenu"}}
- 头像 - {{.User.NickName}} + 头像 + {{.User.NickName}}

diff --git a/views/uinfo.html b/views/uinfo.html index 5f4f3bb..6c34fae 100644 --- a/views/uinfo.html +++ b/views/uinfo.html @@ -20,7 +20,7 @@

ID: {{.User.UserName}}

-

个人主页 >

+

个人主页 >

博客 {{.User.BlogCount}} diff --git a/views/user.html b/views/user.html new file mode 100644 index 0000000..2426164 --- /dev/null +++ b/views/user.html @@ -0,0 +1,41 @@ +{{template "header"}} +【{{.User.NickName}}】个人主页 - 个人随笔 + + + +
+{{template "nav" .}} +
+
+ 头像 +
+ {{/*

{{.User.NickName}}

*/}} +

码农笔录

+
+ {{.User.DescInfo}} +
+
+ 加入 {{.User.Ctime.Format "2006-01-02"}} + 文章 {{.User.BlogCount}} + 访问 {{.User.BlogBrowes}} + 评论 {{.User.BlogComment}} + 收藏 {{.User.BlogLike}} +
+
+
+
+
+ 排序: + 发布时间 + 访问量 +
+ {{range .Page.List}} + +
+ {{end}} +
+
+ + \ No newline at end of file