Ver a proveniência

阿里坑爹货&博客本地保存

layui
yirenyishi há 6 anos
ascendente
cometimento
0cf1b06071
  1. 19
      controllers/BlogController.go
  2. 2
      controllers/NoteController.go
  3. BIN
      data/beeblog.db
  4. 2
      models/DataInit.go
  5. 14
      models/Result.go
  6. 14
      service/CategoryService.go
  7. 1
      static/css/sui.css
  8. 4
      static/js/aljquery.js
  9. 12
      static/js/sui.js
  10. 10
      views/500.html
  11. 7
      views/T.header.tpl
  12. 14
      views/blog.html
  13. 8
      views/blogs.html
  14. 3
      views/iframe/blog.html
  15. 85
      views/newblog.html
  16. 2
      views/note.html

19
controllers/BlogController.go

@ -13,6 +13,12 @@ type BlogController struct {
}
func (this *BlogController) Save() {
uid := this.GetSession("userid")
if uid == nil{
this.Data["json"] = models.ReurnError(401, "")
this.ServeJSON()
return
}
title := this.GetString("title")
blogHtml := this.GetString("blogHtml")
catory := this.GetString("catory")
@ -21,7 +27,7 @@ func (this *BlogController) Save() {
blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: 1}
err := service.SaveBlog(blog, labels)
if err == nil {
this.Data["json"] = blog
this.Data["json"] = models.ReurnSuccess("")
} else {
this.Data["json"] = models.ReurnError(500, "保存失败")
}
@ -40,6 +46,11 @@ func (this *BlogController) Get() {
}
func (this *BlogController) New() {
uid := this.GetSession("userid")
if uid == nil {
this.Redirect("/login.html",302)
return
}
this.TplName = "newblog.html"
}
func (this *BlogController) Blog1() {
@ -47,6 +58,11 @@ func (this *BlogController) Blog1() {
}
func (this *BlogController) BlogsPage() {
cats,errcat := service.GetCats()
if errcat != nil {
this.Redirect("500.html", 302)
return
}
num, _ := this.GetInt("num")
size, _ := this.GetInt("size")
cat, _ := this.GetInt64("cat")
@ -67,6 +83,7 @@ func (this *BlogController) BlogsPage() {
return
}
this.Data["Page"] = pages
this.Data["Cats"] = cats
this.Data["Cat"] = cat
this.Data["Flag"] = flag
this.Data["IsBlog"] = true

2
controllers/NoteController.go

@ -139,7 +139,7 @@ func (this *NoteController) Delete() {
func (this *NoteController) Note() {
uid := this.GetSession("userid")
if uid == nil {
this.Redirect("/login", 302)
this.Redirect("/login.html", 302)
}
noteColls, err := service.GetNoteColl(uid.(int64))
if err == nil {

BIN
data/beeblog.db

Ficheiro binário não mostrado.

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),new(Note),new(NoteColl))
orm.RegisterModel(new(Attachment),new(User),new(Blog),new(NLabel),new(Note),new(NoteColl),new(Category))
orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite)
orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10)
}

14
models/Result.go

@ -5,21 +5,29 @@ type Error struct {
Msg string
}
func ReurnError(status int,msg string) *Error {
func ReurnError(status int, msg string) *Error {
if msg == "" {
msg = "error"
}
return &Error{Status: status, Msg: msg}
}
func ReurnSuccess(msg string) *Error {
if msg == "" {
msg = "success"
}
return &Error{Status: 0, Msg: msg}
}
type Success struct {
Status int
Msg string
Data interface{}
}
func ReurnSuccess(msg string) *Error {
func ReurnData(msg string, data interface{}) *Success {
if msg == "" {
msg = "success"
}
return &Error{Status: 0, Msg: msg}
return &Success{Status: 0, Msg: msg, Data: data}
}

14
service/CategoryService.go

@ -0,0 +1,14 @@
package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
)
func GetCats() ([]*models.Category, error) {
var notes []*models.Category
o := orm.NewOrm()
qs := o.QueryTable(models.Category{})
_, err := qs.All(&notes)
return notes, err
}

1
static/css/sui.css

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

4
static/js/aljquery.js

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

12
static/js/sui.js

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

10
views/500.html

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>500</h1>
</body>
</html>

7
views/T.header.tpl

@ -6,9 +6,12 @@
<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">
{{/*<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="//g.alicdn.com/sui/sui3/0.0.18/js/sui.min.js"></script>*/}}
<link rel="stylesheet" href="/static/css/sui.css">
{{/*<script type="text/javascript" src="/static/js/aljquery.js"></script>*/}}
<script type="text/javascript" src="/static/js/sui.js"></script>
<script type="text/javascript" src="/static/js/layer.js"></script>
<link type="text/css" rel="styleSheet" href="/static/css/common.css"/>
{{end}}

14
views/blog.html

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

8
views/blogs.html

@ -10,11 +10,9 @@
<div style="flex: 1">
<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>
{{range .Cats}}
<option value="{{.Id}}">{{.Title}}</option>
{{end}}
</select>
</span>
<div class="btn-group" role="group" style="display: inline-block;margin-top: -3px">

3
views/iframe/blog.html

@ -88,8 +88,7 @@
});
parent.tobj.labels = tarr
console.log(tarr)
parent.saveBlog(function (flag) {
debugger
parent.saveBlogCallback(function (flag) {
if (flag) {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);

85
views/newblog.html

@ -30,47 +30,78 @@
</div>
</body>
<script>
var storage=window.localStorage
var E = window.wangEditor
var editor = new E('#editor')
editor.customConfig.uploadImgServer = '/upload'
// 或者 var editor = new E( document.getElementById('editor') )
editor.create()
document.onkeydown = keyDown;
function keyDown(e) {
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")
saveBlog()
return
}
}
function saveBlog() {
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();
storage.setItem("blogHtml",tobj.blogHtml);
storage.setItem("blogTitle",tobj.title);
layer.open({
type: 2,
title: '发布文章',
shadeClose: true,
shade: 0.8,
area: ['420px', '280px'],
content: '/iframe/blog.html/' //iframe的url
});
}
var tobj = {}
$(function () {
var oldVal = storage.getItem("blogHtml");
editor.txt.html(oldVal);
var oldTitle = storage.getItem("blogTitle");
$("#blog-title").val(oldTitle);
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
});
saveBlog()
})
})
function saveBlog(callback) {
$.post('/blog/new',tobj,
function saveBlogCallback(callback) {
$.post('/blog/new', tobj,
function (data) {
console.log(data)
debugger
callback(true)
},'json')
if (data.Status == 0) {
storage.removeItem("blogHtml");
storage.removeItem("blogTitle");
layer.msg("保存成功", {icon: 6});
callback(true)
} else if (data.Status == 401) {
window.location.href = "login"
} else if (data.Status == 500) {
layer.msg("保存失败", {icon: 6});
callback(false)
}
}, 'json')
}
</script>
</html>

2
views/note.html

@ -110,7 +110,7 @@
return
}
var noteHtml = editor.txt.html()
if (editor.txt.text() && editor.txt.text().trim().length != 0) {
if (!editor.txt.text() && editor.txt.text().trim().length == 0) {
layer.msg('保存内容为空', function () {
});
return

Carregando…
Cancelar
Guardar