From 6baa1003bf5c70462955bf5bba29d614532ca682 Mon Sep 17 00:00:00 2001 From: yumo Date: Tue, 1 Aug 2023 20:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Index.php | 55 +++++++--------------------------- app/admin/view/index/main.html | 16 ---------- app/common/model/AdminAuth.php | 18 +++++++++++ 3 files changed, 29 insertions(+), 60 deletions(-) diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 02d6430..da64659 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -2,22 +2,9 @@ namespace app\admin\controller; -use app\common\model\AdminAuth; -use app\common\model\Document; -use app\common\model\Document as DocumentModel; -use app\common\model\Tag as TagModel; -use app\common\model\DocumentCategory; -use app\common\model\DocumentCategory as DocumentCategoryModel; -use app\common\model\FriendLink; -use app\common\model\MessageForm; -use app\common\model\AdminNotify; -use app\common\model\Tag; -use app\common\model\User; +use app\common\model\{AdminAuth, Document, FriendLink, MessageForm, AdminNotify, User}; use Exception; -use think\db\exception\DataNotFoundException; -use think\db\exception\DbException; -use think\db\exception\ModelNotFoundException; -use think\facade\Request; +use think\db\exception\{DataNotFoundException, DbException, ModelNotFoundException}; class Index extends AuthController { @@ -29,14 +16,8 @@ class Index extends AuthController public function index() { $this->assign("adminInfo", $this->adminInfo); - $menuList = cache(AdminAuth::getMenuCacheKey($this->adminId)); - if ($menuList === null) { - $menuList = AdminAuth::getMenu(0, $this->auth); - cache(AdminAuth::getMenuCacheKey($this->adminId), $menuList, 1 * 60 * 60); - } - $this->assign("menu", $menuList); - $messageList = AdminNotify::pageList(5); - $this->assign("message", $messageList); + $this->assign("menu", AdminAuth::getAuthList($this->adminId,$this->auth)); + $this->assign("message", AdminNotify::pageList(5)); return $this->fetch(); } @@ -47,20 +28,11 @@ class Index extends AuthController */ public function main() { - $documentCount = Document::counts(new Document()); - $this->assign("document_count", $documentCount); - $userCount = User::counts(new User()); - $this->assign("user_count", $userCount); - $FriendLinkCount = FriendLink::counts(new FriendLink()); - $this->assign("friend_link_count", $FriendLinkCount); - $messageFormCount = MessageForm::counts(new MessageForm()); - $this->assign("message_form_count", $messageFormCount); - $data =[ - "page"=> 0 , - "limit" => 5 - ]; - $articleList = Document::systemPage($data)['data']; - $this->assign("article_list", $articleList); + $this->assign("document_count", Document::counts()); + $this->assign("user_count", User::counts(new User())); + $this->assign("friend_link_count", FriendLink::counts(new FriendLink())); + $this->assign("message_form_count", MessageForm::counts(new MessageForm())); + $this->assign("article_list", Document::systemPage(["page"=> 0 ,"limit" => 5])['data']); return $this->fetch(); } @@ -72,11 +44,6 @@ class Index extends AuthController */ public function menu() { - $menuList = cache(AdminAuth::getMenuCacheKey($this->adminId)); - if ($menuList === null) { - $menuList = AdminAuth::getMenu(0, $this->auth); - cache(AdminAuth::getMenuCacheKey($this->adminId), $menuList, 1 * 60 * 60); - } - return app("json")->success($menuList); + return app("json")->success(AdminAuth::getAuthList($this->adminId,$this->auth)); } -} \ No newline at end of file +} diff --git a/app/admin/view/index/main.html b/app/admin/view/index/main.html index 0e3416e..3167ad8 100644 --- a/app/admin/view/index/main.html +++ b/app/admin/view/index/main.html @@ -69,22 +69,6 @@ -
-
-
-

常用功能

-
-
-
- -
-
-
-
-
-
diff --git a/app/common/model/AdminAuth.php b/app/common/model/AdminAuth.php index e2f16a2..895ff83 100644 --- a/app/common/model/AdminAuth.php +++ b/app/common/model/AdminAuth.php @@ -40,6 +40,24 @@ class AdminAuth extends BaseModel return $authList[$module . '_' . $controller . '_' . $action] ?? -1; } + /** + * 获取用户权限列表 + * @param $admin_id + * @param $auth + * @return array|mixed|object|\think\App + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function getAuthList($admin_id,$auth){ + $menuList = cache(self::getMenuCacheKey($admin_id)); + if ($menuList === null) { + $menuList = self::getMenu(0, $auth); + cache(AdminAuth::getMenuCacheKey($admin_id), $menuList, 1 * 60 * 60); + } + return $menuList; + } + /** * 获取菜单 * @param int $pid