123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- namespace App\Admin\Controllers;
- use App\Http\Controllers\V1\Ai\AiController;
- use App\Models\TaskList;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class WinnowController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new TaskList(), function (Grid $grid) {
- $grid->model()->with('userData')->where('is_handpick', 1)->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('userData.name', '昵称');
- // $grid->column('userData.mobile','手机号');
- $grid->column('userData.avatar', '头像')->image('', 40, 40);
- $grid->column('title')->display(function ($initContent) {
- $maxLength = 10; // 你希望显示的最大字符数
- $ellipsis = '...'; // 省略号
- // 使用 mb_substr 截取字符串
- $displayContent = mb_substr($initContent, 0, $maxLength);
- // 如果原始字符串长度超过最大长度,添加省略号
- if (mb_strlen($initContent) > $maxLength) {
- $displayContent .= $ellipsis;
- }
- return $displayContent;
- });
- // $grid->column('role_id');
- // $grid->column('content');
- // $grid->column('image')->image('',80,80);
- // $grid->column('init_content')->width('300px')->display(function ($initContent) {
- // $maxLength = 10; // 你希望显示的最大字符数
- // $ellipsis = '...'; // 省略号
- //
- // // 使用 mb_substr 截取字符串
- // $displayContent = mb_substr($initContent, 0, $maxLength);
- //
- // // 如果原始字符串长度超过最大长度,添加省略号
- // if (mb_strlen($initContent) > $maxLength) {
- // $displayContent .= $ellipsis;
- // }
- //
- // return $displayContent;
- // });
- // $grid->column('keyword');
- // $grid->column('sd_image');
- // $grid->column('desc');
- // $grid->column('sd_id')->image('',80,80);
- $grid->column('surplus_diamond');
- // $grid->column('nickname');
- // $grid->column('plot');
- $grid->column('sort')->sortable();
- $grid->column('pdf_path')->display(function ($pdfPath) {
- // $downloadUrl = url($pdfPath);
- if (!empty($pdfPath)) {
- return "<a target='_blank' href='" . $pdfPath . "'>下载PDF</a>";
- }
- return '还未生成PDF';
- });
- $grid->column('image_path', '图片地址')->display(function ($image_path) {
- // $downloadUrl = url($pdfPath);
- if (!empty($image_path)) {
- return "<a target='_blank' href='" . $image_path . "'>浏览图片</a>";
- }
- return '还未生成图片';
- });
- // $grid->column('pinyin_content');
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- // $grid->disableEditButton();
- // $grid->disableDeleteButton();
- $grid->disableViewButton();
- // $grid->disableCreateButton();
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->between('created_at')->datetime();
- $filter->like('title');
- // $filter->equal('is_handpick','是否精选')->select([0 => '不是精选',1 => '精选']);
- // $filter->where('mobile', function ($query) {
- // $query->whereHas('userData', function ($query) {
- // $query->where('mobile', 'like', "%{$this->input}%");
- // });
- // }, '用户手机号');
- // $filter->where('name', function ($query) {
- // $query->whereHas('userData', function ($query) {
- // $query->where('name', 'like', "%{$this->input}%");
- // });
- // }, '用户昵称');
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new TaskList(), function (Show $show) {
- $show->field('id');
- $show->field('user_id');
- $show->field('title');
- $show->field('role_id');
- $show->field('content');
- $show->field('state');
- $show->field('image');
- $show->field('init_content');
- $show->field('keyword');
- $show->field('sd_image');
- $show->field('desc');
- $show->field('sd_id');
- $show->field('surplus_diamond');
- $show->field('nickname');
- $show->field('plot');
- $show->field('is_handpick');
- $show->field('sort');
- $show->field('pinyin_content');
- $show->field('pdf_path');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new TaskList(), function (Form $form) {
- $form->display('id');
- $form->hidden('user_id')->default(0);
- // $form->text('title');
- // $form->text('role_id');
- // $form->text('content');
- $form->hidden('state')->default(6);
- $form->text('title')->required();
- $form->image('image')->disk('oss')->autoUpload()->saving(function ($res) {
- if (strstr($res, 'https')) {
- return $res;
- }
- return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
- })->required();
- $form->image('sd_image')->disk('oss')->autoUpload()->saving(function ($res) {
- if (strstr($res, 'https')) {
- return $res;
- }
- return 'zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
- })->required();
- // $form->text('init_content');
- // $form->text('keyword');
- // $form->text('sd_image');
- // $form->text('desc');
- // $form->text('sd_id');
- // $form->text('surplus_diamond');
- // $form->text('nickname');
- // $form->text('plot');
- $form->hidden('is_handpick')->default(1);
- $form->number('sort');
- $form->textarea('pinyin_content')->saving(function ($item) use (&$form) {
- // var_dump($form->sd_image);
- $item = preg_replace('/[^\p{L}\p{N}]/u', '', $item);
- return (new AiController())->extracted($item, 1, 'zhengda.oss-cn-chengdu.aliyuncs.com/' . $form->sd_image);
- });
- $form->file('pdf_path', 'PDF')->disk('oss')->autoUpload()->saving(function ($res) {
- if (strstr($res, 'https')) {
- return $res;
- }
- return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
- })->required();
- $form->image('image_path', '图片')->disk('oss')->autoUpload()->saving(function ($res) {
- if (strstr($res, 'https')) {
- return $res;
- }
- return 'https://zhengda.oss-cn-chengdu.aliyuncs.com/' . $res;
- })->required();
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|