From 90efeac3266e9d1e5b62ee4ce1565963447f8089 Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Tue, 11 Sep 2018 15:57:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:1=E3=80=81=E4=BF=AE=E5=A4=8D=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=97=A0=E6=B3=95=E5=90=8C=E6=97=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E7=9A=84BUG=202=E3=80=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=A0=A1=E9=AA=8C=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/enumerate.go | 3 +++ controllers/BaseController.go | 9 +++++--- controllers/BlogController.go | 7 ++++-- controllers/DocumentController.go | 26 +++++++++++++---------- views/blog/manage_edit.tpl | 23 ++++++++------------ views/document/default_read.tpl | 3 +-- views/document/markdown_edit_template.tpl | 24 ++++++++++----------- views/document/new_html_edit_template.tpl | 21 ++++++++---------- 8 files changed, 59 insertions(+), 57 deletions(-) diff --git a/conf/enumerate.go b/conf/enumerate.go index 59d86bb8..db20f75f 100644 --- a/conf/enumerate.go +++ b/conf/enumerate.go @@ -186,6 +186,9 @@ func IsAllowUploadFileExt(ext string) bool { exts := GetUploadFileExt() for _, item := range exts { + if item == "*" { + return true + } if strings.EqualFold(item, ext) { return true } diff --git a/controllers/BaseController.go b/controllers/BaseController.go index 85a11f13..e17e29c7 100644 --- a/controllers/BaseController.go +++ b/controllers/BaseController.go @@ -12,6 +12,8 @@ import ( "github.com/lifei6671/mindoc/conf" "github.com/lifei6671/mindoc/models" "github.com/lifei6671/mindoc/utils" + "github.com/lifei6671/mindoc/utils/filetil" + "path/filepath" ) type BaseController struct { @@ -56,9 +58,6 @@ func (c *BaseController) Prepare() { } } } - //c.Member = models.NewMember() - //c.Member.Find(1) - //c.Data["Member"] = *c.Member } conf.BaseUrl = c.BaseUrl() c.Data["BaseUrl"] = c.BaseUrl() @@ -78,6 +77,10 @@ func (c *BaseController) Prepare() { } } c.Data["HighlightStyle"] = beego.AppConfig.DefaultString("highlight_style","github") + + if filetil.FileExists(filepath.Join(beego.BConfig.WebConfig.ViewsPath,"widgets","scripts.tpl")) { + c.LayoutSections["Scripts"] = "widgets/scripts.tpl" + } } // SetMember 获取或设置当前登录用户信息,如果 MemberId 小于 0 则标识删除 Session diff --git a/controllers/BlogController.go b/controllers/BlogController.go index 3c98b36b..64f950b3 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -337,7 +337,6 @@ func (c *BlogController) ManageEdit() { blog.ModifyAt = c.Member.MemberId blog.Modified = time.Now() - if err := blog.Save("blog_content","blog_release","modify_at","modify_time","version");err != nil { beego.Error("保存文章失败 -> ",err) c.JsonResult(6011,"保存文章失败") @@ -374,7 +373,11 @@ func (c *BlogController) ManageEdit() { }else{ c.Data["AttachList"] = template.JS("[]") } - + if conf.GetUploadFileSize() > 0 { + c.Data["UploadFileSize"] = conf.GetUploadFileSize() + }else{ + c.Data["UploadFileSize"] = "undefined"; + } c.Data["Model"] = blog } diff --git a/controllers/DocumentController.go b/controllers/DocumentController.go index f0ba9b74..a211b46e 100644 --- a/controllers/DocumentController.go +++ b/controllers/DocumentController.go @@ -186,7 +186,7 @@ func (c *DocumentController) Read() { Body string `json:"body"` Title string `json:"title"` DocInfo string `json:"doc_info"` - Version int64 `json:"version"` + Version int64 `json:"version"` } data.DocTitle = doc.DocumentName data.Body = doc.Release @@ -282,6 +282,12 @@ func (c *DocumentController) Edit() { } c.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "") + + if conf.GetUploadFileSize() > 0 { + c.Data["UploadFileSize"] = conf.GetUploadFileSize() + }else{ + c.Data["UploadFileSize"] = "undefined"; + } } // 创建一个文档 @@ -291,7 +297,7 @@ func (c *DocumentController) Create() { docName := c.GetString("doc_name") parentId, _ := c.GetInt("parent_id", 0) docId, _ := c.GetInt("doc_id", 0) - isOpen,_ := c.GetInt("is_open",0) + isOpen, _ := c.GetInt("is_open", 0) if identify == "" { c.JsonResult(6001, "参数错误") @@ -353,7 +359,7 @@ func (c *DocumentController) Create() { if isOpen == 1 { document.IsOpen = 1 - }else{ + } else { document.IsOpen = 0 } @@ -397,19 +403,17 @@ func (c *DocumentController) Upload() { } if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() { - c.JsonResult(6009, "查过文件允许的上传最大值") + c.JsonResult(6009, "文件大小超过了限定的最大值") } ext := filepath.Ext(moreFile.Filename) - + //文件必须带有后缀名 if ext == "" { c.JsonResult(6003, "无法解析文件的格式") } //如果文件类型设置为 * 标识不限制文件类型 - if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" { - if !conf.IsAllowUploadFileExt(ext) { - c.JsonResult(6004, "不允许的文件类型") - } + if conf.IsAllowUploadFileExt(ext) == false { + c.JsonResult(6004, "不允许的文件类型") } bookId := 0 @@ -504,7 +508,7 @@ func (c *DocumentController) Upload() { if err != nil { os.Remove(filePath) - beego.Error("Attachment Insert => ", err) + beego.Error("文件保存失败 ->", err) c.JsonResult(6006, "文件保存失败") } @@ -512,7 +516,7 @@ func (c *DocumentController) Upload() { attachment.HttpPath = conf.URLFor("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId) if err := attachment.Update(); err != nil { - beego.Error("SaveToFile => ", err) + beego.Error("保存文件失败 ->", err) c.JsonResult(6005, "保存文件失败") } } diff --git a/views/blog/manage_edit.tpl b/views/blog/manage_edit.tpl index 0c4ffefe..52b13dd5 100644 --- a/views/blog/manage_edit.tpl +++ b/views/blog/manage_edit.tpl @@ -237,10 +237,8 @@ formData : { "blogId" : {{.Model.BlogId}}}, pick: "#filePicker", fileVal : "editormd-file-file", - fileNumLimit : 1, + fileSingleSizeLimit: {{.UploadFileSize}}, compress : false - }).on("beforeFileQueued",function (file) { - uploader.reset(); }).on( 'fileQueued', function( file ) { var item = { state : "wait", @@ -249,15 +247,14 @@ file_name : file.name, message : "正在上传" }; - window.vueApp.lists.splice(0,0,item); + window.vueApp.lists.push(item); }).on("uploadError",function (file,reason) { for(var i in window.vueApp.lists){ var item = window.vueApp.lists[i]; if(item.attachment_id == file.id){ item.state = "error"; - item.message = "上传失败"; - break; + item.message = "上传失败:" + reason; } } @@ -267,25 +264,23 @@ var item = window.vueApp.lists[index]; if(item.attachment_id === file.id){ if(res.errcode === 0) { - window.vueApp.lists.splice(index, 1, res.attach); - + window.vueApp.lists.splice(index, 1, res.attach?res.attach:res.data); }else{ item.message = res.message; item.state = "error"; } - break; } } - - }).on("beforeFileQueued",function (file) { - - }).on("uploadComplete",function () { - }).on("uploadProgress",function (file, percentage) { var $li = $( '#'+file.id ), $percent = $li.find('.progress .progress-bar'); $percent.css( 'width', percentage * 100 + '%' ); + }).on("error", function (type) { + if(type === "F_EXCEED_SIZE"){ + layer.msg("文件超过了限定大小"); + } + console.log(type); }); }catch(e){ console.log(e); diff --git a/views/document/default_read.tpl b/views/document/default_read.tpl index 064c0ff6..1559deea 100644 --- a/views/document/default_read.tpl +++ b/views/document/default_read.tpl @@ -278,7 +278,6 @@ +{{.Scripts}} \ No newline at end of file diff --git a/views/document/markdown_edit_template.tpl b/views/document/markdown_edit_template.tpl index e12dd69d..d76adce5 100644 --- a/views/document/markdown_edit_template.tpl +++ b/views/document/markdown_edit_template.tpl @@ -427,10 +427,10 @@ formData : { "identify" : {{.Model.Identify}},"doc_id" : window.selectNode.id }, pick: "#filePicker", fileVal : "editormd-file-file", - fileNumLimit : 1, - compress : false + compress : false, + fileSingleSizeLimit: {{.UploadFileSize}} }).on("beforeFileQueued",function (file) { - uploader.reset(); + // uploader.reset(); this.options.formData.doc_id = window.selectNode.id; }).on( 'fileQueued', function( file ) { var item = { @@ -440,14 +440,14 @@ file_name : file.name, message : "正在上传" }; - window.vueApp.lists.splice(0,0,item); + window.vueApp.lists.push(item); }).on("uploadError",function (file,reason) { for(var i in window.vueApp.lists){ var item = window.vueApp.lists[i]; if(item.attachment_id == file.id){ item.state = "error"; - item.message = "上传失败"; + item.message = "上传失败:" + reason; break; } } @@ -458,25 +458,23 @@ var item = window.vueApp.lists[index]; if(item.attachment_id === file.id){ if(res.errcode === 0) { - window.vueApp.lists.splice(index, 1, res.attach); - + window.vueApp.lists.splice(index, 1, res.attach ? res.attach : res.data); }else{ item.message = res.message; item.state = "error"; } - break; } } - - }).on("beforeFileQueued",function (file) { - - }).on("uploadComplete",function () { - }).on("uploadProgress",function (file, percentage) { var $li = $( '#'+file.id ), $percent = $li.find('.progress .progress-bar'); $percent.css( 'width', percentage * 100 + '%' ); + }).on("error", function (type) { + if(type === "F_EXCEED_SIZE"){ + layer.msg("文件超过了限定大小"); + } + console.log(type); }); }catch(e){ console.log(e); diff --git a/views/document/new_html_edit_template.tpl b/views/document/new_html_edit_template.tpl index 9fca80ba..36518928 100644 --- a/views/document/new_html_edit_template.tpl +++ b/views/document/new_html_edit_template.tpl @@ -419,10 +419,9 @@ formData : { "identify" : {{.Model.Identify}},"doc_id" : window.selectNode.id }, pick: "#filePicker", fileVal : "editormd-file-file", - fileNumLimit : 1, - compress : false + compress : false, + fileSingleSizeLimit: {{.UploadFileSize}} }).on("beforeFileQueued",function (file) { - uploader.reset(); this.options.formData.doc_id = window.selectNode.id; }).on( 'fileQueued', function( file ) { var item = { @@ -432,20 +431,18 @@ file_name : file.name, message : "正在上传" }; - window.vueApp.lists.splice(0,0,item); + window.vueApp.lists.push(item); }).on("uploadError",function (file,reason) { for(var i in window.vueApp.lists){ var item = window.vueApp.lists[i]; if(item.attachment_id == file.id){ item.state = "error"; - item.message = "上传失败"; - break; + item.message = "上传失败:" + reason; } } }).on("uploadSuccess",function (file, res) { - for(var index in window.vueApp.lists){ var item = window.vueApp.lists[index]; if(item.attachment_id === file.id){ @@ -456,19 +453,19 @@ item.message = res.message; item.state = "error"; } - break; } } - }).on("beforeFileQueued",function (file) { - - }).on("uploadComplete",function () { - }).on("uploadProgress",function (file, percentage) { var $li = $( '#'+file.id ), $percent = $li.find('.progress .progress-bar'); $percent.css( 'width', percentage * 100 + '%' ); + }).on("error", function (type) { + if(type === "F_EXCEED_SIZE"){ + layer.msg("文件超过了限定大小"); + } + console.log(type); }); }catch(e){ console.log(e);