| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <?php
- namespace UCore\DcatAdmin;
- use UCore\DcatAdmin\Traits\Options;
- use UCore\DcatAdmin\Traits\UserID;
- use Dcat\Admin\Form;
- class FormHelper
- {
- use Options, UserID;
- /**
- * @var Form
- */
- public $form;
- /**
- * @var AdminController
- */
- public $controller;
- public function __construct($form, $controller)
- {
- $this->form = $form;
- $this->controller = $controller;
- }
- public function enableBack(){
- $this->form->tools(function (Form\Tools $tools){
- $tools->prepend();
- });
- }
- /**
- * @param $field
- * @return Form\Field|Form\Field[]|\Illuminate\Support\Collection|null
- */
- public function field($field)
- {
- return $this->form->field($field);
- }
- /**
- * 开关
- *
- * @param $field
- * @param $default
- * @return Form\Field\SwitchField
- */
- public function switch($field , $label = null)
- {
- return $this->form->switch($field, $label);
- }
- /**
- * number
- *
- * @param $field
- * @return Form\Field\Number
- */
- public function number($field, $label = null)
- {
- return $this->form->number($field, $label);
- }
- /**
- * 字符串
- *
- * @param $field
- * @return Form\Field\Text
- */
- public function text($field, $label = null)
- {
- return $this->form->text($field, $label);
- }
- public function hidden($field, $label = null)
- {
- return $this->form->hidden($field, $label);
- }
- /**
- * 单select
- *
- * @param $field
- * @return Form\Field\Select
- */
- public function select($field, $label = null)
- {
- return $this->form->select($field, $label);
- }
- /**
- * 单select 带枚举的
- *
- * @param string $field 字段
- * @param array $enmu 枚举
- * @return Form\Field\Select|mixed
- */
- public function selectOption($field, $enmu, $label = null)
- {
- return $this->form->select($field, $label)->options($this->useing($field, $enmu));
- }
- /**
- * 多 select
- *
- * @param $field
- * @return Form\Field\MultipleSelect
- */
- public function multipleSelect($field, $label = null)
- {
- return $this->form->multipleSelect($field, $label);
- }
- /**
- * 多 select表,选择器
- *
- * @param $field
- * @return Form\Field\MultipleSelectTable
- */
- public function multipleSelectTable($field, $label = null)
- {
- return $this->form->multipleSelectTable($field, $label);
- }
- /**
- * 多 select表,选择器
- *
- * @param $field
- * @return Form\Field\SelectTable
- */
- public function selectTable($field,$label = null)
- {
- return $this->form->selectTable($field, $label);
- }
- /**
- * 多选
- *
- * @param $field
- * @return Form\Field\Checkbox
- */
- public function checkbox($field, $label = null)
- {
- return $this->form->checkbox($field, $label);
- }
- /**
- * 单选
- *
- * @param $field
- * @param array $enmu
- * @return Form\Field\Radio
- */
- public function radio($field, array $enmu, $label = null )
- {
- $lable = $lable ?? $field;
- return $this->form->radio($field, $label)->options( $enmu);
- }
- /**
- * 列表
- *
- * @param $field
- *
- * @return Form\Field\ListField
- */
- public function list($field, $label = null)
- {
- return $this->form->list($field, $label);
- }
- /**
- * 图片表单
- *
- * @param $field
- * @return $this
- */
- public function image($field, $label = null)
- {
- $this->form->image($field, $label);
- return $this;
- }
- /**
- * @param $field
- * @return $this
- */
- public function editor($field, $label = null)
- {
- $this->form->editor($field, $label);
- return $this;
- }
- public function multipleImage($field, $label = null)
- {
- $this->form->multipleImage($field, $label);
- return $this;
- }
- /**
- * 分割线
- *
- * @param $title
- * @return $this
- */
- public function divider($title = null)
- {
- $this->form->divider($this->controller->_translation('divider-' . $title));
- return $this;
- }
- /**
- * 展示字段
- *
- * @param $field
- * @return Form\Field\Display
- */
- public function display($field, $label = null)
- {
- return $this->form->display($field, $label);
- }
- /**
- * @param $field
- * @return Form\Field\Display
- */
- public function displayOptions($field, $label = null)
- {
- $c = $this->controller;
- return $this->form->display($field, $label)->with(function($value) use ($field,$c) {
- return $c->_option($field.'-'.$value);
- });
- }
- /**
- * 文本
- *
- * @param $field
- * @return $this
- *
- */
- public function textarea($field, $label = null)
- {
- return $this->form->textarea($field, $label);
- }
- /**
- * 增加表格
- * @param $field
- * @param $call
- * @return Form\Field\Table
- */
- public function table($field,$call, $label = null)
- {
- return $this->form->table($field, $label,$call);
- }
- /**
- * tags
- *
- * @param $field
- * @return Form\Field\Tags
- */
- public function tags($field, $label = null)
- {
- return $this->form->tags($field, $label);
- }
- /**
- * 关闭所有的 多余
- * @return void
- */
- public function disableAll()
- {
- $this->form->disableDeleteButton();
- $this->form->disableCreatingCheck();
- $this->form->disableViewButton();
- // $this->form->disableListButton();
- $this->form->disableViewCheck();
- $this->form->disableEditingCheck();
- }
- public function disableButton4()
- {
- $this->form->disableDeleteButton();
- $this->form->disableViewButton();
- // $this->form->disableListButton();
- $this->form->disableViewCheck();
- $this->form->disableEditingCheck();
- }
- }
|