refactor(SidebarMenuItemTitle): ♻️ 去除冗余代码
This commit is contained in:
parent
ef3aa3e61f
commit
1af41faa85
|
|
@ -1,17 +1,15 @@
|
|||
<template>
|
||||
<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>
|
||||
<SvgIcon v-else-if="icon" :icon-class="icon" />
|
||||
<SvgIcon v-else icon-class="menu" />
|
||||
<svg-icon v-else-if="icon" :icon-class="icon" />
|
||||
<svg-icon v-else icon-class="menu" />
|
||||
<span v-if="title" class="ml-1">{{ translateRouteTitle(title) }}</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { translateRouteTitle } from "@/utils/i18n";
|
||||
|
||||
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
|
||||
|
||||
defineProps({
|
||||
icon: {
|
||||
type: String,
|
||||
|
|
@ -22,18 +20,6 @@ defineProps({
|
|||
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>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
Loading…
Reference in New Issue