update dcat-admin-setting
parent
30f95ae8c7
commit
13956a91ab
|
|
@ -1,3 +1,29 @@
|
|||
# Dcat Admin Extension
|
||||
# Dcat Admin Extension Setting
|
||||
|
||||
配置管理, 使用 `dcat-admin` 原有的数据表 `admin_settings`
|
||||
|
||||
## 数据表
|
||||
|
||||
| column | type | nullable | default | comment |
|
||||
| - | - | - | - | - |
|
||||
| slug | varchar(100) | not null | - | 主键 |
|
||||
| name | varchart(100) | null | - | 名称 |
|
||||
| value | longtext | null | - | 内容 |
|
||||
| created_at | timestamp | null | - | 创建时间 |
|
||||
| updated_at | timestamp | null | - | 更新时间 |
|
||||
|
||||
## 权限
|
||||
|
||||
```php
|
||||
$permissions = [
|
||||
'settings' => ['name' => '配置管理', 'curd' => true],
|
||||
];
|
||||
```
|
||||
|
||||
## 菜单
|
||||
|
||||
```php
|
||||
$menus = [
|
||||
['title' => '配置管理', 'icon' => '', 'uri' => '/settings', 'permission' => 'settings'],
|
||||
];
|
||||
```
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
"alias": "setting",
|
||||
"description": "Setting",
|
||||
"type": "library",
|
||||
"keywords": ["dcat-admin", "extension"],
|
||||
"homepage": "https://github.com/peidikeji/setting",
|
||||
"keywords": ["dcat-admin", "extension", "setting"],
|
||||
"homepage": "https://gitea.peidikeji.cn/pdkj/dcat-admin/src/branch/master/packages/setting",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
|
|
@ -12,9 +12,6 @@
|
|||
"email": "1163816051@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Peidikeji\\Setting\\": "src/"
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ class SettingController extends AdminController
|
|||
$grid->column('name');
|
||||
$grid->column('value');
|
||||
|
||||
$grid->disableCreateButton(!(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.settings.create')));
|
||||
$grid->showCreateButton(Admin::user()->can('dcat.admin.settings.create'));
|
||||
$grid->enableDialogCreate();
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableView();
|
||||
$actions->disableEdit();
|
||||
$actions->quickEdit(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.settings.edit'));
|
||||
$actions->quickEdit(Admin::user()->can('dcat.admin.settings.edit'));
|
||||
});
|
||||
|
||||
$grid->quickSearch(['slug', 'name', 'value'])->placeholder('输入 key/名称/value 搜索');
|
||||
|
|
|
|||
|
|
@ -3,29 +3,19 @@
|
|||
namespace Peidikeji\Setting;
|
||||
|
||||
use Dcat\Admin\Extend\ServiceProvider;
|
||||
use Dcat\Admin\Admin;
|
||||
|
||||
class SettingServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $menu = [
|
||||
// ['title' => 'Setting', 'uri' => 'keywords', 'icon' => ''],
|
||||
];
|
||||
// protected $menu = [
|
||||
// ['title' => '配置管理', 'uri' => 'settings', 'icon' => 'fa fa-gear'],
|
||||
// ];
|
||||
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
// public function settingForm()
|
||||
// {
|
||||
// return new Setting($this);
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Dcat\Admin\Models\Permission;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SettingPermissionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$permissions = [
|
||||
'settings' => ['name' => '配置管理', 'curd' => true],
|
||||
];
|
||||
$this->createPermissionData($permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入权限
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param string $key
|
||||
* @param integer $pId
|
||||
*/
|
||||
public function createPermissionData(array $permissions, string $key = '', int $pId = 0)
|
||||
{
|
||||
$curdArr = [
|
||||
'index' => '列表',
|
||||
'create' => '新增',
|
||||
'edit' => '修改',
|
||||
'destroy' => '删除',
|
||||
'show' => '详情',
|
||||
];
|
||||
foreach ($permissions as $slug => $permission) {
|
||||
//是否已存在该权限
|
||||
$slugKey = 'dcat.admin.' . ($key ? $key . '.' . $slug : $slug);
|
||||
|
||||
|
||||
$pper = Permission::updateOrCreate(['slug' => $slugKey], ['name' => is_string($permission) ? $permission : $permission['name'], 'parent_id' => $pId]);
|
||||
|
||||
if (!is_string($permission)) {
|
||||
if (!isset($permission['children'])) {
|
||||
$permission['children'] = [];
|
||||
}
|
||||
//判断是否默认插入curd权限
|
||||
if (isset($permission['curd']) && $permission['curd']) {
|
||||
if (is_array($permission['curd'])) {
|
||||
$permission['curd'] = array_reverse($permission['curd']);
|
||||
foreach ($permission['curd'] as $value) {
|
||||
$permission['children'] = array_merge([$value => $curdArr[$value]], $permission['children']);
|
||||
}
|
||||
} else {
|
||||
$permission['children'] = array_merge($curdArr, $permission['children']);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($permission['children']) > 0) {
|
||||
$_key = $permission['curd'] !== false ? ($key ? $key . '.' . $slug : $slug) : $key;
|
||||
$this->createPermissionData($permission['children'], $_key ?? $slug, $pper->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,5 @@ return [
|
|||
'1.0.0' => [
|
||||
'初始化配置管理',
|
||||
'CreateAdminSettingsTable.php',
|
||||
],
|
||||
'1.0.1' => [
|
||||
'添加配置管理权限迁移文件',
|
||||
'SettingPermissionSeeder.php'
|
||||
]
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue