generated from liutk/owl-admin-base
admin 字典管理模板
parent
ffbb894a75
commit
264b755795
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Services\KeywordService;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
|
|
||||||
|
class BaseKeywordController extends AdminController
|
||||||
|
{
|
||||||
|
protected string $serviceName = KeywordService::class;
|
||||||
|
|
||||||
|
public function list(): Page
|
||||||
|
{
|
||||||
|
$crud = $this->baseCRUD()
|
||||||
|
->loadDataOnce(true)
|
||||||
|
->footerToolbar([])
|
||||||
|
->headerToolbar([
|
||||||
|
$this->createButton(true),
|
||||||
|
...$this->baseHeaderToolBar(),
|
||||||
|
])
|
||||||
|
->columns([
|
||||||
|
amisMake()->TableColumn()->name('id')->label(__('keyword.id')),
|
||||||
|
amisMake()->TableColumn()->name('name')->label(__('keyword.name')),
|
||||||
|
amisMake()->TableColumn()->name('key')->label(__('keyword.key'))->copyable(true),
|
||||||
|
amisMake()->TableColumn()->name('value')->label(__('keyword.value')),
|
||||||
|
amisMake()->TableColumn()->name('sort')->label(__('keyword.sort')),
|
||||||
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
||||||
|
$this->rowEditButton(true),
|
||||||
|
$this->rowDeleteButton(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->baseList($crud);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(): Form
|
||||||
|
{
|
||||||
|
return $this->baseForm()->body([
|
||||||
|
amisMake()->TreeSelectControl()->name('parent_id')->label(__('keyword.parent_id'))
|
||||||
|
->source(admin_url('api/keywords/tree-list?with_parent_key='.request()->input('parent_key')))
|
||||||
|
->labelField('name')
|
||||||
|
->valueField('id')
|
||||||
|
->required(true),
|
||||||
|
amisMake()->TextControl()->name('name')->label('名称')->required(true),
|
||||||
|
amisMake()->TextControl()->name('key')->label('KEY')->required(true),
|
||||||
|
amisMake()->TextControl()->name('value')->label('值'),
|
||||||
|
amisMake()->NumberControl()->name('sort')->value(0)->min()->label(__('keyword.sort')),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,4 +34,9 @@ class KeywordFilter extends ModelFilter
|
||||||
{
|
{
|
||||||
return $this->where('parent_key', $key);
|
return $this->where('parent_key', $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withParentKey($key)
|
||||||
|
{
|
||||||
|
return $this->where(fn($q) => $q->where('parent_key', $key)->orWhere('key', $key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class KeywordService extends BaseService
|
||||||
|
|
||||||
public function getTree()
|
public function getTree()
|
||||||
{
|
{
|
||||||
$list = $this->query()->filter(request()->all(), $this->modelFilterName)->get();
|
$list = $this->query()->sort()->filter(request()->all(), $this->modelFilterName)->get();
|
||||||
$minNum = $list->min('parent_id');
|
$minNum = $list->min('parent_id');
|
||||||
|
|
||||||
return ! $list->isEmpty() ? array2tree($list->toArray(), $minNum) : [];
|
return ! $list->isEmpty() ? array2tree($list->toArray(), $minNum) : [];
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use App\Admin\Controllers\System\AdminMenuController;
|
||||||
use App\Admin\Controllers\System\AdminPermissionController;
|
use App\Admin\Controllers\System\AdminPermissionController;
|
||||||
use App\Admin\Controllers\System\AdminRoleController;
|
use App\Admin\Controllers\System\AdminRoleController;
|
||||||
use App\Admin\Controllers\System\AdminUserController;
|
use App\Admin\Controllers\System\AdminUserController;
|
||||||
|
use App\Admin\Controllers\BaseKeywordController;
|
||||||
use App\Admin\Controllers\System\KeywordController;
|
use App\Admin\Controllers\System\KeywordController;
|
||||||
use Illuminate\Routing\Router;
|
use Illuminate\Routing\Router;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
@ -37,6 +38,14 @@ Route::group([
|
||||||
$router->resource('employees', StoreEmployeeController::class);
|
$router->resource('employees', StoreEmployeeController::class);
|
||||||
// 彩票机管理
|
// 彩票机管理
|
||||||
$router->resource('devices', DeviceController::class);
|
$router->resource('devices', DeviceController::class);
|
||||||
|
// 门店分类
|
||||||
|
$router->resource('categories', BaseKeywordController::class);
|
||||||
|
// 门店等级
|
||||||
|
$router->resource('levels', BaseKeywordController::class);
|
||||||
|
// 经营类别
|
||||||
|
$router->resource('business', BaseKeywordController::class);
|
||||||
|
// 彩种类型
|
||||||
|
$router->resource('lottery-types', BaseKeywordController::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,11 @@ class Keyword extends Model
|
||||||
return $this->hasMany(static::class, 'parent_id');
|
return $this->hasMany(static::class, 'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeSort($q)
|
||||||
|
{
|
||||||
|
return $q->orderBy('sort', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeAllChildrenOfKey($q, $parentKey)
|
public function scopeAllChildrenOfKey($q, $parentKey)
|
||||||
{
|
{
|
||||||
$q->where('path', 'like', '%-'.
|
$q->where('path', 'like', '%-'.
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ return new class extends Migration
|
||||||
$table->string('code')->comment('编号');
|
$table->string('code')->comment('编号');
|
||||||
$table->string('remarks')->nullable()->comment('备注');
|
$table->string('remarks')->nullable()->comment('备注');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->comment('设备管理');
|
$table->comment('彩票机管理');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ class AdminPermissionSeeder extends Seeder
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
// AdminMenu::truncate();
|
||||||
|
// AdminPermission::truncate();
|
||||||
$data = [
|
$data = [
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
@ -50,12 +52,36 @@ class AdminPermissionSeeder extends Seeder
|
||||||
'uri' => '/store/employees',
|
'uri' => '/store/employees',
|
||||||
'resource' => true,
|
'resource' => true,
|
||||||
],
|
],
|
||||||
|
'categories' => [
|
||||||
|
'name' => '门店分类',
|
||||||
|
'icon' => '',
|
||||||
|
'uri' => '/store/categories?parent_key=store_category',
|
||||||
|
'resource' => false,
|
||||||
|
],
|
||||||
|
'levels' => [
|
||||||
|
'name' => '门店等级',
|
||||||
|
'icon' => '',
|
||||||
|
'uri' => '/store/levels?parent_key=store_levels',
|
||||||
|
'resource' => false,
|
||||||
|
],
|
||||||
|
'business' => [
|
||||||
|
'name' => '经营类别',
|
||||||
|
'icon' => '',
|
||||||
|
'uri' => '/store/business?parent_key=store_business',
|
||||||
|
'resource' => false,
|
||||||
|
],
|
||||||
'devices' => [
|
'devices' => [
|
||||||
'name' => '彩票机管理',
|
'name' => '彩票机管理',
|
||||||
'icon' => '',
|
'icon' => '',
|
||||||
'uri' => '/store/devices',
|
'uri' => '/store/devices',
|
||||||
'resource' => true,
|
'resource' => true,
|
||||||
]
|
],
|
||||||
|
'lottery-types' => [
|
||||||
|
'name' => '彩种类型',
|
||||||
|
'icon' => '',
|
||||||
|
'uri' => '/store/lottery-types?parent_key=lottery_type',
|
||||||
|
'resource' => true,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
@ -146,17 +172,18 @@ class AdminPermissionSeeder extends Seeder
|
||||||
|
|
||||||
public function handleAdminMenus(array $data, ?AdminMenu $parent = null): void
|
public function handleAdminMenus(array $data, ?AdminMenu $parent = null): void
|
||||||
{
|
{
|
||||||
|
$sort = 0;
|
||||||
foreach ($data as $slug => $node) {
|
foreach ($data as $slug => $node) {
|
||||||
if (! is_array($node) || ! array_key_exists('uri', $node)) {
|
if (! is_array($node) || ! array_key_exists('uri', $node)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$sort++;
|
||||||
/** @var \Slowlyo\OwlAdmin\Models\AdminMenu */
|
/** @var \Slowlyo\OwlAdmin\Models\AdminMenu */
|
||||||
$menu = AdminMenu::updateOrCreate([
|
$menu = AdminMenu::updateOrCreate([
|
||||||
'slug' => ($parent->slug ?? 'admin').'.'.$slug,
|
'slug' => ($parent->slug ?? 'admin').'.'.$slug,
|
||||||
], [
|
], [
|
||||||
'parent_id' => $parent->id ?? 0,
|
'parent_id' => $parent->id ?? 0,
|
||||||
'order' => $node['order'] ?? 0,
|
'order' => $sort,
|
||||||
'title' => $node['name'],
|
'title' => $node['name'],
|
||||||
'icon' => $node['icon'],
|
'icon' => $node['icon'],
|
||||||
'url' => $node['uri'],
|
'url' => $node['uri'],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => 'ID',
|
||||||
|
'created_at' => '创建时间',
|
||||||
|
'updated_at' => '更新时间',
|
||||||
|
'name' => '名称',
|
||||||
|
'key' => 'KEY',
|
||||||
|
'value' => 'VALUE',
|
||||||
|
'parent_id' => '上级',
|
||||||
|
'parent_key' => '上级',
|
||||||
|
'path' => '上级',
|
||||||
|
'sort' => '排序',
|
||||||
|
'lv' => '层级',
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue