TaskListController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\TaskList;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use TencentCloud\Asr\V20190614\Models\Task;
  9. class TaskListController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new TaskList(), function (Grid $grid) {
  19. $grid->model()->with('userData')->where('is_handpick',0)->orderByDesc('id');
  20. $grid->column('id')->sortable();
  21. $grid->column('userData.name','昵称');
  22. $grid->column('userData.mobile','手机号');
  23. $grid->column('userData.avatar','头像')->image('',40,40);
  24. $grid->column('title')->display(function ($initContent) {
  25. $maxLength = 10; // 你希望显示的最大字符数
  26. $ellipsis = '...'; // 省略号
  27. // 使用 mb_substr 截取字符串
  28. $displayContent = mb_substr($initContent, 0, $maxLength);
  29. // 如果原始字符串长度超过最大长度,添加省略号
  30. if (mb_strlen($initContent) > $maxLength) {
  31. $displayContent .= $ellipsis;
  32. }
  33. return $displayContent;
  34. });;
  35. // $grid->column('role_id');
  36. // $grid->column('content');
  37. $grid->column('state')->using(TaskList::$state)
  38. ->dot(
  39. [
  40. 0 => 'primary',
  41. 1 => 'secondary',
  42. 2 => 'danger',
  43. 3 => 'warning',
  44. 4 => 'info',
  45. 5 => 'light',
  46. 6 => 'success',
  47. ],
  48. 'danger' // 第二个参数为默认值
  49. );;
  50. // $grid->column('image')->image('',80,80);
  51. // $grid->column('init_content')->width('300px')->display(function ($initContent) {
  52. // $maxLength = 10; // 你希望显示的最大字符数
  53. // $ellipsis = '...'; // 省略号
  54. //
  55. // // 使用 mb_substr 截取字符串
  56. // $displayContent = mb_substr($initContent, 0, $maxLength);
  57. //
  58. // // 如果原始字符串长度超过最大长度,添加省略号
  59. // if (mb_strlen($initContent) > $maxLength) {
  60. // $displayContent .= $ellipsis;
  61. // }
  62. //
  63. // return $displayContent;
  64. // });
  65. // $grid->column('keyword');
  66. // $grid->column('sd_image');
  67. // $grid->column('desc');
  68. // $grid->column('sd_id')->image('',80,80);
  69. $grid->column('surplus_diamond');
  70. // $grid->column('nickname');
  71. // $grid->column('plot');
  72. $grid->column('is_handpick')->switch();
  73. $grid->column('sort')->sortable();
  74. $grid->column('pdf_path')->display(function ($pdfPath) {
  75. // $downloadUrl = url($pdfPath);
  76. if (!empty($pdfPath)){
  77. return "<a target='_blank' href='".$pdfPath."'>下载PDF</a>";
  78. }else{
  79. return "还未生成PDF";
  80. }
  81. });
  82. $grid->column('image_path','图片地址')->display(function ($image_path) {
  83. // $downloadUrl = url($pdfPath);
  84. if (!empty($image_path)){
  85. return "<a target='_blank' href='".$image_path."'>浏览图片</a>";
  86. }else{
  87. return "还未生成图片";
  88. }
  89. });
  90. // $grid->column('pinyin_content');
  91. $grid->column('created_at');
  92. $grid->column('updated_at')->sortable();
  93. $grid->disableEditButton();
  94. $grid->disableDeleteButton();
  95. $grid->disableViewButton();
  96. $grid->disableCreateButton();
  97. $grid->filter(function (Grid\Filter $filter) {
  98. $filter->panel();
  99. $filter->between('created_at')->datetime();
  100. $filter->equal('is_handpick','是否精选')->select([0 => '不是精选',1 => '精选']);
  101. $filter->where('mobile', function ($query) {
  102. $query->whereHas('userData', function ($query) {
  103. $query->where('mobile', 'like', "%{$this->input}%");
  104. });
  105. }, '用户手机号');
  106. $filter->where('name', function ($query) {
  107. $query->whereHas('userData', function ($query) {
  108. $query->where('name', 'like', "%{$this->input}%");
  109. });
  110. }, '用户昵称');
  111. });
  112. });
  113. }
  114. /**
  115. * Make a show builder.
  116. *
  117. * @param mixed $id
  118. *
  119. * @return Show
  120. */
  121. protected function detail($id)
  122. {
  123. return Show::make($id, new TaskList(), function (Show $show) {
  124. $show->field('id');
  125. $show->field('user_id');
  126. $show->field('title');
  127. $show->field('role_id');
  128. $show->field('content');
  129. $show->field('state');
  130. $show->field('image');
  131. $show->field('init_content');
  132. $show->field('keyword');
  133. $show->field('sd_image');
  134. $show->field('desc');
  135. $show->field('sd_id');
  136. $show->field('surplus_diamond');
  137. $show->field('nickname');
  138. $show->field('plot');
  139. $show->field('is_handpick');
  140. $show->field('sort');
  141. $show->field('pinyin_content');
  142. $show->field('pdf_path');
  143. $show->field('created_at');
  144. $show->field('updated_at');
  145. });
  146. }
  147. /**
  148. * Make a form builder.
  149. *
  150. * @return Form
  151. */
  152. protected function form()
  153. {
  154. return Form::make(new TaskList(), function (Form $form) {
  155. $form->display('id');
  156. $form->text('user_id');
  157. $form->text('title');
  158. $form->text('role_id');
  159. $form->text('content');
  160. $form->text('state');
  161. $form->text('image');
  162. $form->text('init_content');
  163. $form->text('keyword');
  164. $form->text('sd_image');
  165. $form->text('desc');
  166. $form->text('sd_id');
  167. $form->text('surplus_diamond');
  168. $form->text('nickname');
  169. $form->text('plot');
  170. $form->text('is_handpick');
  171. $form->text('sort');
  172. $form->text('pinyin_content');
  173. $form->text('pdf_path');
  174. $form->display('created_at');
  175. $form->display('updated_at');
  176. });
  177. }
  178. }