Commit a3887f8cd99546cde8882d77271cc430eb7a83f5
1 parent
4baf90a5
feat: add tag display to the menu
Showing
5 changed files
with
76 additions
and
2 deletions
CHANGELOG.zh_CN.md
src/components/Menu/src/MenuContent.tsx
@@ -35,6 +35,23 @@ export default defineComponent({ | @@ -35,6 +35,23 @@ export default defineComponent({ | ||
35 | return icon ? <Icon icon={icon} size={18} class="menu-item-icon" /> : null; | 35 | return icon ? <Icon icon={icon} size={18} class="menu-item-icon" /> : null; |
36 | } | 36 | } |
37 | 37 | ||
38 | + function renderTag() { | ||
39 | + const { item, showTitle } = props; | ||
40 | + if (!item || showTitle) return null; | ||
41 | + | ||
42 | + const { tag } = item; | ||
43 | + if (!tag) return null; | ||
44 | + | ||
45 | + const { dot, content, type = 'error' } = tag; | ||
46 | + if (!dot && !content) return null; | ||
47 | + const cls = ['basic-menu__tag']; | ||
48 | + | ||
49 | + dot && cls.push('dot'); | ||
50 | + type && cls.push(type); | ||
51 | + | ||
52 | + return <span class={cls}>{dot ? '' : content}</span>; | ||
53 | + } | ||
54 | + | ||
38 | return () => { | 55 | return () => { |
39 | if (!props.item) { | 56 | if (!props.item) { |
40 | return null; | 57 | return null; |
@@ -46,17 +63,21 @@ export default defineComponent({ | @@ -46,17 +63,21 @@ export default defineComponent({ | ||
46 | 63 | ||
47 | const beforeStr = name.substr(0, index); | 64 | const beforeStr = name.substr(0, index); |
48 | const afterStr = name.substr(index + searchValue.length); | 65 | const afterStr = name.substr(index + searchValue.length); |
66 | + const cls = showTitle ? 'show-title' : 'basic-menu__name'; | ||
49 | return ( | 67 | return ( |
50 | <> | 68 | <> |
51 | {renderIcon(icon!)} | 69 | {renderIcon(icon!)} |
52 | {index > -1 && searchValue ? ( | 70 | {index > -1 && searchValue ? ( |
53 | - <span class={showTitle ? 'show-title' : ''}> | 71 | + <span class={cls}> |
54 | {beforeStr} | 72 | {beforeStr} |
55 | <span class={`basic-menu__keyword`}>{searchValue}</span> | 73 | <span class={`basic-menu__keyword`}>{searchValue}</span> |
56 | {afterStr} | 74 | {afterStr} |
57 | </span> | 75 | </span> |
58 | ) : ( | 76 | ) : ( |
59 | - <span class={[showTitle ? 'show-title' : '']}>{name}</span> | 77 | + <span class={[cls]}> |
78 | + {name} | ||
79 | + {renderTag()} | ||
80 | + </span> | ||
60 | )} | 81 | )} |
61 | </> | 82 | </> |
62 | ); | 83 | ); |
src/components/Menu/src/index.less
@@ -51,6 +51,45 @@ | @@ -51,6 +51,45 @@ | ||
51 | 51 | ||
52 | // collapsed show title end | 52 | // collapsed show title end |
53 | 53 | ||
54 | + &__name { | ||
55 | + display: flex; | ||
56 | + width: 100%; | ||
57 | + justify-content: space-between; | ||
58 | + align-items: center; | ||
59 | + } | ||
60 | + | ||
61 | + &__tag { | ||
62 | + display: inline-block; | ||
63 | + padding: 2px 4px; | ||
64 | + margin-right: 4px; | ||
65 | + font-size: 12px; | ||
66 | + line-height: 14px; | ||
67 | + color: #fff; | ||
68 | + border-radius: 2px; | ||
69 | + | ||
70 | + &.dot { | ||
71 | + width: 8px; | ||
72 | + height: 8px; | ||
73 | + padding: 0; | ||
74 | + border-radius: 50%; | ||
75 | + } | ||
76 | + | ||
77 | + &.primary { | ||
78 | + background: @primary-color; | ||
79 | + } | ||
80 | + | ||
81 | + &.error { | ||
82 | + background: @error-color; | ||
83 | + } | ||
84 | + | ||
85 | + &.success { | ||
86 | + background: @success-color; | ||
87 | + } | ||
88 | + | ||
89 | + &.warn { | ||
90 | + background: @warning-color; | ||
91 | + } | ||
92 | + } | ||
54 | // scrollbar -s tart | 93 | // scrollbar -s tart |
55 | &__content { | 94 | &__content { |
56 | /* 滚动槽 */ | 95 | /* 滚动槽 */ |
src/router/menus/modules/dashboard.ts
@@ -4,10 +4,16 @@ const menu: MenuModule = { | @@ -4,10 +4,16 @@ const menu: MenuModule = { | ||
4 | menu: { | 4 | menu: { |
5 | name: 'Dashboard', | 5 | name: 'Dashboard', |
6 | path: '/dashboard', | 6 | path: '/dashboard', |
7 | + // tag: { | ||
8 | + // dot: true, | ||
9 | + // }, | ||
7 | children: [ | 10 | children: [ |
8 | { | 11 | { |
9 | path: '/workbench', | 12 | path: '/workbench', |
10 | name: '工作台', | 13 | name: '工作台', |
14 | + // tag: { | ||
15 | + // content: 'new', | ||
16 | + // }, | ||
11 | }, | 17 | }, |
12 | { | 18 | { |
13 | path: '/analysis', | 19 | path: '/analysis', |
src/router/types.d.ts
@@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { | @@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { | ||
43 | props?: any; | 43 | props?: any; |
44 | fullPath?: string; | 44 | fullPath?: string; |
45 | } | 45 | } |
46 | +export interface MenuTag { | ||
47 | + type?: 'primary' | 'error' | 'warn' | 'success'; | ||
48 | + content?: string; | ||
49 | + dot?: boolean; | ||
50 | +} | ||
46 | 51 | ||
47 | export interface Menu { | 52 | export interface Menu { |
48 | name: string; | 53 | name: string; |
@@ -60,6 +65,8 @@ export interface Menu { | @@ -60,6 +65,8 @@ export interface Menu { | ||
60 | roles?: RoleEnum[]; | 65 | roles?: RoleEnum[]; |
61 | 66 | ||
62 | meta?: Partial<RouteMeta>; | 67 | meta?: Partial<RouteMeta>; |
68 | + | ||
69 | + tag?: MenuTag; | ||
63 | } | 70 | } |
64 | export interface MenuModule { | 71 | export interface MenuModule { |
65 | orderNo?: number; | 72 | orderNo?: number; |