mirror of https://github.com/mindoc-org/mindoc.git
实现单页文章功能
parent
3f6555ac82
commit
96ba414dd8
|
@ -89,6 +89,7 @@ func RegisterModel() {
|
|||
new(models.DocumentHistory),
|
||||
new(models.Migration),
|
||||
new(models.Label),
|
||||
new(models.Blog),
|
||||
)
|
||||
//migrate.RegisterMigration()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
)
|
||||
|
||||
type BlogController struct{
|
||||
BaseController
|
||||
|
@ -8,24 +12,93 @@ type BlogController struct{
|
|||
|
||||
func (c *BlogController) Index() {
|
||||
c.Prepare()
|
||||
|
||||
c.TplName = "blog/index.tpl"
|
||||
}
|
||||
|
||||
func (c *BlogController) List() {
|
||||
c.Prepare()
|
||||
c.TplName = "blog/list.tpl"
|
||||
|
||||
}
|
||||
|
||||
//管理后台
|
||||
func (c *BlogController) ManageList() {
|
||||
c.Prepare()
|
||||
c.TplName = "blog/manage_list.tpl"
|
||||
}
|
||||
|
||||
//文章设置
|
||||
func (c *BlogController) ManageSetting() {
|
||||
c.Prepare()
|
||||
c.TplName = "blog/manage_setting.tpl"
|
||||
//如果是post请求
|
||||
if c.Ctx.Input.IsPost() {
|
||||
blogId,_ := c.GetInt("id",0)
|
||||
blogTitle := c.GetString("title")
|
||||
blogIdentify := c.GetString("identify")
|
||||
orderIndex,_ := c.GetInt("order_index",0)
|
||||
blogType,_ := c.GetInt("blog_type",0)
|
||||
documentId,_ := c.GetInt("document_id",0)
|
||||
|
||||
if blogTitle == "" {
|
||||
c.JsonResult(6001,"文章标题不能为空")
|
||||
}
|
||||
if blogType != 0 && blogType != 1 {
|
||||
c.JsonResult(6005,"未知的文章类型")
|
||||
}else if documentId <= 0 && blogType == 1 {
|
||||
c.JsonResult(6006,"请选择链接的文章")
|
||||
}else if blogType == 1 && documentId > 0 && !models.NewDocument().IsExist(documentId){
|
||||
c.JsonResult(6007,"链接的文章不存在")
|
||||
}
|
||||
if strings.Count(blogTitle,"") > 200 {
|
||||
c.JsonResult(6002,"文章标题不能大于200个字符")
|
||||
}
|
||||
var blog *models.Blog
|
||||
var err error
|
||||
//如果文章ID存在,则从数据库中查询文章
|
||||
if blogId > 0 {
|
||||
if c.Member.IsAdministrator() {
|
||||
blog, err = models.NewBlog().Find(blogId)
|
||||
} else {
|
||||
blog, err = models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.JsonResult(6003, "文章不存在")
|
||||
}
|
||||
//如果设置了文章标识
|
||||
if blogIdentify != "" {
|
||||
//如果查询到的文章标识存在并且不是当前文章的id
|
||||
if b,err := models.NewBlog().FindByIdentify(blogIdentify); err == nil && b.BlogId != blogId {
|
||||
c.JsonResult(6004,"文章标识已存在")
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//如果设置了文章标识
|
||||
if blogIdentify != "" {
|
||||
if models.NewBlog().IsExist(blogIdentify) {
|
||||
c.JsonResult(6004,"文章标识已存在")
|
||||
}
|
||||
}
|
||||
|
||||
blog = models.NewBlog()
|
||||
blog.MemberId = c.Member.MemberId
|
||||
}
|
||||
|
||||
|
||||
blog.BlogTitle = blogTitle
|
||||
blog.BlogIdentify = blogIdentify
|
||||
blog.OrderIndex = orderIndex
|
||||
blog.BlogType = blogType
|
||||
if blogType == 1 {
|
||||
blog.DocumentId = documentId
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//文章创建或编辑
|
||||
func (c *BlogController) ManageEdit() {
|
||||
c.Prepare()
|
||||
c.TplName = "blog/manage_edit.tpl"
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ type Blog struct {
|
|||
//排序序号
|
||||
OrderIndex int `orm:"column(order_index);type(int);default(0)" json:"order_index"`
|
||||
//所属用户
|
||||
MemberId int `orm:"column(member_id);type(int);default(0)" json:"member_id"`
|
||||
MemberId int `orm:"column(member_id);type(int);default(0):index" json:"member_id"`
|
||||
//文章类型:0 普通文章/1 链接文章
|
||||
BlogType int `orm:"column(blog_type);type(int);default(0)" json:"blog_type"`
|
||||
//链接到的项目中的文档ID
|
||||
|
@ -80,6 +80,18 @@ func (b *Blog) Find(blogId int) (*Blog,error) {
|
|||
|
||||
return b,nil
|
||||
}
|
||||
//查找指定用户的指定文章
|
||||
func (b *Blog) FindByIdAndMemberId(blogId,memberId int) (*Blog,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id",blogId).Filter("member_id",memberId).One(b)
|
||||
if err != nil {
|
||||
beego.Error("查询文章时失败 -> ",err)
|
||||
return nil,err
|
||||
}
|
||||
|
||||
return b,nil
|
||||
}
|
||||
//根据文章标识查询文章
|
||||
func (b *Blog) FindByIdentify(identify string) (*Blog,error) {
|
||||
o := orm.NewOrm()
|
||||
|
@ -91,7 +103,7 @@ func (b *Blog) FindByIdentify(identify string) (*Blog,error) {
|
|||
}
|
||||
return b,nil
|
||||
}
|
||||
|
||||
//获取指定文章的链接内容
|
||||
func (b *Blog)Link() (*Blog,error) {
|
||||
o := orm.NewOrm()
|
||||
//如果是链接文章,则需要从链接的项目中查找文章内容
|
||||
|
@ -109,3 +121,13 @@ func (b *Blog)Link() (*Blog,error) {
|
|||
return b,nil
|
||||
}
|
||||
|
||||
//判断指定的文章标识是否存在
|
||||
func (b *Blog) IsExist(identify string) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
return o.QueryTable(b.TableNameWithPrefix()).Filter("blog_identify",identify).Exist()
|
||||
}
|
||||
|
||||
func (b *Blog) FindToPager() {
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package models
|
||||
|
||||
|
||||
type BlogResult struct{
|
||||
|
||||
}
|
|
@ -220,3 +220,9 @@ func (m *Document) FindListByBookId(bookId int) (docs []*Document, err error) {
|
|||
|
||||
return
|
||||
}
|
||||
//判断文章是否存在
|
||||
func (m *Document) IsExist(documentId int) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
return o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",documentId).Exist()
|
||||
}
|
|
@ -63,6 +63,15 @@ func init() {
|
|||
beego.Router("/book/setting/token", &controllers.BookController{}, "post:CreateToken")
|
||||
beego.Router("/book/setting/delete", &controllers.BookController{}, "post:Delete")
|
||||
|
||||
//管理文章的路由
|
||||
beego.Router("/blogs", &controllers.BlogController{},"*:ManageList")
|
||||
beego.Router("/blogs/setting/:id", &controllers.BlogController{}, "*:ManageSetting")
|
||||
beego.Router("/blogs/edit/:id",&controllers.BlogController{}, "*:ManageEdit")
|
||||
|
||||
//读文章的路由
|
||||
beego.Router("/blog", &controllers.BlogController{}, "*:List")
|
||||
beego.Router("/blog/:id",&controllers.BlogController{}, "*:Index")
|
||||
|
||||
beego.Router("/api/attach/remove/", &controllers.DocumentController{}, "post:RemoveAttachment")
|
||||
beego.Router("/api/:key/edit/?:id", &controllers.DocumentController{}, "*:Edit")
|
||||
beego.Router("/api/upload", &controllers.DocumentController{}, "post:Upload")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,510 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>我的文章 - Powered by MinDoc</title>
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet" type="text/css">
|
||||
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet" type="text/css">
|
||||
<link href="{{cdncss "/static/bootstrap/plugins/bootstrap-fileinput/4.4.7/css/fileinput.min.css"}}" rel="stylesheet" type="text/css">
|
||||
<link href="{{cdncss "/static/bootstrap/plugins/bootstrap-fileinput/4.4.7/themes/explorer-fa/theme.css"}}" rel="stylesheet" type="text/css">
|
||||
<link href="{{cdncss "/static/css/main.css"}}" rel="stylesheet">
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="manual-reader">
|
||||
{{template "widgets/header.tpl" .}}
|
||||
<div class="container manual-body">
|
||||
<div class="row">
|
||||
<div class="page-left">
|
||||
<ul class="menu">
|
||||
<li {{if eq .ControllerName "BookController"}}class="active"{{end}}><a href="{{urlfor "BookController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 我的项目</a> </li>
|
||||
<li {{if eq .ControllerName "BlogController"}}class="active"{{end}}><a href="{{urlfor "BlogController.ManageList"}}" class="item"><i class="fa fa-file" aria-hidden="true"></i> 我的文章</a> </li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="page-right">
|
||||
<div class="m-box">
|
||||
<div class="box-head">
|
||||
<strong class="box-title">文章列表</strong>
|
||||
|
||||
<button type="button" data-toggle="modal" data-target="#addBlogDialogModal" class="btn btn-success btn-sm pull-right">添加文章</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body" id="bookList">
|
||||
<div class="book-list">
|
||||
<template v-if="lists.length <= 0">
|
||||
<div class="text-center">暂无数据</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
|
||||
<div class="list-item" v-for="item in lists">
|
||||
<div class="book-title">
|
||||
<div class="pull-left">
|
||||
<a :href="'{{.BaseUrl}}/book/' + item.identify + '/dashboard'" title="项目概要" data-toggle="tooltip">
|
||||
<template v-if="item.privately_owned == 0">
|
||||
<i class="fa fa-unlock" aria-hidden="true"></i>
|
||||
</template>
|
||||
<template v-else-if="item.privately_owned == 1">
|
||||
<i class="fa fa-lock" aria-hidden="true"></i>
|
||||
</template>
|
||||
${item.book_name}
|
||||
</a>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<div class="btn-group">
|
||||
<a :href="'{{.BaseUrl}}/book/' + item.identify + '/dashboard'" class="btn btn-default">设置</a>
|
||||
|
||||
<a href="javascript:;" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="caret"></span>
|
||||
<span class="sr-only">Toggle Dropdown</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a :href="'{{urlfor "DocumentController.Index" ":key" ""}}' + item.identify" target="_blank">阅读</a></li>
|
||||
<template v-if="item.role_id != 3">
|
||||
<li><a :href="'{{.BaseUrl}}/api/' + item.identify + '/edit'" target="_blank">编辑</a></li>
|
||||
</template>
|
||||
<template v-if="item.role_id == 0">
|
||||
<li><a :href="'javascript:deleteBook(\''+item.identify+'\');'">删除</a></li>
|
||||
<li><a :href="'javascript:copyBook(\''+item.identify+'\');'">复制</a></li>
|
||||
</template>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
{{/*<a :href="'{{urlfor "DocumentController.Index" ":key" ""}}' + item.identify" title="查看文档" data-toggle="tooltip" target="_blank"><i class="fa fa-eye"></i> 查看文档</a>*/}}
|
||||
{{/*<template v-if="item.role_id != 3">*/}}
|
||||
{{/*<a :href="'/api/' + item.identify + '/edit'" title="编辑文档" data-toggle="tooltip" target="_blank"><i class="fa fa-edit" aria-hidden="true"></i> 编辑文档</a>*/}}
|
||||
{{/*</template>*/}}
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="desc-text">
|
||||
<template v-if="item.description === ''">
|
||||
|
||||
</template>
|
||||
<template v-else="">
|
||||
<a :href="'{{.BaseUrl}}/book/' + item.identify + '/dashboard'" title="项目概要" style="font-size: 12px;">
|
||||
${item.description}
|
||||
</a>
|
||||
</template>
|
||||
</div>
|
||||
<div class="info">
|
||||
<span title="创建时间" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-clock-o"></i>
|
||||
${(new Date(item.create_time)).format("yyyy-MM-dd hh:mm:ss")}
|
||||
|
||||
</span>
|
||||
<span title="创建者" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-user"></i> ${item.create_name}</span>
|
||||
<span title="文档数量" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-pie-chart"></i> ${item.doc_count}</span>
|
||||
<span title="项目角色" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-user-secret"></i> ${item.role_name}</span>
|
||||
<template v-if="item.last_modify_text !== ''">
|
||||
<span title="最后编辑" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-pencil"></i> 最后编辑: ${item.last_modify_text}</span>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="lists.length >= 0">
|
||||
<nav class="pagination-container">
|
||||
{{.PageHtml}}
|
||||
</nav>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "widgets/footer.tpl" .}}
|
||||
</div>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="addBlogDialogModal" tabindex="-1" role="dialog" aria-labelledby="addBlogDialogModalLabel">
|
||||
<div class="modal-dialog modal-lg" role="document" style="min-width: 900px;">
|
||||
<form method="post" autocomplete="off" action="{{urlfor "BookController.Create"}}" id="addBookDialogForm" enctype="multipart/form-data">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">添加文章</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<div class="pull-left">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" placeholder="标题(不超过100字)" name="book_name" id="bookName">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="pull-left" style="padding: 7px 5px 6px 0">
|
||||
{{urlfor "DocumentController.Index" ":key" ""}}
|
||||
</div>
|
||||
<input type="text" class="form-control pull-left" style="width: 410px;vertical-align: middle" placeholder="项目唯一标识(不超过50字)" name="identify" id="identify">
|
||||
<div class="clearfix"></div>
|
||||
<p class="text" style="font-size: 12px;color: #999;margin-top: 6px;">文档标识只能包含小写字母、数字,以及“-”、“.”和“_”符号.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<textarea name="description" id="description" class="form-control" placeholder="描述信息不超过500个字符" style="height: 90px;"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-6">
|
||||
<label>
|
||||
<input type="radio" name="privately_owned" value="0" checked> 公开<span class="text">(任何人都可以访问)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<label>
|
||||
<input type="radio" name="privately_owned" value="1"> 私有<span class="text">(只要参与者或使用令牌才能访问)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<span id="form-error-message"></span>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-success" id="btnSaveDocument" data-loading-text="保存中...">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!--END Modal-->
|
||||
|
||||
<!-- Delete Book Modal -->
|
||||
<div class="modal fade" id="deleteBookModal" tabindex="-1" role="dialog" aria-labelledby="deleteBookModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="post" id="deleteBookForm" action="{{urlfor "BookController.Delete"}}">
|
||||
<input type="hidden" name="identify" value="">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">删除项目</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<span style="font-size: 14px;font-weight: 400;">确定删除项目吗?</span>
|
||||
<p></p>
|
||||
<p class="text error-message">删除项目后将无法找回。</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<span id="form-error-message2" class="error-message"></span>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="submit" id="btnDeleteBook" class="btn btn-primary" data-loading-text="删除中...">确定删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{{cdnjs "/static/jquery/1.12.4/jquery.min.js"}}" type="text/javascript"></script>
|
||||
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}" type="text/javascript"></script>
|
||||
<script src="{{cdnjs "/static/vuejs/vue.min.js"}}" type="text/javascript"></script>
|
||||
<script src="{{cdnjs "/static/js/jquery.form.js"}}" type="text/javascript"></script>
|
||||
<script src="{{cdnjs "/static/bootstrap/plugins/bootstrap-fileinput/4.4.7/js/fileinput.min.js"}}"></script>
|
||||
<script src="{{cdnjs "/static/bootstrap/plugins/bootstrap-fileinput/4.4.7/js/locales/zh.js"}}"></script>
|
||||
<script src="{{cdnjs "/static/layer/layer.js"}}" type="text/javascript" ></script>
|
||||
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
/**
|
||||
* 绘制项目封面
|
||||
* @param $id
|
||||
* @param $font
|
||||
*/
|
||||
function drawBookCover($id,$font) {
|
||||
var draw = document.getElementById($id);
|
||||
//确认浏览器是否支持<canvas>元素
|
||||
if (draw.getContext) {
|
||||
var context = draw.getContext('2d');
|
||||
|
||||
//绘制红色矩形,绿色描边
|
||||
context.fillStyle = '#eee';
|
||||
context.strokeStyle = '#d4d4d5';
|
||||
context.strokeRect(0,0,170,230);
|
||||
context.fillRect(0,0,170,230);
|
||||
|
||||
//设置字体样式
|
||||
context.font = "bold 20px SimSun";
|
||||
context.textAlign = "left";
|
||||
//设置字体填充颜色
|
||||
context.fillStyle = "#3E403E";
|
||||
|
||||
var font = $font;
|
||||
|
||||
var lineWidth = 0; //当前行的绘制的宽度
|
||||
var lastTextIndex = 0; //已经绘制上canvas最后的一个字符的下标
|
||||
var drawWidth = 155,lineHeight = 25,drawStartX = 15,drawStartY=65;
|
||||
//由于改变canvas 的高度会导致绘制的纹理被清空,所以,不预先绘制,先放入到一个数组当中
|
||||
var arr = [];
|
||||
for(var i = 0; i<font.length; i++){
|
||||
//获取当前的截取的字符串的宽度
|
||||
lineWidth = context.measureText(font.substr(lastTextIndex,i-lastTextIndex)).width;
|
||||
|
||||
if(lineWidth > drawWidth){
|
||||
//判断最后一位是否是标点符号
|
||||
if(judgePunctuationMarks(font[i-1])){
|
||||
arr.push(font.substr(lastTextIndex,i-lastTextIndex));
|
||||
lastTextIndex = i;
|
||||
}else{
|
||||
arr.push(font.substr(lastTextIndex,i-lastTextIndex-1));
|
||||
lastTextIndex = i-1;
|
||||
}
|
||||
}
|
||||
//将最后多余的一部分添加到数组
|
||||
if(i === font.length - 1){
|
||||
arr.push(font.substr(lastTextIndex,i-lastTextIndex+1));
|
||||
}
|
||||
}
|
||||
|
||||
for(var i =0; i<arr.length; i++){
|
||||
context.fillText(arr[i],drawStartX,drawStartY+i*lineHeight);
|
||||
}
|
||||
|
||||
//判断是否是需要避开的标签符号
|
||||
function judgePunctuationMarks(value) {
|
||||
var arr = [".",",",";","?","!",":","\"",",","。","?","!",";",":","、"];
|
||||
for(var i = 0; i< arr.length; i++){
|
||||
if(value === arr[i]){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}else{
|
||||
console.log("浏览器不支持")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将base64格式的图片转换为二进制
|
||||
* @param dataURI
|
||||
* @returns {Blob}
|
||||
*/
|
||||
function dataURItoBlob(dataURI) {
|
||||
var byteString = atob(dataURI.split(',')[1]);
|
||||
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
||||
var ab = new ArrayBuffer(byteString.length);
|
||||
var ia = new Uint8Array(ab);
|
||||
for (var i = 0; i < byteString.length; i++) {
|
||||
ia[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
|
||||
return new Blob([ab], {type: mimeString});
|
||||
}
|
||||
/**
|
||||
* 删除项目
|
||||
*/
|
||||
function deleteBook($id) {
|
||||
$("#deleteBookModal").find("input[name='identify']").val($id);
|
||||
$("#deleteBookModal").modal("show");
|
||||
}
|
||||
function copyBook($id){
|
||||
var index = layer.load()
|
||||
$.ajax({
|
||||
url : "{{urlfor "BookController.Copy"}}" ,
|
||||
data : {"identify":$id},
|
||||
type : "POST",
|
||||
dataType : "json",
|
||||
success : function ($res) {
|
||||
layer.close(index);
|
||||
if ($res.errcode === 0) {
|
||||
window.app.lists.splice(0, 0, $res.data);
|
||||
$("#addBookDialogModal").modal("hide");
|
||||
} else {
|
||||
layer.msg($res.message);
|
||||
}
|
||||
},
|
||||
error : function () {
|
||||
layer.close(index);
|
||||
layer.msg('服务器异常');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$("#addBookDialogModal").on("show.bs.modal",function () {
|
||||
window.bookDialogModal = $(this).find("#addBookDialogForm").html();
|
||||
drawBookCover("bookCover","默认封面");
|
||||
}).on("hidden.bs.modal",function () {
|
||||
$(this).find("#addBookDialogForm").html(window.bookDialogModal);
|
||||
});
|
||||
/**
|
||||
* 创建项目
|
||||
*/
|
||||
$("body").on("click","#btnSaveDocument",function () {
|
||||
var $this = $(this);
|
||||
|
||||
|
||||
var bookName = $.trim($("#bookName").val());
|
||||
if (bookName === "") {
|
||||
return showError("项目标题不能为空")
|
||||
}
|
||||
if (bookName.length > 100) {
|
||||
return showError("项目标题必须小于100字符");
|
||||
}
|
||||
|
||||
var identify = $.trim($("#identify").val());
|
||||
if (identify === "") {
|
||||
return showError("项目标识不能为空");
|
||||
}
|
||||
if (identify.length > 50) {
|
||||
return showError("项目标识必须小于50字符");
|
||||
}
|
||||
var description = $.trim($("#description").val());
|
||||
|
||||
if (description.length > 500) {
|
||||
return showError("描述信息不超过500个字符");
|
||||
}
|
||||
|
||||
$this.button("loading");
|
||||
|
||||
var draw = document.getElementById("bookCover");
|
||||
var form = document.getElementById("addBookDialogForm");
|
||||
var fd = new FormData(form);
|
||||
if (draw.getContext) {
|
||||
var dataURL = draw.toDataURL("png", 100);
|
||||
|
||||
var blob = dataURItoBlob(dataURL);
|
||||
|
||||
fd.append('image-file', blob,(new Date()).valueOf() + ".png");
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url : "{{urlfor "BookController.Create"}}",
|
||||
data: fd,
|
||||
type: "POST",
|
||||
dataType :"json",
|
||||
processData: false,
|
||||
contentType: false
|
||||
}).success(function (res) {
|
||||
$this.button("reset");
|
||||
if (res.errcode === 0) {
|
||||
window.app.lists.splice(0, 0, res.data);
|
||||
$("#addBookDialogModal").modal("hide");
|
||||
} else {
|
||||
showError(res.message);
|
||||
}
|
||||
$this.button("reset");
|
||||
}).error(function () {
|
||||
$this.button("reset");
|
||||
return showError("服务器异常");
|
||||
});
|
||||
return false;
|
||||
});
|
||||
/**
|
||||
* 当填写项目标题后,绘制项目封面
|
||||
*/
|
||||
$("#bookName").on("blur",function () {
|
||||
var txt = $(this).val();
|
||||
if(txt !== ""){
|
||||
drawBookCover("bookCover",txt);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 删除项目
|
||||
*/
|
||||
$("#deleteBookForm").ajaxForm({
|
||||
beforeSubmit : function () {
|
||||
$("#btnDeleteBook").button("loading");
|
||||
},
|
||||
success : function (res) {
|
||||
if(res.errcode === 0){
|
||||
window.location = window.location.href;
|
||||
}else{
|
||||
showError(res.message,"#form-error-message2");
|
||||
}
|
||||
$("#btnDeleteBook").button("reset");
|
||||
},
|
||||
error : function () {
|
||||
showError("服务器异常","#form-error-message2");
|
||||
$("#btnDeleteBook").button("reset");
|
||||
}
|
||||
});
|
||||
|
||||
$("#btnImportBook").on("click",function () {
|
||||
var $this = $(this);
|
||||
var $then = $(this).parents("#importBookDialogForm");
|
||||
|
||||
|
||||
var bookName = $.trim($then.find("input[name='book_name']").val());
|
||||
|
||||
if (bookName === "") {
|
||||
return showError("项目标题不能为空","#import-book-form-error-message");
|
||||
}
|
||||
if (bookName.length > 100) {
|
||||
return showError("项目标题必须小于100字符","#import-book-form-error-message");
|
||||
}
|
||||
|
||||
var identify = $.trim($then.find("input[name='identify']").val());
|
||||
if (identify === "") {
|
||||
return showError("项目标识不能为空","#import-book-form-error-message");
|
||||
}
|
||||
var description = $.trim($then.find('textarea[name="description"]').val());
|
||||
if (description.length > 500) {
|
||||
return showError("描述信息不超过500个字符","#import-book-form-error-message");
|
||||
}
|
||||
var filesCount = $('#import-book-upload').fileinput('getFilesCount');
|
||||
console.log(filesCount)
|
||||
if (filesCount <= 0) {
|
||||
return showError("请选择需要上传的文件","#import-book-form-error-message");
|
||||
}
|
||||
//$("#importBookDialogForm").submit();
|
||||
$("#btnImportBook").button("loading");
|
||||
$('#import-book-upload').fileinput('upload');
|
||||
|
||||
});
|
||||
window.app = new Vue({
|
||||
el : "#bookList",
|
||||
data : {
|
||||
lists : {{.Result}}
|
||||
},
|
||||
delimiters : ['${','}'],
|
||||
methods : {
|
||||
}
|
||||
});
|
||||
Vue.nextTick(function () {
|
||||
$("[data-toggle='tooltip']").tooltip();
|
||||
});
|
||||
|
||||
$("#import-book-upload").fileinput({
|
||||
'uploadUrl':"{{urlfor "BookController.Import"}}",
|
||||
'theme': 'fa',
|
||||
'showPreview': false,
|
||||
'showUpload' : false,
|
||||
'required': true,
|
||||
'validateInitialCount': true,
|
||||
"language" : "zh",
|
||||
'allowedFileExtensions': ['zip'],
|
||||
'msgPlaceholder' : '请选择Zip文件',
|
||||
'elErrorContainer' : "#import-book-form-error-message",
|
||||
'uploadExtraData' : function () {
|
||||
var book = {};
|
||||
var $then = $("#importBookDialogForm");
|
||||
book.book_name = $then.find("input[name='book_name']").val();
|
||||
book.identify = $then.find("input[name='identify']").val();
|
||||
book.description = $then.find('textarea[name="description"]').val()
|
||||
|
||||
return book;
|
||||
}
|
||||
});
|
||||
$("#import-book-upload").on("fileuploaded",function (event, data, previewId, index){
|
||||
|
||||
if(data.response.errcode === 0 || data.response.errcode === '0'){
|
||||
showSuccess(data.response.message,"#import-book-form-error-message");
|
||||
}else{
|
||||
showError(data.response.message,"#import-book-form-error-message");
|
||||
}
|
||||
$("#btnImportBook").button("reset");
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -27,7 +27,8 @@
|
|||
<div class="row">
|
||||
<div class="page-left">
|
||||
<ul class="menu">
|
||||
<li class="active"><a href="{{urlfor "BookController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 我的项目</a> </li>
|
||||
<li {{if eq .ControllerName "BookController"}}class="active"{{end}}><a href="{{urlfor "BookController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 我的项目</a> </li>
|
||||
<li {{if eq .ControllerName "BlogController"}}class="active"{{end}}><a href="{{urlfor "BlogController.ManageList"}}" class="item"><i class="fa fa-file" aria-hidden="true"></i> 我的文章</a> </li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="page-right">
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<li {{if eq .ControllerName "HomeController"}}class="active"{{end}}>
|
||||
<a href="{{urlfor "HomeController.Index" }}" title="首页">首页</a>
|
||||
</li>
|
||||
<li {{if eq .ControllerName "BlogController"}}{{if eq .ActionName "List"}}class="active"{{end}}{{end}}>
|
||||
<a href="{{urlfor "BlogController.List" }}" title="文章">文章</a>
|
||||
</li>
|
||||
<li {{if eq .ControllerName "LabelController"}}class="active"{{end}}>
|
||||
<a href="{{urlfor "LabelController.List" }}" title="标签">标签</a>
|
||||
</li>
|
||||
|
@ -37,6 +40,9 @@
|
|||
<li>
|
||||
<a href="{{urlfor "BookController.Index"}}" title="我的项目"><i class="fa fa-book" aria-hidden="true"></i> 我的项目</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{urlfor "BlogController.ManageList"}}" title="我的文章"><i class="fa fa-file" aria-hidden="true"></i> 我的文章</a>
|
||||
</li>
|
||||
{{if eq .Member.Role 0 }}
|
||||
<li>
|
||||
<a href="{{urlfor "ManagerController.Index"}}" title="管理后台"><i class="fa fa-university" aria-hidden="true"></i> 管理后台</a>
|
||||
|
@ -72,6 +78,9 @@
|
|||
<li>
|
||||
<a href="{{urlfor "BookController.Index"}}" title="我的项目"><i class="fa fa-book" aria-hidden="true"></i> 我的项目</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{urlfor "BlogController.ManageList"}}" title="我的文章"><i class="fa fa-file" aria-hidden="true"></i> 我的文章</a>
|
||||
</li>
|
||||
{{if eq .Member.Role 0 1}}
|
||||
<li>
|
||||
<a href="{{urlfor "ManagerController.Index"}}" title="管理后台"><i class="fa fa-university" aria-hidden="true"></i> 管理后台</a>
|
||||
|
|
Loading…
Reference in New Issue