WinnowController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Http\Controllers\V1\Ai\AiController;
  4. use App\Models\TaskList;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class WinnowController 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', 1)->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('image')->image('',80,80);
  38. // $grid->column('init_content')->width('300px')->display(function ($initContent) {
  39. // $maxLength = 10; // 你希望显示的最大字符数
  40. // $ellipsis = '...'; // 省略号
  41. //
  42. // // 使用 mb_substr 截取字符串
  43. // $displayContent = mb_substr($initContent, 0, $maxLength);
  44. //
  45. // // 如果原始字符串长度超过最大长度,添加省略号
  46. // if (mb_strlen($initContent) > $maxLength) {
  47. // $displayContent .= $ellipsis;
  48. // }
  49. //
  50. // return $displayContent;
  51. // });
  52. // $grid->column('keyword');
  53. // $grid->column('sd_image');
  54. // $grid->column('desc');
  55. // $grid->column('sd_id')->image('',80,80);
  56. $grid->column('surplus_diamond');
  57. // $grid->column('nickname');
  58. // $grid->column('plot');
  59. $grid->column('sort')->sortable();
  60. $grid->column('pdf_path')->display(function ($pdfPath) {
  61. // $downloadUrl = url($pdfPath);
  62. if (!empty($pdfPath)) {
  63. return "<a target='_blank' href='" . $pdfPath . "'>下载PDF</a>";
  64. }
  65. return '还未生成PDF';
  66. });
  67. $grid->column('image_path', '图片地址')->display(function ($image_path) {
  68. // $downloadUrl = url($pdfPath);
  69. if (!empty($image_path)) {
  70. return "<a target='_blank' href='" . $image_path . "'>浏览图片</a>";
  71. }
  72. return '还未生成图片';
  73. });
  74. // $grid->column('pinyin_content');
  75. $grid->column('created_at');
  76. $grid->column('updated_at')->sortable();
  77. // $grid->disableEditButton();
  78. // $grid->disableDeleteButton();
  79. $grid->disableViewButton();
  80. // $grid->disableCreateButton();
  81. $grid->filter(function (Grid\Filter $filter) {
  82. $filter->panel();
  83. $filter->between('created_at')->datetime();
  84. $filter->like('title');
  85. // $filter->equal('is_handpick','是否精选')->select([0 => '不是精选',1 => '精选']);
  86. // $filter->where('mobile', function ($query) {
  87. // $query->whereHas('userData', function ($query) {
  88. // $query->where('mobile', 'like', "%{$this->input}%");
  89. // });
  90. // }, '用户手机号');
  91. // $filter->where('name', function ($query) {
  92. // $query->whereHas('userData', function ($query) {
  93. // $query->where('name', 'like', "%{$this->input}%");
  94. // });
  95. // }, '用户昵称');
  96. });
  97. });
  98. }
  99. /**
  100. * Make a show builder.
  101. *
  102. * @return Show
  103. */
  104. protected function detail($id)
  105. {
  106. return Show::make($id, new TaskList(), function (Show $show) {
  107. $show->field('id');
  108. $show->field('user_id');
  109. $show->field('title');
  110. $show->field('role_id');
  111. $show->field('content');
  112. $show->field('state');
  113. $show->field('image');
  114. $show->field('init_content');
  115. $show->field('keyword');
  116. $show->field('sd_image');
  117. $show->field('desc');
  118. $show->field('sd_id');
  119. $show->field('surplus_diamond');
  120. $show->field('nickname');
  121. $show->field('plot');
  122. $show->field('is_handpick');
  123. $show->field('sort');
  124. $show->field('pinyin_content');
  125. $show->field('pdf_path');
  126. $show->field('created_at');
  127. $show->field('updated_at');
  128. });
  129. }
  130. /**
  131. * Make a form builder.
  132. *
  133. * @return Form
  134. */
  135. protected function form()
  136. {
  137. return Form::make(new TaskList(), function (Form $form) {
  138. $form->display('id');
  139. $form->hidden('user_id')->default(0);
  140. // $form->text('title');
  141. // $form->text('role_id');
  142. // $form->text('content');
  143. $form->hidden('state')->default(6);
  144. $form->text('title')->required();
  145. $form->image('image')->disk('oss')->autoUpload()->saving(function ($res) {
  146. if (strstr($res, 'https')) {
  147. return $res;
  148. }
  149. return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
  150. })->required();
  151. $form->image('sd_image')->disk('oss')->autoUpload()->saving(function ($res) {
  152. if (strstr($res, 'https')) {
  153. return $res;
  154. }
  155. return 'zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
  156. })->required();
  157. // $form->text('init_content');
  158. // $form->text('keyword');
  159. // $form->text('sd_image');
  160. // $form->text('desc');
  161. // $form->text('sd_id');
  162. // $form->text('surplus_diamond');
  163. // $form->text('nickname');
  164. // $form->text('plot');
  165. $form->hidden('is_handpick')->default(1);
  166. $form->number('sort');
  167. $form->textarea('pinyin_content')->saving(function ($item) use (&$form) {
  168. // var_dump($form->sd_image);
  169. $item = preg_replace('/[^\p{L}\p{N}]/u', '', $item);
  170. return (new AiController())->extracted($item, 1, 'zhengda.oss-cn-chengdu.aliyuncs.com/' . $form->sd_image);
  171. });
  172. $form->file('pdf_path', 'PDF')->disk('oss')->autoUpload()->saving(function ($res) {
  173. if (strstr($res, 'https')) {
  174. return $res;
  175. }
  176. return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
  177. })->required();
  178. $form->image('image_path', '图片')->disk('oss')->autoUpload()->saving(function ($res) {
  179. if (strstr($res, 'https')) {
  180. return $res;
  181. }
  182. return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
  183. })->required();
  184. $form->display('created_at');
  185. $form->display('updated_at');
  186. });
  187. }
  188. }