AceRight.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Admin\Forms;
  3. use App\Admin\Renderable\DistDistributorTable;
  4. use App\Admin\Repositories\DistAppearance;
  5. use Dcat\Admin\Widgets\Form;
  6. use App\Admin\Repositories\DistAppearanceVariable;
  7. class AceRight extends Form
  8. {
  9. public $distId;
  10. public $appearanceId;
  11. public $templateId;
  12. public function __construct($distId,$appearanceId,$templateId)
  13. {
  14. $this->distId = empty($distId) ? 0 : $distId;
  15. $this->appearanceId = empty($appearanceId) ? 0 : $appearanceId;
  16. $this->templateId = empty($templateId) ? 0 : $templateId;
  17. parent::__construct();
  18. }
  19. /*
  20. * 表单设置
  21. */
  22. public function form()
  23. {
  24. $variableRow = DistAppearanceVariable::getVariableRow($this->distId,$this->appearanceId,$this->templateId);
  25. if ($variableRow) {
  26. $i = 0;
  27. foreach ($variableRow as $key => $value) {
  28. $this->hidden('field['.$i.'][id]',$value->id);
  29. if ($value->variable_type == '1') {
  30. //文本类型
  31. $this->text('field['.$i.']['.$value->variable_name.']',$value->variable_name)
  32. ->default($value->variable_value)
  33. ->width(12,12)
  34. ->setLabelClass('d-flex');
  35. } elseif ($value->variable_type == '2') {
  36. //长文本类型
  37. $this->textarea('field['.$i.']['.$value->variable_name.']',$value->variable_name)
  38. ->default($value->variable_value)
  39. ->width(12,12)
  40. ->setLabelClass('d-flex');
  41. } elseif ($value->variable_type == '3') {
  42. //json类型
  43. $this->textarea('field['.$i.']['.$value->variable_name.']',$value->variable_name)
  44. ->default($value->variable_value)
  45. ->width(12,12)
  46. ->setLabelClass('d-flex');
  47. }
  48. $i++;
  49. }
  50. }
  51. $this->disableSubmitButton();
  52. $this->disableResetButton();
  53. $this->html('<button type="button" class="btn btn-primary">add</button> <button type="button" class="btn btn-success">save</button>');
  54. }
  55. // 处理表单提交请求
  56. public function handle(array $input)
  57. {
  58. return $this->response()->success('Processed successfully.')->refresh();
  59. }
  60. /**
  61. * 返回表单数据,如不需要可以删除此方法
  62. *
  63. * @return array
  64. */
  65. public function default()
  66. {
  67. return [];
  68. }
  69. }