RecentNewsList.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 RecentNewsList extends Component
  10. {
  11. protected $viewFile; //视图地址
  12. protected $plateId;
  13. protected $router_path;
  14. protected $pageSize;
  15. /**
  16. * @throws ApiException
  17. */
  18. public function __construct($viewFile = '',$params = [],$routerPath='',$plateId=BlogPlateModel::NEWS,$pageSize = 3)
  19. {
  20. if (empty($viewFile)) {
  21. throw new ApiException('common.page_none', '您访问的地址不存在~');
  22. }
  23. if (!empty($plateId)) {
  24. $this->plateId = $plateId;
  25. } else {
  26. $this->plateId = BlogPlateModel::NEWS;
  27. }
  28. $this->pageSize = $params['page_size'] ?? $pageSize;
  29. $this->viewFile = $viewFile;
  30. $this->router_path = $params['router_path'] ?? $routerPath;
  31. }
  32. /**
  33. * 最近资讯列表组件
  34. */
  35. public function render()
  36. {
  37. $retData['recent_news_list'] = BlogRenderFacade::getPublishBlogList($this->plateId, '', 1, $this->pageSize, ['pub_date','is_top']);
  38. $pageContent = [];
  39. $retData['menu_data']=WebFacade::getWebMenu();
  40. if (!empty($this->router_path)) {
  41. $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
  42. //$retData['page_content'] = $pageContent['page_content'];
  43. }
  44. $layoutContent = WebFacade::getStaticPageInfo(['route_path' => WebService::LAYOUTS_ROUTE]);
  45. if (!empty($layoutContent['page_content'])) {
  46. foreach ($layoutContent['page_content'] as $key => $content_item) {
  47. if (empty($pageContent['page_content'][$key])) {
  48. $pageContent['page_content'][$key] = $content_item;
  49. }
  50. }
  51. }
  52. if (!empty($pageContent['page_content'])) {
  53. $retData['page_content'] = $pageContent['page_content'];
  54. }
  55. // dd($retData);
  56. return view($this->viewFile, $retData);
  57. }
  58. }