From 448a45af28a23c50e15c26e9242afc11ccf31f94 Mon Sep 17 00:00:00 2001 From: "mail_yanpeng@163.com" Date: Tue, 30 Jun 2020 17:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=AC=94=E8=AE=B0=E8=B5=B0?= =?UTF-8?q?=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/NoteController.go | 14 ++- routers/NoteRouter.go | 2 +- views/note.html | 196 ++++++++++++++++++++-------------- 3 files changed, 127 insertions(+), 85 deletions(-) diff --git a/controllers/NoteController.go b/controllers/NoteController.go index 3fd582a..50c0efc 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -1,10 +1,10 @@ package controllers import ( - "github.com/astaxie/beego" - "strconv" "beeblog/models" "beeblog/service" + "github.com/astaxie/beego" + "strconv" ) type NoteController struct { @@ -16,12 +16,14 @@ func (this *NoteController) Save() { pid, _ := this.GetInt64("pid") title := this.GetString("title") uid := this.GetSession("userid") + noteHtml := this.GetString("noteHtml") + noteVal := this.GetString("noteVal") if uid == nil { this.Data["json"] = models.ReurnError(401, "保存失败") this.ServeJSON() return } - note := &models.Note{Title: title, Pid: pid, UserId: uid.(int64)} + note := &models.Note{Title: title, Pid: pid, UserId: uid.(int64), NoteVal: noteVal, NoteHtml: noteHtml} err := noteService.SaveNote(note) if err == nil { this.Data["json"] = note @@ -35,6 +37,7 @@ func (this *NoteController) Edit() { noteService := service.NoteService{} idStr := this.Ctx.Input.Param(":id") noteHtml := this.GetString("noteHtml") + noteVal := this.GetString("noteVal") id, _ := strconv.ParseInt(idStr, 10, 64) uid := this.GetSession("userid") if uid == nil { @@ -55,6 +58,7 @@ func (this *NoteController) Edit() { return } note.NoteHtml = noteHtml + note.NoteVal = noteVal err := noteService.EditNote(note) if err == nil { this.Data["json"] = models.ReurnSuccess("") @@ -77,7 +81,7 @@ func (this *NoteController) SaveNoteColl() { note := &models.NoteColl{Title: title, UserId: uid.(int64)} err := noteService.SaveNoteColl(note) if err == nil { - this.Data["json"] = models.ReurnData("",note) + this.Data["json"] = models.ReurnData("", note) } else { this.Data["json"] = models.ReurnError(500, "保存失败") } @@ -229,4 +233,4 @@ func (this *NoteController) NoteApi() { } this.Data["json"] = noteColls this.ServeJSON() -} \ No newline at end of file +} diff --git a/routers/NoteRouter.go b/routers/NoteRouter.go index 231056b..887accc 100644 --- a/routers/NoteRouter.go +++ b/routers/NoteRouter.go @@ -8,7 +8,7 @@ import ( func init() { beego.Router("/api/note/:id([0-9]+)", &controllers.NoteController{}, "get:Get") beego.Router("/note", &controllers.NoteController{}, "get:Note") - beego.Router("/note/api", &controllers.NoteController{}, "get:NoteApi") + beego.Router("/api/note", &controllers.NoteController{}, "get:NoteApi") beego.Router("/api/notecoll/save", &controllers.NoteController{}, "post:SaveNoteColl") beego.Router("/api/notecoll/edit", &controllers.NoteController{}, "post:EditNoteColl") beego.Router("/api/note/save", &controllers.NoteController{}, "post:Save") diff --git a/views/note.html b/views/note.html index a443fc6..8cdf821 100644 --- a/views/note.html +++ b/views/note.html @@ -62,7 +62,23 @@
- + + + + + ${ item.title } + + + + + + + + 添加文件夹 添加笔记 @@ -87,7 +103,8 @@ 'mavon-editor': MavonEditor.mavonEditor }, data: { - drawer: true, + modal1: false, + drawer: false, externalLink: { // markdown_css: function() { // // 这是你的markdown css文件路径 @@ -125,7 +142,7 @@ /* 1.3.5 */ undo: true, // 上一步 //redo: true, // 下一步 - //trash: true, // 清空 + trash: true, // 清空 save: true, // 保存(触发events中的save事件) /* 1.4.2 */ navigation: true, // 导航目录 @@ -139,104 +156,125 @@ menu: true, // 预览 }, notes: [], - meval: '' + currentNote: {}, + meval: '', + noteCols: [] + }, mounted() { var _this = this - $.get("/note/api", function (data, status) { + $.get("/api/note", function (data, status) { _this.notes = data + data.forEach((el) => { + _this.noteCols.push({title: el.Title, id: el.Id}) + }) }) }, methods: { + okHandler() { + var _this = this + if (!this.currentNote.pid) { + this.$Notice.warning({ + title: '请选择文件夹后重新保存', + desc: '' + }) + return + } + if (!this.currentNote.title) { + this.$Notice.warning({ + title: '请输入笔记名称后重新保存', + desc: '' + }) + return + } + $.post('/api/note/save/', { + pid: this.currentNote.pid, + title: this.currentNote.title, + noteHtml: this.currentNote.NoteHtml + noteVal: this.currentNote.NoteVal + }, + function (data) { + if (data.Status == 500) { + _this.$Notice.error({ + title: '保存失败', + desc: '' + }) + } else if (data.Status == 401) { + window.location.href = "/login" + } else { + _this.currentNote.Id = data.Id + debugger + _this.$Notice.success({ + title: '保存成功', + desc: '' + }) + } + }, 'json') + }, + cancelHandler() { + this.$Notice.warning({ + title: '笔记没有被保存!!!', + desc: '' + }) + }, noteSelectHandler(id) { var _this = this this.notes.forEach((item) => { item.Notes.forEach((note) => { if (id == note.Id) { + _this.currentNote = note _this.meval = note.NoteVal ? note.NoteVal : note.NoteHtml } }) }) + }, + saveHandler(value, render) { + this.currentNote.NoteVal = value + this.currentNote.NoteHtml = render + if (!this.currentNote.Id) { + this.modal1 = true + } else { + this.editHandler(value, render) + } + }, + editHandler(value, render) { + var _this = this + $.post('/api/note/edit/' + this.currentNote.Id, { + noteHtml: render, + noteVal: value + }, + function (data) { + if (data.Status == 0) { + _this.$Notice.success({ + title: '保存成功', + desc: '' + }) + } else if (data.Status == 401) { + window.location.href = "/login" + } else { + _this.$Notice.error({ + title: '保存失败', + desc: '' + }) + } + }, 'json') } } })