Files
star-erp/resources/js/utils/breadcrumb.ts

101 lines
3.2 KiB
TypeScript
Raw Normal View History

2026-01-07 13:06:49 +08:00
import { BreadcrumbItemType } from "@/Components/shared/BreadcrumbNav";
/**
*
*
*/
export const BREADCRUMB_MAP: Record<string, BreadcrumbItemType[]> = {
dashboard: [
{ label: "首頁", isPage: true }
],
products: [
{ label: "首頁", href: "/" },
{ label: "商品與庫存管理" },
2026-01-07 13:12:07 +08:00
{ label: "商品資料管理", href: "/products", isPage: true }
2026-01-07 13:06:49 +08:00
],
warehouses: [
{ label: "首頁", href: "/" },
{ label: "商品與庫存管理" },
2026-01-07 13:12:07 +08:00
{ label: "倉庫管理", href: "/warehouses", isPage: true }
2026-01-07 13:06:49 +08:00
],
vendors: [
{ label: "首頁", href: "/" },
{ label: "廠商管理" },
2026-01-07 13:12:07 +08:00
{ label: "廠商資料管理", href: "/vendors", isPage: true }
2026-01-07 13:06:49 +08:00
],
purchaseOrders: [
{ label: "首頁", href: "/" },
{ label: "採購管理" },
2026-01-07 13:12:07 +08:00
{ label: "管理採購單", href: "/purchase-orders", isPage: true }
2026-01-07 13:06:49 +08:00
],
};
/**
*
* @param base (key of BREADCRUMB_MAP)
* @param extra ()
*/
export function getBreadcrumbs(base: keyof typeof BREADCRUMB_MAP, extra?: BreadcrumbItemType[]): BreadcrumbItemType[] {
const baseItems = JSON.parse(JSON.stringify(BREADCRUMB_MAP[base] || []));
if (extra && extra.length > 0) {
// 如果有額外路徑,基礎路徑的最後一項不應標記為 isPage
if (baseItems.length > 0) {
baseItems[baseItems.length - 1].isPage = false;
}
return [...baseItems, ...extra];
}
return baseItems;
}
/**
*
*/
export function getCreateBreadcrumbs(base: keyof typeof BREADCRUMB_MAP): BreadcrumbItemType[] {
return getBreadcrumbs(base, [{ label: "新增", isPage: true }]);
}
/**
*
*/
export function getEditBreadcrumbs(base: keyof typeof BREADCRUMB_MAP): BreadcrumbItemType[] {
return getBreadcrumbs(base, [{ label: "編輯", isPage: true }]);
}
/**
*
*/
export function getShowBreadcrumbs(base: keyof typeof BREADCRUMB_MAP, suffix: string = "詳情"): BreadcrumbItemType[] {
return getBreadcrumbs(base, [{ label: suffix, isPage: true }]);
}
/**
*
* > () > []
*/
export function getInventoryBreadcrumbs(warehouseId: string | number, warehouseName: string, subPageLabel?: string): BreadcrumbItemType[] {
const baseItems: BreadcrumbItemType[] = [
...JSON.parse(JSON.stringify(BREADCRUMB_MAP.warehouses || []))
];
// 修改「倉庫管理」不作為最後一頁
if (baseItems.length > 0) {
baseItems[baseItems.length - 1].isPage = false;
}
const inventoryDetailItem: BreadcrumbItemType = {
label: `庫存管理 (${warehouseName})`,
href: `/warehouses/${warehouseId}/inventory`,
isPage: !subPageLabel
};
const finalItems = [...baseItems, inventoryDetailItem];
if (subPageLabel) {
finalItems.push({ label: subPageLabel, isPage: true });
}
return finalItems;
}