提交 7d9ac724 作者: 方治民

feat: 优化菜单 tag 实现,改用 Badge 并优化样式

上级 19c76089
<template> <template>
<span :class="getTagClass" v-if="getShowTag">{{ getContent }}</span> <Badge
v-if="getShowTag"
:class="['vben-simple-menu-badge', !getContent ? 'vben-simple-menu-badge--dot' : '']"
:dot="!getContent"
:count="getContent"
:number-style="{
color: 'f8f8f8',
lineHeight: '18px',
boxShadow: `0 0 0 1px #979797`,
}"
/>
</template> </template>
<script lang="ts"> <script lang="ts">
import type { Menu } from '/@/router/types' import type { Menu } from '/@/router/types'
import { defineComponent, computed } from 'vue' import { defineComponent, computed } from 'vue'
import { Badge } from 'ant-design-vue'
import { useDesign } from '/@/hooks/web/useDesign'
import { propTypes } from '/@/utils/propTypes' import { propTypes } from '/@/utils/propTypes'
export default defineComponent({ export default defineComponent({
name: 'SimpleMenuTag', name: 'SimpleMenuTag',
components: { Badge },
props: { props: {
item: { item: {
type: Object as PropType<Menu>, type: Object as PropType<Menu>,
...@@ -20,8 +31,6 @@ ...@@ -20,8 +31,6 @@
collapseParent: propTypes.bool, collapseParent: propTypes.bool,
}, },
setup(props) { setup(props) {
const { prefixCls } = useDesign('simple-menu')
const getShowTag = computed(() => { const getShowTag = computed(() => {
const { item } = props const { item } = props
...@@ -43,23 +52,16 @@ ...@@ -43,23 +52,16 @@
return dot || collapseParent ? '' : content return dot || collapseParent ? '' : content
}) })
const getTagClass = computed(() => { const getType = computed(() => {
const { item, collapseParent } = props if (!getShowTag.value) return 'error'
const { tag = {} } = item || {} const { item } = props
const { dot, type = 'error' } = tag const { tag } = item
const tagCls = `${prefixCls}-tag` const { type } = tag!
return [ return type ?? 'error'
tagCls,
[`${tagCls}--${type}`],
{
[`${tagCls}--collapse`]: collapseParent,
[`${tagCls}--dot`]: dot || props.dot,
},
]
}) })
return { return {
getTagClass, getType,
getShowTag, getShowTag,
getContent, getContent,
} }
......
...@@ -33,6 +33,16 @@ ...@@ -33,6 +33,16 @@
transition: all 0.3s; transition: all 0.3s;
} }
&-badge {
position: absolute;
right: 16px;
z-index: 1;
&--dot {
right: initial;
}
}
&-tag { &-tag {
position: absolute; position: absolute;
top: calc(50% - 8px); top: calc(50% - 8px);
......
...@@ -72,6 +72,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[], routerMappi ...@@ -72,6 +72,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[], routerMappi
hideMenu, hideMenu,
path: node.path, path: node.path,
...(node.redirect ? { redirect: node.redirect } : {}), ...(node.redirect ? { redirect: node.redirect } : {}),
...(node.tag ? { tag: node.tag } : {}),
} }
}, },
}) })
......
...@@ -13,6 +13,9 @@ const tools: AppRouteModule = { ...@@ -13,6 +13,9 @@ const tools: AppRouteModule = {
icon: 'carbon:tools', icon: 'carbon:tools',
title: t('routes.demo.tools.moduleName'), title: t('routes.demo.tools.moduleName'),
}, },
tag: {
dot: true,
},
children: [ children: [
{ {
path: 'file', path: 'file',
...@@ -49,6 +52,9 @@ const tools: AppRouteModule = { ...@@ -49,6 +52,9 @@ const tools: AppRouteModule = {
icon: 'mdi:database-lock-outline', icon: 'mdi:database-lock-outline',
}, },
component: () => import('/@/views/demo/tools/database/index.vue'), component: () => import('/@/views/demo/tools/database/index.vue'),
tag: {
content: '开发中',
},
}, },
{ {
path: 'online', path: 'online',
......
...@@ -17,10 +17,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { ...@@ -17,10 +17,11 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
children?: AppRouteRecordRaw[] children?: AppRouteRecordRaw[]
props?: Recordable props?: Recordable
fullPath?: string fullPath?: string
tag?: MenuTag
} }
export interface MenuTag { export interface MenuTag {
type?: 'primary' | 'error' | 'warn' | 'success' type?: 'default' | 'warning' | 'error' | 'success' | 'processing'
content?: string content?: string
dot?: boolean dot?: boolean
} }
......
...@@ -47,5 +47,11 @@ declare module 'vue-router' { ...@@ -47,5 +47,11 @@ declare module 'vue-router' {
hideLayout?: boolean hideLayout?: boolean
// 自动全屏 // 自动全屏
autoFullScreen?: boolean autoFullScreen?: boolean
// tag
tag?: {
type?: 'primary' | 'error' | 'warn' | 'success'
content?: string
dot?: boolean
}
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论