add packages
parent
af0a237760
commit
fb88053b95
|
|
@ -10,4 +10,3 @@ pre-dist
|
||||||
/laravel-tests
|
/laravel-tests
|
||||||
*.bak.*
|
*.bak.*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/packages/
|
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,6 @@ return [
|
||||||
'extension' => [
|
'extension' => [
|
||||||
// When you use command `php artisan admin:ext-make` to generate extensions,
|
// When you use command `php artisan admin:ext-make` to generate extensions,
|
||||||
// the extension files will be generated in this directory.
|
// the extension files will be generated in this directory.
|
||||||
'dir' => base_path('dcat-admin-extensions'),
|
'dir' => base_path('vendor/peidikeji/dcat-admin/packages'),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
.DS_Store
|
||||||
|
phpunit.phar
|
||||||
|
/vendor
|
||||||
|
composer.phar
|
||||||
|
composer.lock
|
||||||
|
*.project
|
||||||
|
.idea/
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
# 字典表管理
|
||||||
|
|
||||||
|
## 数据表结构
|
||||||
|
|
||||||
|
| name | type | null | default | index | comment |
|
||||||
|
| - | - | - | - | - | - |
|
||||||
|
| id | bigint unsigned | notnull | - | primary, auto_increment | 主键 |
|
||||||
|
| key | varchar(191) | notnull | - | unique | - |
|
||||||
|
| value | string(191) | nullable | - | - | - |
|
||||||
|
| sort | int unsigned | - | 0 | - | 排序(asc) |
|
||||||
|
| parent_id | bigint unsigned | notnull | 0 | - | 上级id |
|
||||||
|
| type_key | string(191) | nullable | - | - | 上级的key |
|
||||||
|
| level | int unsigned | - | 1 | - | 所属层级 |
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"name": "peidikeji/dcat-admin-extension-keywords",
|
||||||
|
"alias": "keywords",
|
||||||
|
"description": "字典表管理",
|
||||||
|
"type": "library",
|
||||||
|
"keywords": ["dcat-admin", "extension"],
|
||||||
|
"homepage": "https://gitee.com/paddy_technology/dcat-admin-extension-keywords",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "panliang",
|
||||||
|
"email": "1163816051@qq.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.1.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Peidikeji\\Keywords\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"dcat-admin": "Peidikeji\\Keywords\\KeywordsServiceProvider",
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Peidikeji\\Keywords\\KeywordsServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [];
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'labels' => [
|
||||||
|
'Keywords' => '字典表管理',
|
||||||
|
'keywords' => '字典表管理',
|
||||||
|
],
|
||||||
|
'fields' => [
|
||||||
|
'name' => '名称',
|
||||||
|
'key' => '键',
|
||||||
|
'value' => '值',
|
||||||
|
'parent_id' => '上级',
|
||||||
|
],
|
||||||
|
'options' => [
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Keywords\Http\Controllers;
|
||||||
|
|
||||||
|
use Dcat\Admin\Form;
|
||||||
|
use Dcat\Admin\Grid;
|
||||||
|
use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
|
use Dcat\Admin\Show;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Peidikeji\Goods\Resources\KeywordResource;
|
||||||
|
use Peidikeji\Keywords\Models\Keywords;
|
||||||
|
|
||||||
|
class KeywordsController extends AdminController
|
||||||
|
{
|
||||||
|
protected $translation = 'peidikeji.dcat-admin-extension-keywords::keywords';
|
||||||
|
|
||||||
|
public function list(Request $request)
|
||||||
|
{
|
||||||
|
$query = Keywords::filter($request->all());
|
||||||
|
|
||||||
|
$query->select(['id', 'name as text']);
|
||||||
|
|
||||||
|
if ($request->filled('_paginate')) {
|
||||||
|
$list = $query->paginate();
|
||||||
|
} else {
|
||||||
|
$list = $query->get();
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function json(Request $request)
|
||||||
|
{
|
||||||
|
$query = Keywords::filter($request->all());
|
||||||
|
|
||||||
|
$list = $query->get();
|
||||||
|
|
||||||
|
return KeywordResource::collection($list);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function grid()
|
||||||
|
{
|
||||||
|
return Grid::make(new Keywords(), function ($grid) {
|
||||||
|
$grid->column('name')->tree();
|
||||||
|
$grid->column('key');
|
||||||
|
$grid->column('value');
|
||||||
|
|
||||||
|
$grid->enableDialogCreate();
|
||||||
|
|
||||||
|
$grid->quickSearch(['name', 'type_key', 'key']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a show builder.
|
||||||
|
*
|
||||||
|
* @param mixed $id
|
||||||
|
*
|
||||||
|
* @return Show
|
||||||
|
*/
|
||||||
|
protected function detail($id)
|
||||||
|
{
|
||||||
|
return Show::make($id, new Keywords(), function (Show $show) {
|
||||||
|
$show->field('id');
|
||||||
|
$show->field('key');
|
||||||
|
$show->field('name');
|
||||||
|
$show->field('value');
|
||||||
|
$show->field('parent_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a form builder.
|
||||||
|
*
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
|
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'])));
|
||||||
|
|
||||||
|
$unique = Rule::unique((new Keywords())->getTable());
|
||||||
|
if ($form->isEditing()) {
|
||||||
|
$unique->ignore($form->getKey());
|
||||||
|
}
|
||||||
|
$form->text('key')->required()->rules([$unique]);
|
||||||
|
|
||||||
|
$form->text('name')->required();
|
||||||
|
$form->text('value');
|
||||||
|
$form->hidden('type_key');
|
||||||
|
$form->hidden('level')->default(1);
|
||||||
|
|
||||||
|
$form->saving(function (Form $form) {
|
||||||
|
if ($form->parent_id) {
|
||||||
|
$parent = Keywords::findOrFail($form->parent_id);
|
||||||
|
$form->type_key = $parent->key;
|
||||||
|
$form->level = $parent->level + 1;
|
||||||
|
} else {
|
||||||
|
$form->parent_id = 0;
|
||||||
|
}
|
||||||
|
if ($form->isEditing()) {
|
||||||
|
Keywords::where('parent_id', $form->getKey())->update(['type_key' => $form->key]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Goods\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class KeywordResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'name' => $this->name,
|
||||||
|
'key' => $this->key,
|
||||||
|
'type_key' => $this->type_key,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Keywords\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::group([
|
||||||
|
'prefix' => config('admin.route.prefix'),
|
||||||
|
'middleware' => config('admin.route.middleware'),
|
||||||
|
], function () {
|
||||||
|
Route::get('api/keywords', [KeywordsController::class, 'list'])->name('api.keywords');
|
||||||
|
|
||||||
|
Route::resource('keywords', KeywordsController::class)->names('keywords');
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::group([
|
||||||
|
'prefix' => 'api',
|
||||||
|
'middleware' => 'api'
|
||||||
|
], function () {
|
||||||
|
Route::get('keywords', [KeywordsController::class, 'json']);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Keywords;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class KeywordFilter extends ModelFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Related Models that have ModelFilters as well as the method on the ModelFilter
|
||||||
|
* As [relationMethod => [input_key1, input_key2]].
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $relations = [];
|
||||||
|
|
||||||
|
public function q($v)
|
||||||
|
{
|
||||||
|
$this->where(function ($q) use ($v) {
|
||||||
|
$q->where('key', 'like', '%'.$v.'%')->orWhere('name', 'like', '%'.$v.'%');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function key($v)
|
||||||
|
{
|
||||||
|
$this->where('key', $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function typeKey($v)
|
||||||
|
{
|
||||||
|
$this->whereIn('type_key', explode(',', $v));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function type($v)
|
||||||
|
{
|
||||||
|
$this->typeKey($v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function level($v)
|
||||||
|
{
|
||||||
|
$this->where('level', $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parent($v)
|
||||||
|
{
|
||||||
|
$this->where('parent_id', $v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Keywords;
|
||||||
|
|
||||||
|
use Dcat\Admin\Extend\ServiceProvider;
|
||||||
|
|
||||||
|
class KeywordsServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
protected $menu = [
|
||||||
|
['title' => 'Keywords', 'uri' => 'keywords', 'icon' => ''],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function settingForm()
|
||||||
|
// {
|
||||||
|
// return new Setting($this);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Peidikeji\Keywords\Models;
|
||||||
|
|
||||||
|
use Dcat\Admin\Traits\ModelTree;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Peidikeji\Keywords\KeywordFilter;
|
||||||
|
|
||||||
|
class Keywords extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, ModelTree, Filterable;
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $orderColumn = 'sort';
|
||||||
|
protected $titleColumn = 'name';
|
||||||
|
|
||||||
|
protected $fillable = ['type_key', 'key', 'name', 'value', 'sort', 'parent_id', 'level'];
|
||||||
|
|
||||||
|
public function modelFilter()
|
||||||
|
{
|
||||||
|
return KeywordFilter::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parent()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(static::class, 'parent_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function children()
|
||||||
|
{
|
||||||
|
return $this->hasMany(static::class, 'parent_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateKeywordsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!Schema::hasTable('keywords')) {
|
||||||
|
Schema::create('keywords', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('key')->unique();
|
||||||
|
$table->string('name')->comment('名字');
|
||||||
|
$table->string('value')->nullable();
|
||||||
|
$table->string('type_key')->nullable();
|
||||||
|
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||||
|
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级ID');
|
||||||
|
$table->unsignedInteger('level')->default(1)->comment('层级');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('keywords');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'1.0.0' => [
|
||||||
|
'CreateKeywordsTable.php'
|
||||||
|
],
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue