Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

fix: deep sub-categories not showing has password status #527

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/views/post/CategoryList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,23 @@ export default {
categories.forEach(category => (hashMap[category.id] = { ...category, children: [] }))
categories.forEach(category => {
const current = hashMap[category.id]
const parent = hashMap[category.parentId]

if (current.password) {
current.hasPassword = true
}

if (parent && (parent.password || parent.hasPassword)) {
current.hasPassword = true
}

if (category.parentId) {
hashMap[category.parentId].children.push(current)
} else {
treeData.push(current)
}
})

// set hasPassword field for tree node
const setHasPasswordField = (categories, hasPassword = false) => {
categories.forEach(category => {
category.hasPassword = !!category.password || hasPassword
if (category.children && category.children.length) {
setHasPasswordField(category.children, category.hasPassword)
}
})
}
setHasPasswordField(treeData)
return treeData
},

Expand Down