refactor: ♻️ 移除 vicons 使用 unocss 的 icons preset 以获得纯 css icon

This commit is contained in:
xiangshu233 2024-03-02 17:54:00 +08:00
parent facaf8e43c
commit 10115a5331
11 changed files with 55 additions and 97 deletions

View File

@ -41,9 +41,6 @@
"dependencies": { "dependencies": {
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@unocss/reset": "^0.58.5", "@unocss/reset": "^0.58.5",
"@vicons/antd": "^0.12.0",
"@vicons/ionicons5": "^0.12.0",
"@vicons/utils": "^0.1.4",
"@vueuse/core": "^10.7.0", "@vueuse/core": "^10.7.0",
"axios": "^1.4.0", "axios": "^1.4.0",
"date-fns": "^3.0.6", "date-fns": "^3.0.6",
@ -61,6 +58,7 @@
"@antfu/eslint-config": "^2.6.3", "@antfu/eslint-config": "^2.6.3",
"@commitlint/cli": "^18.4.3", "@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3", "@commitlint/config-conventional": "^18.4.3",
"@iconify/json": "^2.2.188",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/mockjs": "^1.0.10", "@types/mockjs": "^1.0.10",
"@types/node": "^20.10.5", "@types/node": "^20.10.5",

10
pnpm-lock.yaml generated
View File

@ -67,6 +67,9 @@ devDependencies:
'@commitlint/config-conventional': '@commitlint/config-conventional':
specifier: ^18.4.3 specifier: ^18.4.3
version: 18.4.3 version: 18.4.3
'@iconify/json':
specifier: ^2.2.188
version: 2.2.188
'@types/fs-extra': '@types/fs-extra':
specifier: ^11.0.4 specifier: ^11.0.4
version: 11.0.4 version: 11.0.4
@ -1292,6 +1295,13 @@ packages:
resolution: {integrity: sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==} resolution: {integrity: sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==}
dev: true dev: true
/@iconify/json@2.2.188:
resolution: {integrity: sha512-gsJwZ60Vb5IrtjYu+Al4qMaML9ZKUnop6Gi0537ZcA6nEhe3Nb58WH4c6b1+mXOHwOkFlLA8AFBXJUHY5nKMdA==}
dependencies:
'@iconify/types': 2.0.0
pathe: 1.1.2
dev: true
/@iconify/types@2.0.0: /@iconify/types@2.0.0:
resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==} resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==}
dev: true dev: true

View File

@ -23,9 +23,10 @@
:key="menu.name" :key="menu.name"
replace replace
:to="menu.path" :to="menu.path"
:icon="(menu.meta?.icon as string)"
> >
{{ menu.meta?.title }} <template #icon>
<i :class="menu.meta?.icon" />
</template>
</van-tabbar-item> </van-tabbar-item>
</van-tabbar> </van-tabbar>
</div> </div>

View File

@ -10,7 +10,7 @@ const routeModuleList: Array<RouteRecordRaw> = [
component: Layout, component: Layout,
meta: { meta: {
title: '主控台', title: '主控台',
icon: 'wap-home', icon: 'i-simple-icons:atlassian',
}, },
children: [ children: [
{ {
@ -29,8 +29,8 @@ const routeModuleList: Array<RouteRecordRaw> = [
redirect: '/message/index', redirect: '/message/index',
component: Layout, component: Layout,
meta: { meta: {
title: '消息', title: '图表',
icon: 'chat', icon: 'i-simple-icons:soundcharts',
}, },
children: [ children: [
{ {
@ -50,7 +50,7 @@ const routeModuleList: Array<RouteRecordRaw> = [
component: Layout, component: Layout,
meta: { meta: {
title: '我的', title: '我的',
icon: 'manager', icon: 'i-simple-icons:docsify',
}, },
children: [ children: [
{ {

View File

@ -5,7 +5,6 @@
<div class="text-darkBlue dark:text-garyWhite mb-4 mt-12 text-center text-2xl font-black"> <div class="text-darkBlue dark:text-garyWhite mb-4 mt-12 text-center text-2xl font-black">
{{ title }} {{ title }}
</div> </div>
<div class="mb-6 mt-4 w-full"> <div class="mb-6 mt-4 w-full">
<van-swipe class="h-30" :autoplay="3000" :indicator-color="designStore.appTheme"> <van-swipe class="h-30" :autoplay="3000" :indicator-color="designStore.appTheme">
<van-swipe-item <van-swipe-item

View File

@ -8,9 +8,7 @@
:rules="getFormRules.username" :rules="getFormRules.username"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-ph:user-bold mr-2 text-lg" />
<UserOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -22,9 +20,7 @@
:rules="getFormRules.mobile" :rules="getFormRules.mobile"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-ic:twotone-smartphone mr-2 text-lg" />
<MobileOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -37,9 +33,7 @@
:rules="getFormRules.sms" :rules="getFormRules.sms"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-material-symbols:edit-square-outline-rounded mr-2 text-lg" />
<EditOutlined />
</Icon>
</template> </template>
<template #button> <template #button>
<van-button size="small" type="primary"> <van-button size="small" type="primary">
@ -72,8 +66,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, reactive, ref, unref } from 'vue' import { computed, reactive, ref, unref } from 'vue'
import type { FormInstance } from 'vant' import type { FormInstance } from 'vant'
import { Icon } from '@vicons/utils'
import { EditOutlined, MobileOutlined, UserOutlined } from '@vicons/antd'
import { LoginStateEnum, useFormRules, useLoginState } from './useLogin' import { LoginStateEnum, useFormRules, useLoginState } from './useLogin'
const { handleBackLogin, getLoginState } = useLoginState() const { handleBackLogin, getLoginState } = useLoginState()

View File

@ -8,9 +8,7 @@
:rules="getFormRules.username" :rules="getFormRules.username"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-ph:user-bold mr-2 text-lg" />
<UserOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
<van-field <van-field
@ -23,17 +21,11 @@
@click-right-icon="switchPassType = !switchPassType" @click-right-icon="switchPassType = !switchPassType"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-iconamoon:lock-bold mr-2 text-lg" />
<LockOutlined />
</Icon>
</template> </template>
<template #right-icon> <template #right-icon>
<Icon v-if="switchPassType"> <i v-if="switchPassType" class="i-mdi:eye-outline mr-2 text-lg" />
<EyeInvisibleOutlined /> <i v-else class="i-mdi:eye-off mr-2 text-lg" />
</Icon>
<Icon v-else>
<EyeOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -71,8 +63,6 @@ import { computed, onMounted, reactive, ref, unref } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { showFailToast, showLoadingToast, showSuccessToast } from 'vant' import { showFailToast, showLoadingToast, showSuccessToast } from 'vant'
import type { FormInstance } from 'vant' import type { FormInstance } from 'vant'
import { Icon } from '@vicons/utils'
import { EyeInvisibleOutlined, EyeOutlined, LockOutlined, UserOutlined } from '@vicons/antd'
import { LoginStateEnum, useFormRules, useLoginState } from './useLogin' import { LoginStateEnum, useFormRules, useLoginState } from './useLogin'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { ResultEnum } from '@/enums/httpEnum' import { ResultEnum } from '@/enums/httpEnum'

View File

@ -1,9 +1,9 @@
<template> <template>
<div class="flex flex-col items-center justify-center"> <div class="flex flex-col items-center justify-center">
<div class="logo enter-y mb-2 mt-8"> <div class="logo enter-y mb-8 mt-8">
<SvgIcon class="!h-30 !w-30" name="logo" /> <SvgIcon class="!h-30 !w-30" name="logo" />
</div> </div>
<div class="text-darkBlue dark:text-garyWhite enter-y mb-8 text-2xl font-black"> <div class="text-darkBlue dark:text-garyWhite enter-y mb-12 text-2xl font-black">
{{ title }} {{ title }}
</div> </div>
</div> </div>

View File

@ -9,9 +9,7 @@
:rules="getFormRules.username" :rules="getFormRules.username"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-ph:user-bold mr-2 text-lg" />
<UserOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -23,9 +21,7 @@
:rules="getFormRules.mobile" :rules="getFormRules.mobile"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-ic:twotone-smartphone mr-2 text-lg" />
<MobileOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -38,9 +34,7 @@
:rules="getFormRules.sms" :rules="getFormRules.sms"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-material-symbols:edit-square-outline-rounded mr-2 text-lg" />
<EditOutlined />
</Icon>
</template> </template>
<template #button> <template #button>
<van-button size="small" type="primary"> <van-button size="small" type="primary">
@ -59,17 +53,11 @@
@click-right-icon="switchPassType = !switchPassType" @click-right-icon="switchPassType = !switchPassType"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-iconamoon:lock-bold mr-2 text-lg" />
<LockOutlined />
</Icon>
</template> </template>
<template #right-icon> <template #right-icon>
<Icon v-if="switchPassType"> <i v-if="switchPassType" class="i-mdi:eye-outline mr-2 text-lg" />
<EyeInvisibleOutlined /> <i v-else class="i-mdi:eye-off mr-2 text-lg" />
</Icon>
<Icon v-else>
<EyeOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -83,17 +71,11 @@
@click-right-icon="switchConfirmPassType = !switchConfirmPassType" @click-right-icon="switchConfirmPassType = !switchConfirmPassType"
> >
<template #left-icon> <template #left-icon>
<Icon> <i class="i-iconamoon:lock-bold mr-2 text-lg" />
<LockOutlined />
</Icon>
</template> </template>
<template #right-icon> <template #right-icon>
<Icon v-if="switchConfirmPassType"> <i v-if="switchConfirmPassType" class="i-mdi:eye-outline mr-2 text-lg" />
<EyeInvisibleOutlined /> <i v-else class="i-mdi:eye-off mr-2 text-lg" />
</Icon>
<Icon v-else>
<EyeOutlined />
</Icon>
</template> </template>
</van-field> </van-field>
@ -135,15 +117,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, reactive, ref, unref } from 'vue' import { computed, reactive, ref, unref } from 'vue'
import type { FormInstance } from 'vant' import type { FormInstance } from 'vant'
import { Icon } from '@vicons/utils'
import {
EditOutlined,
EyeInvisibleOutlined,
EyeOutlined,
LockOutlined,
MobileOutlined,
UserOutlined,
} from '@vicons/antd'
import { LoginStateEnum, useFormRules, useLoginState } from './useLogin' import { LoginStateEnum, useFormRules, useLoginState } from './useLogin'
const { handleBackLogin, getLoginState } = useLoginState() const { handleBackLogin, getLoginState } = useLoginState()

View File

@ -22,41 +22,31 @@
<van-cell :border="false" title="个人信息" is-link to="/editUserInfo"> <van-cell :border="false" title="个人信息" is-link to="/editUserInfo">
<template #icon> <template #icon>
<Icon> <i class="i-mingcute:idcard-fill mr-2 text-xl" />
<IdcardFilled />
</Icon>
</template> </template>
</van-cell> </van-cell>
<van-cell :border="false" title="账号与安全" is-link to="/accountSetting"> <van-cell :border="false" title="账号与安全" is-link to="/accountSetting">
<template #icon> <template #icon>
<Icon> <i class="i-material-symbols:account-box mr-2 text-xl" />
<Person />
</Icon>
</template> </template>
</van-cell> </van-cell>
<van-cell :border="false" title="主题设置" is-link to="/themeSetting"> <van-cell :border="false" title="主题设置" is-link to="/themeSetting">
<template #icon> <template #icon>
<Icon> <i class="i-material-symbols:palette mr-2 text-xl" />
<ColorPalette />
</Icon>
</template> </template>
</van-cell> </van-cell>
<van-cell :border="false" title="隐私政策" is-link> <van-cell :border="false" title="隐私政策" is-link>
<template #icon> <template #icon>
<Icon> <i class="i-material-symbols:list-alt-rounded mr-2 text-xl" />
<DocumentText />
</Icon>
</template> </template>
</van-cell> </van-cell>
<van-cell :border="false" title="退出登录" is-link @click="showLogoutAction = true"> <van-cell :border="false" title="退出登录" is-link @click="showLogoutAction = true">
<template #icon> <template #icon>
<Icon> <i class="i-solar:logout-3-bold mr-2 text-xl" />
<LogOut />
</Icon>
</template> </template>
</van-cell> </van-cell>
@ -74,9 +64,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { Icon } from '@vicons/utils'
import { IdcardFilled } from '@vicons/antd'
import { ColorPalette, DocumentText, LogOut, Person } from '@vicons/ionicons5'
import { showToast } from 'vant' import { showToast } from 'vant'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
@ -102,7 +89,7 @@ const getUserCoverBg = computed(() => {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.my-bg { .my-bg {
clip-path: inset(0 -55% 0 -55% round 0 0 100% 100%); clip-path: inset(0 -55% 0 -55% round 0 0 100% 100%);
background-size: cover; background-size: cover;
@ -125,9 +112,5 @@ const getUserCoverBg = computed(() => {
&:active { &:active {
background-color: var(--van-cell-active-color); background-color: var(--van-cell-active-color);
} }
.xicon {
margin-right: 10px;
}
} }
</style> </style>

View File

@ -26,7 +26,7 @@ export default defineConfig({
// 图标预设: https://unocss.dev/presets/icons // 图标预设: https://unocss.dev/presets/icons
presetIcons({ presetIcons({
cdn: 'https://esm.sh/', // cdn: 'https://esm.sh/',
extraProperties: { extraProperties: {
'display': 'inline-block', 'display': 'inline-block',
'vertical-align': 'middle', 'vertical-align': 'middle',
@ -68,4 +68,15 @@ export default defineConfig({
'text-overflow': 'overflow-hidden whitespace-nowrap text-ellipsis', // 文本溢出显示省略号 'text-overflow': 'overflow-hidden whitespace-nowrap text-ellipsis', // 文本溢出显示省略号
'text-break': 'whitespace-normal break-all break-words', // 文本溢出换行 'text-break': 'whitespace-normal break-all break-words', // 文本溢出换行
}, },
// 由于 UnoCSS 在构建时工作,这意味着只会生成静态呈现的 icon 并将其发送到你的组件中
// 通过模板字符串 :class="menu.meta?.icon" 来动态生成 CSS 类名。
// 这个类名是在运行时计算的UnoCSS 在构建时无法知道 menu.meta?.icon 的具体值,
// 因此无法生成对应的 CSS。为了解决这个问题你可以使用 UnoCSS 的 safelist 选项来指定一些始终需要生成的 CSS 类。
// https://unocss.dev/guide/advanced#safelist
safelist: [
'i-simple-icons:atlassian',
'i-simple-icons:soundcharts',
'i-simple-icons:docsify',
],
}) })