快速添加菜单
This commit is contained in:
parent
befa4d898d
commit
de7d821aaa
|
|
@ -69,6 +69,17 @@ class System extends Base
|
|||
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
||||
}
|
||||
|
||||
#[PostMapping(path: "menu/quick")]
|
||||
#[Auth(needAuth: false, auth: "menu:quick")]
|
||||
public function menuQuickAdd()
|
||||
{
|
||||
$data = Param::only(['pid' => 0, 'title' => '', 'flag', 'name', 'path', 'icon'], $this->request->post());
|
||||
$request = $this->container->get(mRequest::class);
|
||||
$request->scene('quick')->validateResolved();
|
||||
$res = mModel::quickAdd($data);
|
||||
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
||||
}
|
||||
|
||||
#[GetMapping(path: "dept/index")]
|
||||
#[Auth(auth: "dept:index")]
|
||||
public function deptIndex(): ResponseInterface
|
||||
|
|
|
|||
|
|
@ -209,4 +209,38 @@ class Menu extends Model
|
|||
->get()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public static function quickAdd(array $data): bool
|
||||
{
|
||||
Db::beginTransaction();
|
||||
// 1.菜单
|
||||
$data1 = ['pid' => $data['pid'], 'title' => $data['title'] . "管理", 'account_type' => $data['account_type'], 'type' => 0, 'name' => $data['name'], 'path' => $data['path'], 'icon' => $data['icon']];
|
||||
$pid = self::add($data1);
|
||||
// 2.添加按钮
|
||||
$data2 = ['pid' => $pid, 'title' => $data['title'] . '添加', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":add"];
|
||||
$pid2 = self::add($data2);
|
||||
// 3.添加接口
|
||||
$data3 = ['pid' => $pid2, 'title' => $data['title'] . '添加', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":add", 'method' => 'post'];
|
||||
$pid3 = self::add($data3);
|
||||
// 4.修改按钮
|
||||
$data2 = ['pid' => $pid, 'title' => $data['title'] . '修改', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":edit"];
|
||||
$pid2 = self::add($data2);
|
||||
// 5.修改接口
|
||||
$data3 = ['pid' => $pid2, 'title' => $data['title'] . '修改', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":edit", 'method' => 'put'];
|
||||
$pid3 = self::add($data3);
|
||||
// 6.删除按钮
|
||||
$data2 = ['pid' => $pid, 'title' => $data['title'] . '删除', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":del"];
|
||||
$pid2 = self::add($data2);
|
||||
// 7.删除接口
|
||||
$data3 = ['pid' => $pid2, 'title' => $data['title'] . '删除', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":del", 'method' => 'delete'];
|
||||
$pid3 = self::add($data3);
|
||||
// 8.列表接口
|
||||
$data3 = ['pid' => $pid, 'title' => $data['title'] . '列表', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":list", 'method' => 'get'];
|
||||
$pid3 = self::add($data3);
|
||||
// 9.选择接口
|
||||
$data3 = ['pid' => $pid, 'title' => $data['title'] . '选项', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":option", 'method' => 'get'];
|
||||
$pid3 = self::add($data3);
|
||||
Db::commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class Menu extends FormRequest
|
|||
protected array $scenes = [
|
||||
'add' => ['pid', 'title', 'type'],
|
||||
'edit' => ['pid', 'title', 'type','menu_id'],
|
||||
'quick' => ['pid', 'title', 'name', 'flag', 'path', 'icon']
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +32,11 @@ class Menu extends FormRequest
|
|||
'menu_id' => 'required',
|
||||
'pid' => 'required',
|
||||
'title' => 'required',
|
||||
'type' => 'required'
|
||||
'type' => 'required',
|
||||
'name' => 'required',
|
||||
'path' => 'required',
|
||||
'icon' => 'required',
|
||||
'flag' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue