v1.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * The blockPanel 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. require_once dirname(__DIR__) . DS . 'panel' . DS . 'v1.php';
  13. /**
  14. * 仪表盘区块面板(blockPanel)部件类。
  15. * The block panel widget class.
  16. *
  17. * @author Hao Sun
  18. */
  19. class blockPanel extends panel
  20. {
  21. /**
  22. * @var mixed[]
  23. */
  24. protected static $defineProps = array
  25. (
  26. 'class?: string="rounded bg-canvas panel-block"', // 类名。
  27. 'id?: string', // ID。
  28. 'name?: string', // 区块内部名称。
  29. 'block?: object|array', // 区块对象。
  30. 'title?: string', // 标题。
  31. 'headingClass?: string="border-b"', // 标题栏类名。
  32. 'longBlock?: bool', // 是否为长区块。
  33. 'moreLink?: string|array' // 更多链接 URL 或链接按钮属性。
  34. );
  35. protected function created()
  36. {
  37. global $lang;
  38. $props = array();
  39. $name = $this->prop('name');
  40. $block = $this->prop('block', data('block'));
  41. if(is_array($block)) $block = (object)$block;
  42. if(empty($name) && !empty($block))
  43. {
  44. $name = $block->code;
  45. $props['name'] = $name;
  46. if(empty($this->prop('id'))) $props['id'] = $block->module . '-' . $block->code . '-' . $block->id;
  47. }
  48. $moreLink = $this->prop('moreLink');
  49. if(empty($moreLink) && !empty($block) && isset($block->moreLink)) $moreLink = $block->moreLink;
  50. if(empty($this->prop('headingActions')) && !empty($moreLink))
  51. {
  52. $moreBtnProps = array('type' => 'ghost', 'text' => $lang->more, 'caret' => 'right', 'size' => 'sm');
  53. if(is_string($moreLink)) $moreBtnProps['url'] = $moreLink;
  54. elseif(is_array($moreLink)) $moreBtnProps = array_merge($moreBtnProps, $moreLink);
  55. $props['headingActions'] = array($moreBtnProps);
  56. }
  57. if(is_null($this->prop('title'))) $props['title'] = empty($block) ? $lang->block->titleList[$name] : $block->title;
  58. if($this->prop('longBlock') === null) $props['longBlock'] = data('longBlock');
  59. $this->setProp($props);
  60. }
  61. protected function buildProps()
  62. {
  63. $props = parent::buildProps();
  64. $name = $this->prop('name');
  65. if(!empty($name))
  66. {
  67. $props[] = setData('block', $name);
  68. $props[] = setClass("block-{$name}");
  69. $props[] = setID($this->prop('id'));
  70. }
  71. $props[] = setClass($this->prop('longBlock') ? 'is-long' : 'is-short');
  72. return $props;
  73. }
  74. }