Skip to content

Commit 9f73dfe

Browse files
authored
Merge pull request #2106 from Azir-11/dev-286
添加开发环境启动脚本、更新 SvgIcon 组件,支持本地图标和 Iconify 图标、移除未使用的 unocss 依赖
2 parents 7101ec1 + 23e5d74 commit 9f73dfe

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.8.5",
44
"private": true,
55
"scripts": {
6+
"dev": "node openDocument.js && vite --host --mode development",
67
"serve": "node openDocument.js && vite --host --mode development",
78
"build": "vite build --mode production",
89
"limit-build": "npm install increase-memory-limit-fixbug cross-env -g && npm run fix-memory-limit && node ./limit && npm run build",
@@ -14,6 +15,7 @@
1415
"@element-plus/icons-vue": "^2.3.1",
1516
"@form-create/designer": "^3.2.6",
1617
"@form-create/element-ui": "^3.2.10",
18+
"@iconify/vue": "^5.0.0",
1719
"@unocss/transformer-directives": "^66.4.2",
1820
"@vue-office/docx": "^1.6.2",
1921
"@vue-office/excel": "^1.7.11",
@@ -76,7 +78,6 @@
7678
"globals": "^16.3.0",
7779
"sass": "^1.78.0",
7880
"terser": "^5.31.6",
79-
"unocss": "^66.4.2",
8081
"vite": "^6.2.3",
8182
"vite-plugin-banner": "^0.8.0",
8283
"vite-plugin-importer": "^0.2.5",
Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
<template>
2-
<svg :class="svgClass" v-bind="$attrs" :color="color">
3-
<use :xlink:href="'#' + name" rel="external nofollow" />
4-
</svg>
2+
<template v-if="localIcon">
3+
<svg aria-hidden="true" width="1em" height="1em" v-bind="bindAttrs">
4+
<use :xlink:href="'#' + localIcon" rel="external nofollow" />
5+
</svg>
6+
</template>
7+
<template v-else-if="icon">
8+
<Icon :icon="icon" v-bind="bindAttrs" />
9+
</template>
510
</template>
11+
612
<script setup>
7-
import { computed } from 'vue'
8-
const props = defineProps({
9-
name: {
10-
type: String,
11-
required: true
12-
},
13-
color: {
14-
type: String,
15-
default: 'currentColor'
16-
}
17-
})
13+
import { computed, useAttrs } from 'vue';
14+
import { Icon } from '@iconify/vue'
1815
19-
const svgClass = computed(() => {
20-
if (props.name) {
21-
return `svg-icon ${props.name}`
22-
}
23-
return 'svg-icon'
24-
})
25-
</script>
26-
<style scoped>
27-
.svg-icon {
28-
@apply w-4 h-4;
29-
fill: currentColor;
30-
vertical-align: middle;
16+
/**
17+
* 使用示例:
18+
* 本地图标(所有可用的本地图标见控制台输出):
19+
* <SvgIcon localIcon="lock" class="text-red-500 text-3xl" />
20+
*
21+
* 在线图标(相关查询网站:https://icones.js.org/ 或是:https://icon-sets.iconify.design/):
22+
* <SvgIcon icon="mingcute:love-fill" class="text-red-500 text-3xl" />
23+
*/
24+
defineProps({
25+
// 通过 symbol id 使用本地注册的 svg 图标
26+
localIcon: {
27+
type: String,
28+
required: false,
29+
default: ''
30+
},
31+
// Iconify 图标名称, 例如: 'mdi:home'
32+
icon: {
33+
type: String,
34+
required: false,
35+
default: ''
3136
}
32-
</style>
37+
})
38+
const attrs = useAttrs();
39+
40+
const bindAttrs = computed(() => ({
41+
class: (attrs.class) || '',
42+
style: (attrs.style) || ''
43+
}))
44+
</script>

web/src/core/global.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const createIconComponent = (name) => ({
1010
name: 'SvgIcon',
1111
render() {
1212
return h(svgIcon, {
13-
name: name
13+
localIcon: name
1414
})
1515
}
1616
})
@@ -21,6 +21,7 @@ const registerIcons = async (app) => {
2121
'@/plugin/**/assets/icons/**/*.svg'
2222
) // 插件目录 svg 图标
2323
const mergedIconModules = Object.assign({}, iconModules, pluginIconModules) // 合并所有 svg 图标
24+
let allKeys = []
2425
for (const path in mergedIconModules) {
2526
let pluginName = ''
2627
if (path.startsWith('/src/plugin/')) {
@@ -36,16 +37,19 @@ const registerIcons = async (app) => {
3637
continue
3738
}
3839
const key = `${pluginName}${iconName}`
39-
// 开发模式下列出所有 svg 图标,方便开发者直接查找复制使用
40-
import.meta.env.MODE == 'development' &&
41-
console.log(`svg-icon-component: <${key} />`)
4240
const iconComponent = createIconComponent(key)
4341
config.logs.push({
4442
key: key,
4543
label: key
4644
})
4745
app.component(key, iconComponent)
46+
47+
// 开发模式下列出所有 svg 图标,方便开发者直接查找复制使用
48+
allKeys.push(key)
4849
}
50+
51+
import.meta.env.MODE == 'development' &&
52+
console.log(`所有可用的本地图标: ${allKeys.join(', ')}`)
4953
}
5054

5155
export const register = (app) => {

0 commit comments

Comments
 (0)