添加文章管理模板内容
parent
b27ca6e675
commit
e11eb663d8
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
|
use App\Services\Admin\ArticleService;
|
||||||
|
|
||||||
|
class ArticleController extends AdminController
|
||||||
|
{
|
||||||
|
protected string $serviceName = ArticleService::class;
|
||||||
|
|
||||||
|
public function list():Page
|
||||||
|
{
|
||||||
|
$crud = $this->baseCRUD()
|
||||||
|
->headerToolbar([
|
||||||
|
$this->createButton(true),
|
||||||
|
...$this->baseHeaderToolBar(),
|
||||||
|
])
|
||||||
|
->filter($this->baseFilter()->body())
|
||||||
|
->columns([
|
||||||
|
amis()->TableColumn('id', __('admin.id')),
|
||||||
|
amis()->TableColumn('title', __('admin.articles.title')),
|
||||||
|
amis()->TableColumn('category', __('admin.articles.category')),
|
||||||
|
amis()->TableColumn('t_ids', __('admin.articles.tags')),
|
||||||
|
amis()->TableColumn('cover', __('admin.articles.cover')),
|
||||||
|
amis()->TableColumn('published_at', __('admin.articles.published_at')),
|
||||||
|
amis()->TableColumn('is_enable', __('admin.articles.is_enable')),
|
||||||
|
amis()->TableColumn('created_at', __('admin.created_at')),
|
||||||
|
]);
|
||||||
|
return $this->baseList($crud);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(): Form
|
||||||
|
{
|
||||||
|
return $this->baseForm()->body([
|
||||||
|
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function detail(): Form
|
||||||
|
{
|
||||||
|
return $this->baseDetail()->body([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -27,16 +27,21 @@ class KeywordController extends AdminController
|
||||||
amis('reload')->align('right'),
|
amis('reload')->align('right'),
|
||||||
amis('filter-toggler')->align('right'),
|
amis('filter-toggler')->align('right'),
|
||||||
])
|
])
|
||||||
->filter($this->baseFilter()->body(
|
->filter($this->baseFilter()->body([
|
||||||
amis()->TextControl('name', __('admin.keyword'))
|
amis()->TextControl('name', __('admin.keyword'))
|
||||||
|
->size('md')
|
||||||
|
->placeholder(__('admin.keywords.search_name')),
|
||||||
|
amis()->TextControl('parent_name', __('admin.keywords.parent_keyword'))
|
||||||
->size('md')
|
->size('md')
|
||||||
->placeholder(__('admin.keywords.search_name'))
|
->placeholder(__('admin.keywords.search_name'))
|
||||||
|
]
|
||||||
))
|
))
|
||||||
->columns([
|
->columns([
|
||||||
// TableColumn::make()->name('id')->label('ID')->sortable(true),
|
// TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||||
TableColumn::make()->name('name')->label('名称'),
|
TableColumn::make()->name('name')->label('名称'),
|
||||||
TableColumn::make()->name('key')->label('KEY'),
|
TableColumn::make()->name('key')->label('KEY')->copyable(true),
|
||||||
TableColumn::make()->name('value')->label('值'),
|
TableColumn::make()->name('value')->label('值'),
|
||||||
|
TableColumn::make()->name('sort')->label('排序'),
|
||||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||||
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
||||||
$this->rowEditButton(true),
|
$this->rowEditButton(true),
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,6 @@ Route::group([
|
||||||
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
|
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
|
||||||
|
|
||||||
$router->resource('system/keywords', \App\Admin\Controllers\KeywordController::class);
|
$router->resource('system/keywords', \App\Admin\Controllers\KeywordController::class);
|
||||||
|
|
||||||
|
$router->resource('articles', \App\Admin\Controllers\ArticleController::class);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
|
||||||
|
class Article extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use Filterable;
|
||||||
|
|
||||||
|
protected function serializeDate(\DateTimeInterface $date)
|
||||||
|
{
|
||||||
|
return $date->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
'cover',
|
||||||
|
'category',
|
||||||
|
't_ids',
|
||||||
|
'published_at',
|
||||||
|
'is_enable',
|
||||||
|
'is_recommend',
|
||||||
|
'sort',
|
||||||
|
'appendixes',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Filters;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class ArticleFilter extends ModelFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
public function title($title)
|
||||||
|
{
|
||||||
|
return $this->where('title','like', '%'.$title.'%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,15 +3,25 @@
|
||||||
namespace App\Models\Filters;
|
namespace App\Models\Filters;
|
||||||
|
|
||||||
use EloquentFilter\ModelFilter;
|
use EloquentFilter\ModelFilter;
|
||||||
|
use App\Models\Keyword;
|
||||||
|
|
||||||
class KeywordFilter extends ModelFilter
|
class KeywordFilter extends ModelFilter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 所属种植计划
|
* 关键字
|
||||||
*/
|
*/
|
||||||
public function name($name)
|
public function name($name)
|
||||||
{
|
{
|
||||||
return $this->where('name','like', '%'.$name.'%')
|
return $this->where('name','like', '%'.$name.'%')
|
||||||
->orWhere('key','like', '%'.$name.'%');
|
->orWhere('key','like', '%'.$name.'%');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function parentName($parent_name)
|
||||||
|
{
|
||||||
|
return $this->where(function($q) use ($parent_name){
|
||||||
|
$q->where('name','like', '%'.$parent_name.'%')
|
||||||
|
->orWhere('key','like', '%'.$parent_name.'%');
|
||||||
|
})->orWhere('parent_key', Keyword::where('name','like', '%'.$parent_name.'%')
|
||||||
|
->orWhere('key','like', '%'.$parent_name.'%')->value('key') ?? '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Filters\ArticleFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Article getModel()
|
||||||
|
* @method Article|\Illuminate\Database\Query\Builder query()
|
||||||
|
*/
|
||||||
|
class ArticleService extends BaseService
|
||||||
|
{
|
||||||
|
protected string $modelName = Article::class;
|
||||||
|
|
||||||
|
protected string $modelFilterName = ArticleFilter::class;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('articles', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('title')->comment('标题');
|
||||||
|
$table->text('content')->nullable()->comment('内容');
|
||||||
|
$table->string('cover')->nullable()->comment('封面');
|
||||||
|
|
||||||
|
$table->string('category')->nullable()->comment('分类');
|
||||||
|
$table->string('t_ids')->nullable()->comment('标签');
|
||||||
|
|
||||||
|
$table->timestamp('published_at')->nullable()->comment('发布时间');
|
||||||
|
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||||
|
|
||||||
|
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐开关');
|
||||||
|
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||||
|
|
||||||
|
$table->text('appendixes')->nullable()->comment('附件');
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('articles');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -13,5 +13,6 @@ class DatabaseSeeder extends Seeder
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$this->call(AdminMenuSeeder::class);
|
$this->call(AdminMenuSeeder::class);
|
||||||
|
$this->call(KeywordSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Keyword;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
class KeywordSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
Keyword::truncate();
|
||||||
|
$list = [
|
||||||
|
['key' => 'article_category', 'name' => '文章分类', 'list' => [
|
||||||
|
|
||||||
|
]],
|
||||||
|
['key' => 'article_tag', 'name' => '文章标签', 'list' => [
|
||||||
|
|
||||||
|
]],
|
||||||
|
['key' => 'banner_address', 'name' => '广告位置', 'list' => [
|
||||||
|
|
||||||
|
]],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($list as $item) {
|
||||||
|
$type = Keyword::create(Arr::except($item, 'list'));
|
||||||
|
|
||||||
|
if (isset($item['list'])) {
|
||||||
|
$keywords = [];
|
||||||
|
foreach ($item['list'] as $index => $name) {
|
||||||
|
$template = [
|
||||||
|
'key' => $type->key . ($index + 1),
|
||||||
|
'parent_key' => $type->key,
|
||||||
|
'lv' => $type->lv + 1,
|
||||||
|
'sort' => $index + 1
|
||||||
|
];
|
||||||
|
if (is_array($name)) {
|
||||||
|
$template = array_merge($template, $name);
|
||||||
|
} else {
|
||||||
|
$template['name'] = $name;
|
||||||
|
}
|
||||||
|
array_push($keywords, $template);
|
||||||
|
}
|
||||||
|
$type->children()->createMany($keywords);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -60,6 +60,7 @@ return [
|
||||||
'cancel' => '取消',
|
'cancel' => '取消',
|
||||||
'please_login' => '请先登录',
|
'please_login' => '请先登录',
|
||||||
'unauthorized' => '无权访问',
|
'unauthorized' => '无权访问',
|
||||||
|
'id' => '主键',
|
||||||
|
|
||||||
'components' => [
|
'components' => [
|
||||||
'content' => '内容',
|
'content' => '内容',
|
||||||
|
|
@ -268,6 +269,20 @@ return [
|
||||||
'please_install_laravel_excel' => '请先安装 laravel-excel 扩展',
|
'please_install_laravel_excel' => '请先安装 laravel-excel 扩展',
|
||||||
],
|
],
|
||||||
'keywords' => [
|
'keywords' => [
|
||||||
'search_name' => '名称/KEY'
|
'search_name' => '名称/KEY',
|
||||||
|
'parent_keyword' => '父级关键字',
|
||||||
|
],
|
||||||
|
'articles' => [
|
||||||
|
'id' => '主键',
|
||||||
|
'title' => '标题',
|
||||||
|
'content' => '内容',
|
||||||
|
'cover' =>'封面',
|
||||||
|
'category' => '分类',
|
||||||
|
'tags' => '标签',
|
||||||
|
't_ids' => '标签',
|
||||||
|
'published_at' => '发布时间',
|
||||||
|
'is_enable' => '显示',
|
||||||
|
'sort' => '排序',
|
||||||
|
'appendixes' => '附件'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue