Tabs.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * Tabs 组件
  15. * Class Tabs
  16. * @package crmeb\form\components
  17. */
  18. class Tabs implements BuildInterface
  19. {
  20. //组件名
  21. const NAME = 'tabs';
  22. /**
  23. * 规则
  24. * @var array[]
  25. */
  26. protected $rule = [
  27. 'options' => []
  28. ];
  29. /**
  30. * Tabs constructor.
  31. * @param array $options
  32. */
  33. public function __construct(array $options = [])
  34. {
  35. $this->rule['options'] = $options;
  36. }
  37. /**
  38. * 添加单个选项卡组件群
  39. * @param string $label
  40. * @param array $components
  41. * @return $this
  42. */
  43. public function option(string $label, array $components = [])
  44. {
  45. $this->rule['options'][] = ['label' => $label, 'componentsModel' => $components];
  46. return $this;
  47. }
  48. /**
  49. * @return array|array[]
  50. */
  51. public function toArray(): array
  52. {
  53. $this->rule['name'] = self::NAME;
  54. $options = [];
  55. foreach ($this->rule['options'] as $option) {
  56. $data = ['label' => $option['label'], 'componentsModel' => []];
  57. foreach ($option['componentsModel'] as $item) {
  58. if ($item instanceof BuildInterface) {
  59. $data['componentsModel'][] = $item->toArray();
  60. }
  61. }
  62. $options[] = $data;
  63. }
  64. $this->rule['options'] = $options;
  65. return $this->rule;
  66. }
  67. }