colorChajian.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. 颜色操作
  4. */
  5. class colorChajian extends Chajian{
  6. /**
  7. 颜色
  8. */
  9. public function color($color,$l=127.5)
  10. {
  11. $r=hexdec(substr($color,1,2));
  12. $g=hexdec(substr($color,3,2));
  13. $b=hexdec(substr($color,5));
  14. $yb=127.5;
  15. if($l > $yb){
  16. $l = $l - $yb;
  17. $r = ($r * ($yb - $l) + 255 * $l) / $yb;
  18. $g = ($g * ($yb - $l) + 255 * $l) / $yb;
  19. $b = ($b * ($yb - $l) + 255 * $l) / $yb;
  20. }else{
  21. $r = ($r * $l) / $yb;
  22. $g = ($g * $l) / $yb;
  23. $b = ($b * $l) / $yb;
  24. }
  25. $nr=$this->tohex($r);
  26. $ng=$this->tohex($g);
  27. $nb=$this->tohex($b);
  28. return '#'.$nr.$ng.$nb;
  29. }
  30. private function tohex($n)
  31. {
  32. $hexch = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  33. $n = round($n);
  34. $l = $n % 16;
  35. $h = floor(($n / 16)) % 16;
  36. return ''.$hexch[$h].''.$hexch[$l].'';
  37. }
  38. /**
  39. * 获取颜色值
  40. */
  41. public function colorTorgb($color)
  42. {
  43. if(!empty($color)&&(strlen($color)==7)){
  44. $r=hexdec(substr($color,1,2));
  45. $g=hexdec(substr($color,3,2));
  46. $b=hexdec(substr($color,5));
  47. }else{
  48. $r=$g=$b='00';
  49. }
  50. return array($r, $g, $b);
  51. }
  52. /**
  53. * 获取样式的
  54. */
  55. public function getApptheme($nohui=true, $ism=false)
  56. {
  57. $arr = $this->getColor();
  58. $color = $arr['color'];
  59. $colors = $arr['colors'];
  60. $colora = $arr['colora'];
  61. $bodybgcolor = 'rgba('.$colors.',0.03)';
  62. $hgcolor = 'rgba('.$colors.',0.15)';
  63. $vgcolor = 'rgba('.$colors.',0.1)';
  64. $str[] = '<style type="text/css">';
  65. //暗黑模式的var(--rgb-r),var(--rgb-g),var(--rgb-b)
  66. $ishei = false;
  67. if(($color == '#333333' || $color=='#555555') && $nohui)$ishei = true;
  68. $str[] = 'body{';
  69. $str[] = 'background:'.$bodybgcolor.';';
  70. $str[] = '--rgb-r:'.$colora[0].';';
  71. $str[] = '--rgb-g:'.$colora[1].';';
  72. $str[] = '--rgb-b:'.$colora[2].';';
  73. $str[] = '--main-color:'.$color.';';
  74. if($ism)$str[] = '--font-size:16px;';
  75. $str[] = '--main-hgcolor:'.$hgcolor.';';
  76. if(!$ishei){
  77. $str[] = '--main-vgcolor:'.$vgcolor.';';
  78. $str[] = '--border:0.5px rgba('.$colors.',0.1) solid;';
  79. $str[] = '--main-border:rgba('.$colors.',0.1);';
  80. }
  81. $str[] = '}';
  82. if($ishei){
  83. $str[] = '.rock-table .rock-table-tr:nth-child(odd){background:rgba(0,0,0,0.03);}';
  84. $str[] = '.rock-table .rock-table-tr:hover{background:rgba(0,0,0,0.1);}';
  85. }
  86. if($ishei){
  87. $bgcol = 'rgba('.$colors.',0.9)';
  88. $bgcolor = 'rgba('.$colors.',0.5)';
  89. $str[] = 'body{background:'.$bgcol.';color:white;--main-bgcolor:'.$bgcolor.'}';
  90. $str[] = 'a:link,a:visited,input{color:white;}';
  91. $str[] = '.input,.textarea,.form-control,.inputs{background:'.$bgcol.';color:white}';
  92. $str[] = '.input:focus,.inputs:focus,.textarea:focus,.form-control:focus{border:.5px rgba(255,255,255,0.1) solid}';
  93. $str[] = '.zhu{color:white}';
  94. $str[] = '.webbtn:disabled,.btn:disabled{background:var(--main-bgcolor);color:#888888}';
  95. $str[] = '.webbtn-default,.webbtn-default:link,.webbtn-default:visited,.btn{background:var(--main-color);color:white;border:none;}';
  96. }else{
  97. $str[] = '.rockmenuli{background:rgba('.$colora[0].','.$colora[1].','.$colora[2].',0.05)}';
  98. }
  99. $str[] = '</style>';
  100. $str[] = '<script type="text/javascript">';
  101. $str[] = 'maincolor = "'.$color.'";';
  102. if(!$ishei)$str[] = 'bootsSelectColor = "var(--main-hgcolor)";';
  103. $str[] = '</script>';
  104. $path = 'webmain/css/rockmy.css';
  105. if(file_exists($path))$str[] = '<link rel="stylesheet" type="text/css" href="'.$path.'?'.time().'" />';
  106. $str[] = '';
  107. return join(PHP_EOL, $str);
  108. }
  109. /**
  110. * 获取样式
  111. */
  112. public function getColor()
  113. {
  114. $color = $this->getTheme();
  115. $maincolora = $this->colorTorgb($color);
  116. $colors = ''.$maincolora[0].','.$maincolora[1].','.$maincolora[2].'';
  117. return array(
  118. 'color' => $color,
  119. 'colors' => $colors,
  120. 'colora' => $maincolora,
  121. );
  122. }
  123. /**
  124. * 获取对应颜色
  125. */
  126. public function getTheme()
  127. {
  128. $color = getconfig('apptheme','#1389D3');
  129. //$apptheme = $this->rock->get('apptheme');
  130. //if(strlen($apptheme)==6)$this->rock->savecookie('apptheme', $apptheme);
  131. //if(!$apptheme)$apptheme = $this->rock->cookie('apptheme');
  132. //if(strlen($apptheme)==6)$color = '#'.$apptheme.'';
  133. return $color;
  134. }
  135. }
粤ICP备19079148号