yirenyishi há 6 anos
ascendente
cometimento
e403ecd02d
  1. 15
      controllers/BlogController.go
  2. 12
      controllers/PageController.go
  3. BIN
      data/beeblog.db
  4. 1
      models/Blog.go
  5. 9
      models/Category.go
  6. 10
      models/NLabel.go
  7. 3
      routers/BlogRouter.go
  8. 2
      routers/router.go
  9. 13
      service/BlogService.go
  10. 2
      static/css/blog.css
  11. 2
      static/css/common.css
  12. 20
      static/css/newblog.css
  13. 2
      static/js/layer.js
  14. BIN
      static/js/theme/default/icon-ext.png
  15. BIN
      static/js/theme/default/icon.png
  16. 1
      static/js/theme/default/layer.css
  17. BIN
      static/js/theme/default/loading-0.gif
  18. BIN
      static/js/theme/default/loading-1.gif
  19. BIN
      static/js/theme/default/loading-2.gif
  20. 7
      views/T.header.tpl
  21. 57
      views/T.nav.tpl
  22. 2
      views/blog.html
  23. 106
      views/iframe/blog.html
  24. 42
      views/index.html
  25. 77
      views/newblog.html

15
controllers/BlogController.go

@ -5,6 +5,7 @@ import (
"beeblog/models"
"beeblog/service"
"strconv"
"fmt"
)
type BlogController struct {
@ -12,8 +13,14 @@ type BlogController struct {
}
func (this *BlogController) Save() {
blog := &models.Blog{Title: "ELK+logback+kafska+nginx 搭建分布式日志分析平台"}
err := service.SaveBlog(blog)
title := this.GetString("title")
blogHtml := this.GetString("blogHtml")
catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]")
fmt.Println(title,blogHtml,catoryId,labels,labels[0])
blog := &models.Blog{Title: title,BlogHtml:blogHtml,CategoryId:catoryId}
err := service.SaveBlog(blog,labels)
if (err == nil) {
this.Data["json"] = blog
} else {
@ -32,3 +39,7 @@ func (this *BlogController) Get() {
//this.Data["IsHome"] = true
this.TplName = "blog.html"
}
func (this *BlogController) New() {
this.TplName = "newblog.html"
}

12
controllers/PageController.go

@ -0,0 +1,12 @@
package controllers
import "github.com/astaxie/beego"
type PageController struct {
beego.Controller
}
// @router /iframe/blog [get]
func (this *PageController) Blog() {
this.TplName = "iframe/blog.html"
}

BIN
data/beeblog.db

Ficheiro binário não mostrado.

1
models/Blog.go

@ -18,7 +18,6 @@ type Blog struct {
Delflag int `orm:"default(0)"`
CategoryId int64
CtimeStr string `orm:"-"`
UserName string `orm:"-"`
CateName string `orm:"-"`
}

9
models/Category.go

@ -0,0 +1,9 @@
package models
import "time"
type Category struct {
Id int64
Title string
Ctime time.Time `orm:"auto_now_add;type(datetime)"`
}

10
models/NLabel.go

@ -0,0 +1,10 @@
package models
import "time"
type NLabel struct {
Id int64
Title string
UserId int64
Ctime time.Time `orm:"auto_now_add;type(datetime)"`
}

3
routers/BlogRouter.go

@ -6,6 +6,7 @@ import (
)
func init() {
beego.Router("/blog/save", &controllers.BlogController{}, "get:Save")
beego.Router("/blog/new", &controllers.BlogController{}, "post:Save")
beego.Router("/blog/:id([0-9]+)", &controllers.BlogController{}, "get:Get")
beego.Router("/blog/new", &controllers.BlogController{}, "get:New")
}

2
routers/router.go

@ -8,5 +8,5 @@ import (
func init() {
beego.Router("/", &controllers.IndexController{})
beego.Router("/map", &controllers.MapController{})
beego.Include(&controllers.PageController{})
}

13
service/BlogService.go

@ -10,7 +10,7 @@ type BlogService struct {
func GetBlog(id int64) (*models.Blog, error) {
o := orm.NewOrm()
blog := &models.Blog{Id:id}
blog := &models.Blog{Id: id}
err := o.Read(blog)
if err != nil {
return nil, err
@ -18,7 +18,6 @@ func GetBlog(id int64) (*models.Blog, error) {
return blog, nil
}
func FindBlogs() ([]*models.Blog, error) {
o := orm.NewOrm()
qs := o.QueryTable(&models.Blog{})
@ -30,13 +29,21 @@ func FindBlogs() ([]*models.Blog, error) {
return blogs, nil
}
func SaveBlog(blog *models.Blog) error {
func SaveBlog(blog *models.Blog, strs []string) error {
o := orm.NewOrm()
id, eror := o.Insert(blog)
if eror != nil {
return eror
} else {
blog.Id = id
if strs != nil && len(strs) > 0 {
nlabels := make([]*models.NLabel,len(strs))
//var nlabels [len(*strs)]*models.NLabel
for i := 0; i < len(strs); i++ {
nlabels[i] = &models.NLabel{Title:strs[i]}
}
o.InsertMulti(len(nlabels),nlabels)
}
o.Commit()
}
return nil

2
static/css/blog.css

@ -2,4 +2,4 @@
width: 100%;
height: 100%;
margin: 50px 4% 0 4%;
}
}

2
static/css/common.css

@ -19,7 +19,7 @@
}
::-webkit-scrollbar {
width: 1px;
width: 0px;
height: 0px;
}

20
static/css/newblog.css

@ -0,0 +1,20 @@
.blog-title{
display: flex;
height: 50px;
line-height: 50px;
}
.blog-title input{
flex: 1;
height: 44px;
border: 0;
}
.blog-title button{
height: 32px;
margin-top: 9px;
}
.w-e-toolbar{
height: 40px;
line-height: 30px;
}

2
static/js/layer.js

A apresentação das diferenças entre ficheiros foi suprimida porque há linhas demasiado longas

BIN
static/js/theme/default/icon-ext.png

Ficheiro binário não mostrado.

Depois

Largura:  |  Altura:  |  Tamanho: 5.8 KiB

BIN
static/js/theme/default/icon.png

Ficheiro binário não mostrado.

Depois

Largura:  |  Altura:  |  Tamanho: 11 KiB

1
static/js/theme/default/layer.css

A apresentação das diferenças entre ficheiros foi suprimida porque há linhas demasiado longas

BIN
static/js/theme/default/loading-0.gif

Ficheiro binário não mostrado.

Depois

Largura:  |  Altura:  |  Tamanho: 5.7 KiB

BIN
static/js/theme/default/loading-1.gif

Ficheiro binário não mostrado.

Depois

Largura:  |  Altura:  |  Tamanho: 701 B

BIN
static/js/theme/default/loading-2.gif

Ficheiro binário não mostrado.

Depois

Largura:  |  Altura:  |  Tamanho: 1.7 KiB

7
views/T.header.tpl

@ -6,8 +6,9 @@
<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 href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui.min.css" rel="stylesheet">
<script type="text/javascript" src="http://g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="http://g.alicdn.com/sj/dpl/1.5.1/js/sui.min.js"></script>
<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>
<link type="text/css" rel="styleSheet" href="/static/css/common.css"/>
{{end}}

57
views/T.nav.tpl

@ -1,22 +1,43 @@
{{define "nav"}}
<div class='nav-container'>
<div class="sui-navbar">
<div class="navbar-inner">
<a href="/" class="sui-brand">个人随笔</a>
<ul class="sui-nav">
<li {{if .IsHome}}class="active"{{end}}><a href="/">首页</a></li>
<li {{if .IsNote}}class="active"{{end}}><a href="/note">笔记</a></li>
<li {{if .IsMap}}class="active"{{end}}><a href="/map">地图</a></li>
</ul>
<form class="sui-form sui-form pull-left">
<input type="text" placeholder="宝贝/店铺名称...">
<button class="sui-btn">搜索</button>
</form>
<ul class="sui-nav pull-right">
<li><a href="#">个人中心</a></li>
<li><a href="#">帮助</a></li>
</ul>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">个人随笔</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">
<a href="/" target="_blank">首页 </a>
</li>
<li>
<a href="/note" target="_blank">笔记</a>
</li>
<li>
<a href="/map" target="_blank">地图</a>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">个人中心</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
{{end}}

2
views/blog.html

@ -1,6 +1,6 @@
{{template "header"}}
<title>博客 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/blog.css"/>
<link type="text/css" rel="styleSheet" href="/static/css/newblog.css"/>
</head>
<body>
<div class="root-container">

106
views/iframe/blog.html

@ -0,0 +1,106 @@
<!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: 10px 0;
}
.tag {
margin: 3px 0;
}
</style>
</head>
<body>
<div style="margin: 5px 10px">
<div class="common">
<span>开发语言:</span>
<span>
<select class="form-control " style="width: 150px;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 style="flex: 1;height: 30px;line-height: 30px;">文章标签:</span>
<div class="tag-group tag-removable" data-toggle='tag' id="labels">
</div>
</div>
<div class="common">
<span>添加标签:</span>
<input type="text" placeholder="输入标签" class="input-xfat" style="height: 26px;" id="lable">
<button type="button" class="btn btn-primary" style="height: 26px;margin-top: -5px;" id="addBtn">添加</button>
</div>
<div class="common" style="text-align: center">
<button type="button" class="btn btn-primary" id="saveBtn">首要</button>
<button type="button" class="btn btn-warning" id="cacelBtn">取消</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)
}
}
$("#addBtn").click(function () {
var temp = $("#lable").val()
if (temp.trim().length != 0) {
if ($("#labels").children().length > 5) {
layer.msg('5个标签还不够', function () {
});
return
}
var child = "<label class='tag tag-primary'>" + temp + "<a name='remove'><i class=\"iconfont icon-close\"></i></a> "
+ "<input type='checkbox' class='simple-tag' name='simple-tag-1' value='" + temp + "' checked='checked'/></label>"
$("#labels").append(child)
$("#lable").val("")
}
})
$("#saveBtn").click(function () {
parent.tobj.catory = $("#catory").val()
var tarr = []
$.each($(".simple-tag"), function () {
tarr.push($(this).val())
});
parent.tobj.labels = tarr
console.log(tarr)
parent.saveBlog(function (flag) {
debugger
if (flag) {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
}
})
})
$("#cacelBtn").click(function () {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
})
})
</script>
</html>

42
views/index.html

@ -8,26 +8,21 @@
<div class="home-container">
<div class="home-hearder">
<div style="flex: 1">
<span class="sui-dropdown dropdown-bordered select dropdown-large">
<span class="dropdown-inner">
<a id="select" role="button" href="javascript:void(0);" data-toggle="dropdown"
class="dropdown-toggle">
<input value="hz" name="city" type="hidden"><i class="caret"></i><span>选择分类</span></a>
<ul role="menu" aria-labelledby="drop4" class="sui-dropdown-menu">
<li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0);"
value="bj">北京</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0);" value="sb">圣彼得堡</a></li>
<li role="presentation" class="active"><a role="menuitem" tabindex="-1" href="javascript:void(0);"
value="hz">杭州</a></li>
</ul>
<span>
<select class="form-control input-lg" style="width: 150px;display: inline-block;height: 32px">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</span>
</span>
<div class="sui-btn-group ">
<button class="sui-btn btn-primary btn-large btn-bordered">最新</button>
<button class="sui-btn btn-primary btn-large btn-bordered">最热</button>
<div class="btn-group" role="group" style="display: inline-block;margin-top: -3px">
<button type="button" class="btn btn-default btn-xl">最新</button>
<button type="button" class="btn btn-default btn-xl">最热</button>
</div>
</div>
<a href="/blog/new" target="_blank" class="sui-btn btn-bordered btn-large nelson-btn">写文章</a>
<button type="button" onclick="window.open('/blog/new')" class="btn btn-danger" style="border-radius: 12px">写文章</button>
</div>
<div>
<div class="home-content" style="min-height: 40px;line-height: 40px;color: #888">
@ -49,14 +44,14 @@
<div>
<div class="home-content">
<div class="home-content-title cursor">
<a href="/blog/{{.Id}}">{{.Title}}</a>
<a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a>
</div>
<div style="display: inline-block;width: 260px">
<div class="home-content-desc">
<span style="width: 60px;font-size: 14px">{{.CateName}}</span>
<span style="width: 60px" class="cursor">{{.UserName}}</span>
<span style="width: 60px;font-size: 14px">2555</span>
<span style="flex: 1;font-size: 14px">{{.CtimeStr}}</span>
<span style="width: 60px;font-size: 14px">{{.Browses}}</span>
<span style="flex: 1;font-size: 14px">{{.Ctime.Format "2006-01-02"}}</span>
</div>
</div>
</div>
@ -64,4 +59,11 @@
</div>
{{end}}
</body>
<script>
// $(function () {
// $("#").click(function () {
// window.open("")
// })
// })
</script>
</html>

