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

动态参数菜单功能建议。 #824

Closed
noahlann opened this issue Jun 29, 2021 · 5 comments
Closed

动态参数菜单功能建议。 #824

noahlann opened this issue Jun 29, 2021 · 5 comments

Comments

@noahlann
Copy link

有些时候需要左侧菜单携带动态参数(params)

  1. 能够携带参数正常使用菜单。
  2. 切换菜单时能够使用上次的参数。
  3. 手动更换参数能够正常识别,且切换时能够正常携带已更换的参数。

实现方案:

  1. 新增一个guard(paramMenuGuard.ts),放置于createPermissionGuard之后(即需要先生成菜单,再进行修改)
  2. 根据不同的模式读取菜单(FrontMenuListBackMenuList)(BackMode/RouteMappingMode
  3. 使用正则获取类似所有 :paramKey 的参数组,与 to.params 进行一一匹配替换
  4. 将替换后的path填装到menu中,同时需要保留原path,故于 types (interface Menu)新增了属性 paramPath?: string
  5. 将原path保留至paramPath中,完成操作。

示例如图

建议:

permissionStore可新增一个方法,getMenuList,内部判断模式,最终输出当前使用的菜单。

如有需要,则提pr,功能已做好,但可能实现方式略微奇怪。

@ghost
Copy link

ghost commented Jul 1, 2021

我也在尝试实现这个功能, 因为层级参数对我们的项目是必须的:
例如:
/device-type/01_01_001/control
/device-type/01_01_001/device
要求导航菜单能正常工作(还是定位到device-type上, 面包屑导航正常定位到/设备类型> 参数

@noahlann
Copy link
Author

noahlann commented Jul 1, 2021

@thinkershare

我这个已经可以正常工作,支持多个参数的情况,上面的gif是实录。

比如

/device/:deviceId
/device/:deviceId/detail
/device/:deviceId/sub-device/:subDiviceId
/device/:deviceId/sub-device/:subDiviceId/detail

# 诸如此类

就是不知道实现方式是否影响性能。没经过测试。

也存在一个问题,就是 首次进入页面时,参数得存在(不过这应该也不是什么大问题)

另外,面包屑经过测试不能工作(具体我得去看看作者如何使用面包屑的)

我稍后会提一个pr上去,看看接不接受。

@noahlann
Copy link
Author

noahlann commented Jul 1, 2021

@thinkershare
已提交pr #845 ,你可以试试看。

@ghost
Copy link

ghost commented Jul 2, 2021

@thinkershare

我这个已经可以正常工作,支持多个参数的情况,上面的gif是实录。

比如

/device/:deviceId
/device/:deviceId/detail
/device/:deviceId/sub-device/:subDiviceId
/device/:deviceId/sub-device/:subDiviceId/detail

# 诸如此类

就是不知道实现方式是否影响性能。没经过测试。

也存在一个问题,就是 首次进入页面时,参数得存在(不过这应该也不是什么大问题)

另外,面包屑经过测试不能工作(具体我得去看看作者如何使用面包屑的)

我稍后会提一个pr上去,看看接不接受。

其实并不存在首次进入参数必须要存在的问题, 因为id?是可选的, 而且UI的路由匹配模式决定了id必须符合指定正则, 还有默认界面是没有通过导航栏进入的入口, 都是link进去的, 就不允许用户直接进入这个链接, 如果id不存在, 则页面会按照逻辑选择一个默认的id, 也就是说这里的路由参数需要检测3个模式: 一个是路由参数, 正则约束, 可选条件, 要这三都正常工作, 但没有id时候, 左侧如果需要导航菜单, 则直接使用/devices/parameter就好了, 这时候:id是缺省的, 路由一样可以正常匹配

@noahlann
Copy link
Author

noahlann commented Jul 3, 2021

已经融合至主分支,关闭。

@noahlann noahlann closed this as completed Jul 3, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant