From 892513a641d621f67983e78431a0e54c9a8b8206 Mon Sep 17 00:00:00 2001 From: yirenyishi Date: Mon, 19 Nov 2018 23:07:28 +0800 Subject: [PATCH] session --- controllers/NoteController.go | 32 ++++++++++++++--- controllers/PageController.go | 6 ---- controllers/UserController.go | 3 +- data/beeblog.db | Bin 36864 -> 40960 bytes main.go | 2 +- models/DataInit.go | 2 +- models/NoteColl.go | 2 ++ routers/NoteRouter.go | 1 + service/NoteService.go | 4 +-- views/iframe/note.html | 1 + views/note.html | 64 +++++++++++++++++++++++----------- 11 files changed, 81 insertions(+), 36 deletions(-) diff --git a/controllers/NoteController.go b/controllers/NoteController.go index b327fbf..ed6655e 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -13,15 +13,15 @@ type NoteController struct { } func (this *NoteController) Save() { - pid,_ := this.GetInt64("pid") - fmt.Println("pid",pid) + pid, _ := this.GetInt64("pid") + fmt.Println("pid", pid) title := this.GetString("title") uid := this.GetSession("userid").(int64) note := &models.Note{Title: title, Pid: pid, UserId: uid} err := service.SaveNote(note) if err == nil { - this.Data["json"] = note + this.Data["json"] = note } else { this.Data["json"] = models.ReurnError("保存失败") } @@ -35,7 +35,7 @@ func (this *NoteController) SaveNoteColl() { note := &models.NoteColl{Title: title, UserId: uid} err := service.SaveNoteColl(note) if err == nil { - this.Data["json"] = note + this.Data["json"] = note } else { this.Data["json"] = models.ReurnError("保存失败") } @@ -52,3 +52,27 @@ func (this *NoteController) Get() { } this.ServeJSON() } + +func (this *NoteController) Note() { + uid := this.GetSession("userid") + fmt.Println("userid", uid) + if uid == nil { + this.Redirect("/login", 302) + } + noteColls, err := service.GetNoteColl(uid.(int64)) + if err != nil { + if len(noteColls) > 0 { + for i := 0; i < len(noteColls); i++ { + notes, err1 := service.GetNoteByPid(noteColls[i].Id) + if err1 != nil { + noteColls[i].Notes = notes + } + } + } + } else { + noteColls = make([]*models.NoteColl, 0) + } + fmt.Println(noteColls) + this.Data["NoteColls"] = noteColls + this.TplName = "note.html" +} diff --git a/controllers/PageController.go b/controllers/PageController.go index 66f70a4..d26277a 100644 --- a/controllers/PageController.go +++ b/controllers/PageController.go @@ -15,9 +15,3 @@ func (this *PageController) Blog() { func (this *PageController) IframeNote() { this.TplName = "iframe/note.html" } - -// @router /note [get] -func (this *PageController) Note() { - this.Data["IsNote"] = true - this.TplName = "note.html" -} diff --git a/controllers/UserController.go b/controllers/UserController.go index 4d337f8..571246d 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -60,8 +60,7 @@ func (this *UserController) Login() { if userpwd == user.UserPwd { this.Data["json"] = models.ReurnSuccess("") this.SetSession("userid", user.Id) - tt := this.GetSession("userid").(int64) - fmt.Println(tt > 0) + fmt.Println(this.CruSession) } else { this.Data["json"] = models.ReurnError("用户名或密码错误") } diff --git a/data/beeblog.db b/data/beeblog.db index a2344af38e23516c6d970623001778c1ea1726bc..04a32076be5e7c2a0dc3325480d53120364c114c 100644 GIT binary patch delta 558 zcmZozz|?SnX@az%J_7>-7ZAe$_e33Id3^>wjVxY1Wd=?*TL!+{e4TvS+zq_HIQ=>7 z*?~eE8~3wXGP^_#88}sWIsKnb?SdmC149d4LqlCd zO9ewCD-%mABSSq?BTFL#6GLqS11kdqeO90@X`rr@#9|Oa)?jF5YGGw+sb^qdY;0s| z2GL-^0@NT2)KHw50z`?$P#yJPJHT3uO!W**O^hv!Eg)KSn1NbEfm*VG0L=n(D?>{? z3ll>#Q@Cm-sOsVrROc9goMU9BXJBM*YHVl(HJcHtdh+dlRRLaLJhJc~VBr7C{~Q=X z2Y?~7f!{%Zg#{QgFD9&bv2P!Q6lMmBXuq7X|M|rEPnRrzHhtTZ-HUmcfP%6>!C=Q1 Q>$h++0(s)VfDCp4069sP9{>OV delta 118 zcmZoTz|^pSX@az%Dgy%pClJE`*F+s-Sycu-jVxY1Wd;s*P6oc)e4TvS+zq_HIQ=>7 z**P~03iPsV=4AgZ!NbCTje-9g|4aV+{MUfO$M`wfS(rsR^YTklH{aJ+4PayBzr?_Q N2`F`ffAXb%JphM29Q^ @@ -76,21 +76,8 @@
  • Product 4
  • Product 5
  • - - - - - - - -{{/* */}} + + @@ -107,19 +94,31 @@ document.onkeydown = keyDown; function keyDown(e) { - e.preventDefault(); + // e.preventDefault(); var currKey = 0, e = e || event || window.event; currKey = e.keyCode || e.which || e.charCode; if (currKey == 83 && (e.ctrlKey || e.metaKey)) { layer.msg("ctrl+s") return false; } + } function noteClick(id) { layer.msg(id) } + function addNoteCallback(obj) { + var subMenu = $(".sub-menu") + $.each(subMenu, function (index, el) { + if ($(this).attr("value") == obj.Pid) { + var child = '
  • ' + obj.Title + '
  • ' + $(".sub-menu").append(child) + return + } + }) + } + $(function () { var height = document.documentElement.clientHeight $(".w-e-text-container").height(height - 40 - 3); @@ -127,7 +126,7 @@ layer.tips('文章列表点我', '#slide-container', { tips: [3, '#78BA32'] }); - + $("#newNote").click(function () { layer.open({ type: 2, @@ -138,6 +137,31 @@ content: '/iframe/note.html' //iframe的url }); }) + $("#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) { + debugger + 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