mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-19 19:57:09 +08:00
add prev&next read (#941)
* add prev&next read * add prev&next in default read.tpl * update prev&next
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
// "gorm.io/driver/sqlite"
|
||||
// "gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DocumentTree struct {
|
||||
@@ -19,14 +21,24 @@ type DocumentTree struct {
|
||||
Version int64 `json:"version"`
|
||||
State *DocumentSelected `json:"-"`
|
||||
AAttrs map[string]interface{} `json:"a_attr"`
|
||||
Children []*DocumentTree `json:"children"`
|
||||
}
|
||||
|
||||
// type DocumentTreeJson struct {
|
||||
// gorm.Model
|
||||
// DocumentId int `json:"id"`
|
||||
// DocumentName string `json:"text"`
|
||||
// ParentId interface{} `json:"parent"`
|
||||
// Children []*DocumentTreeJson `json:"children" gorm:"-"`
|
||||
// }
|
||||
|
||||
type DocumentSelected struct {
|
||||
Selected bool `json:"selected"`
|
||||
Opened bool `json:"opened"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
//获取项目的文档树状结构
|
||||
// 获取项目的文档树状结构
|
||||
func (item *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
@@ -79,6 +91,59 @@ func (item *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
||||
return trees, nil
|
||||
}
|
||||
|
||||
// 获取项目的文档树状结构2
|
||||
func (item *Document) FindDocumentTree2(bookId int) ([]*DocumentTree, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
trees := make([]*DocumentTree, 0)
|
||||
|
||||
var docs []*Document
|
||||
|
||||
count, err := o.QueryTable(item).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
|
||||
}
|
||||
book, _ := NewBook().Find(bookId)
|
||||
|
||||
trees = make([]*DocumentTree, count)
|
||||
|
||||
for index, item := range docs {
|
||||
tree := &DocumentTree{
|
||||
AAttrs: map[string]interface{}{"is_open": false, "opened": 0},
|
||||
}
|
||||
if index == 0 {
|
||||
tree.State = &DocumentSelected{Selected: true, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{"is_open": true, "opened": 1}
|
||||
} else if item.IsOpen == 1 {
|
||||
tree.State = &DocumentSelected{Selected: false, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{"is_open": true, "opened": 1}
|
||||
}
|
||||
if item.IsOpen == 2 {
|
||||
tree.State = &DocumentSelected{Selected: false, Opened: false, Disabled: true}
|
||||
tree.AAttrs = map[string]interface{}{"disabled": true, "opened": 2}
|
||||
}
|
||||
tree.DocumentId = item.DocumentId
|
||||
tree.Identify = item.Identify
|
||||
tree.Version = item.Version
|
||||
tree.BookIdentify = book.Identify
|
||||
// if item.ParentId > 0 {
|
||||
tree.ParentId = item.ParentId
|
||||
// } else {
|
||||
// tree.ParentId = "#"
|
||||
// }
|
||||
|
||||
tree.DocumentName = item.DocumentName
|
||||
|
||||
trees[index] = tree
|
||||
}
|
||||
|
||||
return trees, nil
|
||||
}
|
||||
|
||||
func (item *Document) CreateDocumentTreeForHtml(bookId, selectedId int) (string, error) {
|
||||
trees, err := item.FindDocumentTree(bookId)
|
||||
if err != nil {
|
||||
@@ -94,7 +159,7 @@ func (item *Document) CreateDocumentTreeForHtml(bookId, selectedId int) (string,
|
||||
|
||||
}
|
||||
|
||||
//使用递归的方式获取指定ID的顶级ID
|
||||
// 使用递归的方式获取指定ID的顶级ID
|
||||
func getSelectedNode(array []*DocumentTree, parent_id int) int {
|
||||
|
||||
for _, item := range array {
|
||||
|
||||
Reference in New Issue
Block a user