QuestionsAndAnswers.php 1.8 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 QuestionsAndAnswers extends Component
  10. {
  11. protected $page; //这是参数
  12. protected $pageSize;
  13. protected $keyword;
  14. protected $viewFile; //视图地址
  15. protected $plateId;
  16. protected $router_path;
  17. /**
  18. * @throws ApiException
  19. */
  20. public function __construct($viewFile = '', $params = [], $keyword = '', $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->keyword = $params['keyword'] ?? $keyword;
  28. $this->plateId = BlogPlateModel::Q_AND_A;
  29. $this->router_path = $params['router_path'] ?? $routerPath;
  30. $this->viewFile = $viewFile;
  31. }
  32. /**
  33. * 问答列表组件
  34. */
  35. public function render()
  36. {
  37. $retData = [
  38. 'recent_news_list' => []
  39. ];
  40. $retData['q_and_a_list'] = BlogRenderFacade::getPublishBlogList(
  41. $this->plateId,
  42. $this->keyword,
  43. $this->page,
  44. $this->pageSize,
  45. [],
  46. 0,
  47. 0,
  48. 'a.id,a.title,a.description,a.total_view'
  49. );
  50. if (!empty($this->router_path)) {
  51. $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
  52. $retData['page_content'] = $pageContent['page_content'];
  53. }
  54. $retData['menu_data']=WebFacade::getWebMenu();
  55. return view($this->viewFile, $retData);
  56. }
  57. }