DiyTable.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\BaseComponent;
  13. use crmeb\form\BuildInterface;
  14. /**
  15. * 自定义表格
  16. * Class DiyTable
  17. * @package crmeb\form\components
  18. */
  19. class DiyTable extends BaseComponent implements BuildInterface
  20. {
  21. /**
  22. * 组件名称
  23. */
  24. const NAME = 'diyTable';
  25. //内部表格自定义类型
  26. const TYPE = ['input', 'select', 'inputNumber', 'switch'];
  27. /**
  28. * 规则
  29. * @var string[]
  30. */
  31. protected $rule = [
  32. 'title' => '',
  33. 'value' => [],
  34. 'type' => '',
  35. 'field' => '',
  36. 'options' => [],
  37. 'info' => '',
  38. ];
  39. /**
  40. * DiyTable constructor.
  41. * @param string $field
  42. * @param string $title
  43. * @param array $value
  44. * @param array $options
  45. */
  46. public function __construct(string $field, string $title, array $value = [], array $options = [])
  47. {
  48. $this->rule['title'] = $title;
  49. $this->rule['field'] = $field;
  50. $this->rule['options'] = $options;
  51. $this->rule['value'] = $value;
  52. }
  53. /**
  54. * @param string $info
  55. * @return $this
  56. */
  57. public function info(string $info)
  58. {
  59. $this->rule['info'] = $info;
  60. return $this;
  61. }
  62. /**
  63. * 设置列
  64. * @param string $name
  65. * @param string $key
  66. * @param string $type
  67. * @param array $props
  68. * @return $this
  69. */
  70. public function column(string $name, string $key, string $type = 'input', array $props = [])
  71. {
  72. $this->rule['options'][] = ['name' => $name, 'key' => $key, 'type' => $type, 'props' => $props];
  73. return $this;
  74. }
  75. public function toArray(): array
  76. {
  77. $this->rule['name'] = self::NAME;
  78. $this->before();
  79. return $this->rule;
  80. }
  81. }