77
views/newblog.html

@ -0,0 +1,77 @@
{{template "header"}}
<title>博客 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/newblog.css"/>
<script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>
{{/*<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>*/}}
</head>
<body>
<div class="root-container">
<div class="blog-title">
<input type="text" id="blog-title">
<button type="button" id="newBtn" class="btn btn-danger" style="border-radius: 12px">发布文章</button>
</div>
<div id="editor" class="editor">
</div>
<div id="myModal" tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
<h4 id="myModalLabel" class="modal-title">Modal title</h4>
</div>
<div class="modal-body">我是内容body</div>
<div class="modal-footer">
<button type="button" data-ok="modal" class="sui-btn btn-primary btn-large">可自定ok</button>
<button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">可自定dismiss</button>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var E = window.wangEditor
var editor = new E('#editor')
editor.customConfig.uploadImgServer = '/upload'
// 或者 var editor = new E( document.getElementById('editor') )
editor.create()
var tobj = {}
$(function () {
var height = document.documentElement.clientHeight
$(".w-e-text-container").height(height - 50 - 40 - 1);
$("#newBtn").click(function () {
var title = $("#blog-title").val();
if (title.trim().length < 3) {
layer.msg('文章标题最少三个字', function () {
});
return
}
tobj.title = $("#blog-title").val();
if (editor.txt.text().trim().length == 0) {
layer.msg('文章内容不能为空哦', function () {
});
return
}
tobj.blogHtml = editor.txt.html();
layer.open({
type: 2,
title: '发布文章',
shadeClose: true,
shade: 0.8,
area: ['420px', '280px'],
content: '/iframe/blog.html/' //iframe的url
});
})
})
function saveBlog(callback) {
$.post('/blog/new',tobj,
function (data) {
console.log(data)
debugger
callback(true)
},'json')
}
</script>
</html>
Carregando…
Cancelar
Guardar