Frame.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * FormBuilder表单生成器
  4. * Author: xaboy
  5. * Github: https://github.com/xaboy/form-builder
  6. */
  7. namespace FormBuilder\components;
  8. use FormBuilder\FormComponentDriver;
  9. /**
  10. * 框架组件
  11. * Class Frame
  12. * @package FormBuilder\components
  13. * @method $this type(String $type) rame类型, 有input, file, image, 默认为input
  14. * @method $this src(String $src) iframe地址
  15. * @method $this maxLength(int $length) value的最大数量, 默认无限制
  16. * @method $this icon(String $icon) 打开弹出框的按钮图标
  17. * @method $this height(String $height) 弹出框高度
  18. * @method $this width(String $width) 弹出框宽度
  19. * @method $this spin(Boolean $bool) 是否显示加载动画, 默认为 true
  20. * @method $this frameTitle(String $title) 弹出框标题
  21. * @method $this handleIcon(Boolean $bool) 操作按钮的图标, 设置为false将不显示, 设置为true为默认的预览图标, 类型为file时默认为false, image类型默认为true
  22. * @method $this allowRemove(Boolean $bool) 是否可删除, 设置为false是不显示删除按钮
  23. *
  24. *
  25. */
  26. class Frame extends FormComponentDriver
  27. {
  28. protected $name = 'frame';
  29. const TYPE_IMAGE = 'image';
  30. const TYPE_FILE = 'file';
  31. const TYPE_INPUT = 'input';
  32. protected $props = [
  33. 'type' => self::TYPE_INPUT,
  34. 'maxLength' => 0
  35. ];
  36. protected static $propsRule = [
  37. 'type' => 'string',
  38. 'src' => 'string',
  39. 'maxLength' => 'int',
  40. 'icon' => 'string',
  41. 'height' => 'string',
  42. 'width' => 'string',
  43. 'spin' => 'boolean',
  44. 'frameTitle' => ['string', 'title'],
  45. 'handleIcon' => 'boolean',
  46. 'allowRemove' => 'boolean',
  47. ];
  48. protected function init()
  49. {
  50. $this->frameTitle('请选择' . $this->title);
  51. }
  52. public function build()
  53. {
  54. $value = $this->value;
  55. if ($this->props['maxLength'] == 1)
  56. $value = is_array($value) && isset($value[0]) ? $value[0] : '';
  57. return [
  58. 'type' => $this->name,
  59. 'field' => $this->field,
  60. 'title' => $this->title,
  61. 'value' => $value,
  62. 'props' => (object)$this->props,
  63. 'validate' => $this->validate
  64. ];
  65. }
  66. }