|
@@ -28,33 +28,17 @@ const props = defineProps({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-const getExtraIconStyle = computed((): CSSProperties => {
|
|
|
- if (!isCollapse.value) {
|
|
|
- return {
|
|
|
- position: "absolute",
|
|
|
- right: "10px"
|
|
|
- };
|
|
|
- } else {
|
|
|
- return {
|
|
|
- position: "static"
|
|
|
- };
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-const getNoDropdownStyle = computed((): CSSProperties => {
|
|
|
+const getSpanStyle = computed((): CSSProperties => {
|
|
|
return {
|
|
|
- display: "flex",
|
|
|
- alignItems: "center"
|
|
|
+ width: "100%",
|
|
|
+ textAlign: "center"
|
|
|
};
|
|
|
});
|
|
|
|
|
|
-const getDivStyle = computed((): CSSProperties => {
|
|
|
+const getNoDropdownStyle = computed((): CSSProperties => {
|
|
|
return {
|
|
|
- width: !isCollapse.value ? "" : "100%",
|
|
|
display: "flex",
|
|
|
- alignItems: "center",
|
|
|
- justifyContent: "space-between",
|
|
|
- overflow: "hidden"
|
|
|
+ alignItems: "center"
|
|
|
};
|
|
|
});
|
|
|
|
|
@@ -66,22 +50,45 @@ const getMenuTextStyle = computed(() => {
|
|
|
};
|
|
|
});
|
|
|
|
|
|
-const getSubTextStyle = computed((): CSSProperties => {
|
|
|
+const getDivStyle = computed((): CSSProperties => {
|
|
|
return {
|
|
|
- width: !isCollapse.value ? "210px" : "",
|
|
|
- display: "inline-block",
|
|
|
- overflow: "hidden",
|
|
|
- textOverflow: "ellipsis"
|
|
|
+ width: "100%",
|
|
|
+ display: "flex",
|
|
|
+ alignItems: "center",
|
|
|
+ justifyContent: "space-between",
|
|
|
+ overflow: "hidden"
|
|
|
};
|
|
|
});
|
|
|
|
|
|
-const getSpanStyle = computed(() => {
|
|
|
+const getsubMenuIconStyle = computed((): CSSProperties => {
|
|
|
return {
|
|
|
- overflow: "hidden",
|
|
|
- textOverflow: "ellipsis"
|
|
|
+ display: "flex",
|
|
|
+ justifyContent: "center",
|
|
|
+ alignItems: "center",
|
|
|
+ margin:
|
|
|
+ layout.value === "horizontal"
|
|
|
+ ? "0 5px 0 0"
|
|
|
+ : isCollapse.value
|
|
|
+ ? "0 auto"
|
|
|
+ : "0 5px 0 0"
|
|
|
};
|
|
|
});
|
|
|
|
|
|
+const getSubTextStyle = computed((): CSSProperties => {
|
|
|
+ if (!isCollapse.value) {
|
|
|
+ return {
|
|
|
+ width: "210px",
|
|
|
+ display: "inline-block",
|
|
|
+ overflow: "hidden",
|
|
|
+ textOverflow: "ellipsis"
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ width: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
const expandCloseIcon = computed(() => {
|
|
|
if (!getConfig()?.MenuArrowIconNoTransition) return "";
|
|
|
return {
|
|
@@ -115,6 +122,20 @@ function hoverMenu(key) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+// 左侧菜单折叠后,当菜单没有图标时只显示第一个文字并加上省略号
|
|
|
+function overflowSlice(text, item?: any) {
|
|
|
+ const newText =
|
|
|
+ (text?.length > 1 ? text.toString().slice(0, 1) : text) + "...";
|
|
|
+ if (item && !(isCollapse.value && item?.parentId === null)) {
|
|
|
+ return layout.value === "mix" &&
|
|
|
+ item?.pathList?.length === 2 &&
|
|
|
+ isCollapse.value
|
|
|
+ ? newText
|
|
|
+ : text;
|
|
|
+ }
|
|
|
+ return newText;
|
|
|
+}
|
|
|
+
|
|
|
function hasOneShowingChild(
|
|
|
children: childrenType[] = [],
|
|
|
parent: childrenType
|
|
@@ -151,84 +172,84 @@ function resolvePath(routePath) {
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <template
|
|
|
+ <el-menu-item
|
|
|
v-if="
|
|
|
hasOneShowingChild(props.item.children, props.item) &&
|
|
|
(!onlyOneChild.children || onlyOneChild.noShowingChildren)
|
|
|
"
|
|
|
+ :index="resolvePath(onlyOneChild.path)"
|
|
|
+ :class="{ 'submenu-title-noDropdown': !isNest }"
|
|
|
+ :style="getNoDropdownStyle"
|
|
|
>
|
|
|
- <el-menu-item
|
|
|
- :index="resolvePath(onlyOneChild.path)"
|
|
|
- :class="{ 'submenu-title-noDropdown': !isNest }"
|
|
|
- :style="getNoDropdownStyle"
|
|
|
+ <div
|
|
|
+ v-if="toRaw(props.item.meta.icon)"
|
|
|
+ class="sub-menu-icon"
|
|
|
+ :style="getsubMenuIconStyle"
|
|
|
>
|
|
|
- <div class="sub-menu-icon" v-if="toRaw(props.item.meta.icon)">
|
|
|
- <component
|
|
|
- :is="
|
|
|
- useRenderIcon(
|
|
|
- toRaw(onlyOneChild.meta.icon) ||
|
|
|
- (props.item.meta && toRaw(props.item.meta.icon))
|
|
|
- )
|
|
|
- "
|
|
|
- />
|
|
|
- </div>
|
|
|
- <div
|
|
|
- v-if="
|
|
|
- isCollapse &&
|
|
|
- layout === 'vertical' &&
|
|
|
- props.item?.pathList?.length === 1
|
|
|
+ <component
|
|
|
+ :is="
|
|
|
+ useRenderIcon(
|
|
|
+ toRaw(onlyOneChild.meta.icon) ||
|
|
|
+ (props.item.meta && toRaw(props.item.meta.icon))
|
|
|
+ )
|
|
|
"
|
|
|
- :style="getDivStyle"
|
|
|
- >
|
|
|
- <span :style="getMenuTextStyle">
|
|
|
- {{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- <div
|
|
|
- v-if="
|
|
|
- isCollapse && layout === 'mix' && props.item?.pathList?.length === 2
|
|
|
- "
|
|
|
- :style="getDivStyle"
|
|
|
- >
|
|
|
- <span :style="getMenuTextStyle">
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <span
|
|
|
+ v-if="
|
|
|
+ !props.item?.meta.icon &&
|
|
|
+ isCollapse &&
|
|
|
+ layout === 'vertical' &&
|
|
|
+ props.item?.pathList?.length === 1
|
|
|
+ "
|
|
|
+ :style="getSpanStyle"
|
|
|
+ >
|
|
|
+ {{ overflowSlice(transformI18n(onlyOneChild.meta.title)) }}
|
|
|
+ </span>
|
|
|
+ <span
|
|
|
+ v-if="
|
|
|
+ !onlyOneChild.meta.icon &&
|
|
|
+ isCollapse &&
|
|
|
+ layout === 'mix' &&
|
|
|
+ props.item?.pathList?.length === 2
|
|
|
+ "
|
|
|
+ :style="getSpanStyle"
|
|
|
+ >
|
|
|
+ {{ overflowSlice(transformI18n(onlyOneChild.meta.title)) }}
|
|
|
+ </span>
|
|
|
+ <template #title>
|
|
|
+ <div :style="getDivStyle">
|
|
|
+ <span v-if="layout === 'horizontal'">
|
|
|
{{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
</span>
|
|
|
- </div>
|
|
|
- <template #title>
|
|
|
- <div :style="getDivStyle">
|
|
|
- <span v-if="layout === 'horizontal'">
|
|
|
+ <el-tooltip
|
|
|
+ v-else
|
|
|
+ placement="top"
|
|
|
+ :effect="tooltipEffect"
|
|
|
+ :offset="-10"
|
|
|
+ :disabled="!onlyOneChild.showTooltip"
|
|
|
+ >
|
|
|
+ <template #content>
|
|
|
{{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
- </span>
|
|
|
- <el-tooltip
|
|
|
- v-else
|
|
|
- placement="top"
|
|
|
- :effect="tooltipEffect"
|
|
|
- :offset="-10"
|
|
|
- :disabled="!onlyOneChild.showTooltip"
|
|
|
+ </template>
|
|
|
+ <span
|
|
|
+ ref="menuTextRef"
|
|
|
+ :style="getMenuTextStyle"
|
|
|
+ @mouseover="hoverMenu(onlyOneChild)"
|
|
|
>
|
|
|
- <template #content>
|
|
|
- {{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
- </template>
|
|
|
- <span
|
|
|
- ref="menuTextRef"
|
|
|
- :style="getMenuTextStyle"
|
|
|
- @mouseover="hoverMenu(onlyOneChild)"
|
|
|
- >
|
|
|
- {{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
- </span>
|
|
|
- </el-tooltip>
|
|
|
- <FontIcon
|
|
|
- v-if="onlyOneChild.meta.extraIcon"
|
|
|
- width="30px"
|
|
|
- height="30px"
|
|
|
- :style="getExtraIconStyle"
|
|
|
- :icon="onlyOneChild.meta.extraIcon.name"
|
|
|
- :svg="onlyOneChild.meta.extraIcon.svg ? true : false"
|
|
|
- />
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-menu-item>
|
|
|
- </template>
|
|
|
+ {{ transformI18n(onlyOneChild.meta.title) }}
|
|
|
+ </span>
|
|
|
+ </el-tooltip>
|
|
|
+ <FontIcon
|
|
|
+ v-if="onlyOneChild.meta.extraIcon"
|
|
|
+ width="30px"
|
|
|
+ height="30px"
|
|
|
+ :icon="onlyOneChild.meta.extraIcon.name"
|
|
|
+ :svg="onlyOneChild.meta.extraIcon.svg ? true : false"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-menu-item>
|
|
|
|
|
|
<el-sub-menu
|
|
|
v-else
|
|
@@ -237,7 +258,11 @@ function resolvePath(routePath) {
|
|
|
:index="resolvePath(props.item.path)"
|
|
|
>
|
|
|
<template #title>
|
|
|
- <div v-if="toRaw(props.item.meta.icon)" class="sub-menu-icon">
|
|
|
+ <div
|
|
|
+ v-if="toRaw(props.item.meta.icon)"
|
|
|
+ :style="getsubMenuIconStyle"
|
|
|
+ class="sub-menu-icon"
|
|
|
+ >
|
|
|
<component
|
|
|
:is="useRenderIcon(props.item.meta && toRaw(props.item.meta.icon))"
|
|
|
/>
|
|
@@ -255,21 +280,25 @@ function resolvePath(routePath) {
|
|
|
<template #content>
|
|
|
{{ transformI18n(props.item.meta.title) }}
|
|
|
</template>
|
|
|
- <div
|
|
|
+ <span
|
|
|
+ v-if="
|
|
|
+ !(
|
|
|
+ isCollapse &&
|
|
|
+ toRaw(props.item.meta.icon) &&
|
|
|
+ props.item.parentId === null
|
|
|
+ )
|
|
|
+ "
|
|
|
ref="menuTextRef"
|
|
|
:style="getSubTextStyle"
|
|
|
@mouseover="hoverMenu(props.item)"
|
|
|
>
|
|
|
- <span :style="getSpanStyle">
|
|
|
- {{ transformI18n(props.item.meta.title) }}
|
|
|
- </span>
|
|
|
- </div>
|
|
|
+ {{ overflowSlice(transformI18n(props.item.meta.title), props.item) }}
|
|
|
+ </span>
|
|
|
</el-tooltip>
|
|
|
<FontIcon
|
|
|
v-if="props.item.meta.extraIcon"
|
|
|
width="30px"
|
|
|
height="30px"
|
|
|
- style="position: absolute; right: 10px"
|
|
|
:icon="props.item.meta.extraIcon.name"
|
|
|
:svg="props.item.meta.extraIcon.svg ? true : false"
|
|
|
/>
|