This commit is contained in:
2025-08-27 15:31:25 +08:00
parent 9e034d85ce
commit 989bf299b5
16 changed files with 1044 additions and 10 deletions
@@ -0,0 +1,33 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictService;
class SysDictController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,33 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictItemService;
class SysDictItemController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictItemService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDictItem;
class SysDictItemLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictItem::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDict;
class SysDictLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDict::class;
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysDictItemValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysDictItem;
class SysDictItemService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictItem::class;
/**
* 验证器
*/
protected $validator = SysDictItemValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysDictValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysDict;
use support\Request;
class SysDictService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDict::class;
/**
* 验证器
*/
protected $validator = SysDictValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['dict_name','dict_code','description','whatsapp','contacts'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
// ====== ====== 关联 ====== ======
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
case 'show':
$config['where']['id'] = $p['id'];
// ====== ====== 关联 ====== ======
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
}
return $config;
}
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysDictItemValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysDictValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}