Skip to content

Commit

Permalink
feat: edit global.js support plugin svg
Browse files Browse the repository at this point in the history
  • Loading branch information
clh021 authored Sep 18, 2024
1 parent a6651ff commit 4bc95bd
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions web/src/core/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,28 @@ const createIconComponent = (name) => ({
})

const registerIcons = async(app) => {
const iconModules = import.meta.glob('@/assets/icons/**/*.svg')
for (const path in iconModules) {
const iconModules = import.meta.glob('@/assets/icons/**/*.svg') // 系统目录 svg 图标
const pluginIconModules = import.meta.glob('@/plugin/**/assets/icons/**/*.svg') // 插件目录 svg 图标
const mergedIconModules = Object.assign({}, iconModules, pluginIconModules); // 合并所有 svg 图标
for (const path in mergedIconModules) {
let pluginName = ""
if (path.startsWith("/src/plugin/")) {
pluginName = `${path.split('/')[3]}-`
}
const iconName = path.split('/').pop().replace(/\.svg$/, '')
// 如果iconName带空格则不加入到图标库中并且提示名称不合法
if (iconName.indexOf(' ') !== -1) {
console.error(`icon ${iconName}.svg includes whitespace`)
console.error(`icon ${iconName}.svg includes whitespace in ${path}`)
continue
}
const key = `${pluginName}${iconName}`
console.log(key)
const iconComponent = createIconComponent(iconName)
config.logs.push({
'key': iconName,
'key': key,
'label': iconName,
})
app.component(iconName, iconComponent)
app.component(key, iconComponent)
}
}

Expand Down

0 comments on commit 4bc95bd

Please sign in to comment.