Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 3.x按钮分配了权限,但是不显示 #515

Open
Darknesser opened this issue Dec 31, 2024 · 5 comments
Open

[BUG] 3.x按钮分配了权限,但是不显示 #515

Darknesser opened this issue Dec 31, 2024 · 5 comments
Labels

Comments

@Darknesser
Copy link

执行命令并粘贴以下结果。

Command: uname -a && php -v && composer info | grep mine && php --ri swoole

# Paste the result here.
Darwin DantondeMacBook-Pro.local 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec  6 18:41:43 PST 2024; root:xnu-11215.61.5~2/RELEASE_X86_64 x86_64
PHP 8.3.15 (cli) (built: Dec 17 2024 18:18:02) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.15, Copyright (c), by Zend Technologies
mineadmin/access                   3.0-RC             Mineadmin Access Component
mineadmin/app-store                3.0-RC             Mineadmin 2.0 AppStore Extension
mineadmin/auth-jwt                 3.0-RC             Mineadmin New Jwt Auth Component
mineadmin/casbin                   3.0-RC             Mineadmin Casbin Component
mineadmin/core                     3.0-RC             Mineadmin Core Component
mineadmin/jwt                      3.0-RC             Mineadmin jwt component
mineadmin/support                  3.0-RC             MineAdmin Support component
mineadmin/swagger                  3.0-RC             Mineadmin Swagger component
mineadmin/upload                   3.0-RC             Mineadmin Upload component

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.1.4
Built => Sep 24 2024 10:06:31
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1w  11 Sep 2023
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
c-ares => 1.34.4
zlib => 1.2.12
brotli => E16781312/D16781312
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144

bug描述:

接口返回的菜单是对的,代码定位到这个方法,item.meta?.type !== 'B',直接排除了按钮类型,没理解

function menuToRoutes(routerMap: any[]) {
      const accessedRouters: any = []
      routerMap.forEach((item: any) => {
        if (item.meta?.type !== 'B') {
          if (item.meta.type === 'I') {
            item.meta.url = item.path
            item.path = `/maIframe/${item.name}`
            item.component = () => import(('@/layouts/components/iframe/index.tsx'))
          }

          const suffix: string = item.meta?.componentSuffix ?? '.vue'

          let component: any | null = null
          if (item.component && item.meta?.type !== 'I') {
            if (moduleViews[`../../modules/${item.component}${suffix}`]) {
              component = moduleViews[`../../modules/${item.component}${suffix}`]
            }
            else if (pluginViews[`../../plugins/${item.component}${suffix}`]) {
              component = pluginViews[`../../plugins/${item.component}${suffix}`]
            }
            else {
              console.warn(`MineAdmin-UI: 路由 [${item.meta.title}] 找不到 ${item.component}${suffix} 页面`)
            }
          }

          const route = {
            path: item.path,
            name: item.name,
            meta: item.meta,
            children: item.children ? menuToRoutes(item.children) : null,
            component: item.meta?.type === 'I' ? item.component : component,
          }
          accessedRouters.push(route)
        }
      })
      return accessedRouters
    }

重现步骤:

admin/permission/menus接口响应数据如下

