From 713b747eb8e07b5b60ab4b461959e18817f788af Mon Sep 17 00:00:00 2001 From: yirenyishi Date: Sat, 24 Nov 2018 22:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E5=8D=9A?= =?UTF-8?q?=E5=AE=A2=E7=AE=A1=E7=90=86&=E7=AC=94=E8=AE=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BlogController.go | 35 ++++++++++++++- controllers/NoteController.go | 66 +++++++++++++++++++++------ controllers/UserController.go | 4 ++ data/beeblog.db | Bin 86016 -> 86016 bytes routers/BlogRouter.go | 1 + routers/NoteRouter.go | 2 + service/BlogService.go | 6 +++ service/NoteService.go | 38 +++++++++++++++- static/css/me.css | 2 +- views/T.me.tpl | 2 +- views/note.html | 27 +----------- views/ublogs.html | 36 ++++++++++++--- views/unote.html | 81 +++++++++++++++++++++++++++++++++- 13 files changed, 249 insertions(+), 51 deletions(-) diff --git a/controllers/BlogController.go b/controllers/BlogController.go index ab4b113..658541f 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -41,7 +41,7 @@ func (this *BlogController) Get() { id, _ := strconv.ParseInt(idStr, 10, 64) blog, err := service.GetBlog(id) if err != nil { - this.Redirect("/500",302) + this.Redirect("/500", 302) return } this.Data["Blog"] = blog @@ -53,6 +53,39 @@ func (this *BlogController) Get() { return } +func (this *BlogController) Del() { + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + blog, err := service.GetBlog(id) + if err != nil { + this.Data["json"] = models.ReurnError(500, "") + this.ServeJSON() + return + } + if blog.UserId != uid.(int64) { + this.Data["json"] = models.ReurnError(503, "") + this.ServeJSON() + return + } + blog.Delflag = 1 + err = service.DelBlog(blog) + if err!=nil { + this.Data["json"] = models.ReurnError(500, "") + this.ServeJSON() + return + } + this.Data["json"] = models.ReurnSuccess("") + this.ServeJSON() + service.CountBlog(uid.(int64)) + return +} + func (this *BlogController) New() { uid := this.GetSession("userid") if uid == nil { diff --git a/controllers/NoteController.go b/controllers/NoteController.go index bb89916..1e52f17 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -16,7 +16,7 @@ func (this *NoteController) Save() { title := this.GetString("title") uid := this.GetSession("userid") if uid == nil { - this.Data["json"] = models.ReurnError(401,"保存失败") + this.Data["json"] = models.ReurnError(401, "保存失败") this.ServeJSON() return } @@ -25,7 +25,7 @@ func (this *NoteController) Save() { if err == nil { this.Data["json"] = note } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -35,20 +35,20 @@ func (this *NoteController) Edit() { noteHtml := this.GetString("noteHtml") id, _ := strconv.ParseInt(idStr, 10, 64) uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return } - note := &models.Note{Id:id} + note := &models.Note{Id: id} err1 := service.GetNote(note) if err1 != nil { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") this.ServeJSON() return } if uid != note.UserId { - this.Data["json"] = models.ReurnError(403,"") + this.Data["json"] = models.ReurnError(403, "") this.ServeJSON() return } @@ -57,7 +57,7 @@ func (this *NoteController) Edit() { if err == nil { this.Data["json"] = models.ReurnSuccess("") } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -66,7 +66,7 @@ func (this *NoteController) Edit() { func (this *NoteController) SaveNoteColl() { title := this.GetString("title") uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -74,9 +74,28 @@ func (this *NoteController) SaveNoteColl() { note := &models.NoteColl{Title: title, UserId: uid.(int64)} err := service.SaveNoteColl(note) if err == nil { - this.Data["json"] = note + this.Data["json"] = models.ReurnSuccess("") } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") + } + this.ServeJSON() + return +} + +func (this *NoteController) EditNoteColl() { + title := this.GetString("title") + id, _ := this.GetInt64("id") + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + err := service.EditNoteColl(title, id, uid.(int64)) + if err == nil { + this.Data["json"] = models.ReurnSuccess("") + } else { + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -84,7 +103,7 @@ func (this *NoteController) SaveNoteColl() { func (this *NoteController) Get() { uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -104,9 +123,28 @@ func (this *NoteController) Get() { this.ServeJSON() return } +func (this *NoteController) DelNoteColl() { + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + err := service.DelNoteColl(id, uid.(int64)) + if err != nil { + this.Data["json"] = models.ReurnError(500, "") + } else { + this.Data["json"] = models.ReurnSuccess("") + } + this.ServeJSON() + return +} + func (this *NoteController) Delete() { uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -116,7 +154,7 @@ func (this *NoteController) Delete() { note := &models.Note{Id: id} err := service.GetNote(note) if err != nil { - this.Data["json"] = models.ReurnError(500,"") + this.Data["json"] = models.ReurnError(500, "") this.ServeJSON() return } @@ -127,7 +165,7 @@ func (this *NoteController) Delete() { } err = service.DelNote(note) if err != nil { - this.Data["json"] = models.ReurnError(500,"") + this.Data["json"] = models.ReurnError(500, "") this.ServeJSON() return } diff --git a/controllers/UserController.go b/controllers/UserController.go index d4ed0c2..0eda188 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -48,6 +48,8 @@ func (this *UserController) PersonBlog() { return } } + this.Data["NickName"] = this.GetSession("nickname") + this.Data["IsLogin"] = this.GetSession("nickname") != nil this.Data["Page"] = page this.Data["IsMeBlog"] = true this.Data["Flag"] = 0 @@ -85,6 +87,8 @@ func (this *UserController) PersonNote() { return } } + this.Data["NickName"] = this.GetSession("nickname") + this.Data["IsLogin"] = this.GetSession("nickname") != nil this.Data["Note"] = notColl this.Data["IsMeNote"] = true this.Data["User"] = user diff --git a/data/beeblog.db b/data/beeblog.db index 18c5617b5936bb5b2b45d374972d6c039530865c..3068f8f310ab12aec44421d09f6de6ad4a4a5e85 100644 GIT binary patch delta 193 zcmZozz}m2Yb%HeG+leyHjBht4l;|^ZY`&_mp}@>7ym?aqivb&h00RSm%Vw^IDt;CQ z28No+9sOn?hSTIj{VrVB82G>Nzv92oe{Hj%z-E41Ax_m76IQ&~w+})B)#9ylGPaivb%Ge+vWuzRg?>Rs1X# z!t4x_JNnI79E5<3L;WsX2N?Lj@;~Rl#D8G3puh%x2LToq22Rx%6IQ&~w+})JGXq7m zU(VS7eB%74OO`*IzU|5G#XL+vL0O<+u;YvMTR0hkJn^SfyMkRdEtsgcd178F

我的博客

-

我的笔记

+

笔记文件夹

我的收藏

我的资料

diff --git a/views/note.html b/views/note.html index 741eea2..be66fab 100644 --- a/views/note.html +++ b/views/note.html @@ -48,7 +48,7 @@ @@ -216,31 +216,6 @@ }); }) - - $("#newNoteColl").click(function () { - layer.prompt({title: '请输入文件夹名称'}, function (val, index) { - if (val.trim().length < 3) { - layer.msg('文件夹名称最低三个字哦', function () { - }); - layer.close(index); - return - } - $.post('/notecoll/save', { - title: val.trim() - }, - function (data) { - if (!data.Status) { - parent.layer.msg("保存成功", {icon: 6}); - var child = '
  • \n' + - ' ' + data.Titled + '\n' + - ' \n' + - '
  • ' - $(".cd-navigation").append(child) - layer.close(index); - } - }, 'json') - }); - }) }) \ No newline at end of file diff --git a/views/ublogs.html b/views/ublogs.html index 33af7ab..443ca59 100644 --- a/views/ublogs.html +++ b/views/ublogs.html @@ -15,12 +15,15 @@
  • 管理博客
  • {{range .Page.List}} -

    {{.Title}}

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

    {{.Title}}

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

    {{end}} @@ -51,4 +54,27 @@ + \ No newline at end of file diff --git a/views/unote.html b/views/unote.html index 4a3a3d6..ba62b9c 100644 --- a/views/unote.html +++ b/views/unote.html @@ -13,6 +13,7 @@
  • 个人中心
  • 笔记文件夹
  • 管理文件夹
  • + @@ -20,8 +21,10 @@

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

    - 删除 - 编辑 + 删除 + 重命名

    @@ -34,4 +37,78 @@ + \ No newline at end of file