字典管理

This commit is contained in:
zhang zhuo 2025-12-01 16:24:26 +08:00
parent 689aaeaf17
commit 026ca74f1e
7 changed files with 320 additions and 3 deletions

View File

@ -26,6 +26,10 @@ use App\Request\AssetCategory as acRequest;
use App\Model\SystemConfig as scModel;
use App\Request\SystemConfig as scRequest;
use App\Model\Asset as asModel;
use App\Model\Dict as dtModel;
use App\Request\Dict as dtRequest;
use App\Model\DictData as ddModel;
use App\Request\DictData as ddRequest;
use App\Utils\AppInfoHelper;
use App\Utils\CpuHelper;
use App\Utils\DiskInfoHelper;
@ -814,4 +818,106 @@ class System extends Base
$ids = $this->request->input("ids");
return $this->toAjax(scModel::del($ids));
}
#[GetMapping(path: "dict/list")]
#[Auth(auth: "dict:list")]
public function dictList()
{
$param = Param::only(["dict_name", "dict_type", "limit"=>10]);
return $this->success("列表接口", dtModel::list($param));
}
#[GetMapping(path: "dict/option")]
#[Auth(needAuth: false)]
public function dictOption()
{
return $this->success(dtModel::options());
}
#[GetMapping(path: "dict/info")]
#[Auth(auth: "dict:info")]
public function dictInfo()
{
$id = $this->request->input("id");
return $this->success(dtModel::getById($id));
}
#[PostMapping(path: "dict/add")]
#[Auth(auth: "dict:add")]
public function dictAdd()
{
$request = $this->container->get(dtRequest::class);
$request->scene('add')->validateResolved();
$data = Param::only(["dict_name", "dict_type", "remark"]);
return $this->toAjax(dtModel::add($data));
}
#[PutMapping(path: "dict/edit")]
#[Auth(auth: "dict:edit")]
public function dictEdit()
{
$request = $this->container->get(dtRequest::class);
$request->scene('edit')->validateResolved();
$data = Param::only(["dict_id", "dict_name", "dict_type", "remark"]);
return $this->toAjax(dtModel::edit($data));
}
#[DeleteMapping(path: "dict/del")]
#[Auth(auth: "dict:del")]
public function dictDel()
{
$ids = $this->request->input("ids");
return $this->toAjax(dtModel::del($ids));
}
#[GetMapping(path: "dict_data/list")]
#[Auth(auth: "dict_data:list")]
public function dictDataList()
{
$param = Param::only(["dict_id", "dict_label", "status", "limit"=>10]);
return $this->success("列表接口", ddModel::list($param));
}
#[GetMapping(path: "dict_data/option")]
#[Auth(needAuth: false)]
public function dictDataOption()
{
return $this->success(ddModel::options());
}
#[GetMapping(path: "dict_data/info")]
#[Auth(auth: "dict_data:info")]
public function dictDataInfo()
{
$id = $this->request->input("id");
return $this->success(ddModel::getById($id));
}
#[PostMapping(path: "dict_data/add")]
#[Auth(auth: "dict_data:add")]
public function dictDataAdd()
{
$request = $this->container->get(ddRequest::class);
$request->scene('add')->validateResolved();
$data = Param::only(["dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark"]);
return $this->toAjax(ddModel::add($data));
}
#[PutMapping(path: "dict_data/edit")]
#[Auth(auth: "dict_data:edit")]
public function dictDataEdit()
{
$request = $this->container->get(ddRequest::class);
$request->scene('edit')->validateResolved();
$data = Param::only(["data_id", "dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark"]);
return $this->toAjax(ddModel::edit($data));
}
#[DeleteMapping(path: "dict_data/del")]
#[Auth(auth: "dict_data:del")]
public function dictDataDel()
{
$ids = $this->request->input("ids");
return $this->toAjax(ddModel::del($ids));
}
}

