KnowledgeCentre.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Web\Components\Blog;
  3. use App\Exceptions\ApiException;
  4. use App\Web\Facades\BlogRenderFacade;
  5. use App\Web\Facades\WebFacade;
  6. use App\Web\Models\BlogPlateModel;
  7. use App\Web\Services\WebService;
  8. use Illuminate\View\Component;
  9. class KnowledgeCentre extends Component
  10. {
  11. protected $page; //这是参数
  12. protected $pageSize;
  13. protected $viewFile; //视图地址
  14. protected $typeId;
  15. protected $plateId;
  16. protected $router_path;
  17. /**
  18. * @throws ApiException
  19. */
  20. public function __construct($viewFile = '', $params = [], $typeId = 0, $page = 1, $pageSize = 10,$routerPath='')
  21. {
  22. if (empty($viewFile)) {
  23. throw new ApiException('common.page_none', '您访问的地址不存在~');
  24. }
  25. $this->page = $params['page'] ?? $page;
  26. $this->pageSize = $params['page_size'] ?? $pageSize;
  27. $this->typeId = $params['type_id'] ?? $typeId;
  28. $this->router_path = $params['router_path'] ?? $routerPath;
  29. $this->plateId = BlogPlateModel::KNOWLEDGECENTRE;
  30. $this->viewFile = $viewFile;
  31. }
  32. /**
  33. * 知识中心列表组件
  34. */
  35. public function render()
  36. {
  37. $retData['train_list'] = [];
  38. $recommend = BlogRenderFacade::getPublishBlogList(
  39. $this->plateId,
  40. '',
  41. $this->page,
  42. $this->pageSize,
  43. ['pub_date'],
  44. (int)$this->typeId,
  45. 0,
  46. 'a.id,a.title,a.image_url,a.image_alt,a.pub_date,a.author,a.total_view,b.urla'
  47. );
  48. if(!empty($recommend['data'])) {
  49. $retData = $recommend;
  50. }
  51. if (!empty($this->router_path)) {
  52. $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
  53. $retData['page_content'] = $pageContent['page_content'];
  54. }
  55. $retData['menu_data']=WebFacade::getWebMenu();
  56. return view($this->viewFile, $retData);
  57. }
  58. }