提交 a3887f8c 作者: vben

feat: add tag display to the menu

上级 4baf90a5
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
### ✨ Features ### ✨ Features
- 表单项的`componentsProps`支持函数类型 - 表单项的`componentsProps`支持函数类型
- 菜单新增 tag 显示
### ⚡ Performance Improvements ### ⚡ Performance Improvements
......
...@@ -35,6 +35,23 @@ export default defineComponent({ ...@@ -35,6 +35,23 @@ export default defineComponent({
return icon ? <Icon icon={icon} size={18} class="menu-item-icon" /> : null; return icon ? <Icon icon={icon} size={18} class="menu-item-icon" /> : null;
} }
function renderTag() {
const { item, showTitle } = props;
if (!item || showTitle) return null;
const { tag } = item;
if (!tag) return null;
const { dot, content, type = 'error' } = tag;
if (!dot && !content) return null;
const cls = ['basic-menu__tag'];
dot && cls.push('dot');
type && cls.push(type);
return <span class={cls}>{dot ? '' : content}</span>;
}
return () => { return () => {
if (!props.item) { if (!props.item) {
return null; return null;
...@@ -46,17 +63,21 @@ export default defineComponent({ ...@@ -46,17 +63,21 @@ export default defineComponent({
const beforeStr = name.substr(0, index); const beforeStr = name.substr(0, index);
const afterStr = name.substr(index + searchValue.length); const afterStr = name.substr(index + searchValue.length);
const cls = showTitle ? 'show-title' : 'basic-menu__name';
return ( return (
<> <>
{renderIcon(icon!)} {renderIcon(icon!)}
{index > -1 && searchValue ? ( {index > -1 && searchValue ? (
<span class={showTitle ? 'show-title' : ''}> <span class={cls}>
{beforeStr} {beforeStr}
<span class={`basic-menu__keyword`}>{searchValue}</span> <span class={`basic-menu__keyword`}>{searchValue}</span>
{afterStr} {afterStr}
</span> </span>
) : ( ) : (
<span class={[showTitle ? 'show-title' : '']}>{name}</span> <span class={[cls]}>
{name}
{renderTag()}
</span>
)} )}
</> </>
); );
......
...@@ -51,6 +51,45 @@ ...@@ -51,6 +51,45 @@
// collapsed show title end // collapsed show title end
&__name {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
}
&__tag {
display: inline-block;
padding: 2px 4px;
margin-right: 4px;
font-size: 12px;
line-height: 14px;
color: #fff;
border-radius: 2px;
&.dot {
width: 8px;
height: 8px;
padding: 0;
border-radius: 50%;
}
&.primary {
background: @primary-color;
}
&.error {
background: @error-color;
}
&.success {
background: @success-color;
}
&.warn {
background: @warning-color;
}
}
// scrollbar -s tart // scrollbar -s tart
&__content { &__content {
/* 滚动槽 */ /* 滚动槽 */
......
...@@ -4,10 +4,16 @@ const menu: MenuModule = { ...@@ -4,10 +4,16 @@ const menu: MenuModule = {
menu: { menu: {
name: 'Dashboard', name: 'Dashboard',
path: '/dashboard', path: '/dashboard',
// tag: {
// dot: true,
// },
children: [ children: [
{ {
path: '/workbench', path: '/workbench',
name: '工作台', name: '工作台',
// tag: {
// content: 'new',
// },
}, },
{ {
path: '/analysis', path: '/analysis',
......
...@@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { ...@@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
props?: any; props?: any;
fullPath?: string; fullPath?: string;
} }
export interface MenuTag {
type?: 'primary' | 'error' | 'warn' | 'success';
content?: string;
dot?: boolean;
}
export interface Menu { export interface Menu {
name: string; name: string;
...@@ -60,6 +65,8 @@ export interface Menu { ...@@ -60,6 +65,8 @@ export interface Menu {
roles?: RoleEnum[]; roles?: RoleEnum[];
meta?: Partial<RouteMeta>; meta?: Partial<RouteMeta>;
tag?: MenuTag;
} }
export interface MenuModule { export interface MenuModule {
orderNo?: number; orderNo?: number;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论