FormHelper.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. namespace UCore\DcatAdmin;
  3. use UCore\DcatAdmin\Traits\Options;
  4. use UCore\DcatAdmin\Traits\UserID;
  5. use Dcat\Admin\Form;
  6. class FormHelper
  7. {
  8. use Options, UserID;
  9. /**
  10. * @var Form
  11. */
  12. public $form;
  13. /**
  14. * @var AdminController
  15. */
  16. public $controller;
  17. public function __construct($form, $controller)
  18. {
  19. $this->form = $form;
  20. $this->controller = $controller;
  21. }
  22. public function enableBack(){
  23. $this->form->tools(function (Form\Tools $tools){
  24. $tools->prepend();
  25. });
  26. }
  27. /**
  28. * @param $field
  29. * @return Form\Field|Form\Field[]|\Illuminate\Support\Collection|null
  30. */
  31. public function field($field)
  32. {
  33. return $this->form->field($field);
  34. }
  35. /**
  36. * 开关
  37. *
  38. * @param $field
  39. * @param $default
  40. * @return Form\Field\SwitchField
  41. */
  42. public function switch($field , $label = null)
  43. {
  44. return $this->form->switch($field, $label);
  45. }
  46. /**
  47. * number
  48. *
  49. * @param $field
  50. * @return Form\Field\Number
  51. */
  52. public function number($field, $label = null)
  53. {
  54. return $this->form->number($field, $label);
  55. }
  56. /**
  57. * 字符串
  58. *
  59. * @param $field
  60. * @return Form\Field\Text
  61. */
  62. public function text($field, $label = null)
  63. {
  64. return $this->form->text($field, $label);
  65. }
  66. public function hidden($field, $label = null)
  67. {
  68. return $this->form->hidden($field, $label);
  69. }
  70. /**
  71. * 单select
  72. *
  73. * @param $field
  74. * @return Form\Field\Select
  75. */
  76. public function select($field, $label = null)
  77. {
  78. return $this->form->select($field, $label);
  79. }
  80. /**
  81. * 单select 带枚举的
  82. *
  83. * @param string $field 字段
  84. * @param array $enmu 枚举
  85. * @return Form\Field\Select|mixed
  86. */
  87. public function selectOption($field, $enmu, $label = null)
  88. {
  89. return $this->form->select($field, $label)->options($this->useing($field, $enmu));
  90. }
  91. /**
  92. * 多 select
  93. *
  94. * @param $field
  95. * @return Form\Field\MultipleSelect
  96. */
  97. public function multipleSelect($field, $label = null)
  98. {
  99. return $this->form->multipleSelect($field, $label);
  100. }
  101. /**
  102. * 多 select表,选择器
  103. *
  104. * @param $field
  105. * @return Form\Field\MultipleSelectTable
  106. */
  107. public function multipleSelectTable($field, $label = null)
  108. {
  109. return $this->form->multipleSelectTable($field, $label);
  110. }
  111. /**
  112. * 多 select表,选择器
  113. *
  114. * @param $field
  115. * @return Form\Field\SelectTable
  116. */
  117. public function selectTable($field,$label = null)
  118. {
  119. return $this->form->selectTable($field, $label);
  120. }
  121. /**
  122. * 多选
  123. *
  124. * @param $field
  125. * @return Form\Field\Checkbox
  126. */
  127. public function checkbox($field, $label = null)
  128. {
  129. return $this->form->checkbox($field, $label);
  130. }
  131. /**
  132. * 单选
  133. *
  134. * @param $field
  135. * @param array $enmu
  136. * @return Form\Field\Radio
  137. */
  138. public function radio($field, array $enmu, $label = null )
  139. {
  140. $lable = $lable ?? $field;
  141. return $this->form->radio($field, $label)->options( $enmu);
  142. }
  143. /**
  144. * 列表
  145. *
  146. * @param $field
  147. *
  148. * @return Form\Field\ListField
  149. */
  150. public function list($field, $label = null)
  151. {
  152. return $this->form->list($field, $label);
  153. }
  154. /**
  155. * 图片表单
  156. *
  157. * @param $field
  158. * @return $this
  159. */
  160. public function image($field, $label = null)
  161. {
  162. $this->form->image($field, $label);
  163. return $this;
  164. }
  165. /**
  166. * @param $field
  167. * @return $this
  168. */
  169. public function editor($field, $label = null)
  170. {
  171. $this->form->editor($field, $label);
  172. return $this;
  173. }
  174. public function multipleImage($field, $label = null)
  175. {
  176. $this->form->multipleImage($field, $label);
  177. return $this;
  178. }
  179. /**
  180. * 分割线
  181. *
  182. * @param $title
  183. * @return $this
  184. */
  185. public function divider($title = null)
  186. {
  187. $this->form->divider($this->controller->_translation('divider-' . $title));
  188. return $this;
  189. }
  190. /**
  191. * 展示字段
  192. *
  193. * @param $field
  194. * @return Form\Field\Display
  195. */
  196. public function display($field, $label = null)
  197. {
  198. return $this->form->display($field, $label);
  199. }
  200. /**
  201. * @param $field
  202. * @return Form\Field\Display
  203. */
  204. public function displayOptions($field, $label = null)
  205. {
  206. $c = $this->controller;
  207. return $this->form->display($field, $label)->with(function($value) use ($field,$c) {
  208. return $c->_option($field.'-'.$value);
  209. });
  210. }
  211. /**
  212. * 文本
  213. *
  214. * @param $field
  215. * @return $this
  216. *
  217. */
  218. public function textarea($field, $label = null)
  219. {
  220. return $this->form->textarea($field, $label);
  221. }
  222. /**
  223. * 增加表格
  224. * @param $field
  225. * @param $call
  226. * @return Form\Field\Table
  227. */
  228. public function table($field,$call, $label = null)
  229. {
  230. return $this->form->table($field, $label,$call);
  231. }
  232. /**
  233. * tags
  234. *
  235. * @param $field
  236. * @return Form\Field\Tags
  237. */
  238. public function tags($field, $label = null)
  239. {
  240. return $this->form->tags($field, $label);
  241. }
  242. /**
  243. * 关闭所有的 多余
  244. * @return void
  245. */
  246. public function disableAll()
  247. {
  248. $this->form->disableDeleteButton();
  249. $this->form->disableCreatingCheck();
  250. $this->form->disableViewButton();
  251. // $this->form->disableListButton();
  252. $this->form->disableViewCheck();
  253. $this->form->disableEditingCheck();
  254. }
  255. public function disableButton4()
  256. {
  257. $this->form->disableDeleteButton();
  258. $this->form->disableViewButton();
  259. // $this->form->disableListButton();
  260. $this->form->disableViewCheck();
  261. $this->form->disableEditingCheck();
  262. }
  263. }