isCli()) { \think\Console::addDefaultCommands([ 'addons\shopro\console\ShoproChat', 'addons\shopro\console\ShoproHelp' ]); } // 全局共享 暗色类型 变量 \think\View::share('DARK_TYPE', $this->getDarkType()); } public function configInit(&$config) { // 全局 js共享 暗色类型 变量 $config['dark_type'] = $this->getDarkType(); } private static function getMenu() { $newMenu = []; $config_file = ADDON_PATH . "shopro" . DS . 'config' . DS . "menu.php"; if (is_file($config_file)) { $newMenu = include $config_file; } $oldMenu = AuthRule::where('name', 'like', "shopro%")->select(); $oldMenu = array_column($oldMenu, null, 'name'); return ['new' => $newMenu, 'old' => $oldMenu]; } /** * 获取暗黑类型 * * @return string */ private function getDarkType() { $dark_type = 'none'; if (in_array('darktheme', get_addonnames())) { // 有暗黑主题 $darkthemeConfig = get_addon_config('darktheme'); $dark_type = $darkthemeConfig['mode'] ?? 'none'; $thememode = cookie("thememode"); if ($thememode && in_array($thememode, ['dark', 'light'])) { $dark_type = $thememode; } } return $dark_type; } }