Browse Source

笔记保存

layui
mail_yanpeng@163.com 6 years ago
parent
commit
35892fcbfe
  1. 48
      controllers/NoteController.go
  2. 5
      controllers/PageController.go
  3. BIN
      data/beeblog.db
  4. 1
      main.go
  5. 2
      models/DataInit.go
  6. 19
      models/Note.go
  7. 9
      models/NoteColl.go
  8. 12
      routers/NoteRouter.go
  9. 49
      service/NoteService.go
  10. 73
      static/css/menunav.css
  11. 14
      static/css/notemenu.css
  12. BIN
      static/img/menu.png
  13. 79
      views/iframe/note.html
  14. 117
      views/note.html

48
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()
}

5
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

BIN
data/beeblog.db

Binary file not shown.

1
main.go

@ -17,7 +17,6 @@ func main() {
orm.Debug = true
orm.RunSyncdb("default",false,true)
beego.Run()
}

2
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)
}

19
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
}
Id int64
UserId int64
Title string
NoteHtml string `type(text)"`
Pid int64
Utime time.Time `orm:"auto_now_add;type(datetime)"`
}

9
models/NoteColl.go

@ -0,0 +1,9 @@
package models
/**
文章
*/
type NoteColl struct {
Id int64
UserId int64
Title string
}

12
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")
}

49
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
}

73
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;
}

14
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;

BIN
static/img/menu.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

79
views/iframe/note.html

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="个人随笔是一个面向IT技术人员,提供个人平时工作总结和在线记录学习笔记,个人技术博客,在线云笔记,码农笔录,最新的技术博客,www.aiprose.com">
<meta name="keywords"
content="个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,www.aiprose.com,aiprose.com,aiprose">
<link rel="stylesheet" href="//g.alicdn.com/sui/sui3/0.0.18/css/sui.min.css">
<script type="text/javascript" src="//g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="//g.alicdn.com/sui/sui3/0.0.18/js/sui.min.js"></script>
<script type="text/javascript" src="/static/js/layer.js"></script>
<title>首页 - 个人随笔</title>
<style>
.common {
margin: 15px 0;
display: flex;
height: 32px;
line-height: 32px;
}
</style>
</head>
<body>
<div style="margin: 20px 35px;">
<div class="common">
<span>所属文件夹:</span>
<span style="flex: 1">
<select class="form-control " style="display: inline-block;height: 32px" id="catory">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</span>
</div>
<div class="common">
<span>新笔记名称:</span>
<input type="text" placeholder="输入标签" class="input-xfat" style="height: 32px;flex: 1" id="lable">
</div>
<div class="common" style="text-align: center">
<button type="button" class="btn btn-primary btn-lg btn-block" id="saveBtn">保存</button>
</div>
</div>
</body>
<script>
$(function () {
// if (parent.tobj.catory) {
// $("#catory").val(parent.tobj.catory)
// }
// if (parent.tobj.labels) {
// for (var i = 0; i < parent.tobj.labels.length; i++) {
// var child = "<label class='tag tag-primary'>" + parent.tobj.labels[i] + "<a name='remove'><i class=\"iconfont icon-close\"></i></a> "
// + "<input type='checkbox' class='simple-tag' name='simple-tag-1' value='" + parent.tobj.labels[i] + "' checked='checked'/></label>"
// $("#labels").append(child)
// }
// }
$("#saveBtn").click(function () {
var pid = $("#catory").val()
var title = $("#lable").val()
$.post('/note/save', {
pid: pid,
title: title
},
function (data) {
debugger
if (!data.Status) {
parent.layer.msg("保存成功", {icon: 6});
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
}
}, 'json')
})
})
</script>
</html>

117
views/note.html

