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 a2344af..04a3207 100644 Binary files a/data/beeblog.db and b/data/beeblog.db differ diff --git a/main.go b/main.go index 6bd5e27..6666e32 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ func init() { func main() { orm.Debug = true orm.RunSyncdb("default",false,true) - + beego.BConfig.WebConfig.Session.SessionOn = true beego.Run() } diff --git a/models/DataInit.go b/models/DataInit.go index 32d491d..6474f16 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),new(Note)) + orm.RegisterModel(new(Attachment),new(User),new(Blog),new(NLabel),new(Note),new(NoteColl)) orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite) orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10) } \ No newline at end of file diff --git a/models/NoteColl.go b/models/NoteColl.go index 9b4e144..9119abe 100644 --- a/models/NoteColl.go +++ b/models/NoteColl.go @@ -6,4 +6,6 @@ type NoteColl struct { Id int64 UserId int64 Title string + + Notes []*Note `orm:"-"` } \ No newline at end of file diff --git a/routers/NoteRouter.go b/routers/NoteRouter.go index 44c631c..7b5385a 100644 --- a/routers/NoteRouter.go +++ b/routers/NoteRouter.go @@ -7,6 +7,7 @@ import ( func init() { beego.Router("/note/:id([0-9]+)", &controllers.NoteController{}, "get:Get") + beego.Router("/note", &controllers.NoteController{}, "get:Note") 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 index 88fbbb9..7970113 100644 --- a/service/NoteService.go +++ b/service/NoteService.go @@ -26,7 +26,7 @@ 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) + _, err := qs.Filter("Pid", pid).All(¬es) return notes,err } @@ -44,6 +44,6 @@ 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) + _, err := qs.Filter("UserId", uid).All(¬es) return notes,err } \ No newline at end of file diff --git a/views/iframe/note.html b/views/iframe/note.html index bbf5110..ac051d3 100644 --- a/views/iframe/note.html +++ b/views/iframe/note.html @@ -68,6 +68,7 @@ function (data) { debugger if (!data.Status) { + parent.addNoteCallback(data) parent.layer.msg("保存成功", {icon: 6}); var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); diff --git a/views/note.html b/views/note.html index 32b49d6..77ed0c3 100644 --- a/views/note.html +++ b/views/note.html @@ -47,10 +47,10 @@ style="width: 25px;height: 25px;"> @@ -76,21 +76,8 @@
  • Product 4
  • Product 5
  • - - - - - - - -{{/*
    - Twitter - Git Hub - Facebook - Google Plus -
    */}} + + @@ -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