Alert.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 Alert
  16. * @package crmeb\form\components
  17. */
  18. class Alert implements BuildInterface
  19. {
  20. //组件名
  21. const NAME = 'alert';
  22. //提示类型
  23. const INFO = 'info';
  24. //成功类型
  25. const SUCCESS = 'success';
  26. //警告类型
  27. const WARNING = 'warning';
  28. //错误类型
  29. const ERROR = 'error';
  30. //组件类型
  31. const TYPE = [self::INFO, self::SUCCESS, self::WARNING, self::ERROR];
  32. /**
  33. * 规则
  34. * @var array
  35. */
  36. protected $rule = [
  37. 'title' => '',
  38. 'type' => '',
  39. 'closable' => false,
  40. 'showIcon' => false
  41. ];
  42. /**
  43. * Alert constructor.
  44. * @param string $title
  45. * @param string $type
  46. * @param bool $closable
  47. * @param bool $showIcon
  48. */
  49. public function __construct(string $title, string $type = '', bool $closable = false, bool $showIcon = false)
  50. {
  51. $this->rule['type'] = in_array($type, self::TYPE) ? $type : '';
  52. $this->rule['title'] = $title;
  53. $this->rule['closable'] = $closable;
  54. $this->rule['showIcon'] = $showIcon;
  55. }
  56. /**
  57. * 设置类型
  58. * @param string $type
  59. * @return $this
  60. */
  61. public function type(string $type)
  62. {
  63. $this->rule['type'] = in_array($type, self::TYPE) ? $type : '';
  64. return $this;
  65. }
  66. /**
  67. * 是否可关闭
  68. * @param bool $closable
  69. * @return $this
  70. */
  71. public function closable(bool $closable = false)
  72. {
  73. $this->rule['closable'] = $closable;
  74. return $this;
  75. }
  76. /**
  77. * 是否展示图标
  78. * @param bool $showIcon
  79. * @return $this
  80. */
  81. public function showIcon(bool $showIcon = false)
  82. {
  83. $this->rule['showIcon'] = $showIcon;
  84. return $this;
  85. }
  86. public function toArray(): array
  87. {
  88. $this->rule['name'] = self::NAME;
  89. return $this->rule;
  90. }
  91. }