refactor: modify icons usage

This commit is contained in:
chansee97 2024-04-03 11:21:07 +08:00
parent 609a26b847
commit 09e4d7d332
30 changed files with 69 additions and 81 deletions

View File

@ -1,5 +1,5 @@
# 是否开启压缩资源 # 是否开启压缩资源
VITE_COMPRESS_OPEN=N VITE_BUILD_COMPRESS=N
# 压缩算法 gzip | brotliCompress | deflate | deflateRaw # 压缩算法 gzip | brotliCompress | deflate | deflateRaw
VITE_COMPRESS_TYPE=gzip VITE_COMPRESS_TYPE=gzip

View File

@ -1,4 +1,3 @@
import path from 'node:path'
import UnoCSS from '@unocss/vite' import UnoCSS from '@unocss/vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx' import vueJsx from '@vitejs/plugin-vue-jsx'
@ -7,13 +6,11 @@ import AutoImport from 'unplugin-auto-import/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import viteCompression from 'vite-plugin-compression' import viteCompression from 'vite-plugin-compression'
import Icons from 'unplugin-icons/vite' import Icons from 'unplugin-icons/vite'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
// https://github.com/antfu/unplugin-icons // https://github.com/antfu/unplugin-icons
import IconsResolver from 'unplugin-icons/resolver' import IconsResolver from 'unplugin-icons/resolver'
// https://github.com/vbenjs/vite-plugin-svg-icons/blob/main/README.zh_CN.md
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
/** /**
* @description: vite插件配置 * @description: vite插件配置
* @param {*} env - * @param {*} env -
@ -43,28 +40,31 @@ export function createVitePlugins(env: ImportMetaEnv) {
// auto import components lib // auto import components lib
Components({ Components({
dts: 'src/typings/components.d.ts', dts: 'src/typings/components.d.ts',
resolvers: [IconsResolver(), NaiveUiResolver()], resolvers: [
IconsResolver({
prefix: false,
customCollections: [
'svg-icons',
],
}),
NaiveUiResolver(),
],
}), }),
// auto import iconify's icons // auto import iconify's icons
Icons({ Icons({
defaultStyle: 'display:inline-block', defaultStyle: 'display:inline-block',
compiler: 'vue3', compiler: 'vue3',
customCollections: {
'svg-icons': FileSystemIconLoader(
'src/assets/svg-icons',
svg => svg.replace(/^<svg /, '<svg fill="currentColor" width="1.2em" height="1.2em"'),
),
},
}), }),
// auto use svg icon
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(__dirname, '../src/assets/icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
// inject: 'body-last',
// customDomId: '__svg__icons__dom__',
}),
] ]
// use compression // use compression
if (env.VITE_COMPRESS_OPEN === 'Y') { if (env.VITE_BUILD_COMPRESS === 'Y') {
const { VITE_COMPRESS_TYPE = 'gzip' } = env const { VITE_COMPRESS_TYPE = 'gzip' } = env
plugins.push(viteCompression({ plugins.push(viteCompression({
algorithm: VITE_COMPRESS_TYPE, // 压缩算法 algorithm: VITE_COMPRESS_TYPE, // 压缩算法

View File

@ -86,7 +86,6 @@
"vite": "^5.1.6", "vite": "^5.1.6",
"vite-bundle-visualizer": "^1.1.0", "vite-bundle-visualizer": "^1.1.0",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-svg-icons": "^2.0.1",
"vue-tsc": "^2.0.6" "vue-tsc": "^2.0.6"
}, },
"simple-git-hooks": { "simple-git-hooks": {

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 902 B

After

Width:  |  Height:  |  Size: 902 B

View File

@ -35,9 +35,9 @@ function renderLabel(option: any) {
<template> <template>
<n-popselect :value="appStore.storeColorMode" :render-label="renderLabel" :options="options" trigger="click" @update:value="appStore.setColorMode"> <n-popselect :value="appStore.storeColorMode" :render-label="renderLabel" :options="options" trigger="click" @update:value="appStore.setColorMode">
<CommonWrapper> <CommonWrapper>
<i-icon-park-outline-moon v-if="appStore.storeColorMode === 'dark'" /> <icon-park-outline-moon v-if="appStore.storeColorMode === 'dark'" />
<i-icon-park-outline-sun-one v-if="appStore.storeColorMode === 'light'" /> <icon-park-outline-sun-one v-if="appStore.storeColorMode === 'light'" />
<i-icon-park-outline-laptop-computer v-if="appStore.storeColorMode === 'auto'" /> <icon-park-outline-laptop-computer v-if="appStore.storeColorMode === 'auto'" />
</CommonWrapper> </CommonWrapper>
</n-popselect> </n-popselect>
</template> </template>

View File

@ -14,7 +14,7 @@ const text = useVModel(props, 'modelValue', emit)
{{ text }} {{ text }}
</n-ellipsis> </n-ellipsis>
<span v-copy="text" class="copy_icon"> <span v-copy="text" class="copy_icon">
<i-icon-park-outline-copy /> <icon-park-outline-copy />
</span> </span>
</div> </div>
</template> </template>

View File

@ -18,7 +18,7 @@ function handleSelectIcon(icon: string) {
<template #trigger> <template #trigger>
<n-input v-model:value="currentIcon" readonly placeholder="选择目标图标"> <n-input v-model:value="currentIcon" readonly placeholder="选择目标图标">
<template #suffix> <template #suffix>
<e-icon :icon="currentIcon || 'icon-park-outline:all-application'" /> <nova-icon :icon="currentIcon || 'icon-park-outline:all-application'" />
</template> </template>
</n-input> </n-input>
</template> </template>
@ -33,7 +33,7 @@ function handleSelectIcon(icon: string) {
class="border border-gray-200 m-2px p-5px flex-center" class="border border-gray-200 m-2px p-5px flex-center"
@click="handleSelectIcon(item)" @click="handleSelectIcon(item)"
> >
<e-icon :icon="item" :size="24" /> <nova-icon :icon="item" :size="24" />
</div> </div>
</div> </div>
<n-empty v-else class="w-full" description="没有符合条件的图标" /> <n-empty v-else class="w-full" description="没有符合条件的图标" />

View File

@ -2,19 +2,23 @@
import { Icon } from '@iconify/vue' import { Icon } from '@iconify/vue'
interface iconPorps { interface iconPorps {
/* 图标名称 */
icon?: string icon?: string
/* 图标颜色 */
color?: string color?: string
/* 图标大小 */
size?: number size?: number
/* 图标深度 */
depth?: 1 | 2 | 3 | 4 | 5 depth?: 1 | 2 | 3 | 4 | 5
} }
const props = withDefaults(defineProps<iconPorps>(), { const props = withDefaults(defineProps<iconPorps>(), {
size: 18, size: 18,
icon: 'icon-park-outline:baby-feet',
}) })
</script> </script>
<template> <template>
<n-icon <n-icon
v-if="props.icon"
:size="props.size" :size="props.size"
:depth="props.depth" :depth="props.depth"
:color="props.color" :color="props.color"

