- 新增首页导航页:常用分组沿用侧边栏分组,下面是全部业务模块(可展开) - Pages@home 由跳转首个业务页改为渲染首页;侧边栏分组定义抽到 SidebarMenu 复用 - 侧边栏顶部标识可点回首页 - 更新钉钉登录落地断言,补充首页导航测试
140 lines
5.4 KiB
PHP
140 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use App\Models\Auth\User;
|
|
|
|
class SidebarMenu
|
|
{
|
|
/**
|
|
* 侧边栏与首页共用的功能分组,按当前账号可访问的页面过滤,标题跟随后台自定义名称。
|
|
*
|
|
* @return array<int, array{title: string, items: array<int, array{section: string, page: string, title: string, icon: string}>}>
|
|
*/
|
|
public static function groups(?User $user = null): array
|
|
{
|
|
$user ??= user();
|
|
|
|
$groups = [
|
|
['title' => '工作台', 'items' => [
|
|
['workspace', 'overview', '经营总览', 'monitoring'],
|
|
]],
|
|
['title' => '经营报表', 'items' => [
|
|
['company-management', 'subject-operating-report', '主体维度经营报表', 'domain'],
|
|
['company-management', 'company-cost-arrangement', '公司成本安排', 'account_balance_wallet'],
|
|
['company-management', 'tax-forecast', '税金预测表', 'calculate'],
|
|
['store-management', 'store-report', '店铺维度报表', 'storefront'],
|
|
['store-management', 'internal-flow-report', '内部流转报表', 'swap_horiz'],
|
|
['company-management', 'personnel-inventory', '人员盘点表', 'groups'],
|
|
]],
|
|
['title' => '基础资料', 'items' => [
|
|
['store-management', 'basic-information', '店铺基础信息', 'shopping_bag'],
|
|
['store-management', 'store-accounts', '店铺账号密码', 'key'],
|
|
['company-management', 'basic-information', '公司基础信息', 'badge'],
|
|
['trademark-management', 'information', '商标基础信息', 'workspace_premium'],
|
|
]],
|
|
['title' => '规则信息', 'items' => [
|
|
['trademark-management', 'subject-trademark-rules', '主体商标规则', 'rule'],
|
|
['trademark-management', 'store-change-rules', '店铺变更规则', 'rule'],
|
|
['trademark-management', 'store-report-data-logic', '店铺维度报表逻辑配置', 'table_chart'],
|
|
['trademark-management', 'tax-forecast-data-logic', '税金预测表逻辑配置', 'calculate'],
|
|
]],
|
|
['title' => '业务进度', 'items' => [
|
|
['company-management', 'company-progress', '公司进度表', 'timeline'],
|
|
['store-management', 'change-progress', '店铺变更进度表', 'swap_horiz'],
|
|
['trademark-management', 'trademark-progress', '商标进度表', 'format_list_bulleted'],
|
|
['workspace', 'tasks', '待办事项', 'assignment_turned_in'],
|
|
['workspace', 'warnings', '预警页面', 'warning_amber'],
|
|
]],
|
|
['title' => '财务报表', 'items' => [
|
|
['prototype-finance-reports', 'profit-report', '公司利润报表', 'request_quote'],
|
|
['prototype-finance-reports', 'asset-report', '公司资产报表', 'account_balance'],
|
|
]],
|
|
];
|
|
|
|
$visiblePages = self::visiblePages($user);
|
|
|
|
$groups = array_map(function (array $group) use ($visiblePages): array {
|
|
$items = [];
|
|
|
|
foreach ($group['items'] as [$section, $page, $title, $icon]) {
|
|
$key = $section . '/' . $page;
|
|
|
|
if (! isset($visiblePages[$key])) {
|
|
continue;
|
|
}
|
|
|
|
$items[] = [
|
|
'section' => $section,
|
|
'page' => $page,
|
|
'title' => $visiblePages[$key],
|
|
'icon' => $icon,
|
|
];
|
|
}
|
|
|
|
$group['items'] = $items;
|
|
|
|
return $group;
|
|
}, $groups);
|
|
|
|
return array_values(array_filter($groups, static fn (array $group): bool => $group['items'] !== []));
|
|
}
|
|
|
|
/**
|
|
* 当前账号可访问的全部业务模块及页面,供首页做完整导航。
|
|
*
|
|
* @return array<int, array{slug: string, title: string, icon: string, pages: array<int, array{slug: string, title: string}>}>
|
|
*/
|
|
public static function sections(?User $user = null): array
|
|
{
|
|
$user ??= user();
|
|
|
|
$sections = [];
|
|
|
|
foreach (SidebarPermissions::navigationFor($user) as $section) {
|
|
$pages = [];
|
|
|
|
foreach ($section['pages'] ?? [] as $page) {
|
|
$pages[] = ['slug' => $page['slug'], 'title' => $page['title']];
|
|
|
|
foreach ($page['children'] ?? [] as $child) {
|
|
$pages[] = ['slug' => $child['slug'], 'title' => $child['title']];
|
|
}
|
|
}
|
|
|
|
if ($pages === []) {
|
|
continue;
|
|
}
|
|
|
|
$sections[] = [
|
|
'slug' => $section['slug'],
|
|
'title' => $section['title'],
|
|
'icon' => $section['icon'] ?? 'folder',
|
|
'pages' => $pages,
|
|
];
|
|
}
|
|
|
|
return $sections;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string> 「section/page」 => 页面标题
|
|
*/
|
|
private static function visiblePages(User $user): array
|
|
{
|
|
$pages = [];
|
|
|
|
foreach (SidebarPermissions::navigationFor($user) as $section) {
|
|
foreach ($section['pages'] ?? [] as $page) {
|
|
$pages[$section['slug'] . '/' . $page['slug']] = $page['title'];
|
|
|
|
foreach ($page['children'] ?? [] as $child) {
|
|
$pages[$section['slug'] . '/' . $child['slug']] = $child['title'];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $pages;
|
|
}
|
|
}
|