添加文章管理样式
parent
dddff27e78
commit
7adb8316e1
|
|
@ -9,10 +9,10 @@ class Components extends BaseRenderer {
|
|||
/**
|
||||
* 父级选择器
|
||||
*/
|
||||
public function parentControl($apiUrl = '', $name ='parent_id', $labelField = 'name', $valueField = 'id')
|
||||
public function parentControl($apiUrl = '', $name ='parent_id', $label ='父级', $labelField = 'name', $valueField = 'id')
|
||||
{
|
||||
return amisMake()->TreeSelectControl()
|
||||
->name($name)->label('父级')
|
||||
->name($name)->label($label)
|
||||
->showIcon(false)
|
||||
->labelField($labelField)
|
||||
->valueField($valueField)
|
||||
|
|
@ -23,7 +23,10 @@ class Components extends BaseRenderer {
|
|||
* 排序字段
|
||||
*/
|
||||
public function sortControl($name ='sort', $label = '排序'){
|
||||
return amisMake()->NumberControl()->name($name)->label($label)->min(0);
|
||||
return amisMake()->NumberControl()
|
||||
->name($name)->label($label)
|
||||
->value(0)
|
||||
->min(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\ArticleCategoryService;
|
||||
use App\Admin\Components;
|
||||
|
||||
class ArticleCategoryController extends AdminController
|
||||
{
|
||||
protected string $serviceName = ArticleCategoryService::class;
|
||||
|
||||
protected string $pageTitle = '文章分类';//待完善-todo
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton(true),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('name')->label('名称'),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
$this->rowActions(true),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('name')->label('名称')->required(true),
|
||||
amisMake()->ImageControl()->name('icon')->label('icon')->autoUpload(true),
|
||||
Components::make()->parentControl(),
|
||||
Components::make()->sortControl(),
|
||||
amisMake()->SwitchControl()->name('is_enable')->label('状态'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('name')->label('名称'),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTreeList(Request $request){
|
||||
return $this->service->getTree();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\ArticleService;
|
||||
use App\Admin\Components;
|
||||
|
||||
class ArticleController extends AdminController
|
||||
{
|
||||
protected string $serviceName = ArticleService::class;
|
||||
|
||||
protected string $pageTitle = '文章管理';//待完善-todo
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton(true, 'lg'),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('title')->label('标题'),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
$this->rowActions(true, 'lg'),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('title')->label('标题')->required(true),
|
||||
TextControl::make()->name('sub_title')->label('副标题'),
|
||||
amisMake()->ImageControl()->name('cover')->label('封面')->autoUpload(true),
|
||||
Components::make()->parentControl('', 'category_id', '分类'),
|
||||
Components::make()->fuEditorControl(),
|
||||
Components::make()->sortControl(),
|
||||
\amisMake()->DateTimeControl()->name('published_at')->label('发布时间')->description('*不填写则默认为创建时间'),
|
||||
\amisMake()->SwitchControl()->name('is_enable')->label('显示'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('title')->label('标题'),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,10 @@ Route::group([
|
|||
|
||||
//公告管理
|
||||
$router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class);
|
||||
//文章分类
|
||||
$router->resource('article-categories', \App\Admin\Controllers\ArticleCategoryController::class);
|
||||
//文章管理
|
||||
$router->resource('articles', \App\Admin\Controllers\ArticleController::class);
|
||||
|
||||
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?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 $fillable = [];
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
class ArticleCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = [];
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\ArticleCategory;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
|
||||
/**
|
||||
* @method ArticleCategory getModel()
|
||||
* @method ArticleCategory|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class ArticleCategoryService extends AdminService
|
||||
{
|
||||
protected string $modelName = ArticleCategory::class;
|
||||
|
||||
public function getTree()
|
||||
{
|
||||
$list = $this->query()->orderByDesc('sort')->get()->toArray();
|
||||
return array2tree($list);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\Article;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
|
||||
/**
|
||||
* @method Article getModel()
|
||||
* @method Article|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class ArticleService extends AdminService
|
||||
{
|
||||
protected string $modelName = Article::class;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('article_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('名称');
|
||||
$table->string('icon')->nullable()->comment('图标');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级ID');
|
||||
$table->unsignedInteger('level')->default(1)->comment('层级');
|
||||
$table->string('path')->default('-')->comment('所有的父级ID');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('article_categories');
|
||||
}
|
||||
};
|
||||
|
|
@ -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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('articles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->string('sub_title')->nullable()->comment('副标题');
|
||||
$table->unsignedBigInteger('category_id')->nullable()->comment('文章分类');
|
||||
$table->text('content')->nullable()->comment('文章内容');
|
||||
$table->timestamp('published_at')->nullable()->comment('发布时间');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
|
||||
//可能用到的额外字段
|
||||
$table->string('cover')->nullable()->comment('封面');
|
||||
$table->string('author')->nullable()->comment('作者/来源');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('articles');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue