Card.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\form\components;
  12. use crmeb\form\BuildInterface;
  13. /**
  14. * 卡片组件
  15. * Class Card
  16. * @package crmeb\form\components
  17. */
  18. class Card implements BuildInterface
  19. {
  20. /**
  21. * 组件名
  22. */
  23. const NAME = 'card';
  24. /**
  25. * 规则
  26. * @var array
  27. */
  28. protected $rule = [
  29. 'componentsModel' => [],
  30. 'title' => '',
  31. ];
  32. /**
  33. * Card constructor.
  34. * @param string $title
  35. */
  36. public function __construct(string $title)
  37. {
  38. $this->rule['title'] = $title;
  39. }
  40. /**
  41. * 添加组件群
  42. * @param array $components
  43. * @return $this
  44. */
  45. public function components(array $components = [])
  46. {
  47. $this->rule['componentsModel'] = $components;
  48. return $this;
  49. }
  50. /**
  51. * @return array
  52. */
  53. public function toArray(): array
  54. {
  55. $this->rule['name'] = self::NAME;
  56. $componentsModel = [];
  57. foreach ($this->rule['componentsModel'] as $item) {
  58. if ($item instanceof BuildInterface) {
  59. $componentsModel[] = $item->toArray();
  60. }
  61. }
  62. $this->rule['componentsModel'] = $componentsModel;
  63. return $this->rule;
  64. }
  65. }