mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-15 15:09:25 +00:00
31 lines
997 B
JavaScript
31 lines
997 B
JavaScript
|
|
export default function getAllPageIds (collectionQuery, collectionId, collectionView, viewIds) {
|
|
if (!collectionQuery && !collectionView) {
|
|
return []
|
|
}
|
|
// 优先按照第一个视图排序
|
|
let pageIds = []
|
|
try {
|
|
if (viewIds && viewIds.length > 0) {
|
|
const ids = collectionQuery[collectionId][viewIds[0]]?.collection_group_results?.blockIds
|
|
for (const id of ids) {
|
|
pageIds.push(id)
|
|
}
|
|
}
|
|
} catch (error) {
|
|
|
|
}
|
|
|
|
// 否则按照数据库原始排序
|
|
if (pageIds.length === 0 && collectionQuery && Object.values(collectionQuery).length > 0) {
|
|
const pageSet = new Set()
|
|
Object.values(collectionQuery[collectionId]).forEach(view => {
|
|
view?.blockIds?.forEach(id => pageSet.add(id)) // group视图
|
|
view?.collection_group_results?.blockIds?.forEach(id => pageSet.add(id)) // table视图
|
|
})
|
|
pageIds = [...pageSet]
|
|
// console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length)
|
|
}
|
|
return pageIds
|
|
}
|