|
@@ -0,0 +1,92 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+declare (strict_types=1);
|
|
|
+namespace App\Controller;
|
|
|
+
|
|
|
+use App\JsonRpc\AuthorityServiceInterface;
|
|
|
+use Hyperf\Di\Annotation\Inject;
|
|
|
+use Hyperf\HttpServer\Annotation\AutoController;
|
|
|
+use App\Tools\Result;
|
|
|
+use App\Constants\ErrorCode;
|
|
|
+use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
|
|
+/**
|
|
|
+ * Class AuthorityController
|
|
|
+ * @package App\Controller
|
|
|
+ */
|
|
|
+#[AutoController]
|
|
|
+class AuthorityController extends AbstractController
|
|
|
+{
|
|
|
+ use \Hyperf\Di\Aop\ProxyTrait;
|
|
|
+ use \Hyperf\Di\Aop\PropertyHandlerTrait;
|
|
|
+ function __construct(\Hyperf\Logger\LoggerFactory $loggerFactory)
|
|
|
+ {
|
|
|
+ if (method_exists(parent::class, '__construct')) {
|
|
|
+ parent::__construct(...func_get_args());
|
|
|
+ }
|
|
|
+ $this->__handlePropertyHandler(__CLASS__);
|
|
|
+ }
|
|
|
+ #[Inject]
|
|
|
+ protected ValidatorFactoryInterface $validationFactory;
|
|
|
+ /**
|
|
|
+ * @var AuthorityServiceInterface
|
|
|
+ */
|
|
|
+ #[Inject]
|
|
|
+ private $authorityServiceClient;
|
|
|
+ /**
|
|
|
+ * 获取菜单列表
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getMenuList()
|
|
|
+ {
|
|
|
+ $id = (int) $this->request->input("id", 0);
|
|
|
+ $page = (int) $this->request->input("page", 1);
|
|
|
+ $pageSize = (int) $this->request->input("pageSize", 10);
|
|
|
+ $data = ['id' => $id, 'page' => $page, 'pageSize' => $pageSize];
|
|
|
+ $result = $this->authorityServiceClient->getMenuList($data);
|
|
|
+ return $result ? Result::success($result['data']) : Result::error($result['message']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除菜单
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function delMenu()
|
|
|
+ {
|
|
|
+ $id = (int) $this->request->input("id", 0);
|
|
|
+ $data = ['id' => $id, 'page' => 1, 'pageSize' => 2];
|
|
|
+ $result = $this->authorityServiceClient->getMenuList($data);
|
|
|
+ if (count($result['data']['rows']) > 0) {
|
|
|
+ return Result::error("有子菜单不能删除");
|
|
|
+ }
|
|
|
+ return $this->authorityServiceClient->delMenu($data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加菜单
|
|
|
+ * @return array|void
|
|
|
+ */
|
|
|
+ public function addMent()
|
|
|
+ {
|
|
|
+ $requireData = $this->request->all();
|
|
|
+ $validator = $this->validationFactory->make($requireData, ['pid' => 'required', 'label' => 'required', 'url' => 'required'], ['pid.required' => '父级id不能为空', 'label.required' => '菜单名称不能为空', 'url.required' => '路由地址不能为空']);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ $errorMessage = $validator->errors()->first();
|
|
|
+ return Result::error($errorMessage);
|
|
|
+ }
|
|
|
+ $result = $this->authorityServiceClient->addMenu($requireData);
|
|
|
+ return $result ? Result::success($result['data']) : Result::error($result['message']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改菜单
|
|
|
+ * @return array|void
|
|
|
+ */
|
|
|
+ public function updateMent()
|
|
|
+ {
|
|
|
+ $requireData = $this->request->all();
|
|
|
+ $validator = $this->validationFactory->make($requireData, ['id' => 'required', 'pid' => 'required', 'label' => 'required', 'url' => 'required'], ['id.required' => 'id不能为空', 'pid.required' => '父级id不能为空', 'label.required' => '菜单名称不能为空', 'url.required' => '路由地址不能为空']);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ $errorMessage = $validator->errors()->first();
|
|
|
+ return Result::error($errorMessage);
|
|
|
+ }
|
|
|
+ $result = $this->authorityServiceClient->updateMenu($requireData);
|
|
|
+ return $result ? Result::success($result['data']) : Result::error($result['message']);
|
|
|
+ }
|
|
|
+}
|