53
app/Model/Dict.php Normal file
View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $dict_id
* @property string $dict_name
* @property string $dict_type
* @property string $remark
* @property string $create_time
* @property string $update_time
* @property string $deleted_at
*/
class Dict extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'dict';
protected string $primaryKey = 'dict_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['dict_id' => 'integer'];
public static function list(array $param)
{
$model = self::query();
if (isset($param['dict_name']) && $param['dict_name'] != '') {
$model = $model->where('dict_name', "like", "%{$param['dict_name']}%");
}
if (isset($param['dict_type']) && $param['dict_type'] != '') {
$model = $model->where('dict_type', "like", "%{$param['dict_type']}%");
}
return $model->orderByDesc("dict_id")
->select(["dict_id", "dict_name", "dict_type", "remark", "create_time", "update_time"])
->paginate((int)$param['limit']);
}
public static function options()
{
return self::select(["dict_id", "dict_name"])->get()->toArray();
}
}

60
app/Model/DictData.php Normal file
View File

@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $data_id
* @property int $dict_id
* @property string $dict_label
* @property string $dict_value
* @property int $is_default
* @property int $rank
* @property int $status
* @property string $remark
* @property string $create_time
* @property string $update_time
* @property string $deleted_at
*/
class DictData extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'dict_data';
protected string $primaryKey = 'data_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['data_id' => 'integer', 'dict_id' => 'integer', 'is_default' => 'integer', 'rank' => 'integer', 'status' => 'integer'];
public static function list(array $param)
{
$model = self::query();
if (isset($param['dict_id']) && $param['dict_id'] != '') {
$model = $model->where('dict_id', $param['dict_id']);
}
if (isset($param['dict_label']) && $param['dict_label'] != '') {
$model = $model->where('dict_label', 'like', "%{$param['dict_label']}%");
}
if (isset($param['status']) && $param['status'] != '') {
$model = $model->where('status', $param['status']);
}
return $model->orderByDesc("rank")
->orderByDesc("dict_id")
->select(["data_id", "dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark", "create_time", "update_time"])
->paginate((int)$param['limit']);
}
public static function options()
{
return self::select(["data_id", "data_name"])->get()->toArray();
}
}

44
app/Request/Dict.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace App\Request;
use Hyperf\Validation\Request\FormRequest;
class Dict extends FormRequest
{
protected array $scenes = [
'add' => ["dict_name", "dict_type"],
'edit' => ["dict_id", "dict_name", "dict_type"],
];
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'dict_id' => 'required',
'dict_name' => 'required',
'dict_type' => 'required',
'remark' => 'required',
];
}
public function messages(): array
{
return [
'dict_id.required' => 'ID必传',
'dict_name.required' => '字典名称必传!',
'dict_type.required' => '字典类型必传!',
'remark.required' => '备注必传!',
];
}
}

51
app/Request/DictData.php Normal file
View File

@ -0,0 +1,51 @@
<?php
namespace App\Request;
use Hyperf\Validation\Request\FormRequest;
class DictData extends FormRequest
{
protected array $scenes = [
'add' => ["dict_id", "dict_label", "dict_value", "is_default"],
'edit' => ["data_id", "dict_id", "dict_label", "dict_value", "is_default"],
];
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'data_id' => 'required',
'dict_id' => 'required',
'dict_label' => 'required',
'dict_value' => 'required',
'is_default' => 'required',
'rank' => 'required',
'status' => 'required'
];
}
public function messages(): array
{
return [
'data_id.required' => 'ID必传',
'dict_id.required' => '字典ID必传',
'dict_label.required' => '字典标签必传!',
'dict_value.required' => '字典键值必传!',
'is_default.required' => '是否默认必传!',
'rank.required' => '排序必传!',
'status.required' => '是否启用必传!',
'remark.required' => '备注必传!',
];
}
}

View File

@ -121,15 +121,18 @@
}
//编辑
async function edit(row) {
function edit(row) {
dialogShow.value = true
nextTick(() => {
if (row instanceof PointerEvent) {
row = selection.value[0]
}
dialogRef.value.open('edit', row)
})
}
//查看
async function show(row) {
function show(row) {
dialogShow.value = true
nextTick(() => {
dialogRef.value.open('show', row)

View File

@ -96,5 +96,5 @@
emit('success')
visible.value = false;
proxy.$message.success(res.msg)
}}
}
</script>