refactor(SidebarMenuItemTitle): ♻️ 去除冗余代码
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-icon v-if="icon && icon.startsWith('el-icon')" class="sub-el-icon">
|
<el-icon v-if="icon && icon.startsWith('el-icon')" class="sub-el-icon">
|
||||||
<component :is="renderIcon(icon.replace('el-icon-', ''))" />
|
<component :is="icon.replace('el-icon-', '')" />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<SvgIcon v-else-if="icon" :icon-class="icon" />
|
<svg-icon v-else-if="icon" :icon-class="icon" />
|
||||||
<SvgIcon v-else icon-class="menu" />
|
<svg-icon v-else icon-class="menu" />
|
||||||
<span v-if="title" class="ml-1">{{ translateRouteTitle(title) }}</span>
|
<span v-if="title" class="ml-1">{{ translateRouteTitle(title) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { translateRouteTitle } from "@/utils/i18n";
|
import { translateRouteTitle } from "@/utils/i18n";
|
||||||
|
|
||||||
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
|
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
icon: {
|
icon: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -22,18 +20,6 @@ defineProps({
|
|||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 渲染图标组件
|
|
||||||
*/
|
|
||||||
type IconNames = keyof typeof ElementPlusIconsVue;
|
|
||||||
const renderIcon = (iconName: string) => {
|
|
||||||
const iconComponent = ElementPlusIconsVue[iconName as IconNames];
|
|
||||||
if (iconComponent) {
|
|
||||||
return h(resolveComponent(iconComponent.name));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user