From 57a745cc6302b8f0aac7083fe0a33ec73429600c Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Tue, 14 Aug 2018 18:17:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=9E=E7=8E=B0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=96=87=E6=A1=A3=E6=A0=91=E7=9A=84=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/DocumentController.go | 9 ++++++++- models/DocumentHistory.go | 3 +++ models/DocumentModel.go | 4 +++- models/DocumentTree.go | 15 ++++++++++----- static/js/editor.js | 12 ++++++++++-- static/js/markdown.js | 15 ++++++++++++--- views/document/markdown_edit_template.tpl | 20 +++++++++++++++++--- 7 files changed, 63 insertions(+), 15 deletions(-) diff --git a/controllers/DocumentController.go b/controllers/DocumentController.go index c7bc008d..fed65d03 100644 --- a/controllers/DocumentController.go +++ b/controllers/DocumentController.go @@ -301,6 +301,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) if identify == "" { c.JsonResult(6001, "参数错误") @@ -360,8 +361,14 @@ func (c *DocumentController) Create() { document.DocumentName = docName document.ParentId = parentId + if isOpen == 1 { + document.IsOpen = 1 + }else{ + document.IsOpen = 0 + } + if err := document.InsertOrUpdate(); err != nil { - beego.Error("InsertOrUpdate => ", err) + beego.Error("添加或更新文档时出错 -> ", err) c.JsonResult(6005, "保存失败") } else { c.JsonResult(0, "ok", document) diff --git a/models/DocumentHistory.go b/models/DocumentHistory.go index 95cae2a4..0e9973ed 100644 --- a/models/DocumentHistory.go +++ b/models/DocumentHistory.go @@ -21,6 +21,7 @@ type DocumentHistory struct { ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"` ModifyAt int `orm:"column(modify_at);type(int)" json:"-"` Version int64 `orm:"type(bigint);column(version)" json:"version"` + IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"` } type DocumentHistorySimpleResult struct { @@ -101,6 +102,7 @@ func (m *DocumentHistory) Restore(historyId, docId, uid int) error { history.Version = time.Now().Unix() history.Action = "restore" history.ActionName = "恢复文档" + history.IsOpen = doc.IsOpen history.InsertOrUpdate() @@ -109,6 +111,7 @@ func (m *DocumentHistory) Restore(historyId, docId, uid int) error { doc.Markdown = m.Markdown doc.Release = m.Content doc.Version = time.Now().Unix() + doc.IsOpen = m.IsOpen _, err = o.Update(doc) diff --git a/models/DocumentModel.go b/models/DocumentModel.go index f2ffbb59..a04210f2 100644 --- a/models/DocumentModel.go +++ b/models/DocumentModel.go @@ -36,7 +36,9 @@ type Document struct { MemberId int `orm:"column(member_id);type(int)" json:"member_id"` ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"` ModifyAt int `orm:"column(modify_at);type(int)" json:"-"` - Version int64 `orm:"type(bigint);column(version)" json:"version"` + Version int64 `orm:"column(version);type(bigint);" json:"version"` + //是否展开子目录:0 否/1 是 + IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"` AttachList []*Attachment `orm:"-" json:"attach"` } diff --git a/models/DocumentTree.go b/models/DocumentTree.go index 30d126c2..6e05d904 100644 --- a/models/DocumentTree.go +++ b/models/DocumentTree.go @@ -18,6 +18,7 @@ type DocumentTree struct { BookIdentify string `json:"-"` Version int64 `json:"version"` State *DocumentSelected `json:"state,omitempty"` + AAttrs map[string]interface{} `json:"a_attr"` } type DocumentSelected struct { Selected bool `json:"selected"` @@ -32,7 +33,7 @@ func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) { var docs []*Document - count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify") + count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify","is_open") if err != nil { return trees, err @@ -45,6 +46,10 @@ func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) { tree := &DocumentTree{} if index == 0 { tree.State = &DocumentSelected{Selected: true, Opened: true} + tree.AAttrs = map[string]interface{}{ "is_open": true} + }else if item.IsOpen == 1 { + tree.State = &DocumentSelected{Selected: false, Opened: true} + tree.AAttrs = map[string]interface{}{ "is_open": true} } tree.DocumentId = item.DocumentId tree.Identify = item.Identify @@ -107,14 +112,14 @@ func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, select if item.DocumentId == selectedId { selected = ` class="jstree-clicked"` } - selected_li := "" - if item.DocumentId == selectedParentId { - selected_li = ` class="jstree-open"` + selectedLi := "" + if item.DocumentId == selectedParentId || (item.State != nil && item.State.Opened) { + selectedLi = ` class="jstree-open"` } buf.WriteString("
  • - +

    文档标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头

    +
    +
    + +
    +
    + +
    + +
    +
    - +