fix: 修正操作手冊選單顯示邏輯並強化內容
This commit is contained in:
@@ -309,19 +309,23 @@ export default function AuthenticatedLayout({
|
||||
const menuItems = useMemo(() => {
|
||||
return allMenuItems
|
||||
.map((item) => {
|
||||
// 如果有子項目,先過濾子項目
|
||||
// 如果有子項目
|
||||
if (item.children && item.children.length > 0) {
|
||||
const filteredChildren = item.children.filter(hasPermissionForItem);
|
||||
// 若所有子項目都無權限,則隱藏整個群組
|
||||
if (filteredChildren.length === 0) return null;
|
||||
return { ...item, children: filteredChildren };
|
||||
|
||||
// 若有子項目符合權限,則顯示該群組(群組本身的權限僅作為額外過濾)
|
||||
if (filteredChildren.length > 0) {
|
||||
return { ...item, children: filteredChildren };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 無子項目的單一選單,直接檢查權限
|
||||
if (!hasPermissionForItem(item)) return null;
|
||||
return item;
|
||||
})
|
||||
.filter((item): item is MenuItem => item !== null);
|
||||
}, [can, canAny]);
|
||||
}, [allMenuItems, hasPermissionForItem]);
|
||||
|
||||
// 初始化狀態:優先讀取 localStorage
|
||||
const [expandedItems, setExpandedItems] = useState<string[]>(() => {
|
||||
|
||||
Reference in New Issue
Block a user