From 35892fcbfe3425e97291ab74b01f1be23052be53 Mon Sep 17 00:00:00 2001 From: "mail_yanpeng@163.com" Date: Mon, 19 Nov 2018 18:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=94=E8=AE=B0=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/NoteController.go | 48 +++++++++++++- controllers/PageController.go | 5 ++ data/beeblog.db | Bin 32768 -> 36864 bytes main.go | 1 - models/DataInit.go | 2 +- models/Note.go | 19 ++++-- models/NoteColl.go | 9 +++ routers/NoteRouter.go | 12 ++++ service/NoteService.go | 49 ++++++++++++++ static/css/menunav.css | 73 +++++++++++++++++++++ static/css/notemenu.css | 14 ++-- static/img/menu.png | Bin 0 -> 297 bytes views/iframe/note.html | 79 +++++++++++++++++++++++ views/note.html | 117 ++++++++++++++++++++++++++-------- 14 files changed, 383 insertions(+), 45 deletions(-) create mode 100644 models/NoteColl.go create mode 100644 routers/NoteRouter.go create mode 100644 service/NoteService.go create mode 100644 static/css/menunav.css create mode 100644 static/img/menu.png create mode 100644 views/iframe/note.html diff --git a/controllers/NoteController.go b/controllers/NoteController.go index 9da9171..b327fbf 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -1,8 +1,54 @@ package controllers -import "github.com/astaxie/beego" +import ( + "github.com/astaxie/beego" + "strconv" + "beeblog/models" + "beeblog/service" + "fmt" +) type NoteController struct { beego.Controller } +func (this *NoteController) Save() { + 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 + } else { + this.Data["json"] = models.ReurnError("保存失败") + } + this.ServeJSON() +} + +func (this *NoteController) SaveNoteColl() { + title := this.GetString("title") + uid := this.GetSession("userid").(int64) + + note := &models.NoteColl{Title: title, UserId: uid} + err := service.SaveNoteColl(note) + if err == nil { + this.Data["json"] = note + } else { + this.Data["json"] = models.ReurnError("保存失败") + } + this.ServeJSON() +} + +func (this *NoteController) Get() { + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + note := &models.Note{Id: id} + err := service.GetNote(note) + if err == nil { + this.Data["json"] = note + } + this.ServeJSON() +} diff --git a/controllers/PageController.go b/controllers/PageController.go index 48db4dc..66f70a4 100644 --- a/controllers/PageController.go +++ b/controllers/PageController.go @@ -11,6 +11,11 @@ func (this *PageController) Blog() { this.TplName = "iframe/blog.html" } +// @router /iframe/note [get] +func (this *PageController) IframeNote() { + this.TplName = "iframe/note.html" +} + // @router /note [get] func (this *PageController) Note() { this.Data["IsNote"] = true diff --git a/data/beeblog.db b/data/beeblog.db index 40d3cd7e24b938b20e4675e4a6b3a65fdabbce60..a2344af38e23516c6d970623001778c1ea1726bc 100644 GIT binary patch delta 249 zcmZo@U}{*vG(lQWm4ShQ6Nq7eYod;^tSW<^MiwuhG6M%YCj;MYzD_=E?grjpoc~B1E(l2r+-Omafy+Ep@puY ep{}8&f}w$xfq|8&k)EZ2nTe&Dg*K39U;qGdB0xC+ delta 88 zcmZozz|_#dG(lQWk%57M1BhXOeWH%Bv?7C^MiwuhG6Oq@JpnjET0MR%UwEzGB diff --git a/main.go b/main.go index b370be4..6bd5e27 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ func main() { orm.Debug = true orm.RunSyncdb("default",false,true) - beego.Run() } diff --git a/models/DataInit.go b/models/DataInit.go index b456bdb..32d491d 100644 --- a/models/DataInit.go +++ b/models/DataInit.go @@ -19,7 +19,7 @@ func RegistDB() { os.Create(_DB_NAME) } //orm.RegisterModel(new(Attachment),new(Topic)) - orm.RegisterModel(new(Attachment),new(User),new(Blog),new(NLabel)) + orm.RegisterModel(new(Attachment),new(User),new(Blog),new(NLabel),new(Note)) orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite) orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10) } \ No newline at end of file diff --git a/models/Note.go b/models/Note.go index c8e9394..adcde5a 100644 --- a/models/Note.go +++ b/models/Note.go @@ -1,10 +1,15 @@ package models +import "time" + +/** + 笔记 + */ type Note struct { - Id int64 - UserId int64 - Title string - NoteVal string `orm:"size(3500)"` - NoteHtml string `orm:"size(5000)"` - Pid int64 -} \ No newline at end of file + Id int64 + UserId int64 + Title string + NoteHtml string `type(text)"` + Pid int64 + Utime time.Time `orm:"auto_now_add;type(datetime)"` +} diff --git a/models/NoteColl.go b/models/NoteColl.go new file mode 100644 index 0000000..9b4e144 --- /dev/null +++ b/models/NoteColl.go @@ -0,0 +1,9 @@ +package models +/** + 文章 + */ +type NoteColl struct { + Id int64 + UserId int64 + Title string +} \ No newline at end of file diff --git a/routers/NoteRouter.go b/routers/NoteRouter.go new file mode 100644 index 0000000..44c631c --- /dev/null +++ b/routers/NoteRouter.go @@ -0,0 +1,12 @@ +package routers + +import ( + "github.com/astaxie/beego" + "beeblog/controllers" +) + +func init() { + beego.Router("/note/:id([0-9]+)", &controllers.NoteController{}, "get:Get") + beego.Router("/notecoll/save", &controllers.NoteController{}, "post:SaveNoteColl") + beego.Router("/note/save", &controllers.NoteController{}, "post:Save") +} diff --git a/service/NoteService.go b/service/NoteService.go new file mode 100644 index 0000000..88fbbb9 --- /dev/null +++ b/service/NoteService.go @@ -0,0 +1,49 @@ +package service + +import ( + "beeblog/models" + "github.com/astaxie/beego/orm" +) + +type NoteService struct { +} + +func SaveNote(note *models.Note) error { + o := orm.NewOrm() + id, err := o.Insert(note) + if err == nil { + note.Id = id + } + return err +} + +func GetNote(note *models.Note) error { + o := orm.NewOrm() + return o.Read(note) +} + +func GetNoteByPid(pid int64) ([]*models.Note, error) { + var notes []*models.Note + o := orm.NewOrm() + qs := o.QueryTable(models.Note{}) + _, err := qs.Filter("Pid", pid).All(notes) + return notes,err +} + + +func SaveNoteColl(note *models.NoteColl) error { + o := orm.NewOrm() + id, err := o.Insert(note) + if err == nil { + note.Id = id + } + return err +} + +func GetNoteColl(uid int64) ([]*models.NoteColl, error) { + var notes []*models.NoteColl + o := orm.NewOrm() + qs := o.QueryTable(models.NoteColl{}) + _, err := qs.Filter("UserId", uid).All(notes) + return notes,err +} \ No newline at end of file diff --git a/static/css/menunav.css b/static/css/menunav.css new file mode 100644 index 0000000..3e1764f --- /dev/null +++ b/static/css/menunav.css @@ -0,0 +1,73 @@ +.note-nav{ + position: fixed; + left: 0; + top: 50%; + z-index: 99999; +} + + +input[id*="joacims-menu"] { + display:none; +} + +input[id*="joacims-menu"] + label { + display:block; + width:35px; + height:35px; + background:#222; + cursor:pointer; + font-size:30px; + color:#fff; + position:relative; +} + +input[id*="joacims-menu"] + label span { + display:block; + position:absolute; + top: 2px; + left: 5px; + transition:.2s; +} + +input[id*="joacims-menu"]:checked + label span { + transform:rotate(45deg); + font-size:34px; + top:0px; + left:5px; +} + +.note-nav a { + display:block; + height:40px; + line-height:40px; + background:#3e3e3e; + width:100px; + padding-left:10px; + text-decoration:none; + color:white; + box-shadow:5px 0 0 #000; +} + +input[id*="joacims-menu"] ~ nav a:nth-child(1) { box-shadow:5px 0 0 #3498db; transition-delay:.05s; } +input[id*="joacims-menu"] ~ nav a:nth-child(2) { box-shadow:5px 0 0 #2ecc71; transition-delay:.10s; } +input[id*="joacims-menu"] ~ nav a:nth-child(3) { box-shadow:5px 0 0 #e67e22; transition-delay:.15s; } +input[id*="joacims-menu"] ~ nav a:nth-child(4) { box-shadow:5px 0 0 #c0392b; transition-delay:.20s; } +input[id*="joacims-menu"] ~ nav a:nth-child(5) { box-shadow:5px 0 0 #2c3e50; transition-delay:.25s; } +input[id*="joacims-menu"] ~ nav a:nth-child(6) { box-shadow:5px 0 0 #f1c40f; transition-delay:.30s; } + +input[id*="joacims-menu"]:checked ~ nav a { + margin-left:0px; +} + +input[id*="joacims-menu"]:checked ~ nav a:hover { + width:110px; +} + +input[id*="joacims-menu"] ~ nav a { + margin-left:-110px; + transition:.6s margin; +} + +input[id*="joacims-menu"] ~ nav a:hover { + background:#999; +} \ No newline at end of file diff --git a/static/css/notemenu.css b/static/css/notemenu.css index 4a3a497..106c5a1 100644 --- a/static/css/notemenu.css +++ b/static/css/notemenu.css @@ -88,9 +88,8 @@ header { position: absolute; top: 0; right: 0; - height: 20px; - width: 20px; - background: #4e6361; + height: 39px; + width: 40px; z-index: 3; /* Force Hardware Acceleration in WebKit */ -webkit-transform: translateZ(0); @@ -115,7 +114,7 @@ header.is-fixed { } @media only screen and (min-width: 768px) { header { - height: 20px; + height: 39px; } } @@ -138,7 +137,7 @@ header.is-fixed { right: 0; top: 0; height: 100%; - width: 50px; + width: 40px; background-color: #64807d; } #cd-menu-trigger .cd-menu-text { @@ -207,7 +206,7 @@ header.is-fixed { } @media only screen and (min-width: 768px) { #cd-menu-trigger { - width: 110px; + width: 40px; padding-left: 1.25em; } #cd-menu-trigger .cd-menu-text { @@ -215,7 +214,7 @@ header.is-fixed { line-height: 70px; } #cd-menu-trigger .cd-menu-icon { - left: auto; + left: 30%; right: 1.25em; -webkit-transform: translateX(0); -moz-transform: translateX(0); @@ -263,6 +262,7 @@ header.is-fixed { line-height: 2em; padding: 0 16px 0 32px; color: #aab5b7; + text-decoration:none; } #cd-lateral-nav a.current { background-color: #3a4a4d; diff --git a/static/img/menu.png b/static/img/menu.png new file mode 100644 index 0000000000000000000000000000000000000000..62476be25befbc9afc352072df2c8a1ccd5630ff GIT binary patch literal 297 zcmV+^0oMMBP)J+c2a{ zwc#hQ9rz + + + + + + + + + + + 首页 - 个人随笔 + + + +
+
+ 所属文件夹: + + + +
+
+ 新笔记名称: + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/views/note.html b/views/note.html index e1eacb2..32b49d6 100644 --- a/views/note.html +++ b/views/note.html @@ -4,71 +4,95 @@ - + - {{/**/}} +{{/**/}} 笔记 - 个人随笔 + + -
- - +
+
-
+ +
- @@ -78,5 +102,42 @@ editor.customConfig.uploadImgServer = '/upload' // 或者 var editor = new E( document.getElementById('editor') ) editor.create() + editor.txt.html("

点击右上角菜单新建或者选择笔记

"); + + document.onkeydown = keyDown; + + function keyDown(e) { + 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 () { + var height = document.documentElement.clientHeight + $(".w-e-text-container").height(height - 40 - 3); + + layer.tips('文章列表点我', '#slide-container', { + tips: [3, '#78BA32'] + }); + + $("#newNote").click(function () { + layer.open({ + type: 2, + title: '新增笔记', + shadeClose: true, + shade: 0.8, + area: ['360px', '280px'], + content: '/iframe/note.html' //iframe的url + }); + }) + }) \ No newline at end of file