1
0
Fork 0
develop
panliang 2023-04-26 10:28:42 +08:00
parent 16443e49e0
commit f7a908c593
8 changed files with 131 additions and 18 deletions

View File

@ -4,7 +4,7 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
@ -17,7 +17,7 @@ DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
FILESYSTEM_DISK=public
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

View File

@ -9,26 +9,31 @@ use Slowlyo\OwlAdmin\Renderers\TextControl;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\ArticleCategoryService;
use App\Admin\Components;
use Illuminate\Http\Request;
class ArticleCategoryController extends AdminController
{
protected string $serviceName = ArticleCategoryService::class;
protected string $pageTitle = '文章分类';//待完善-todo
protected string $pageTitle = '文章分类';
public function list(): Page
{
$crud = $this->baseCRUD()
->filterTogglable(false)
->loadDataOnce(true)
->footerToolbar([])
->headerToolbar([
$this->createButton(true),
...$this->baseHeaderToolBar(),
amis('reload')->align('right'),
amis('filter-toggler')->align('right'),
])
->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),
TableColumn::make()->name('id')->label('ID'),
TableColumn::make()->name('name')->label('名称'),
TableColumn::make()->name('icon')->type('image')->label('Icon'),
TableColumn::make()->name('sort')->label('Sort'),
TableColumn::make()->name('is_enable')->type('status')->label('Enable'),
$this->rowActions(true),
]);
@ -40,9 +45,9 @@ class ArticleCategoryController extends AdminController
return $this->baseForm()->body([
TextControl::make()->name('name')->label('名称')->required(true),
amisMake()->ImageControl()->name('icon')->label('icon')->autoUpload(true),
Components::make()->parentControl(),
Components::make()->parentControl(admin_url('api/article-categories/tree-list')),
Components::make()->sortControl(),
amisMake()->SwitchControl()->name('is_enable')->label('显示'),
amisMake()->SwitchControl()->name('is_enable')->value(true)->label('显示'),
]);
}
@ -56,7 +61,15 @@ class ArticleCategoryController extends AdminController
]);
}
public function getTreeList(Request $request){
public function getTreeList(Request $request)
{
return $this->service->getTree();
}
public function quickSave(Request $request)
{
logger('1', $request->all());
return $this->response()->success();
}
}

View File

@ -13,6 +13,7 @@ Route::group([
'prefix' => 'api',
], function (Router $router) {
$router->get('keywords/tree-list', '\App\Admin\Controllers\KeywordController@getTreeList')->name('api.keywords.tree-list');
$router->get('article-categories/tree-list', '\App\Admin\Controllers\ArticleCategoryController@getTreeList')->name('api.article-categories.tree-list');
});
$router->get('dashboard', '\App\Admin\Controllers\HomeController@index');

View File

@ -0,0 +1,55 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
class ModelFillable extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'model:fillable {table} {--connection}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'get model fillable ';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
*/
public function handle()
{
$table = $this->argument('table');
$ignore = ['id', 'created_at', 'updated_at', 'deleted_at'];
$connection = $this->option('connection');
if (!$connection) {
$connection = config('database.default');
}
if (Schema::connection($connection)->hasTable($table)) {
$list = Schema::connection($connection)->getColumnListing($table);
$list = array_filter($list, function ($value) use ($ignore) {
return !in_array($value, $ignore);
});
$this->info("protected \$fillable = ['".implode('\', \'', $list)."'];");
}
}
}

View File

@ -2,18 +2,37 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class ArticleCategory extends Model
{
use HasFactory;
use Filterable;
protected $fillable = [];
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
'updated_at' => 'datetime:Y-m-d H:i:s',
];
protected function serializeDate(\DateTimeInterface $date){
return $date->format('Y-m-d H:i:s');
protected $fillable = ['icon', 'is_enable', 'level', 'name', 'parent_id', 'path', 'sort'];
protected function icon(): Attribute
{
return Attribute::make(
get: fn($value) => $value ? (Str::startsWith($value, ['http://', 'https://']) ? $value : Storage::url($value)) : '',
);
}
public function parent()
{
return $this->belongsTo(static::class, 'parent_id');
}
public function children()
{
return $this->hasMany(static::class, 'parent_id');
}
}

View File

@ -4,6 +4,7 @@ namespace App\Services\Admin;
use App\Models\ArticleCategory;
use Slowlyo\OwlAdmin\Services\AdminService;
use Illuminate\Http\Request;
/**
* @method ArticleCategory getModel()
@ -18,4 +19,27 @@ class ArticleCategoryService extends AdminService
$list = $this->query()->orderByDesc('sort')->get()->toArray();
return array2tree($list);
}
public function list()
{
return ['items' => $this->getTree()];
}
public function store($data): bool
{
$pid = data_get($data, 'parent_id');
if ($pid && $parent = ArticleCategory::find($pid)) {
$data['level'] = $parent->level + 1;
$data['path'] = $parent->path . $parent->id . '-';
} else {
$data['level'] = 1;
$data['path'] = '-';
}
return parent::store($data);
}
public function delete(string $ids): mixed
{
return $this->query()->whereIn($this->primaryKey(), explode(',', $ids))->delete();
}
}

View File

@ -24,9 +24,10 @@ return new class extends Migration
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
$table->unsignedInteger('sort')->default(0)->comment('排序');
//可能用到的额外字段
// 可能用到的额外字段
$table->string('cover')->nullable()->comment('封面');
$table->string('author')->nullable()->comment('作者/来源');
$table->string('category_path')->nullable()->comment('上级分类');
$table->timestamps();
});
}

View File

@ -5,7 +5,7 @@
<link rel="icon" href="/admin/logo.png"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title></title>
<title>agriculture</title>
<script type="module" crossorigin src="/admin/assets/index.d4616be0.js"></script>
<link rel="stylesheet" href="/admin/assets/index.b0993078.css">
</head>