@ -4,71 +4,95 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content="个人随笔是一个面向IT技术人员,提供个人平时工作总结和在线记录学习笔记,个人技术博客,在线云笔记,码农笔录,最新的技术博客,www.aiprose.com">
<meta name="keywords" content="个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,www.aiprose.com,aiprose.com,aiprose">
<meta name="keywords"
content="个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,www.aiprose.com,aiprose.com,aiprose">
<link rel="stylesheet" href="//g.alicdn.com/sui/sui3/0.0.18/css/sui.min.css">
{{/*<script type="text/javascript" src="//g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>*/}}
{{/*<script type="text/javascript" src="//g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>*/}}
<title>笔记 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/menu-reset.css"/>
<link type="text/css" rel="styleSheet" href="/static/css/notemenu.css"/>
<link type="text/css" rel="styleSheet" href="/static/css/menunav.css"/>
<script src="/static/js/menu.js"></script> <!-- Modernizr -->
<script src="/static/js/jquery-1.11.1.min.js"></script>
<script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>
<style>
.w-e-toolbar {
height: 40px;
line-height: 30px;
}
::-webkit-scrollbar {
width: 1px;
height: 5px;
}
::-webkit-scrollbar-track-piece {
background-color: rgba(0, 0, 0, 0.1);
-webkit-border-radius: 6px;
}
</style>
</head>
<body>
<header>
<a id="cd-menu-trigger" href="#0"><span class="cd-menu-icon"></span></a>
<header id="slide-container">
<a id="cd-menu-trigger" href="javascript:void(0)"><span class="cd-menu-icon"></span></a>
</header>
<div class="cd-main-content">
<div id="editor" class="editor">
</div>
<nav class="note-nav">
<input type="checkbox" id="joacims-menu"/>
<label for="joacims-menu"><span><img src="/static/img/menu.png"
style="width: 25px;height: 25px;"> </span></label>
<nav>
<a href="/" target="_blank">首页</a>
<a href="http://sc.chinaz.com/">个人中心</a>
<a href="javascript:void(0)" id="newNote">新增笔记</a>
<a href="javascript:void(0)">Blog</a>
<a href="javascript:void(0)">Portfolio</a>
<a href="javascript:void(0)">Shortcodes</a>
</nav>
</nav>
</div> <!-- cd-main-content -->
<nav id="cd-lateral-nav">
<ul class="cd-navigation">
<li class="item-has-children">
<a href="#0">Services</a>
<a href="javascript:void(0)">Services</a>
<ul class="sub-menu">
<li><a href="#0">Brand</a></li>
<li><a href="#0">Web Apps</a></li>
<li><a href="#0">Mobile Apps</a></li>
<li><a href="javascript:void(0)" onclick="noteClick(1)">Brand</a></li>
<li><a href="javascript:void(0)">Web Apps</a></li>
<li><a href="javascript:void(0)">Mobile Apps</a></li>
</ul>
</li> <!-- item-has-children -->
<li class="item-has-children">
<a href="#0">Products</a>
<a href="javascript:void(0)">Products</a>
<ul class="sub-menu">
<li><a href="#0">Product 1</a></li>
<li><a href="#0">Product 2</a></li>
<li><a href="#0">Product 3</a></li>
<li><a href="#0">Product 4</a></li>
<li><a href="#0">Product 5</a></li>
<li><a href="javascript:void(0)">Product 1</a></li>
<li><a href="javascript:void(0)">Product 2</a></li>
<li><a href="javascript:void(0)">Product 3</a></li>
<li><a href="javascript:void(0)">Product 4</a></li>
<li><a href="javascript:void(0)">Product 5</a></li>
</ul>
</li> <!-- item-has-children -->
</ul> <!-- cd-navigation -->
<ul class="cd-navigation cd-single-item-wrapper">
<li><a href="#0">Tour</a></li>
<li><a href="#0">Login</a></li>
<li><a href="#0">Register</a></li>
<li><a href="#0">Pricing</a></li>
<li><a href="#0">Support</a></li>
<li><a href="javascript:void(0)">新增文章</a></li>
</ul> <!-- cd-single-item-wrapper -->
<!-- cd-single-item-wrapper -->
<div class="cd-navigation socials">
<a class="cd-twitter cd-img-replace" href="#0">Twitter</a>
<a class="cd-github cd-img-replace" href="#0">Git Hub</a>
<a class="cd-facebook cd-img-replace" href="#0">Facebook</a>
<a class="cd-google cd-img-replace" href="#0">Google Plus</a>
</div> <!-- socials -->
{{/* <div class="cd-navigation socials">
<a class="cd-twitter cd-img-replace" href="javascript:void(0)">Twitter</a>
<a class="cd-github cd-img-replace" href="javascript:void(0)">Git Hub</a>
<a class="cd-facebook cd-img-replace" href="javascript:void(0)">Facebook</a>
<a class="cd-google cd-img-replace" href="javascript:void(0)">Google Plus</a>
</div>*/}}
</nav>
<script src="/static/js/menu.js"></script> <!-- Resource jQuery -->
<script type="text/javascript" src="/static/js/layer.js"></script>
</body>
@ -78,5 +102,42 @@
editor.customConfig.uploadImgServer = '/upload'
// 或者 var editor = new E( document.getElementById('editor') )
editor.create()
editor.txt.html("<p>点击右上角菜单新建或者选择笔记</p>");
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
});
})
})
</script>
</html>
Loading…
Cancel
Save