|
@@ -1,5 +1,17 @@
|
|
|
-import {createVNode} from 'vue';
|
|
|
|
|
|
|
+import {createVNode, h} from 'vue';
|
|
|
import * as $Icon from '@ant-design/icons-vue';
|
|
import * as $Icon from '@ant-design/icons-vue';
|
|
|
|
|
+const svgRawModules = import.meta.glob('../assets/icons/*.svg', {
|
|
|
|
|
+ eager: true,
|
|
|
|
|
+ query: '?raw',
|
|
|
|
|
+ import: 'default',
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const svgModules = Object.fromEntries(
|
|
|
|
|
+ Object.entries(svgRawModules).map(([path, raw]) => [
|
|
|
|
|
+ path.split('/').pop().replace(/\.svg$/, ''),
|
|
|
|
|
+ raw,
|
|
|
|
|
+ ])
|
|
|
|
|
+);
|
|
|
|
|
|
|
|
// 实现动态加载antd的图标
|
|
// 实现动态加载antd的图标
|
|
|
export const BearJiaIcon = (props) => {
|
|
export const BearJiaIcon = (props) => {
|
|
@@ -79,7 +91,21 @@ export const BearJiaIcon = (props) => {
|
|
|
// console.log('$Icon[iconName]=' + $Icon[iconName]);
|
|
// console.log('$Icon[iconName]=' + $Icon[iconName]);
|
|
|
if ($Icon[iconName]) {
|
|
if ($Icon[iconName]) {
|
|
|
return createVNode($Icon[iconName]);
|
|
return createVNode($Icon[iconName]);
|
|
|
- } else {
|
|
|
|
|
|
|
+ } else if (iconName.startsWith('OL')) { // 自定义svg
|
|
|
|
|
+ const raw = svgModules[iconName];
|
|
|
|
|
+ if (raw) {
|
|
|
|
|
+ return h(
|
|
|
|
|
+ 'span',
|
|
|
|
|
+ {
|
|
|
|
|
+ class: 'anticon bearjia-svg-icon',
|
|
|
|
|
+ role: 'img',
|
|
|
|
|
+ innerHTML: raw,
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ console.warn(`[BearJiaIcon] 未找到自定义图标: ${iconName}`);
|
|
|
|
|
+ return createVNode($Icon['BarsOutlined']);
|
|
|
|
|
+ }else {
|
|
|
// 获取不到对应图标时,使用默认图标
|
|
// 获取不到对应图标时,使用默认图标
|
|
|
return createVNode($Icon['BarsOutlined']);
|
|
return createVNode($Icon['BarsOutlined']);
|
|
|
}
|
|
}
|