mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 支持浏览卡包内的闪卡 https://github.com/siyuan-note/siyuan/issues/6943
This commit is contained in:
parent
0a525c0fe3
commit
51b4f68035
2 changed files with 14 additions and 5 deletions
|
|
@ -40,7 +40,7 @@ func getRiffCards(c *gin.Context) {
|
||||||
page := int(arg["page"].(float64))
|
page := int(arg["page"].(float64))
|
||||||
blockIDs, total, pageCount := model.GetFlashcards(deckID, page)
|
blockIDs, total, pageCount := model.GetFlashcards(deckID, page)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blockIDs": blockIDs,
|
"blocks": blockIDs,
|
||||||
"total": total,
|
"total": total,
|
||||||
"pageCount": pageCount,
|
"pageCount": pageCount,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -40,8 +41,8 @@ import (
|
||||||
var Decks = map[string]*riff.Deck{}
|
var Decks = map[string]*riff.Deck{}
|
||||||
var deckLock = sync.Mutex{}
|
var deckLock = sync.Mutex{}
|
||||||
|
|
||||||
func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount int) {
|
func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
blockIDs = []string{}
|
blocks = []*Block{}
|
||||||
deck := Decks[deckID]
|
deck := Decks[deckID]
|
||||||
if nil == deck {
|
if nil == deck {
|
||||||
return
|
return
|
||||||
|
|
@ -62,11 +63,19 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount
|
||||||
if end > len(allBlockIDs) {
|
if end > len(allBlockIDs) {
|
||||||
end = len(allBlockIDs)
|
end = len(allBlockIDs)
|
||||||
}
|
}
|
||||||
blockIDs = allBlockIDs[start:end]
|
blockIDs := allBlockIDs[start:end]
|
||||||
total = len(allBlockIDs)
|
total = len(allBlockIDs)
|
||||||
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
||||||
if 1 > len(blockIDs) {
|
if 1 > len(blockIDs) {
|
||||||
blockIDs = []string{}
|
blocks = []*Block{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlBlocks := sql.GetBlocks(blockIDs)
|
||||||
|
blocks = fromSQLBlocks(&sqlBlocks, "", 36)
|
||||||
|
if 1 > len(blocks) {
|
||||||
|
blocks = []*Block{}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue