perf:优化部分代码

This commit is contained in:
lifei6671 2018-08-16 10:58:49 +08:00
parent 42dbe12f6b
commit 9f73286115
2 changed files with 21 additions and 14 deletions

View File

@ -63,9 +63,7 @@ func (c *DocumentController) Index() {
if bookResult.IsUseFirstDocument {
doc, err := bookResult.FindFirstDocumentByBookId(bookResult.BookId)
if err == nil {
if strings.TrimSpace(doc.Release) != "" {
doc.Release += "<div class=\"wiki-bottom\">文档更新时间: " + doc.ModifyTime.Local().Format("2006-01-02 15:04") + "</div>";
}
doc.AppendInfo()
selected = doc.DocumentId
c.Data["Title"] = doc.DocumentName
c.Data["Content"] = template.HTML(doc.Release)
@ -179,17 +177,7 @@ func (c *DocumentController) Read() {
if doc.ModifyTime != doc.CreateTime {
docInfo += ";更新于 "
docInfo += doc.ModifyTime.Local().Format("2006-01-02 15:04")
if strings.TrimSpace(doc.Release) != "" {
doc.Release += "<div class=\"wiki-bottom\">文档更新时间: " + doc.ModifyTime.Local().Format("2006-01-02 15:04") + " &nbsp;&nbsp;作者:";
if docCreator != nil {
if docCreator.RealName != "" {
doc.Release += docCreator.RealName
} else {
doc.Release += docCreator.Account
}
}
doc.Release += "</div>"
}
doc.AppendInfo()
}
if c.IsAjax() {

View File

@ -298,4 +298,23 @@ func (item *Document) ReleaseContent() error {
}
}
return nil
}
//追加一些文档信息.
func (doc *Document) AppendInfo() *Document {
docCreator, err := NewMember().Find(doc.MemberId,"real_name","account")
if strings.TrimSpace(doc.Release) != "" {
doc.Release += "<div class=\"wiki-bottom\">文档更新时间: " + doc.ModifyTime.Local().Format("2006-01-02 15:04") + " &nbsp;&nbsp;作者:";
if err == nil && docCreator != nil {
if docCreator.RealName != "" {
doc.Release += docCreator.RealName
} else {
doc.Release += docCreator.Account
}
}
doc.Release += "</div>"
}
return doc
}