FormInfo.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Web\Components\Form;
  3. use App\Exceptions\ApiException;
  4. use App\Form\Controllers\FormController;
  5. use App\Form\Facades\FormItemFacade;
  6. use App\Form\Services\FormInfoService;
  7. use App\Web\Facades\WebFacade;
  8. use App\Web\Services\WebService;
  9. use Illuminate\View\Component;
  10. class FormInfo extends Component
  11. {
  12. protected $formId; //这是参数
  13. protected $viewFile;
  14. protected $router_path;
  15. protected $element_code;
  16. /**
  17. * @throws ApiException
  18. */
  19. public function __construct($viewFile = '', $formId = '', $routerPath = '', $elementCode = '')
  20. {
  21. if (empty($viewFile)) {
  22. throw new ApiException('common.page_none', '您访问的地址不存在~');
  23. }
  24. $this->formId = $formId;
  25. $this->viewFile = $viewFile;
  26. $this->router_path = $params['router_path'] ?? $routerPath;
  27. $this->element_code = $elementCode ?? '';
  28. }
  29. /**
  30. * 表单组件
  31. */
  32. public function render()
  33. {
  34. $retData = [];
  35. $retData['form_id'] = $this->formId;
  36. $retData['form_items'] = FormItemFacade::getData($this->formId);
  37. $layoutContent = WebFacade::getStaticPageInfo(['route_path' => WebService::LAYOUTS_ROUTE]);
  38. if (!empty($this->router_path)) {
  39. $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
  40. $retData['page_content'] = $pageContent['page_content'];
  41. if (!empty($layoutContent['page_content'])) {
  42. foreach ($layoutContent['page_content'] as $key => $content_item) {
  43. if (empty($retData['page_content'][$key])) {
  44. $retData['page_content'][$key] = $content_item;
  45. }
  46. }
  47. }
  48. }
  49. $retData['menu_data'] = WebFacade::getWebMenu();
  50. if (!empty($this->element_code)) {
  51. $retData['element_code'] = $this->element_code;
  52. }
  53. //dd($retData);
  54. return view($this->viewFile, $retData);
  55. }
  56. }