1
0
Fork 0

添加公告基础样式

develop
vine_liutk 2023-03-20 11:36:30 +08:00
parent e20253c2bf
commit b8fbc8394a
7 changed files with 169 additions and 4 deletions

View File

@ -6,13 +6,46 @@ use Slowlyo\OwlAdmin\Renderers\BaseRenderer;
class Components extends BaseRenderer {
/**
* 父级选择器
*/
public function parentControl($apiUrl = '', $name ='parent_id', $labelField = 'name', $valueField = 'id')
{
return amisMake()->TreeSelectControl()
->name('parent_id')->label('父级')
->name($name)->label('父级')
->showIcon(false)
->labelField($labelField)
->valueField($valueField)
->value(0)->source($apiUrl);
}
/**
* 排序字段
*/
public function sortControl($name ='sort', $label = '排序'){
return amisMake()->NumberControl()->name($name)->label($label)->min(0);
}
/**
* 富文本编辑器
*/
public function fuEditorControl($name ='content', $label = '内容', $uploadUrl = ''){
return amisMake()->RichTextControl()->vendor('tinymce')
->options([
"menubar"=>false,
"min_height" => 500,
"toolbar"=> "undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | link image | help",
"help_tabs" => []
])
->name($name)->label($label);
//froala去除授权提示但是保存会有额外内容需要处理
//<style type="text/css">
// a[href="https://froala.com/wysiwyg-editor"], a[href="https://www.froala.com/wysiwyg-editor?k=u"]{
// display: none !important;
// position: absolute;
// top: -99999999px;
// }
// </style>
}
}

View File

@ -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\AdminNoticeService;
use App\Admin\Components;
class AdminNoticeController extends AdminController
{
protected string $serviceName = AdminNoticeService::class;
protected string $pageTitle = '公告管理';
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('article_id')->label('关联文章')->className('text-primary'),
TableColumn::make()->name('is_enable')->type('switch')->label('显示'),
TableColumn::make()->name('published_at')->label('发布时间')->type('datetime')->sortable(true),
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([
\amisMake()->TextControl()->name('title')->label('标题')->required(true),
Components::make()->fuEditorControl(),
\amisMake()->SelectControl()->name('article_id')->label('关联文章'),
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('更新时间')
]);
}
}

View File

@ -16,9 +16,10 @@ Route::group([
$router->resource('dashboard', \App\Admin\Controllers\HomeController::class);
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
//公告管理
$router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class);
// $router->resource('system/re-roles', \App\Admin\Controllers\AdminRoleController::class);
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
});

View File

@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
class AdminNotice extends Model
{
use HasFactory;
use Filterable;
protected $fillable = ['title', 'content', 'article_id', 'remark', 'is_enable', 'published_at' ,'sort'];
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Services\Admin;
use App\Models\AdminNotice;
use Slowlyo\OwlAdmin\Services\AdminService;
/**
* @method AdminNotice getModel()
* @method AdminNotice|\Illuminate\Database\Query\Builder query()
*/
class AdminNoticeService extends AdminService
{
protected string $modelName = AdminNotice::class;
}

View File

@ -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('admin_notices', function (Blueprint $table) {
$table->id();
$table->string('title')->comment('标题');
$table->text('content')->nullable()->comment('内容');
$table->unsignedBigInteger('article_id')->nullable()->comment('关联文章ID');
$table->string('remark')->nullable()->comment('备注');
$table->timestamp('published_at')->nullable()->comment('发布时间');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
$table->unsignedInteger('sort')->default(0)->comment('排序');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admin_notices');
}
};

View File

@ -22,7 +22,7 @@ class AdminMenuSeeder extends Seeder
['title' => '主页', 'icon' => 'icon-park:home-two', 'url' => '/dashboard', 'is_home'=>1],
['title' => '公众号管理', 'icon' => 'icon-park:wechat', 'url' => '',
'children' => [
['title' => '公告管理', 'icon' => 'icon-park:volume-notice', 'url' => '/notices'],
['title' => '公告管理', 'icon' => 'icon-park:volume-notice', 'url' => '/admin-notices'],
['title' => '文章分类', 'icon' => 'icon-park:book-one', 'url' => '/article-categories'],
['title' => '文章管理', 'icon' => 'icon-park:file-search', 'url' => '/articles'],
['title' => '图片位置', 'icon' => 'icon-park:graphic-design-two', 'url' => '/banner-addresses'],