feat: ✨ iconSelect图标选择器和动态路由菜单支持element图标
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<el-icon v-if="icon && icon.includes('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-', ''))" />
|
||||
</el-icon>
|
||||
<SvgIcon v-else-if="icon" :icon-class="icon" />
|
||||
<SvgIcon v-else icon-class="menu" />
|
||||
<span v-if="title" class="ml-1">{{ translateRouteTitle(title) }}</span>
|
||||
@@ -8,6 +10,8 @@
|
||||
<script setup lang="ts">
|
||||
import { translateRouteTitle } from "@/utils/i18n";
|
||||
|
||||
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
|
||||
|
||||
defineProps({
|
||||
icon: {
|
||||
type: String,
|
||||
@@ -18,12 +22,25 @@ 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>
|
||||
.sub-el-icon {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
width: 14px !important;
|
||||
margin-right: 0 !important;
|
||||
font-size: 14px !important;
|
||||
color: currentcolor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user