dootask/app/Module/SystemFunctions.php
kuaifan 1c90a11211 feat: 系统功能应用统一管理内置功能入口
- 新增 SystemFunctions 模块与 api/apps/functions 接口,读取 system-functions 应用的安装状态和开关字段
- 工作报告、日历、我的收藏、最近打开、签到打卡的入口(应用中心、头像菜单、左侧导航)统一受开关控制,卸载后全部隐藏
- 导出签到数据随签到打卡一起隐藏;日历停用后访问日历页跳回仪表盘
- 头像菜单按分组计算分割线,隐藏菜单项后不留多余分割线
- 新增迁移:无配置时自动安装并全部启用,已有配置不覆盖
- 同步 ai-kb 与 api-map
2026-09-30 12:44:18 +00:00

104 lines
2.8 KiB
PHP
Raw Permalink 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\Module;
use App\Services\RequestContext;
use Symfony\Component\Yaml\Yaml;
/**
* 「系统功能」内置应用(appstore 应用 system-functions)。
*
* 该应用不启动容器,只通过应用字段保存各内置功能的开关;
* 主程序据此统一控制工作报告、日历、我的收藏、最近打开、签到打卡的入口。
* 仅控制入口显示,不拦截接口、不影响数据。
*/
class SystemFunctions
{
const APP_ID = 'system-functions';
/**
* 功能标识 => 应用字段名
*/
const FUNCTIONS = [
'report' => 'REPORT',
'calendar' => 'CALENDAR',
'favorite' => 'FAVORITE',
'recent' => 'RECENT',
'checkin' => 'CHECKIN',
];
/**
* 应用安装配置文件路径
*
* @return string
*/
public static function configFile(): string
{
return base_path('docker/appstore/config/' . self::APP_ID . '/config.yml');
}
/**
* 获取应用安装状态与各功能的启用状态。
* 应用未安装时全部为停用;已安装时缺失的字段视为启用(字段默认值即启用)。
*
* @return array ['installed' => bool, 'functions' => ['report' => bool, ...]]
*/
public static function status(): array
{
$key = 'system_functions_status';
if (RequestContext::has($key)) {
return RequestContext::get($key);
}
$params = Apps::isInstalled(self::APP_ID) ? self::readParams() : null;
$functions = [];
foreach (self::FUNCTIONS as $name => $field) {
$functions[$name] = $params !== null && self::isOn($params[$field] ?? true);
}
return RequestContext::save($key, [
'installed' => $params !== null,
'functions' => $functions,
]);
}
/**
* 指定功能是否启用
*
* @param string $name 功能标识(report/calendar/favorite/recent/checkin)
* @return bool
*/
public static function enabled(string $name): bool
{
return (bool)(self::status()['functions'][$name] ?? false);
}
/**
* 读取应用安装参数
*
* @return array
*/
private static function readParams(): array
{
try {
$config = Yaml::parseFile(self::configFile());
} catch (\Throwable $e) {
return [];
}
$params = is_array($config) ? ($config['params'] ?? []) : [];
return is_array($params) ? $params : [];
}
/**
* 开关值是否为开启(兼容布尔值与字符串)
*
* @param mixed $value
* @return bool
*/
private static function isOn($value): bool
{
if (is_string($value)) {
return !in_array(strtolower(trim($value)), ['', '0', 'false', 'off', 'no'], true);
}
return (bool)$value;
}
}