• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / admin / 4134200542

pending completion
4134200542

push

github

twinh
feat(admin): 后台菜单增加 `removeChildByUrl` 方法

22 of 54 branches covered (40.74%)

5 of 5 new or added lines in 1 file covered. (100.0%)

9 existing lines in 1 file now uncovered.

129 of 506 relevant lines covered (25.49%)

1.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

3.85
/src/AdminPlugin.php
1
<?php
2

3
namespace Miaoxing\Admin;
4

5
use Miaoxing\Admin\Service\AdminLogModel;
6
use Miaoxing\Admin\Service\AdminMenu;
7
use Miaoxing\Plugin\BasePlugin;
8
use Miaoxing\Plugin\Service\User;
9
use Miaoxing\Plugin\Service\UserModel;
10
use Wei\RetTrait;
11

12
class AdminPlugin extends BasePlugin
13
{
14
    use RetTrait;
15

16
    protected $name = '后台';
17

18
    protected $description = '提供后台布局,头部菜单,侧边栏菜单等功能';
19

20
    protected $code = 203;
21

22
    public function onAdminMenuGetMenus(AdminMenu $menu)
23
    {
24
        $user = $menu->addChild('user')->setLabel('用户')->setSort(700);
×
25
        $menu->addChild('content')->setLabel('内容')->setSort(500);
×
26
        $menu->addChild('marketing')->setLabel('营销')->setSort(400);
×
27
        $setting = $menu->addChild('setting')->setLabel('设置')->setSort(300);
×
UNCOV
28
        $menu->addChild()->setLabel('修改密码')->setUrl('admin/password')->setExtra('visible', false);
×
29
        $menu->addChild()->setLabel('修改资料')->setUrl('admin/user')->setExtra('visible', false);
×
30

31
        $admins = $user->addChild()->setLabel('管理员管理')->setUrl('admin/admins');
×
32
        $admins->addChild()->setUrl('admin/admins/new')->setLabel('添加');
×
33
        $admins->addChild()->setUrl('admin/admins/[id]/edit')->setLabel('编辑');
×
34

UNCOV
35
        $groups = $user->addChild()->setLabel('分组管理')->setUrl('admin/groups');
×
36
        $groups->addChild()->setLabel('添加')->setUrl('admin/groups/new');
×
37
        $groups->addChild()->setLabel('编辑')->setUrl('admin/groups/[id]/edit');
×
38

39
        $setting->addChild()->setLabel('后台设置')->setUrl('admin/admin-settings')->setSort(10);
×
40
    }
41

42
    public function onUserLogin(UserModel $user)
43
    {
44
        if ($user->isAdmin) {
6✔
UNCOV
45
            AdminLogModel::log('用户登陆', $user);
×
46
        }
47
    }
2✔
48

49
    public function onBeforeUserLogout(UserModel $user)
50
    {
UNCOV
51
        if ($user->isAdmin) {
×
UNCOV
52
            AdminLogModel::log('用户退出', $user);
×
53
        }
54
    }
55

56
    public function onCheckAuth()
57
    {
UNCOV
58
        if (!$this->app->isAdmin()) {
×
UNCOV
59
            return;
×
60
        }
61

62
        $ret = User::checkLogin();
×
63
        if ($ret->isErr()) {
×
64
            // 指定后台登录的地址
UNCOV
65
            $ret['next'] = 'admin/login';
×
66
            return $ret;
×
67
        }
68

69
        if (!User::cur()->isAdmin) {
×
70
            return $this->err([
×
UNCOV
71
                'message' => '很抱歉,您没有权限访问当前页面',
×
72
                'next' => 'admin/login',
73
            ]);
74
        }
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc