Skip to content

Commit

Permalink
feat: add tag display to the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 10, 2020
1 parent 4baf90a commit a3887f8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### ✨ Features

- 表单项的`componentsProps`支持函数类型
- 菜单新增 tag 显示

### ⚡ Performance Improvements

Expand Down
25 changes: 23 additions & 2 deletions src/components/Menu/src/MenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ export default defineComponent({
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 () => {
if (!props.item) {
return null;
Expand All @@ -46,17 +63,21 @@ export default defineComponent({

const beforeStr = name.substr(0, index);
const afterStr = name.substr(index + searchValue.length);
const cls = showTitle ? 'show-title' : 'basic-menu__name';
return (
<>
{renderIcon(icon!)}
{index > -1 && searchValue ? (
<span class={showTitle ? 'show-title' : ''}>
<span class={cls}>
{beforeStr}
<span class={`basic-menu__keyword`}>{searchValue}</span>
{afterStr}
</span>
) : (
<span class={[showTitle ? 'show-title' : '']}>{name}</span>
<span class={[cls]}>
{name}
{renderTag()}
</span>
)}
</>
);
Expand Down
39 changes: 39 additions & 0 deletions src/components/Menu/src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,45 @@

// 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
&__content {
/* 滚动槽 */
Expand Down
6 changes: 6 additions & 0 deletions src/router/menus/modules/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ const menu: MenuModule = {
menu: {
name: 'Dashboard',
path: '/dashboard',
// tag: {
// dot: true,
// },
children: [
{
path: '/workbench',
name: '工作台',
// tag: {
// content: 'new',
// },
},
{
path: '/analysis',
Expand Down
7 changes: 7 additions & 0 deletions src/router/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
props?: any;
fullPath?: string;
}
export interface MenuTag {
type?: 'primary' | 'error' | 'warn' | 'success';
content?: string;
dot?: boolean;
}

export interface Menu {
name: string;
Expand All @@ -60,6 +65,8 @@ export interface Menu {
roles?: RoleEnum[];

meta?: Partial<RouteMeta>;

tag?: MenuTag;
}
export interface MenuModule {
orderNo?: number;
Expand Down

0 comments on commit a3887f8

Please sign in to comment.