-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: dynamic menus #60
feat: dynamic menus #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有2个问题:
1、// 排序索引 sort: number 是可选参数吗? 注意顺序
2、整体代码有没有 lint ?
|
目前 route.meta 的参数肯定是不足的,看后期还要加什么 |
✅ Deploy Preview for vue-hbs-admin ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
修改好了! |
v-model:selectedKeys="selectedKeys" | ||
mode="inline" | ||
theme="dark" | ||
v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys" mode="inline" theme="dark" | ||
:inline-collapsed="getCollapsed" | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
属性较长建议换行,可读性要高一些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看到类似这个,所以我怀疑 有没有 lint ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非常尴尬的是,我确实运行了 pnpm lint -- --fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint 有时候并不能很好的去规避所有的格式问题,只能起到一个辅助的作用。一般我都更喜欢自己手动去做这件事,所以之前没有在 lint 的时候,加上 --fix。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
学到了
const currentRoute = router.currentRoute.value | ||
selectedKeys.value = getCurrentMenuRecursive(menus.value, currentRoute.path) | ||
openKeys.value = selectedKeys.value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setSelectMenuWhenRefreshPage
这个命名更像是解决了什么问题。可以简单点,比如:setupCurrentMenu
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数主要是解决刷新后当前路由对应左侧菜单的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我无法分辨哪个名字更好,你觉得呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实我也不咋会起名字。不过要我感觉,setupCurrentMenu
这个加上你上面写的注释就很完美了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的!
src/router/routes/modules/about.ts
Outdated
@@ -1,11 +1,21 @@ | |||
import type { RouteRecordRaw } from 'vue-router' | |||
import { | |||
SettingOutlined | |||
} from '@ant-design/icons-vue' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单个不必折行
single?: boolean | ||
// 排序索引 | ||
sort: number | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single
字段是不是可有可无?如果可无,是否可以舍去?- 当存在 3 级导航,
isMenu
还好用吗,或者说用一个type: 1 | 2 | 3
替代会好一些? sort
字段我感觉只有一级导航才需要,使用动态导入顺序不可控。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- single 的作用是标识一下当前的一级菜单就是一个 menuItem,没有二级菜单
- 这个我要思考一下,可能当时没考虑到三级菜单我要实验一下
- 我有用 sort 递归排序所有的路由,所以 sort 的顺序我觉得还是有用的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要说明一下 2 的 isMenu
是 false 的话,是不会展示的,主要是这个作用,不过倒是提醒了我三级导航的问题 @Hongbusi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
果然,我没有完全读懂哈哈
@Hongbusi @RainyNight9 重大更新,目前已适配多级菜单,理论上 99 菜单都会自动适配 |
将 |
文档记得更新一下哦~ |
等合并后😊 |
Description
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).About This PR
close #51
目前已实现动态读取
routes/modules/xx.ts
中的路由,并自动渲染视图feat
以上内容需要放在 route 定义的 meta 字段中,例如
根据 children 自动适配多级菜单,若子 route 有 children,那么说明该路由是一个父级菜单,可展开。
理论上可以自动适配任意多级的菜单
实现原理
读取 routes,并 v-for 渲染,因此一定要配置好
meta
字段中的内容关于文档,将会在 merge 后去改
自动适配多级菜单的原理就是写了两个组件,一个是单独的,一个是含有子级的,根据其 children 递归渲染
修改较多,review 可能比较困难,辛苦大家了!