elm.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App;
  3. require '../vendor/autoload.php';
  4. use FormBuilder\Annotation\Col;
  5. use FormBuilder\Annotation\Emit;
  6. use FormBuilder\Annotation\Group;
  7. use FormBuilder\Annotation\Validate\Required;
  8. use FormBuilder\Annotation\Validate\Min;
  9. use FormBuilder\Annotation\Validate\Range;
  10. use FormBuilder\Factory\Elm;
  11. use FormBuilder\Handle\ElmFormHandle;
  12. use FormBuilder\UI\Elm\Components\Rate;
  13. use FormBuilder\UI\Iview\Components\DatePicker;
  14. class GoodsForm extends ElmFormHandle
  15. {
  16. protected $action = 'save.php';
  17. protected $title = '测试 Handle';
  18. protected $fieldTitles = [
  19. 'start_time' => '开启时间',
  20. 'star' => '点赞'
  21. ];
  22. protected $scene = 'get';
  23. protected function getScene()
  24. {
  25. // $this->except = ['goods_name'];
  26. }
  27. /**
  28. * @Col(6)
  29. * @return \FormBuilder\UI\Elm\Components\Input
  30. */
  31. public function goods_name_field()
  32. {
  33. return Elm::input('goods_name', '商品名称')->required();
  34. }
  35. /**
  36. * @Required()
  37. * @Group()
  38. * @Col(8)
  39. * @Range({10,1000},message = "最少输入10个字")
  40. * @return \FormBuilder\UI\Elm\Components\Input
  41. */
  42. public function goods_info_field()
  43. {
  44. return Elm::textarea('goods_info', '商品简介');
  45. }
  46. /**
  47. * @Group()
  48. * @Col(8)
  49. * @Emit({"change","click"})
  50. * @return \FormBuilder\UI\Elm\Components\Switches
  51. */
  52. public function is_open_field()
  53. {
  54. return Elm::switches('is_open', '是否开启');
  55. }
  56. /**
  57. * @Group(2)
  58. * @Col(12)
  59. * @return \FormBuilder\UI\Elm\Components\Frame
  60. */
  61. public function frame_field()
  62. {
  63. return Elm::frameFile('as', 'asd', 'afsdfasdf');
  64. }
  65. /**
  66. * @Group(2)
  67. * @Col(12)
  68. * @return \FormBuilder\UI\Elm\Components\Upload
  69. */
  70. public function test_field()
  71. {
  72. return Elm::uploadFiles('aaa', 'aaa', 'bbb', [1])->required();
  73. }
  74. /**
  75. * @return \FormBuilder\UI\Elm\Components\Hidden
  76. */
  77. public function id_field()
  78. {
  79. return Elm::hidden('1', '1');
  80. }
  81. /**
  82. * @Required("请输入 testRow")
  83. * @return array
  84. */
  85. public function row_field()
  86. {
  87. // return [
  88. // 'type' => 'row',
  89. // 'children' =>
  90. // [
  91. return [
  92. 'type' => 'input',
  93. 'field' => 'row',
  94. 'title' => 'test Row',
  95. 'value' => '123',
  96. 'col' => [
  97. 'span' => 12
  98. ]
  99. ];
  100. // ,
  101. // Elm::input('row2', 'row2', 'asdf')->col(12)
  102. // ],
  103. // 'native' => true
  104. // ];
  105. }
  106. /**
  107. * 通过依赖注入方式生成组件
  108. *
  109. * @param DatePicker $date
  110. * @return DatePicker
  111. */
  112. public function start_time_field(DatePicker $date)
  113. {
  114. return $date->required()->info('asdfasdfasdfsf');
  115. }
  116. public function starField(Rate $rate)
  117. {
  118. return $rate;
  119. }
  120. protected function getFormConfig()
  121. {
  122. $config = Elm::config();
  123. $config->createResetBtn()->show(true);
  124. return $config;
  125. }
  126. protected function getFormData()
  127. {
  128. return [
  129. 'goods_name' => 'goods_name123',
  130. 'asdf' => 'asdfafd',
  131. 'is_open' => '0',
  132. 'goods_info' => "asdf\r\nadfa",
  133. 'star' => 0,
  134. 'row' => 'adsfasdfasd'
  135. ];
  136. }
  137. }
  138. $formHtml = (new GoodsForm())->view();
  139. //$formHtml = (new GoodsForm())->form()->view();
  140. echo $formHtml;