Showing
6 changed files
with
175 additions
and
6 deletions
... | @@ -2,6 +2,7 @@ | ... | @@ -2,6 +2,7 @@ |
2 | 2 | ||
3 | namespace App\Admin\Controllers; | 3 | namespace App\Admin\Controllers; |
4 | 4 | ||
5 | +use App\Admin\Renderable\VerseTable; | ||
5 | use App\Admin\Repositories\OnePoem; | 6 | use App\Admin\Repositories\OnePoem; |
6 | use App\Admin\Repositories\Verse; | 7 | use App\Admin\Repositories\Verse; |
7 | use App\Models\Author; | 8 | use App\Models\Author; |
... | @@ -11,7 +12,7 @@ use Dcat\Admin\Grid; | ... | @@ -11,7 +12,7 @@ use Dcat\Admin\Grid; |
11 | use Dcat\Admin\Layout\Content; | 12 | use Dcat\Admin\Layout\Content; |
12 | use Dcat\Admin\Show; | 13 | use Dcat\Admin\Show; |
13 | use Dcat\Admin\Http\Controllers\AdminController; | 14 | use Dcat\Admin\Http\Controllers\AdminController; |
14 | -use Dcat\Admin\Widgets\Card; | 15 | +use Illuminate\Http\Request; |
15 | 16 | ||
16 | class OnePoemController extends AdminController | 17 | class OnePoemController extends AdminController |
17 | { | 18 | { |
... | @@ -70,7 +71,7 @@ class OnePoemController extends AdminController | ... | @@ -70,7 +71,7 @@ class OnePoemController extends AdminController |
70 | ->title($this->title()) | 71 | ->title($this->title()) |
71 | ->description('注意:基础库中内容只做参考,创建的一言与其他表数据不耦合!理论上可自行组装句子,也可按诗词原文复制。') | 72 | ->description('注意:基础库中内容只做参考,创建的一言与其他表数据不耦合!理论上可自行组装句子,也可按诗词原文复制。') |
72 | // ->description($this->description()['create'] ?? trans('admin.create')) | 73 | // ->description($this->description()['create'] ?? trans('admin.create')) |
73 | - ->body(Card::make($this->PoetryGrid())) | 74 | +// ->body(Card::make($this->PoetryGrid())) |
74 | ->body($this->form()); | 75 | ->body($this->form()); |
75 | } | 76 | } |
76 | 77 | ||
... | @@ -85,16 +86,33 @@ class OnePoemController extends AdminController | ... | @@ -85,16 +86,33 @@ class OnePoemController extends AdminController |
85 | $form->display('id'); | 86 | $form->display('id'); |
86 | $form->text('title'); | 87 | $form->text('title'); |
87 | $form->text('author'); | 88 | $form->text('author'); |
88 | - $form->textarea('content'); | 89 | + |
89 | - $form->text('annotate'); | 90 | + $form->hasMany('components','诗句组', function (Form\NestedForm $form) { |
90 | - $form->text('spelling'); | 91 | + |
91 | - $form->text('en'); | 92 | + $form->selectTable('font_file','诗句') |
93 | + ->title('字体选择') | ||
94 | + ->from(VerseTable::make()) | ||
95 | + ->model(\App\Models\Verse::class,'id','stanza'); | ||
96 | + | ||
97 | + | ||
98 | + }); | ||
99 | + | ||
100 | +// $form->textarea('content'); | ||
101 | +// $form->text('annotate'); | ||
102 | +// $form->text('spelling'); | ||
103 | +// $form->text('en'); | ||
92 | 104 | ||
93 | $form->display('created_at'); | 105 | $form->display('created_at'); |
94 | $form->display('updated_at'); | 106 | $form->display('updated_at'); |
95 | }); | 107 | }); |
96 | } | 108 | } |
97 | 109 | ||
110 | + public function store() | ||
111 | + { | ||
112 | + return request()->all(); | ||
113 | +// return $this->form()->store(); | ||
114 | + } | ||
115 | + | ||
98 | protected function PoetryGrid() | 116 | protected function PoetryGrid() |
99 | { | 117 | { |
100 | return Grid::make(new Verse(), function (Grid $grid) { | 118 | return Grid::make(new Verse(), function (Grid $grid) { | ... | ... |
app/Admin/Renderable/VerseTable.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: lishuai | ||
5 | + * Date: 2022/1/10 | ||
6 | + * Time: 5:57 PM | ||
7 | + */ | ||
8 | + | ||
9 | +namespace App\Admin\Renderable; | ||
10 | + | ||
11 | +use Dcat\Admin\Grid; | ||
12 | +use Dcat\Admin\Grid\LazyRenderable; | ||
13 | +use App\Models\Author; | ||
14 | +use App\Models\Poetry; | ||
15 | +use App\Models\Verse; | ||
16 | + | ||
17 | +class VerseTable extends LazyRenderable | ||
18 | +{ | ||
19 | + | ||
20 | + public function grid(): Grid | ||
21 | + { | ||
22 | + return Grid::make(new Verse(), function (Grid $grid) { | ||
23 | + $grid->model()->with(['poetry']); | ||
24 | + | ||
25 | + $grid->column('id')->sortable(); | ||
26 | + $grid->column('author_id')->display(function (){ | ||
27 | + $id = $this->poetry_id; | ||
28 | + $poetry = Poetry::query()->find($id); | ||
29 | + $author_id = $poetry->author_id; | ||
30 | + $author = Author::query()->find($author_id); | ||
31 | + return $author->name; | ||
32 | + })->copyable(); | ||
33 | + $grid->column('poetry.name')->copyable(); | ||
34 | + | ||
35 | + $grid->column('stanza')->copyable(); | ||
36 | + $grid->column('annotate')->copyable(); | ||
37 | + $grid->column('spelling')->copyable(); | ||
38 | + $grid->column('en')->copyable(); | ||
39 | +// $grid->column('created_at'); | ||
40 | +// $grid->column('updated_at')->sortable(); | ||
41 | + | ||
42 | + | ||
43 | + $grid->withBorder(); | ||
44 | + $grid->quickSearch(['stanza'])->placeholder('快捷搜索诗句(节)'); | ||
45 | + | ||
46 | + $grid->paginate(5); | ||
47 | + $grid->simplePaginate(); | ||
48 | + | ||
49 | + $grid->disableActions(); | ||
50 | + $grid->disableCreateButton(); | ||
51 | + | ||
52 | + $grid->expandFilter(); // 默认展开搜索 | ||
53 | + $grid->filter(function (Grid\Filter $filter) { | ||
54 | +// $filter->where('author_id',function ($query){ | ||
55 | +// $author = Author::query()->where('name','like',"%{$this->input}%")->get()->pluck('id'); | ||
56 | +// $poetry =Poetry::query()->whereIn('author_id',$author)->get()->pluck('id'); | ||
57 | +// $query->whereIn('poetry_id',$poetry); | ||
58 | +// })->width(3); | ||
59 | + $filter->like('poetry.name')->width(6); | ||
60 | +// $filter->like('stanza')->width(4); | ||
61 | + $filter->panel(); | ||
62 | + | ||
63 | + }); | ||
64 | + }); | ||
65 | + } | ||
66 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -73,6 +73,7 @@ class HomeController extends Controller | ... | @@ -73,6 +73,7 @@ class HomeController extends Controller |
73 | 73 | ||
74 | public function poem($id) | 74 | public function poem($id) |
75 | { | 75 | { |
76 | + // todo 多对多关系 | ||
76 | try{ | 77 | try{ |
77 | return Response::success(OnePoem::query()->find($id)); | 78 | return Response::success(OnePoem::query()->find($id)); |
78 | }catch (\Exception $exception){ | 79 | }catch (\Exception $exception){ | ... | ... |
app/Models/OnePoem2.php
0 → 100755
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Models; | ||
4 | + | ||
5 | +use Dcat\Admin\Traits\HasDateTimeFormatter; | ||
6 | + | ||
7 | +use Illuminate\Database\Eloquent\Model; | ||
8 | + | ||
9 | +class OnePoem2 extends Model | ||
10 | +{ | ||
11 | + use HasDateTimeFormatter; | ||
12 | + protected $table = 'one_poem2'; | ||
13 | + | ||
14 | + | ||
15 | + public function admin_make_video() | ||
16 | + { | ||
17 | + return $this->belongsTo(AdminMakeVideo::class,'poem_id'); | ||
18 | + } | ||
19 | +} |
1 | +<?php | ||
2 | + | ||
3 | +use Illuminate\Database\Migrations\Migration; | ||
4 | +use Illuminate\Database\Schema\Blueprint; | ||
5 | +use Illuminate\Support\Facades\Schema; | ||
6 | + | ||
7 | +class CreateOnePoem2Table extends Migration | ||
8 | +{ | ||
9 | + /** | ||
10 | + * Run the migrations. | ||
11 | + * | ||
12 | + * @return void | ||
13 | + */ | ||
14 | + public function up() | ||
15 | + { | ||
16 | + Schema::create('one_poem2', function (Blueprint $table) { | ||
17 | + $table->id(); | ||
18 | + $table->string('title')->default('')->comment('一言标题'); | ||
19 | + $table->string('author')->default('')->comment('作者'); | ||
20 | + $table->timestamps(); | ||
21 | + }); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * Reverse the migrations. | ||
26 | + * | ||
27 | + * @return void | ||
28 | + */ | ||
29 | + public function down() | ||
30 | + { | ||
31 | + Schema::dropIfExists('one_poem2'); | ||
32 | + } | ||
33 | +} |
1 | +<?php | ||
2 | + | ||
3 | +use Illuminate\Database\Migrations\Migration; | ||
4 | +use Illuminate\Database\Schema\Blueprint; | ||
5 | +use Illuminate\Support\Facades\Schema; | ||
6 | + | ||
7 | +class CreateOnePoem2Table extends Migration | ||
8 | +{ | ||
9 | + /** | ||
10 | + * Run the migrations. | ||
11 | + * | ||
12 | + * @return void | ||
13 | + */ | ||
14 | + public function up() | ||
15 | + { | ||
16 | + Schema::create('verse_poem2', function (Blueprint $table) { | ||
17 | + $table->id(); | ||
18 | + $table->integer('verse_id')->comment('诗句id'); | ||
19 | + $table->integer('poem_id')->comment('一言id'); | ||
20 | + }); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * Reverse the migrations. | ||
25 | + * | ||
26 | + * @return void | ||
27 | + */ | ||
28 | + public function down() | ||
29 | + { | ||
30 | + Schema::dropIfExists('verse_poem2'); | ||
31 | + } | ||
32 | +} |
-
Please register or login to post a comment