View File

@ -5,7 +5,7 @@
<n-tooltip placement="left" trigger="hover"> <n-tooltip placement="left" trigger="hover">
<template #trigger> <template #trigger>
<div wh-full flex-center> <div wh-full flex-center>
<i-icon-park-outline-to-top /> <icon-park-outline-to-top />
</div> </div>
</template> </template>
<span>返回顶部</span> <span>返回顶部</span>

View File

@ -21,7 +21,7 @@ interface Emits {
</n-ellipsis> </n-ellipsis>
</template> </template>
<template #avatar> <template #avatar>
<e-icon :icon="item.icon" :size="30" class="c-primary" /> <nova-icon :icon="item.icon" :size="30" class="c-primary" />
</template> </template>
<template v-if="item.tagTitle" #header-extra> <template v-if="item.tagTitle" #header-extra>
<n-tag :bordered="false" :type="item.tagType" size="small"> <n-tag :bordered="false" :type="item.tagType" size="small">

View File

@ -21,7 +21,7 @@ const appStore = useAppStore()
class="flex-center gap-2 cursor-pointer split" class="flex-center gap-2 cursor-pointer split"
@click="router.push(item.path)" @click="router.push(item.path)"
> >
<e-icon v-if="appStore.showBreadcrumbIcon" :icon="item.meta.icon" /> <nova-icon v-if="appStore.showBreadcrumbIcon" :icon="item.meta.icon" />
<span class="whitespace-nowrap">{{ item.meta.title }}</span> <span class="whitespace-nowrap">{{ item.meta.title }}</span>
</n-el> </n-el>
</TransitionGroup> </TransitionGroup>

View File

@ -8,8 +8,8 @@ const appStore = useAppStore()
<n-tooltip placement="bottom" trigger="hover"> <n-tooltip placement="bottom" trigger="hover">
<template #trigger> <template #trigger>
<CommonWrapper @click="appStore.toggleCollapse()"> <CommonWrapper @click="appStore.toggleCollapse()">
<i-icon-park-outline-menu-unfold v-if="appStore.collapsed" /> <icon-park-outline-menu-unfold v-if="appStore.collapsed" />
<i-icon-park-outline-menu-fold v-else /> <icon-park-outline-menu-fold v-else />
</CommonWrapper> </CommonWrapper>
</template> </template>
<span>切换侧边栏</span> <span>切换侧边栏</span>

View File

@ -8,8 +8,8 @@ const appStore = useAppStore()
<n-tooltip placement="bottom" trigger="hover"> <n-tooltip placement="bottom" trigger="hover">
<template #trigger> <template #trigger>
<CommonWrapper @click="appStore.toggleFullScreen()"> <CommonWrapper @click="appStore.toggleFullScreen()">
<i-icon-park-outline-off-screen-two v-if="appStore.fullScreen" /> <icon-park-outline-off-screen-two v-if="appStore.fullScreen" />
<i-icon-park-outline-full-screen-two v-else /> <icon-park-outline-full-screen-two v-else />
</CommonWrapper> </CommonWrapper>
</template> </template>
<span>全屏</span> <span>全屏</span>

View File

@ -102,7 +102,7 @@ const groupMessage = computed(() => {
<template #trigger> <template #trigger>
<CommonWrapper> <CommonWrapper>
<n-badge :value="massageCount" :max="99" style="color: unset"> <n-badge :value="massageCount" :max="99" style="color: unset">
<i-icon-park-outline-remind /> <icon-park-outline-remind />
</n-badge> </n-badge>
</CommonWrapper> </CommonWrapper>
</template> </template>

View File

@ -48,7 +48,7 @@ function handleSelect(value: string) {
> >
<template #prefix> <template #prefix>
<n-icon> <n-icon>
<i-icon-park-outline-search /> <icon-park-outline-search />
</n-icon> </n-icon>
</template> </template>
</n-auto-complete> </n-auto-complete>

View File

@ -76,7 +76,7 @@ function resetSetting() {
<template #trigger> <template #trigger>
<CommonWrapper @click="openSetting"> <CommonWrapper @click="openSetting">
<div> <div>
<i-icon-park-outline-setting-two /> <icon-park-outline-setting-two />
<n-drawer v-model:show="drawerActive" :width="300"> <n-drawer v-model:show="drawerActive" :width="300">
<n-drawer-content title="系统设置" closable> <n-drawer-content title="系统设置" closable>
<n-space vertical> <n-space vertical>

View File

@ -12,10 +12,7 @@ const name = import.meta.env.VITE_APP_NAME
class="h-60px text-xl flex-center cursor-pointer" class="h-60px text-xl flex-center cursor-pointer"
@click="router.push('/')" @click="router.push('/')"
> >
<SvgIcon <svg-icons-logo class="text-1.5em" />
name="logo"
:size="32"
/>
<span <span
v-show="!appStore.collapsed" v-show="!appStore.collapsed"
class="mx-3 text-ellipsis overflow-hidden whitespace-nowrap" class="mx-3 text-ellipsis overflow-hidden whitespace-nowrap"

View File

@ -18,7 +18,7 @@ function handleReload() {
<n-tooltip placement="bottom" trigger="hover"> <n-tooltip placement="bottom" trigger="hover">
<template #trigger> <template #trigger>
<CommonWrapper @click="handleReload"> <CommonWrapper @click="handleReload">
<i-icon-park-outline-refresh :class="{ 'animate-spin': loading }" /> <icon-park-outline-refresh :class="{ 'animate-spin': loading }" />
</CommonWrapper> </CommonWrapper>
</template> </template>
<span>刷新页面</span> <span>刷新页面</span>

View File

@ -130,7 +130,7 @@ function handleDropTabs(key: string, option: any) {
@contextmenu="handleContextMenu($event, item)" @contextmenu="handleContextMenu($event, item)"
> >
<div class="flex-x-center gap-2"> <div class="flex-x-center gap-2">
<e-icon :icon="item.meta.icon" /> {{ item.meta.title }} <nova-icon :icon="item.meta.icon" /> {{ item.meta.title }}
</div> </div>
</n-tab> </n-tab>
<template #suffix> <template #suffix>
@ -144,7 +144,7 @@ function handleDropTabs(key: string, option: any) {
@select="handleDropTabs" @select="handleDropTabs"
> >
<CommonWrapper> <CommonWrapper>
<i-icon-park-outline-application-menu /> <icon-park-outline-application-menu />
</CommonWrapper> </CommonWrapper>
</n-dropdown> </n-dropdown>
</template> </template>

View File

@ -1,6 +1,5 @@
import 'uno.css' import 'uno.css'
import '@/styles/index.css' import '@/styles/index.css'
import 'virtual:svg-icons-register'
// 全局引入的静态资源 // 全局引入的静态资源
export function install() { export function install() {

View File

@ -14,7 +14,7 @@ interface ImportMetaEnv {
/** 开启请求代理 */ /** 开启请求代理 */
readonly VITE_HTTP_PROXY?: 'Y' | 'N' readonly VITE_HTTP_PROXY?: 'Y' | 'N'
/** 是否开启打包压缩 */ /** 是否开启打包压缩 */
readonly VITE_COMPRESS_OPEN?: 'Y' | 'N' readonly VITE_BUILD_COMPRESS?: 'Y' | 'N'
/** 压缩算法类型 */ /** 压缩算法类型 */
readonly VITE_COMPRESS_TYPE?: readonly VITE_COMPRESS_TYPE?:
| 'gzip' | 'gzip'

View File

@ -1,6 +0,0 @@
declare module '~icons/*' {
import type { FunctionalComponent, SVGAttributes } from 'vue'
const component: FunctionalComponent<SVGAttributes>
export default component
}

View File

@ -50,7 +50,7 @@ const tableData = [
color="#de4307" color="#de4307"
size="42" size="42"
> >
<i-icon-park-outline-chart-histogram /> <icon-park-outline-chart-histogram />
</n-icon> </n-icon>
</n-space> </n-space>
<template #footer> <template #footer>
@ -82,7 +82,7 @@ const tableData = [
color="#ffb549" color="#ffb549"
size="42" size="42"
> >
<i-icon-park-outline-chart-graph /> <icon-park-outline-chart-graph />
</n-icon> </n-icon>
</n-space> </n-space>
<template #footer> <template #footer>
@ -114,7 +114,7 @@ const tableData = [
color="#1687a7" color="#1687a7"
size="42" size="42"
> >
<i-icon-park-outline-average /> <icon-park-outline-average />
</n-icon> </n-icon>
</n-space> </n-space>
<template #footer> <template #footer>
@ -146,7 +146,7 @@ const tableData = [
color="#42218E" color="#42218E"
size="42" size="42"
> >
<i-icon-park-outline-chart-pie /> <icon-park-outline-chart-pie />
</n-icon> </n-icon>
</n-space> </n-space>
<template #footer> <template #footer>

View File

@ -29,7 +29,7 @@ const { userInfo } = useAuthStore()
<template #avatar> <template #avatar>
<n-el> <n-el>
<n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999"> <n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:user" /> <nova-icon :size="26" icon="icon-park-outline:user" />
</n-icon-wrapper> </n-icon-wrapper>
</n-el> </n-el>
</template> </template>
@ -47,7 +47,7 @@ const { userInfo } = useAuthStore()
<template #avatar> <template #avatar>
<n-el> <n-el>
<n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999"> <n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:every-user" /> <nova-icon :size="26" icon="icon-park-outline:every-user" />
</n-icon-wrapper> </n-icon-wrapper>
</n-el> </n-el>
</template> </template>
@ -65,7 +65,7 @@ const { userInfo } = useAuthStore()
<template #avatar> <template #avatar>
<n-el> <n-el>
<n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999"> <n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:preview-open" /> <nova-icon :size="26" icon="icon-park-outline:preview-open" />
</n-icon-wrapper> </n-icon-wrapper>
</n-el> </n-el>
</template> </template>
@ -83,7 +83,7 @@ const { userInfo } = useAuthStore()
<template #avatar> <template #avatar>
<n-el> <n-el>
<n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999"> <n-icon-wrapper :size="46" color="var(--success-color)" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:star" /> <nova-icon :size="26" icon="icon-park-outline:star" />
</n-icon-wrapper> </n-icon-wrapper>
</n-el> </n-el>
</template> </template>
@ -237,7 +237,7 @@ const { userInfo } = useAuthStore()
订单数 订单数
</n-text> </n-text>
<n-icon-wrapper :size="46" :border-radius="999"> <n-icon-wrapper :size="46" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:all-application" /> <nova-icon :size="26" icon="icon-park-outline:all-application" />
</n-icon-wrapper> </n-icon-wrapper>
<n-text strong class="text-2xl"> <n-text strong class="text-2xl">
1,234,123 1,234,123
@ -253,7 +253,7 @@ const { userInfo } = useAuthStore()
</n-text> </n-text>
<n-el> <n-el>
<n-icon-wrapper :size="46" color="var(--warning-color)" :border-radius="999"> <n-icon-wrapper :size="46" color="var(--warning-color)" :border-radius="999">
<e-icon :size="26" icon="icon-park-outline:list-bottom" /> <nova-icon :size="26" icon="icon-park-outline:list-bottom" />
</n-icon-wrapper> </n-icon-wrapper>
</n-el> </n-el>
<n-text strong class="text-2xl"> <n-text strong class="text-2xl">

View File

@ -104,7 +104,7 @@ const radioDate = [
color="#de4307" color="#de4307"
size="24" size="24"
> >
<i-icon-park-outline-chart-histogram /> <icon-park-outline-chart-histogram />
</n-icon> </n-icon>
</template> </template>
<template #action> <template #action>

View File

@ -187,13 +187,13 @@ function handleAddTable() {
<n-flex class="mt-1em" justify="end"> <n-flex class="mt-1em" justify="end">
<NButton type="primary" @click="getUserList"> <NButton type="primary" @click="getUserList">
<template #icon> <template #icon>
<i-icon-park-outline-search /> <icon-park-outline-search />
</template> </template>
搜索 搜索
</NButton> </NButton>
<NButton strong secondary @click="handleResetSearch"> <NButton strong secondary @click="handleResetSearch">
<template #icon> <template #icon>
<i-icon-park-outline-redo /> <icon-park-outline-redo />
</template> </template>
重置 重置
</NButton> </NButton>
@ -204,19 +204,19 @@ function handleAddTable() {
<div class="flex gap-4"> <div class="flex gap-4">
<NButton type="primary" @click="handleAddTable"> <NButton type="primary" @click="handleAddTable">
<template #icon> <template #icon>
<i-icon-park-outline-add-one /> <icon-park-outline-add-one />
</template> </template>
新建 新建
</NButton> </NButton>
<NButton strong secondary> <NButton strong secondary>
<template #icon> <template #icon>
<i-icon-park-outline-afferent /> <icon-park-outline-afferent />
</template> </template>
批量导入 批量导入
</NButton> </NButton>
<NButton strong secondary class="ml-a"> <NButton strong secondary class="ml-a">
<template #icon> <template #icon>
<i-icon-park-outline-download /> <icon-park-outline-download />
</template> </template>
下载 下载
</NButton> </NButton>

View File

@ -69,10 +69,10 @@ checkUserAccount()
<n-form-item path="pwd"> <n-form-item path="pwd">
<n-input v-model:value="formValue.pwd" type="password" placeholder="输入密码" clearable show-password-on="click"> <n-input v-model:value="formValue.pwd" type="password" placeholder="输入密码" clearable show-password-on="click">
<template #password-invisible-icon> <template #password-invisible-icon>
<i-icon-park-outline-preview-close-one /> <icon-park-outline-preview-close-one />
</template> </template>
<template #password-visible-icon> <template #password-visible-icon>
<i-icon-park-outline-preview-open /> <icon-park-outline-preview-open />
</template> </template>
</n-input> </n-input>
</n-form-item> </n-form-item>
@ -99,17 +99,17 @@ checkUserAccount()
<n-space justify="center"> <n-space justify="center">
<n-button circle> <n-button circle>
<template #icon> <template #icon>
<n-icon><i-icon-park-outline-wechat /></n-icon> <n-icon><icon-park-outline-wechat /></n-icon>
</template> </template>
</n-button> </n-button>
<n-button circle> <n-button circle>
<template #icon> <template #icon>
<n-icon><i-icon-park-outline-tencent-qq /></n-icon> <n-icon><icon-park-outline-tencent-qq /></n-icon>
</template> </template>
</n-button> </n-button>
<n-button circle> <n-button circle>
<template #icon> <template #icon>
<n-icon><i-icon-park-outline-github-one /></n-icon> <n-icon><icon-park-outline-github-one /></n-icon>
</template> </template>
</n-button> </n-button>
</n-space> </n-space>

View File

@ -58,10 +58,10 @@ function handleRegister() {}
show-password-on="click" show-password-on="click"
> >
<template #password-invisible-icon> <template #password-invisible-icon>
<i-icon-park-outline-preview-close-one /> <icon-park-outline-preview-close-one />
</template> </template>
<template #password-visible-icon> <template #password-visible-icon>
<i-icon-park-outline-preview-open /> <icon-park-outline-preview-open />
</template> </template>
</n-input> </n-input>
</n-form-item> </n-form-item>
@ -74,10 +74,10 @@ function handleRegister() {}
show-password-on="click" show-password-on="click"
> >
<template #password-invisible-icon> <template #password-invisible-icon>
<i-icon-park-outline-preview-close-one /> <icon-park-outline-preview-close-one />
</template> </template>
<template #password-visible-icon> <template #password-visible-icon>
<i-icon-park-outline-preview-open /> <icon-park-outline-preview-open />
</template> </template>
</n-input> </n-input>
</n-form-item> </n-form-item>

View File

@ -11,9 +11,4 @@ export default defineConfig({
'flex-x-center': 'flex justify-center', 'flex-x-center': 'flex justify-center',
'flex-y-center': 'flex items-center', 'flex-y-center': 'flex items-center',
}, },
theme: {
colors: {
primary: '#165DFFFF',
},
},
}) })