初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
47
app/Http/Controllers/Api/DepartmentController.php
Normal file
47
app/Http/Controllers/Api/DepartmentController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\DepartmentService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class DepartmentController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = DepartmentService::getInstance();
|
||||
// insertField / updateField 既是必填校验清单,也是入库字段白名单,漏写的字段不会被收进 params
|
||||
$this->insertField = ['name'];
|
||||
$this->updateField = ['id', 'name'];
|
||||
// 这几个允许缺省:pid 缺省为顶级,status 缺省为正常
|
||||
$this->notRequest = ['pid', 'desc', 'status', 'color'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门树下拉(表单选上级部门用)
|
||||
* @Method GET
|
||||
*/
|
||||
public function treeOption(): JsonResponse
|
||||
{
|
||||
$isSelect = filter_var(request()->get('is_select', false), FILTER_VALIDATE_BOOLEAN);
|
||||
return jok($this->service->getTreeOption($isSelect), '列表获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用 / 启用部门
|
||||
* @Method POST
|
||||
* @throws Exception
|
||||
*/
|
||||
public function status(): JsonResponse
|
||||
{
|
||||
$id = request()->post('id');
|
||||
$status = request()->post('status');
|
||||
if (empty($id) || !in_array((string) $status, ['0', '1'], true)) {
|
||||
return jerr('参数错误');
|
||||
}
|
||||
return jok($this->service->status($id, $status), '操作成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user