4
0
Fork 0

update keywords

master
panliang 2022-09-15 10:09:03 +08:00
parent 13956a91ab
commit 82d81c5db4
8 changed files with 21 additions and 84 deletions

View File

@ -11,3 +11,19 @@
| parent_id | bigint unsigned | notnull | 0 | - | 上级id |
| type_key | string(191) | nullable | - | - | 上级的key |
| level | int unsigned | - | 1 | - | 所属层级 |
## 权限
```php
$permissions = [
'keywords' => ['name' => '字典管理', 'curd' => true],
];
```
## 菜单
```php
$menus = [
['title' => '字典管理', 'icon' => '', 'uri' => '/keywords', 'permission' => 'keywords'],
];
```

View File

@ -4,7 +4,7 @@
"description": "字典表管理",
"type": "library",
"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",
"authors": [
{
@ -12,9 +12,6 @@
"email": "1163816051@qq.com"
}
],
"require": {
"php": ">=7.1.0"
},
"autoload": {
"psr-4": {
"Peidikeji\\Keywords\\": "src/"

View File

@ -7,7 +7,7 @@ return [
],
'fields' => [
'name' => '名称',
'key' => '',
'key' => 'Key',
'value' => '值',
'parent_id' => '上级',
],

View File

@ -84,13 +84,13 @@ class KeywordsController extends AdminController
protected function 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());
if ($form->isEditing()) {
$unique->ignore($form->getKey());
}
$form->text('key')->required()->rules([$unique]);
$form->text('key')->required()->rules([$unique])->help('不能重复');
$form->text('name')->required();
$form->text('value');

View File

@ -7,16 +7,11 @@ use Dcat\Admin\Extend\ServiceProvider;
class KeywordsServiceProvider extends ServiceProvider
{
protected $menu = [
// ['title' => 'Keywords', 'uri' => 'keywords', 'icon' => ''],
['title' => 'Keywords', 'uri' => 'keywords', 'icon' => 'feather icon-list'],
];
public function init()
{
parent::init();
}
// public function settingForm()
// {
// return new Setting($this);
// }
}

View File

@ -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();
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -3,6 +3,5 @@
return [
'1.0.0' => [
'CreateKeywordsTable.php',
'KeywordsTableSeeder.php'
],
];