UploadFrame.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 UploadFrame
  17. * @package crmeb\form\components
  18. */
  19. class UploadFrame extends BaseComponent implements BuildInterface
  20. {
  21. /**
  22. * 组件名
  23. */
  24. const NAME = 'uploadFrame';
  25. /**
  26. * 规则
  27. * @var array
  28. */
  29. protected $rule = [
  30. 'upload' => [
  31. 'url' => '',
  32. 'width' => '960px',
  33. 'height' => '505px',
  34. 'field' => 'att_dir',
  35. 'maxNum' => 1,
  36. ],
  37. 'field' => '',
  38. 'title' => '',
  39. 'value' => '',
  40. 'info' => '',
  41. ];
  42. /**
  43. * UploadFrame constructor.
  44. * @param string $field
  45. * @param string $title
  46. * @param null $value
  47. */
  48. public function __construct(string $field, string $title, $value = null)
  49. {
  50. $this->rule['title'] = $title;
  51. $this->rule['field'] = $field;
  52. $this->rule['value'] = !is_null($value) ? $value : null;
  53. }
  54. /**
  55. * 设置iframe跳转地址
  56. * @param string $url
  57. * @return $this
  58. */
  59. public function url(string $url)
  60. {
  61. $this->rule['upload']['url'] = $url;
  62. return $this;
  63. }
  64. /**
  65. * 设置iframe宽
  66. * @param string $width
  67. * @return $this
  68. */
  69. public function width(string $width = '960px')
  70. {
  71. $this->rule['upload']['width'] = $width;
  72. return $this;
  73. }
  74. /**
  75. * 设置iframe高
  76. * @param string $height
  77. * @return $this
  78. */
  79. public function height(string $height = '505px')
  80. {
  81. $this->rule['upload']['height'] = $height;
  82. return $this;
  83. }
  84. /**
  85. * 设置提取字段
  86. * @param string $field
  87. * @return $this
  88. */
  89. public function field(string $field)
  90. {
  91. $this->rule['upload']['field'] = $field;
  92. return $this;
  93. }
  94. /**
  95. * 多图单图选择
  96. * @param int $maxNum
  97. * @return $this
  98. */
  99. public function maxNum(int $maxNum = 1)
  100. {
  101. $this->rule['upload']['maxNum'] = $maxNum;
  102. return $this;
  103. }
  104. /**
  105. * 设置提示
  106. * @param string $info
  107. * @return $this
  108. */
  109. public function info(string $info)
  110. {
  111. $this->rule['info'] = $info;
  112. return $this;
  113. }
  114. /**
  115. * @return array
  116. */
  117. public function toArray(): array
  118. {
  119. if ($this->rule['upload']['maxNum'] > 1 && $this->rule['value'] && !is_array($this->rule['value'])) {
  120. $this->rule['value'] = [];
  121. }
  122. $this->rule['name'] = self::NAME;
  123. $this->before();
  124. return $this->rule;
  125. }
  126. }