diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index be7ff38d..64fc8a9a 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -39,7 +39,7 @@ class Index extends Backend 'version' => get_sys_config('version'), 'cdnUrl' => full_url(), 'apiUrl' => Config::get('buildadmin.api_url'), - 'upload' => keys_to_camel_case(get_upload_config()), + 'upload' => keys_to_camel_case(get_upload_config(), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types']), ], 'terminal' => [ 'installServicePort' => Config::get('terminal.install_service_port'), diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 988ba765..62fb047c 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -72,7 +72,7 @@ class Index extends Frontend 'recordNumber' => get_sys_config('record_number'), 'version' => get_sys_config('version'), 'cdnUrl' => full_url(), - 'upload' => keys_to_camel_case(get_upload_config()), + 'upload' => keys_to_camel_case(get_upload_config(), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types']), ], 'openMemberCenter' => Config::get('buildadmin.open_member_center'), 'userInfo' => $this->auth->getUserInfo(), diff --git a/app/common.php b/app/common.php index 78ae6649..3e331531 100644 --- a/app/common.php +++ b/app/common.php @@ -433,16 +433,18 @@ if (!function_exists('get_auth_token')) { if (!function_exists('keys_to_camel_case')) { /** - * 将数组所有 key 的命名方式转换为小写驼峰 - * @param array $array + * 将数组 key 的命名方式转换为小写驼峰 + * @param array $array 被转换的数组 + * @param array $keys 要转换的 key,默认所有 * @return array */ - function keys_to_camel_case(array $array): array + function keys_to_camel_case(array $array, array $keys = []): array { $result = []; foreach ($array as $key => $value) { // 将键名转换为驼峰命名 - $camelCaseKey = parse_name($key, 1, false); + $camelCaseKey = $keys && in_array($key, $keys) ? parse_name($key, 1, false) : $key; + if (is_array($value)) { // 如果值是数组,递归转换 $result[$camelCaseKey] = keys_to_camel_case($value);