-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit 67023d0ce494b46460729cf39a45af8c9fd10124 Author: Sun <[email protected]> Date: Fri Dec 8 12:17:45 2023 +0800 修改原图标组件为在线图标组件 commit 379441c869489fdf44cb92a0cace75f9e5318915 Author: Sun <[email protected]> Date: Fri Dec 8 12:14:59 2023 +0800 适配本地化图标 commit da6feaa655e792d176f56777e089393f7658eda2 Author: Sun <[email protected]> Date: Fri Dec 8 12:14:07 2023 +0800 图标本地化 commit 02d84f66069653dedfc35578b1b26dad6edac0e3 Author: Sun <[email protected]> Date: Thu Dec 7 23:09:41 2023 +0800 增加离线图标库(源svgicon组件)的兼容并增加在线图标库组件
- Loading branch information
Showing
24 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
src/assets/svg-icons/material-symbols-ad-group-outline-rounded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
<script setup lang='ts'> | ||
import { computed, useAttrs } from 'vue' | ||
import { Icon } from '@iconify/vue' | ||
<script setup lang="ts"> | ||
import { computed, onMounted, ref, useAttrs } from 'vue' | ||
interface Props { | ||
const props = defineProps<{ | ||
icon?: string | ||
} | ||
defineProps<Props>() | ||
}>() | ||
const attrs = useAttrs() | ||
const iconName = ref(compatibleName(props.icon || '')) | ||
const iconContent = ref<string | null>(null) | ||
const bindAttrs = computed<{ class: string; style: string }>(() => ({ | ||
class: (attrs.class as string) || '', | ||
style: (attrs.style as string) || '', | ||
})) | ||
const loadIcon = async () => { | ||
try { | ||
const iconPath = import.meta.glob('@/assets/svg-icons/*.svg') | ||
const iconModule = await iconPath[`/src/assets/svg-icons/${iconName.value}.svg`]() | ||
const moduleDefault = iconModule as { default: string } | ||
const response = await fetch(moduleDefault.default) | ||
const content = await response.text() | ||
if (isValidSvg(content)) | ||
iconContent.value = content | ||
else | ||
console.error(`Invalid SVG format for icon ${iconName.value}`) | ||
} | ||
catch (error) { | ||
console.error(`Error loading icon ${iconName.value}:`, error) | ||
} | ||
} | ||
function isValidSvg(content: string): boolean { | ||
const parser = new DOMParser() | ||
const doc = parser.parseFromString(content, 'image/svg+xml') | ||
return doc.documentElement.tagName.toLowerCase() === 'svg' | ||
} | ||
function compatibleName(inputString: string): string { | ||
// 使用正则表达式替换所有的冒号 | ||
const resultString = inputString.replace(/:/g, '-') | ||
return resultString | ||
} | ||
onMounted(() => { | ||
loadIcon() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Icon :icon="icon ?? ''" v-bind="bindAttrs" /> | ||
<div v-if="iconContent" v-bind="bindAttrs" v-html="iconContent" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup lang='ts'> | ||
import { computed, useAttrs } from 'vue' | ||
import { Icon } from '@iconify/vue' | ||
interface Props { | ||
icon?: string | ||
} | ||
defineProps<Props>() | ||
const attrs = useAttrs() | ||
const bindAttrs = computed<{ class: string; style: string }>(() => ({ | ||
class: (attrs.class as string) || '', | ||
style: (attrs.style as string) || '', | ||
})) | ||
</script> | ||
|
||
<template> | ||
<Icon :icon="icon ?? ''" v-bind="bindAttrs" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters