mirror of https://github.com/mindoc-org/mindoc.git
优化单页打印
parent
915c568a4a
commit
152d71a5a0
|
@ -90,10 +90,15 @@ func (m *Document) InsertOrUpdate(cols ...string) error {
|
|||
if m.Identify == "" {
|
||||
book := NewBook()
|
||||
identify := "docs"
|
||||
if err := o.QueryTable(book.TableNameWithPrefix()).One(book,"identify");err == nil {
|
||||
if err := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id",m.BookId).One(book,"identify");err == nil {
|
||||
identify = book.Identify
|
||||
}
|
||||
m.Identify = fmt.Sprintf("%s-%d%d",identify,m.BookId,time.Now().Unix())
|
||||
|
||||
m.Identify = fmt.Sprintf("%s-%s",identify,strconv.FormatInt(time.Now().UnixNano(), 32))
|
||||
}
|
||||
if m.OrderSort == 0{
|
||||
sort,_ := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",m.BookId).Filter("parent_id",m.ParentId).Count()
|
||||
m.OrderSort = int(sort) + 1
|
||||
}
|
||||
_, err = o.Insert(m)
|
||||
NewBook().ResetDocumentNumber(m.BookId)
|
|
@ -25,19 +25,19 @@ type DocumentSelected struct {
|
|||
}
|
||||
|
||||
//获取项目的文档树状结构
|
||||
func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree, error) {
|
||||
func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
trees := make([]*DocumentTree, 0)
|
||||
|
||||
var docs []*Document
|
||||
|
||||
count, err := o.QueryTable(m).Filter("book_id", book_id).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")
|
||||
|
||||
if err != nil {
|
||||
return trees, err
|
||||
}
|
||||
book, _ := NewBook().Find(book_id)
|
||||
book, _ := NewBook().Find(bookId)
|
||||
|
||||
trees = make([]*DocumentTree, count)
|
||||
|
||||
|
@ -64,16 +64,16 @@ func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree, error) {
|
|||
return trees, nil
|
||||
}
|
||||
|
||||
func (m *Document) CreateDocumentTreeForHtml(book_id, selected_id int) (string, error) {
|
||||
trees, err := m.FindDocumentTree(book_id)
|
||||
func (m *Document) CreateDocumentTreeForHtml(bookId, selectedId int) (string, error) {
|
||||
trees, err := m.FindDocumentTree(bookId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
parentId := getSelectedNode(trees, selected_id)
|
||||
parentId := getSelectedNode(trees, selectedId)
|
||||
|
||||
buf := bytes.NewBufferString("")
|
||||
|
||||
getDocumentTree(trees, 0, selected_id, parentId, buf)
|
||||
getDocumentTree(trees, 0, selectedId, parentId, buf)
|
||||
|
||||
return buf.String(), nil
|
||||
|
||||
|
@ -92,7 +92,7 @@ func getSelectedNode(array []*DocumentTree, parent_id int) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func getDocumentTree(array []*DocumentTree, parent_id int, selected_id int, selected_parent_id int, buf *bytes.Buffer) {
|
||||
func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, selectedParentId int, buf *bytes.Buffer) {
|
||||
buf.WriteString("<ul>")
|
||||
|
||||
for _, item := range array {
|
||||
|
@ -101,14 +101,14 @@ func getDocumentTree(array []*DocumentTree, parent_id int, selected_id int, sele
|
|||
if p, ok := item.ParentId.(int); ok {
|
||||
pid = p
|
||||
}
|
||||
if pid == parent_id {
|
||||
if pid == parentId {
|
||||
|
||||
selected := ""
|
||||
if item.DocumentId == selected_id {
|
||||
if item.DocumentId == selectedId {
|
||||
selected = ` class="jstree-clicked"`
|
||||
}
|
||||
selected_li := ""
|
||||
if item.DocumentId == selected_parent_id {
|
||||
if item.DocumentId == selectedParentId {
|
||||
selected_li = ` class="jstree-open"`
|
||||
}
|
||||
buf.WriteString("<li id=\"")
|
||||
|
@ -130,7 +130,7 @@ func getDocumentTree(array []*DocumentTree, parent_id int, selected_id int, sele
|
|||
|
||||
for _, sub := range array {
|
||||
if p, ok := sub.ParentId.(int); ok && p == item.DocumentId {
|
||||
getDocumentTree(array, p, selected_id, selected_parent_id, buf)
|
||||
getDocumentTree(array, p, selectedId, selectedParentId, buf)
|
||||
break
|
||||
}
|
||||
}
|
|
@ -61,6 +61,9 @@ function loadDocument($url, $id, $callback) {
|
|||
},
|
||||
complete : function () {
|
||||
NProgress.done();
|
||||
},
|
||||
error : function () {
|
||||
layer.msg("加载失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue