v1.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * The progressBar widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. /**
  13. * 进度条(progressBar)部件类
  14. * The progressBar widget class
  15. */
  16. class progressBar extends wg
  17. {
  18. /**
  19. * Define widget properties.
  20. *
  21. * @var array
  22. * @access protected
  23. */
  24. protected static $defineProps = array
  25. (
  26. 'percent?: number|array=50', // 百分比。
  27. 'color?: string', // 颜色。
  28. 'background?: string', // 背景色。
  29. 'height: number=20', // 高度。
  30. 'width: string|number="auto"', // 宽度,可以为 'auto' | '100%' | number | ({} & string)。
  31. 'striped?: bool', // 是否显示条纹。
  32. 'active?: bool' // 是否显示动画。
  33. );
  34. /**
  35. * Build widget.
  36. *
  37. * @access protected
  38. * @return mixed
  39. */
  40. protected function build()
  41. {
  42. list($percent, $color, $background, $height, $width, $striped, $active) = $this->prop(array('percent', 'color', 'background', 'height', 'width', 'striped', 'active'));
  43. $style = array
  44. (
  45. 'width' => is_numeric($width) ? "{$width}px" : $width,
  46. 'height' => is_numeric($height) ? "{$height}px" : $height,
  47. '--progress-bg' => $background,
  48. '--progress-bar-color' => $color
  49. );
  50. if(!is_array($percent)) $percent = array($percent);
  51. $bars = array();
  52. foreach($percent as $info)
  53. {
  54. if(!is_array($info)) $info = array('value' => $info);
  55. $bars[] = div
  56. (
  57. setClass('progress-bar'),
  58. setStyle(array('width' => "{$info['value']}%", '--progress-bar-color' => isset($info['color']) ? $info['color'] : $color))
  59. );
  60. }
  61. return div
  62. (
  63. setClass('progress', $striped ? 'progress-striped' : '', $active ? 'active' : ''),
  64. setStyle($style),
  65. set($this->getRestProps()),
  66. $bars,
  67. $this->children()
  68. );
  69. }
  70. }