From 50a678714e1e75541a8d696ca105af961d962748 Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Thu, 8 Aug 2024 01:46:39 +0800 Subject: [PATCH] fixed --- .../application/index/controller/Test.php | 86 +++++++++++++- digital_doctor/public/api_docs/api_list.html | 112 +++++++++++------- digital_doctor/public/api_docs/api_list.md | 15 ++- .../src/api/ApiDocument.php | 34 ++++-- 4 files changed, 190 insertions(+), 57 deletions(-) diff --git a/digital_doctor/application/index/controller/Test.php b/digital_doctor/application/index/controller/Test.php index d54483a..e69bf2a 100644 --- a/digital_doctor/application/index/controller/Test.php +++ b/digital_doctor/application/index/controller/Test.php @@ -88,6 +88,16 @@ dump($requestUrl); // 运行事件循环 $loop->run(); } + //function stringToColor($string) { + // // 使用crc32函数计算字符串的哈希值 + // $hash = crc32($string); + // + // // 将整数哈希值转换为16进制,并填充0以确保6位长度 + // $color = sprintf("%06X", $hash & 0xFFFFFF); + // + // // 返回颜色码 + // return '#' . $color; + //} function stringToColor($string) { // 使用crc32函数计算字符串的哈希值 $hash = crc32($string); @@ -95,12 +105,86 @@ dump($requestUrl); // 将整数哈希值转换为16进制,并填充0以确保6位长度 $color = sprintf("%06X", $hash & 0xFFFFFF); + // 分解颜色码为RGB三个部分 + $r = hexdec(substr($color, 0, 2)); + $g = hexdec(substr($color, 2, 2)); + $b = hexdec(substr($color, 4, 2)); + + // 计算亮度调整 + $brightnessFactor = 30; // 减少亮度因子以使颜色更浅 + $contrastThreshold = 80; // 进一步降低对比度阈值以允许更浅的颜色 + $maxBrightness = 100; // 降低最大亮度限制,防止生成过于接近白色的颜色 + + // 调整RGB值以确保颜色足够亮且与黑色有足够的对比度 + $r = min($maxBrightness, max($r + $brightnessFactor, $contrastThreshold)); + $g = min($maxBrightness, max($g + $brightnessFactor, $contrastThreshold)); + $b = min($maxBrightness, max($b + $brightnessFactor, $contrastThreshold)); + + // 将调整后的RGB值转换回16进制颜色码 + $adjustedColor = sprintf("#%02X%02X%02X", $r, $g, $b); + // 返回颜色码 - return '#' . $color; + return $adjustedColor; } + + + function test() { + $api_cache_arr['aaa'][] = ['api_name'=>111,'doc_txt'=>222]; + $api_cache_arr['bb'][] = ['api_name'=>777,'doc_txt'=>777]; + $api_cache_arr['aaa'][] = ['api_name'=>666,'doc_txt'=>666]; + $api_cache_arr['ccc'][] = ['api_name'=>111,'doc_txt'=>222]; + $api_cache_arr['aaa'][] = ['api_name'=>555,'doc_txt'=>555]; + $api_cache_arr['ccc'][] = ['api_name'=>333,'doc_txt'=>333]; + dump($api_cache_arr);die; + // 使用示例 + $color = $this->stringToColor("example string"); + //echo $color; // 输出颜色码 + echo '