1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| import { VueSvgIcon } from '@yzfe/vue3-svgicon'
| import { defineComponent } from 'vue'
| import '@yzfe/svgicon/lib/svgicon.css'
| import styles from './SvgIcon.module.scss'
|
| const svgFiles = import.meta.glob('../../assets/svg-icon/*.svg', {
| eager: true,
| })
|
| const icons: Record<string, any> = Object.entries(svgFiles).reduce(
| (acc, [key, value]: any[]) => {
| const name = key.replace('../../assets/svg-icon/', '').replace('.svg', '')
| return {
| ...acc,
| [name]: value.default,
| }
| },
| {}
| )
|
| const SvgIcon = defineComponent({
| name: 'SvgIcon',
| props: {
| type: {
| type: String,
| },
| color: {
| type: String,
| },
| width: {
| type: [String, Number],
| },
| height: {
| type: [String, Number],
| },
| scale: {
| type: [String, Number],
| },
| title: {
| type: String,
| },
| class: {
| type: String,
| },
| style: {
| type: Object,
| },
| },
| emits: ['click'],
| setup(props: any, { attrs, emit }) {
| return () => {
| if (props.title) {
| return (
| <el-tooltip effect="dark" content={props.title} placement="top">
| <VueSvgIcon
| onClick={() => emit('click')}
| class={styles.container}
| data={icons[props.type]}
| {...props}
| {...attrs}
| />
| </el-tooltip>
| )
| }
| return (
| <VueSvgIcon
| onClick={() => emit('click')}
| class={styles.container}
| data={icons[props.type]}
| {...props}
| {...attrs}
| />
| )
| }
| },
| })
|
| export default SvgIcon
|
|