iview.php 3.1 KB

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