123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace crmeb\form\components;
- use crmeb\form\BaseComponent;
- use crmeb\form\BuildInterface;
- class UploadFrame extends BaseComponent implements BuildInterface
- {
-
- const NAME = 'uploadFrame';
-
- protected $rule = [
- 'upload' => [
- 'url' => '',
- 'width' => '960px',
- 'height' => '505px',
- 'field' => 'att_dir',
- 'maxNum' => 1,
- ],
- 'field' => '',
- 'title' => '',
- 'value' => '',
- 'info' => '',
- ];
-
- public function __construct(string $field, string $title, $value = null)
- {
- $this->rule['title'] = $title;
- $this->rule['field'] = $field;
- $this->rule['value'] = !is_null($value) ? $value : null;
- }
-
- public function url(string $url)
- {
- $this->rule['upload']['url'] = $url;
- return $this;
- }
-
- public function width(string $width = '960px')
- {
- $this->rule['upload']['width'] = $width;
- return $this;
- }
-
- public function height(string $height = '505px')
- {
- $this->rule['upload']['height'] = $height;
- return $this;
- }
-
- public function field(string $field)
- {
- $this->rule['upload']['field'] = $field;
- return $this;
- }
-
- public function maxNum(int $maxNum = 1)
- {
- $this->rule['upload']['maxNum'] = $maxNum;
- return $this;
- }
-
- public function info(string $info)
- {
- $this->rule['info'] = $info;
- return $this;
- }
-
- public function toArray(): array
- {
- if ($this->rule['upload']['maxNum'] > 1 && $this->rule['value'] && !is_array($this->rule['value'])) {
- $this->rule['value'] = [];
- }
- $this->rule['name'] = self::NAME;
- $this->before();
- return $this->rule;
- }
- }
|