ResController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace UCore\DcatAdmin\Traits;
  3. use App\Admin\Jz\LazyRenderable\TeamInfo;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Layout\Content;
  6. trait ResController
  7. {
  8. /**
  9. * Index interface.
  10. *
  11. * @param Content $content
  12. * @return Content
  13. */
  14. public function index(Content $content)
  15. {
  16. $res = $this->callContent($content);
  17. if($res){
  18. return $res;
  19. }
  20. return $content
  21. ->translation($this->translation())
  22. ->title($this->title())
  23. ->description($this->description()['index'] ?? trans('admin.list'))
  24. ->body($this->grid());
  25. }
  26. /**
  27. * Show interface.
  28. *
  29. * @param mixed $id
  30. * @param Content $content
  31. * @return Content
  32. */
  33. public function show($id, Content $content)
  34. {
  35. $res = $this->callContent($content);
  36. if ($res) {
  37. return $res;
  38. }
  39. return $content
  40. ->translation($this->translation())
  41. ->body($this->detail($id))
  42. ->title($this->title())
  43. ->description($this->description()['show'] ?? trans('admin.show'));
  44. }
  45. /**
  46. * Edit interface.
  47. *
  48. * @param mixed $id
  49. * @param Content $content
  50. * @return Content
  51. */
  52. public function edit($id, Content $content)
  53. {
  54. $res = $this->callContent($content);
  55. if ($res) {
  56. return $res;
  57. }
  58. return $content
  59. ->translation($this->translation())
  60. ->body($this->form()->edit($id)->title($this->title()))
  61. ->title($this->title())
  62. ->description($this->description()['edit'] ?? trans('admin.edit'));
  63. }
  64. /**
  65. * Create interface.
  66. *
  67. * @param Content $content
  68. * @return Content
  69. */
  70. public function create(Content $content)
  71. {
  72. $res = $this->callContent($content);
  73. if($res){
  74. return $res;
  75. }
  76. return $content
  77. ->translation($this->translation())
  78. ->title($this->title())
  79. ->description($this->description()['create'] ?? trans('admin.create'))
  80. ->body($this->form());
  81. }
  82. /**
  83. * Update the specified resource in storage.
  84. *
  85. * @param int $id
  86. * @return \Illuminate\Http\Response
  87. */
  88. public function update($id)
  89. {
  90. return $this->form()->update($id);
  91. }
  92. /**
  93. * Store a newly created resource in storage.
  94. *
  95. * @return mixed
  96. */
  97. public function store()
  98. {
  99. return $this->form()->store();
  100. }
  101. /**
  102. * Remove the specified resource from storage.
  103. *
  104. * @param int $id
  105. * @return \Illuminate\Http\Response
  106. */
  107. public function destroy($id)
  108. {
  109. return $this->form()->destroy($id);
  110. }
  111. public function callContent(Content &$content)
  112. {
  113. if (request()->header('Sec-Fetch-Dest') == 'iframe'|| request('in_iframe')) {
  114. $content->full();
  115. Admin::disablePjax();
  116. }
  117. if (request()->header('Sec-Fetch-Dest') == 'iframe' && !request('in_iframe')) {
  118. return admin_redirect('/iframe?to=' . url()->current());
  119. }
  120. }
  121. }