CaiWuXiTong/app/Utilities/FocusMode.php

24 lines
956 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Utilities;
class FocusMode
{
/**
* 单页模式(钉钉工作台入口,或显式 ?focus=1):只保留该目录自己的页签,隐藏全局菜单。
* 网页端正常登录时不启用,避免页面上的目录页签和左侧菜单、已打开页面标签栏重复。
*/
public static function activeFor(?string $sectionSlug = null): bool
{
$section = $sectionSlug ?: (string) (request()->route('section') ?: request()->segment(3));
// 钉钉工作台打开时 UA 可能被替换成普通浏览器,Referer 仍指向钉钉域名。
$referer = strtolower((string) request()->headers->get('referer'));
$fromDingTalk = str_contains((string) request()->userAgent(), 'DingTalk')
|| str_contains($referer, 'dingtalk');
return in_array($section, ['financial-risk-control'], true)
&& (request()->boolean('focus') || $fromDingTalk);
}
}