update keywords
parent
13956a91ab
commit
82d81c5db4
|
|
@ -11,3 +11,19 @@
|
||||||
| parent_id | bigint unsigned | notnull | 0 | - | 上级id |
|
| parent_id | bigint unsigned | notnull | 0 | - | 上级id |
|
||||||
| type_key | string(191) | nullable | - | - | 上级的key |
|
| type_key | string(191) | nullable | - | - | 上级的key |
|
||||||
| level | int unsigned | - | 1 | - | 所属层级 |
|
| level | int unsigned | - | 1 | - | 所属层级 |
|
||||||
|
|
||||||
|
## 权限
|
||||||
|
|
||||||
|
```php
|
||||||
|
$permissions = [
|
||||||
|
'keywords' => ['name' => '字典管理', 'curd' => true],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
## 菜单
|
||||||
|
|
||||||
|
```php
|
||||||
|
$menus = [
|
||||||
|
['title' => '字典管理', 'icon' => '', 'uri' => '/keywords', 'permission' => 'keywords'],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "字典表管理",
|
"description": "字典表管理",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": ["dcat-admin", "extension"],
|
"keywords": ["dcat-admin", "extension"],
|
||||||
"homepage": "https://gitee.com/paddy_technology/dcat-admin-extension-keywords",
|
"homepage": "https://gitea.peidikeji.cn/pdkj/dcat-admin/src/branch/master/packages/keywords",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|
@ -12,9 +12,6 @@
|
||||||
"email": "1163816051@qq.com"
|
"email": "1163816051@qq.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
|
||||||
"php": ">=7.1.0"
|
|
||||||
},
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Peidikeji\\Keywords\\": "src/"
|
"Peidikeji\\Keywords\\": "src/"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ return [
|
||||||
],
|
],
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'name' => '名称',
|
'name' => '名称',
|
||||||
'key' => '键',
|
'key' => 'Key',
|
||||||
'value' => '值',
|
'value' => '值',
|
||||||
'parent_id' => '上级',
|
'parent_id' => '上级',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -84,13 +84,13 @@ class KeywordsController extends AdminController
|
||||||
protected function form()
|
protected function form()
|
||||||
{
|
{
|
||||||
return Form::make(new Keywords(), function (Form $form) {
|
return Form::make(new Keywords(), function (Form $form) {
|
||||||
$form->select('parent_id')->ajax(admin_url('api/keywords?'.http_build_query(['_paginate' => 1, 'parent_id' => '0'])));
|
$form->select('parent_id')->ajax(admin_url('api/keywords?'.http_build_query(['_paginate' => 1, 'parent_id' => '0'])))->model(Keywords::class, 'id', 'name');
|
||||||
|
|
||||||
$unique = Rule::unique((new Keywords())->getTable());
|
$unique = Rule::unique((new Keywords())->getTable());
|
||||||
if ($form->isEditing()) {
|
if ($form->isEditing()) {
|
||||||
$unique->ignore($form->getKey());
|
$unique->ignore($form->getKey());
|
||||||
}
|
}
|
||||||
$form->text('key')->required()->rules([$unique]);
|
$form->text('key')->required()->rules([$unique])->help('不能重复');
|
||||||
|
|
||||||
$form->text('name')->required();
|
$form->text('name')->required();
|
||||||
$form->text('value');
|
$form->text('value');
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,11 @@ use Dcat\Admin\Extend\ServiceProvider;
|
||||||
class KeywordsServiceProvider extends ServiceProvider
|
class KeywordsServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
protected $menu = [
|
protected $menu = [
|
||||||
// ['title' => 'Keywords', 'uri' => 'keywords', 'icon' => ''],
|
['title' => 'Keywords', 'uri' => 'keywords', 'icon' => 'feather icon-list'],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function settingForm()
|
|
||||||
// {
|
|
||||||
// return new Setting($this);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Peidikeji\Keywords;
|
|
||||||
|
|
||||||
use Dcat\Admin\Extend\Setting as Form;
|
|
||||||
|
|
||||||
class Setting extends Form
|
|
||||||
{
|
|
||||||
public function form()
|
|
||||||
{
|
|
||||||
$this->text('key1')->required();
|
|
||||||
$this->text('key2')->required();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Dcat\Admin\Models\Permission;
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
|
|
||||||
class KeywordsTableSeeder extends Seeder
|
|
||||||
{
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
// 添加权限
|
|
||||||
$permissions = [
|
|
||||||
'keywords' => ['name' => '字典管理', 'curd' => true]
|
|
||||||
];
|
|
||||||
// Permission::where('slug', 'like', 'dcat.admin.keywords%')->delete();
|
|
||||||
$this->createPermissionData($permissions);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,5 @@
|
||||||
return [
|
return [
|
||||||
'1.0.0' => [
|
'1.0.0' => [
|
||||||
'CreateKeywordsTable.php',
|
'CreateKeywordsTable.php',
|
||||||
'KeywordsTableSeeder.php'
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue