From 72060f67a5f3ce59827adace5edc25499004e50a Mon Sep 17 00:00:00 2001 From: "gary.fu" Date: Fri, 5 Jul 2024 11:14:48 +0800 Subject: [PATCH] =?UTF-8?q?icon=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/icons/index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/icons/index.js b/src/icons/index.js index f6b4d54..280e46c 100644 --- a/src/icons/index.js +++ b/src/icons/index.js @@ -1,9 +1,10 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue' -import * as MaterialIconsVue from '@vicons/material' import { kebabCase } from 'lodash-es' +import { defineAsyncComponent } from 'vue' export const INSTALL_ICONS = [] export const ICON_PREFIX = 'icon-' + /** * icon组件注册工具,默认增加icon-前缀,如果重复,再增加前缀 * @param app {import('vue').App} Vue实例 @@ -23,15 +24,26 @@ const registryIconComponent = (app, key, component, prefix) => { export default { /** - * 注册图标 - * @param app {import('vue').App} - */ + * 注册图标 + * @param app {import('vue').App} + */ install (app) { for (const [key, component] of Object.entries(ElementPlusIconsVue)) { registryIconComponent(app, key, component, 'El') } - for (const [key, component] of Object.entries(MaterialIconsVue)) { - registryIconComponent(app, key, component, 'Md') + const materialIcons = import.meta.glob([ + '/node_modules/@vicons/material/es/*Filled.js', + '/node_modules/@vicons/material/es/*Outlined.js' + ], { eager: false }) + for (const path in materialIcons) { + const component = materialIcons[path] + const matchResult = /.+\/(\w+)\.js/g.exec(path) + if (matchResult[1]) { + const name = matchResult[1] + registryIconComponent(app, name, defineAsyncComponent(component), 'Md') + } } + // 更多图标可以再注册 + // registryIconComponent(app, key, component, 'Md') } }