From e7e443778c29e82a266a6e0fe08ebfd440844757 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 30 Mar 2022 17:04:55 +0800 Subject: [PATCH] fix: deep sub-categories not showing has password status (#527) Signed-off-by: Ryan Wang --- src/views/post/CategoryList.vue | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/views/post/CategoryList.vue b/src/views/post/CategoryList.vue index f3674ce1..04786c2b 100644 --- a/src/views/post/CategoryList.vue +++ b/src/views/post/CategoryList.vue @@ -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 },