2022-08-05 14:26:29 +00:00
|
|
|
const api = require('./api')
|
2019-10-01 12:19:10 +00:00
|
|
|
|
2022-06-21 11:50:03 +00:00
|
|
|
const Tree = window.__nfptree && window.__nfptree.tree || []
|
2022-07-20 00:33:06 +00:00
|
|
|
const TreeMap = new Map()
|
2019-10-01 12:19:10 +00:00
|
|
|
|
|
|
|
exports.Tree = Tree
|
2022-07-20 00:33:06 +00:00
|
|
|
exports.TreeMap = TreeMap
|
2019-10-01 12:19:10 +00:00
|
|
|
|
2022-07-20 00:33:06 +00:00
|
|
|
function parseLeaf(tree) {
|
|
|
|
for (let branch of tree) {
|
|
|
|
TreeMap.set(branch.path, branch)
|
|
|
|
|
|
|
|
if (branch.children && branch.children.length) {
|
|
|
|
parseLeaf(branch.children)
|
|
|
|
}
|
|
|
|
}
|
2019-10-01 12:19:10 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 00:33:06 +00:00
|
|
|
parseLeaf(Tree)
|
|
|
|
|
2022-07-27 08:41:18 +00:00
|
|
|
function processPageBranch(arr, branches, prefix) {
|
|
|
|
branches.forEach((page) => {
|
|
|
|
arr.push({ id: page.id, name: prefix + page.name })
|
|
|
|
if (page.children && page.children.length) {
|
|
|
|
processPageBranch(arr, page.children, page.name + ' -> ')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getFlatTree = function() {
|
|
|
|
let arr = []
|
|
|
|
processPageBranch(arr, Tree, '')
|
|
|
|
return arr
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.refreshTree = function() {
|
2022-08-05 14:26:29 +00:00
|
|
|
return api.sendRequest({
|
2022-07-27 08:41:18 +00:00
|
|
|
method: 'GET',
|
|
|
|
url: '/api/pagetree',
|
|
|
|
})
|
|
|
|
.then(pages => {
|
|
|
|
Tree.splice(0, Tree.length)
|
|
|
|
Tree.push.apply(Tree, pages.tree)
|
|
|
|
TreeMap.clear()
|
|
|
|
parseLeaf(Tree)
|
|
|
|
})
|
2022-08-05 14:26:29 +00:00
|
|
|
}
|