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 | 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 | 55 | return () => { |
39 | 56 | if (!props.item) { |
40 | 57 | return null; |
... | ... | @@ -46,17 +63,21 @@ export default defineComponent({ |
46 | 63 | |
47 | 64 | const beforeStr = name.substr(0, index); |
48 | 65 | const afterStr = name.substr(index + searchValue.length); |
66 | + const cls = showTitle ? 'show-title' : 'basic-menu__name'; | |
49 | 67 | return ( |
50 | 68 | <> |
51 | 69 | {renderIcon(icon!)} |
52 | 70 | {index > -1 && searchValue ? ( |
53 | - <span class={showTitle ? 'show-title' : ''}> | |
71 | + <span class={cls}> | |
54 | 72 | {beforeStr} |
55 | 73 | <span class={`basic-menu__keyword`}>{searchValue}</span> |
56 | 74 | {afterStr} |
57 | 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 | 51 | |
52 | 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 | 93 | // scrollbar -s tart |
55 | 94 | &__content { |
56 | 95 | /* 滚动槽 */ | ... | ... |
src/router/menus/modules/dashboard.ts
... | ... | @@ -4,10 +4,16 @@ const menu: MenuModule = { |
4 | 4 | menu: { |
5 | 5 | name: 'Dashboard', |
6 | 6 | path: '/dashboard', |
7 | + // tag: { | |
8 | + // dot: true, | |
9 | + // }, | |
7 | 10 | children: [ |
8 | 11 | { |
9 | 12 | path: '/workbench', |
10 | 13 | name: '工作台', |
14 | + // tag: { | |
15 | + // content: 'new', | |
16 | + // }, | |
11 | 17 | }, |
12 | 18 | { |
13 | 19 | path: '/analysis', | ... | ... |
src/router/types.d.ts
... | ... | @@ -43,6 +43,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { |
43 | 43 | props?: any; |
44 | 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 | 52 | export interface Menu { |
48 | 53 | name: string; |
... | ... | @@ -60,6 +65,8 @@ export interface Menu { |
60 | 65 | roles?: RoleEnum[]; |
61 | 66 | |
62 | 67 | meta?: Partial<RouteMeta>; |
68 | + | |
69 | + tag?: MenuTag; | |
63 | 70 | } |
64 | 71 | export interface MenuModule { |
65 | 72 | orderNo?: number; | ... | ... |