Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-Server
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
李帅
2023-03-24 16:44:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
932a3028c4c4dddb8f7219aa4c416ef15b4238f2
932a3028
1 parent
2ca93b27
1.又重构一言表,一对多已完成
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
96 additions
and
62 deletions
app/Admin/Controllers/OnePoemController.php
app/Admin/Controllers/PackPoemController.php
app/Console/Commands/DevFFmpeg.php
app/Jobs/AdminMakeImmerse.php
app/Jobs/UserMakeImmerse.php
app/Models/OnePoem2.php
app/Models/OneSentence.php
app/Models/PackPoem.php
database/migrations/2023_03_24_154109_create_one_sentences_table.php
app/Admin/Controllers/OnePoemController.php
View file @
932a302
...
...
@@ -2,8 +2,6 @@
namespace
App\Admin\Controllers
;
use
App\Admin\Renderable\VerseTable
;
use
App\Admin\Repositories\OnePoem
;
use
App\Admin\Repositories\Verse
;
use
App\Models\Author
;
use
App\Models\OnePoem2
;
...
...
@@ -13,7 +11,8 @@ use Dcat\Admin\Grid;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Illuminate\Http\Request
;
use
Dcat\Admin\Widgets\Card
;
use
Dcat\Admin\Widgets\Table
;
class
OnePoemController
extends
AdminController
{
...
...
@@ -46,11 +45,12 @@ class OnePoemController extends AdminController
$grid
->
column
(
'id'
)
->
sortable
();
$grid
->
column
(
'title'
);
$grid
->
column
(
'author'
);
// $grid->column('content');
$grid
->
verses
(
'正文'
)
->
pluck
(
'stanza'
)
->
label
();
// $grid->column('annotate');
// $grid->column('spelling');
// $grid->column('en');
$grid
->
column
(
''
,
'诗句组'
)
->
display
(
'展开'
)
->
expand
(
function
(){
$th
=
[
'id'
,
'一言Id'
,
'正文'
,
'注释'
,
'拼音'
,
'英文'
,
'创建时间'
,
'修改时间'
];
return
Table
::
make
(
$th
,
$this
->
verses
->
toArray
())
->
withBorder
();
});
$grid
->
column
(
'created_at'
);
$grid
->
column
(
'updated_at'
)
->
sortable
();
...
...
@@ -69,7 +69,7 @@ class OnePoemController extends AdminController
*/
protected
function
detail
(
$id
)
{
return
Show
::
make
(
$id
,
new
OnePoem
(),
function
(
Show
$show
)
{
return
Show
::
make
(
$id
,
new
OnePoem
2
(),
function
(
Show
$show
)
{
$show
->
field
(
'id'
);
$show
->
field
(
'title'
);
$show
->
field
(
'content'
);
...
...
@@ -90,7 +90,7 @@ class OnePoemController extends AdminController
->
title
(
$this
->
title
())
->
description
(
'注意:基础库中内容只做参考,创建的一言与其他表数据不耦合!理论上可自行组装句子,也可按诗词原文复制。'
)
// ->description($this->description()['create'] ?? trans('admin.create'))
//
->body(Card::make($this->PoetryGrid()))
->
body
(
Card
::
make
(
$this
->
PoetryGrid
()))
->
body
(
$this
->
form
());
}
...
...
@@ -101,41 +101,24 @@ class OnePoemController extends AdminController
*/
protected
function
form
()
{
return
Form
::
make
(
new
OnePoem
(),
function
(
Form
$form
)
{
$builder
=
OnePoem2
::
with
([
'verses'
]);
return
Form
::
make
(
$builder
,
function
(
Form
$form
)
{
$form
->
display
(
'id'
);
$form
->
text
(
'title'
);
$form
->
text
(
'author'
);
$form
->
hasMany
(
'verses'
,
'诗句组'
,
function
(
Form\NestedForm
$form
)
{
$form
->
selectTable
(
'verse_id'
,
'诗句'
)
->
title
(
'字体选择'
)
->
from
(
VerseTable
::
make
())
->
model
(
\App\Models\Verse
::
class
,
'id'
,
'stanza
'
);
});
$form
->
textarea
(
'content'
);
$form
->
textarea
(
'annotate'
);
$form
->
textarea
(
'spelling'
);
$form
->
textarea
(
'en
'
);
})
->
useTable
()
;
$form
->
display
(
'created_at'
);
$form
->
display
(
'updated_at'
);
});
}
public
function
store
()
{
// 写 一言表
$post
=
request
()
->
all
();
$poem2
=
OnePoem2
::
query
()
->
create
([
'title'
=>
$post
[
'title'
],
'author'
=>
$post
[
'author'
],
]);
// 写关联表
$verse_ids
=
[];
foreach
(
$post
[
'verses'
]
as
$verse
){
$verse_ids
[]
=
$verse
[
'verse_id'
];
}
$poem2
->
verses
()
->
sync
(
$verse_ids
);
return
$this
->
form
()
->
response
()
->
success
(
'添加成功'
)
->
redirect
(
'/poem'
);
}
protected
function
PoetryGrid
()
{
...
...
@@ -143,7 +126,7 @@ class OnePoemController extends AdminController
$grid
->
model
()
->
with
([
'poetry'
]);
$grid
->
column
(
'id'
)
->
sortable
();
$grid
->
column
(
'author_id'
)
->
display
(
function
(){
$grid
->
column
(
'author_id'
,
'作者'
)
->
display
(
function
(){
$id
=
$this
->
poetry_id
;
$poetry
=
Poetry
::
query
()
->
find
(
$id
);
$author_id
=
$poetry
->
author_id
;
...
...
@@ -156,12 +139,9 @@ class OnePoemController extends AdminController
$grid
->
column
(
'annotate'
)
->
copyable
();
$grid
->
column
(
'spelling'
)
->
copyable
();
$grid
->
column
(
'en'
)
->
copyable
();
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
$grid
->
withBorder
();
$grid
->
quickSearch
([
'stanza'
])
->
placeholder
(
'快捷搜索诗
句(节
)'
);
$grid
->
quickSearch
([
'stanza'
])
->
placeholder
(
'快捷搜索诗
节(支持模糊查询
)'
);
$grid
->
paginate
(
5
);
$grid
->
simplePaginate
();
...
...
@@ -169,17 +149,16 @@ class OnePoemController extends AdminController
$grid
->
disableActions
();
$grid
->
disableCreateButton
();
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
$filter
->
where
(
'author_id'
,
function
(
$query
){
$author
=
Author
::
query
()
->
where
(
'name'
,
'like'
,
"%
{
$this
->
input
}
%"
)
->
get
()
->
pluck
(
'id'
);
$poetry
=
Poetry
::
query
()
->
whereIn
(
'author_id'
,
$author
)
->
get
()
->
pluck
(
'id'
);
$query
->
whereIn
(
'poetry_id'
,
$poetry
);
})
->
width
(
3
);
}
,
'作者'
)
->
width
(
3
);
$filter
->
like
(
'poetry.name'
)
->
width
(
3
);
$filter
->
like
(
'stanza'
)
->
width
(
4
);
$filter
->
panel
();
$filter
->
expand
();
});
});
}
...
...
app/Admin/Controllers/PackPoemController.php
View file @
932a302
...
...
@@ -72,23 +72,17 @@ class PackPoemController extends AdminController
*/
protected
function
form
()
{
return
Form
::
make
(
new
PackPoem
([
'poem'
]),
function
(
Form
$form
)
{
return
Form
::
make
(
PackPoem
::
with
([
'poem'
]),
function
(
Form
$form
)
{
$form
->
display
(
'id'
);
$form
->
text
(
'title'
);
$form
->
text
(
'subtitle'
);
$form
->
text
(
'left_text'
);
$form
->
text
(
'right_text'
);
if
(
$form
->
isEditing
())
{
$form
->
display
(
'poem.title'
);
$form
->
display
(
'poem.author'
);
$form
->
display
(
'poem.content'
);
}
else
{
$form
->
selectTable
(
'poem_id'
)
->
title
(
'一言诗词库'
)
->
from
(
PoemTable
::
make
())
->
model
(
OnePoem
::
class
,
'id'
,
'title'
);
}
$form
->
selectTable
(
'poem.poem_id'
,
'一言'
)
->
title
(
'一言诗词库'
)
->
from
(
PoemTable
::
make
())
->
model
(
OnePoem
::
class
,
'id'
,
'title'
);
$form
->
display
(
'created_at'
);
$form
->
display
(
'updated_at'
);
...
...
app/Console/Commands/DevFFmpeg.php
View file @
932a302
...
...
@@ -70,7 +70,7 @@ class DevFFmpeg extends Command
// $arr = json_decode($json,true);
// dd($arr);
// dd(AdminMakeVideo::query()->find(1)->poem2());
// dd(AdminMakeVideo::query()->find(1
)->poem2->verses->toArray());
dd
(
AdminMakeVideo
::
query
()
->
find
(
33
)
->
poem2
->
verses
->
toArray
());
// return 0;
// dd(AdminMakeVideo::query()->find(33)->temp->components->toArray());
dd
(
AdminMakeVideo
::
query
()
->
find
(
33
)
->
temp
->
toArray
());
...
...
app/Jobs/AdminMakeImmerse.php
View file @
932a302
...
...
@@ -219,12 +219,12 @@ class AdminMakeImmerse implements ShouldQueue
switch
(
$component
->
name
){
case
'one_poem'
:
foreach
(
$this
->
adminMakeVideo
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$contents
[]
=
$item
->
stanza
;
if
(
$item
->
content
!=
''
)
$contents
[]
=
$item
->
content
;
}
break
;
case
'one_poem_with_annotate'
:
foreach
(
$this
->
adminMakeVideo
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$contents
[]
=
$item
->
stanza
;
if
(
$item
->
content
!=
''
)
$contents
[]
=
$item
->
content
;
if
(
$item
->
annotate
!=
''
)
$contents
[]
=
$item
->
annotate
;
}
break
;
...
...
@@ -269,7 +269,7 @@ class AdminMakeImmerse implements ShouldQueue
case
'one_poem'
:
$stanzas
=
''
;
foreach
(
$this
->
adminMakeVideo
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$stanzas
=
$item
->
stanza
.
"
\n
"
;
if
(
$item
->
content
!=
''
)
$stanzas
.=
$item
->
content
.
"
\n
"
;
}
$contents
[]
=
$stanzas
;
break
;
...
...
app/Jobs/UserMakeImmerse.php
View file @
932a302
...
...
@@ -506,12 +506,12 @@ class UserMakeImmerse implements ShouldQueue
switch
(
$component
->
name
){
case
'one_poem'
:
foreach
(
$this
->
immerse
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$contents
[]
=
$item
->
stanza
;
if
(
$item
->
content
!=
''
)
$contents
[]
=
$item
->
content
;
}
break
;
case
'one_poem_with_annotate'
:
foreach
(
$this
->
immerse
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$contents
[]
=
$item
->
stanza
;
if
(
$item
->
content
!=
''
)
$contents
[]
=
$item
->
content
;
if
(
$item
->
annotate
!=
''
)
$contents
[]
=
$item
->
annotate
;
}
break
;
...
...
@@ -556,7 +556,7 @@ class UserMakeImmerse implements ShouldQueue
case
'one_poem'
:
$stanzas
=
''
;
foreach
(
$this
->
immerse
->
poem2
->
verses
as
$item
)
{
if
(
$item
->
stanza
!=
''
)
$stanzas
=
$item
->
stanza
.
"
\n
"
;
if
(
$item
->
content
!=
''
)
$stanzas
.=
$item
->
content
.
"
\n
"
;
}
$contents
[]
=
$stanzas
;
break
;
...
...
app/Models/OnePoem2.php
View file @
932a302
...
...
@@ -20,6 +20,6 @@ class OnePoem2 extends Model
public
function
verses
()
{
return
$this
->
belongsToMany
(
Verse
::
class
,
'verse_poem2'
,
'poem_id'
,
'verse
_id'
);
return
$this
->
hasMany
(
OneSentence
::
class
,
'poem
_id'
);
}
}
...
...
app/Models/OneSentence.php
0 → 100644
View file @
932a302
<?php
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
class
OneSentence
extends
Model
{
use
HasFactory
;
protected
$fillable
=
[
'content'
,
'annotate'
,
'spelling'
,
'en'
];
public
function
poem2
()
{
return
$this
->
belongsTo
(
OnePoem2
::
class
,
'poem_id'
);
}
}
app/Models/PackPoem.php
View file @
932a302
...
...
@@ -11,10 +11,15 @@ class PackPoem extends Model
use
HasDateTimeFormatter
;
protected
$table
=
'pack_poem'
;
protected
$with
=
[
'poem'
];
//
protected $with = ['poem'];
public
function
poem
()
{
return
$this
->
belongsTo
(
OnePoem
::
class
);
}
public
function
poem2
()
{
return
$this
->
belongsTo
(
OnePoem2
::
class
);
}
}
...
...
database/migrations/2023_03_24_154109_create_one_sentences_table.php
0 → 100644
View file @
932a302
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateOneSentencesTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
dropIfExists
(
'verse_poem2'
);
Schema
::
create
(
'one_sentences'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
unsignedTinyInteger
(
'poem_id'
);
$table
->
string
(
'content'
)
->
default
(
''
)
->
comment
(
'正文'
);
$table
->
text
(
'annotate'
)
->
nullable
()
->
comment
(
'注解'
);
$table
->
text
(
'spelling'
)
->
nullable
()
->
comment
(
'拼音'
);
$table
->
text
(
'en'
)
->
nullable
()
->
comment
(
'英文解释'
);
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'one_sentences'
);
}
}
Please
register
or
login
to post a comment