{
    "code": 200,
    "message": "成功",
    "data": [
        {
            "id": 56,
            "parent_id": 0,
            "name": "trademark",
            "meta": {
                "i18n": "menu.trademark.index",
                "icon": "ant-design:trademark-circle-outlined",
                "type": "M",
                "affix": false,
                "cache": true,
                "title": "商标管理",
                "hidden": false,
                "copyright": true,
                "componentPath": "modules\/",
                "componentSuffix": ".vue",
                "breadcrumbEnable": true
            },
            "path": "\/trademark",
            "component": "",
            "redirect": "",
            "status": 1,
            "sort": 0,
            "created_by": 1,
            "updated_by": 0,
            "created_at": "2024-12-11 14:54:59",
            "updated_at": "2024-12-11 14:54:59",
            "remark": "",
            "pivot": {
                "v0": "trademarkManager",
                "v1": "trademark"
            },
            "children": [
                {
                    "id": 57,
                    "parent_id": 56,
                    "name": "trademark:order",
                    "meta": {
                        "i18n": "menu.trademark.order",
                        "icon": "ant-design:table-outlined",
                        "type": "M",
                        "affix": false,
                        "cache": true,
                        "title": "商标订单",
                        "hidden": false,
                        "copyright": true,
                        "componentPath": "modules\/",
                        "componentSuffix": ".vue",
                        "breadcrumbEnable": true
                    },
                    "path": "\/trademark\/order",
                    "component": "biz\/views\/trademark\/order\/index",
                    "redirect": "",
                    "status": 1,
                    "sort": 0,
                    "created_by": 1,
                    "updated_by": 0,
                    "created_at": "2024-12-11 15:01:17",
                    "updated_at": "2024-12-11 15:01:17",
                    "remark": "",
                    "children": [
                        {
                            "id": 58,
                            "parent_id": 57,
                            "name": "trademark:order:index",
                            "meta": {
                                "i18n": "menu.trademark.orderList",
                                "type": "B",
                                "title": "商标订单"
                            },
                            "path": "",
                            "component": "",
                            "redirect": "",
                            "status": 1,
                            "sort": 0,
                            "created_by": 0,
                            "updated_by": 0,
                            "created_at": "2024-12-11 15:04:22",
                            "updated_at": "2024-12-11 15:04:23",
                            "remark": "",
                            "children": []
                        },
                        {
                            "id": 59,
                            "parent_id": 57,
                            "name": "trademark:order:save",
                            "meta": {
                                "i18n": "menu.trademark.orderSave",
                                "type": "B",
                                "title": "订单保存"
                            },
                            "path": "",
                            "component": "",
                            "redirect": "",
                            "status": 1,
                            "sort": 0,
                            "created_by": 0,
                            "updated_by": 0,
                            "created_at": "2024-12-11 15:06:49",
                            "updated_at": "2024-12-11 15:06:50",
                            "remark": "",
                            "children": []
                        },
                        {
                            "id": 60,
                            "parent_id": 57,
                            "name": "trademark:order:update",
                            "meta": {
                                "i18n": "menu.trademark.orderUpdate",
                                "type": "B",
                                "title": "订单更新"
                            },
                            "path": "",
                            "component": "",
                            "redirect": "",
                            "status": 1,
                            "sort": 0,
                            "created_by": 0,
                            "updated_by": 0,
                            "created_at": "2024-12-11 15:07:46",
                            "updated_at": "2024-12-11 15:07:48",
                            "remark": "",
                            "children": []
                        },
                        {
                            "id": 61,
                            "parent_id": 57,
                            "name": "trademark:order:delete",
                            "meta": {
                                "i18n": "menu.trademark.orderDelete",
                                "type": "B",
                                "title": "订单删除"
                            },
                            "path": "",
                            "component": "",
                            "redirect": "",
                            "status": 1,
                            "sort": 0,
                            "created_by": 0,
                            "updated_by": 0,
                            "created_at": "2024-12-11 15:08:58",
                            "updated_at": "2024-12-11 15:08:57",
                            "remark": "",
                            "children": []
                        }
                    ]
                }
            ]
        }
    ]
}
@Darknesser Darknesser added the bug label Dec 31, 2024
Copy link

boring-cyborg bot commented Dec 31, 2024

Thanks for opening your first issue here! Be sure to follow the issue template! 感谢您在这里反馈第一个问题!请务必遵循问题模板!

Copy link

dosubot bot commented Dec 31, 2024

Hello, @Darknesser! I'm here to help with your bug. I'm a bot that can assist you with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this bug together!

按钮类型 ('B') 在菜单中不显示是因为 menuToRoutes 函数中有一个条件 item.meta?.type !== 'B',这个条件会过滤掉所有类型为 'B' 的项目。这是因为按钮类型不对应于应用程序中的可导航路由。按钮通常用于执行特定操作,而不是导航到新页面或显示组件,因此它们不会被添加到路由中[1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@zds-s
Copy link
Member

zds-s commented Jan 2, 2025

@kanyxmo

@kanyxmo
Copy link
Member

kanyxmo commented Jan 8, 2025

菜单里排除了 type === 'B' 的,权限列表里没有排除,可以用 useUserStore().getPermissions() 打印看看

ps:你的版本还处在rc,尽快升级到正式版吧

@Darknesser
Copy link
Author

菜单里排除了 type === 'B' 的,权限列表里没有排除,可以用 useUserStore().getPermissions() 打印看看

ps:你的版本还处在rc,尽快升级到正式版吧

版本升级到3.0
image
打印useUserStore().getPermissions()
image
接口数据和上面一样,只显示了列表,其他按钮均不显示

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants