feat(tabbar): 为标签栏项目添加字体图标支持
将图标组件替换为字体图标,以提供更灵活的图标定制能力。更新了标签栏配置、工具函数和组件逻辑,使其支持从配置中读取字体图标类名,并回退到默认图标。同时移除了对 @nutui/icons-vue-taro 的硬编码依赖。
Showing
3 changed files
with
31 additions
and
20 deletions
| ... | @@ -13,11 +13,10 @@ | ... | @@ -13,11 +13,10 @@ |
| 13 | > | 13 | > |
| 14 | <view class="app-tabbar__item-inner"> | 14 | <view class="app-tabbar__item-inner"> |
| 15 | <view class="app-tabbar__icon"> | 15 | <view class="app-tabbar__icon"> |
| 16 | - <component | 16 | + <i |
| 17 | - :is="item.icon" | 17 | + class="app-tabbar__icon-font" |
| 18 | - size="18" | 18 | + :class="getIconClass(item)" |
| 19 | - :color="isActive(item.key) ? activeColor : inactiveColor" | 19 | + ></i> |
| 20 | - /> | ||
| 21 | </view> | 20 | </view> |
| 22 | <text class="app-tabbar__label">{{ item.title }}</text> | 21 | <text class="app-tabbar__label">{{ item.title }}</text> |
| 23 | </view> | 22 | </view> |
| ... | @@ -30,7 +29,6 @@ | ... | @@ -30,7 +29,6 @@ |
| 30 | <script setup> | 29 | <script setup> |
| 31 | import { computed, onMounted } from 'vue' | 30 | import { computed, onMounted } from 'vue' |
| 32 | import Taro from '@tarojs/taro' | 31 | import Taro from '@tarojs/taro' |
| 33 | -import { Category, Home, My, Notice, Service } from '@nutui/icons-vue-taro' | ||
| 34 | import { useTabbarStore } from '@/stores/tabbar' | 32 | import { useTabbarStore } from '@/stores/tabbar' |
| 35 | 33 | ||
| 36 | const props = defineProps({ | 34 | const props = defineProps({ |
| ... | @@ -42,25 +40,19 @@ const props = defineProps({ | ... | @@ -42,25 +40,19 @@ const props = defineProps({ |
| 42 | 40 | ||
| 43 | const activeColor = '#a67939' | 41 | const activeColor = '#a67939' |
| 44 | const inactiveColor = '#8b95a7' | 42 | const inactiveColor = '#8b95a7' |
| 43 | +const defaultIcon = 'fa-circle-o' | ||
| 45 | 44 | ||
| 46 | const tabbarStore = useTabbarStore() | 45 | const tabbarStore = useTabbarStore() |
| 47 | - | 46 | +const tabItems = computed(() => tabbarStore.visibleTabItems) |
| 48 | -const tabIconMap = { | ||
| 49 | - home: Home, | ||
| 50 | - message: Notice, | ||
| 51 | - application: Category, | ||
| 52 | - mine: My, | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -const tabItems = computed(() => ( | ||
| 56 | - tabbarStore.visibleTabItems.map((item) => ({ | ||
| 57 | - ...item, | ||
| 58 | - icon: tabIconMap[item.key] || Service, | ||
| 59 | - })) | ||
| 60 | -)) | ||
| 61 | 47 | ||
| 62 | const isActive = (name) => name === props.current | 48 | const isActive = (name) => name === props.current |
| 63 | 49 | ||
| 50 | +const getIconClass = (item) => { | ||
| 51 | + const icon = String(item?.class || item?.icon || defaultIcon).trim() || defaultIcon | ||
| 52 | + const fontClass = icon.startsWith('fa-') ? 'fa' : 'iconfont' | ||
| 53 | + return [fontClass, icon] | ||
| 54 | +} | ||
| 55 | + | ||
| 64 | const handleTabClick = (item) => { | 56 | const handleTabClick = (item) => { |
| 65 | if (!item?.page_url || item.key === props.current) { | 57 | if (!item?.page_url || item.key === props.current) { |
| 66 | return | 58 | return |
| ... | @@ -123,6 +115,12 @@ onMounted(() => { | ... | @@ -123,6 +115,12 @@ onMounted(() => { |
| 123 | align-items: center; | 115 | align-items: center; |
| 124 | justify-content: center; | 116 | justify-content: center; |
| 125 | line-height: 1; | 117 | line-height: 1; |
| 118 | + color: #8b95a7; | ||
| 119 | + font-size: 38rpx; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + .app-tabbar__icon-font { | ||
| 123 | + line-height: 1; | ||
| 126 | } | 124 | } |
| 127 | 125 | ||
| 128 | .app-tabbar__label { | 126 | .app-tabbar__label { |
| ... | @@ -134,5 +132,9 @@ onMounted(() => { | ... | @@ -134,5 +132,9 @@ onMounted(() => { |
| 134 | .app-tabbar__item.is-active .app-tabbar__item-inner { | 132 | .app-tabbar__item.is-active .app-tabbar__item-inner { |
| 135 | color: #a67939; | 133 | color: #a67939; |
| 136 | } | 134 | } |
| 135 | + | ||
| 136 | + .app-tabbar__item.is-active .app-tabbar__icon { | ||
| 137 | + color: #a67939; | ||
| 138 | + } | ||
| 137 | } | 139 | } |
| 138 | </style> | 140 | </style> | ... | ... |
| ... | @@ -3,11 +3,13 @@ export const getTabbarConfigFixture = () => ({ | ... | @@ -3,11 +3,13 @@ export const getTabbarConfigFixture = () => ({ |
| 3 | { | 3 | { |
| 4 | key: 'home', | 4 | key: 'home', |
| 5 | title: '首页', | 5 | title: '首页', |
| 6 | + class: 'fa-home', | ||
| 6 | visible: true, | 7 | visible: true, |
| 7 | }, | 8 | }, |
| 8 | { | 9 | { |
| 9 | key: 'message', | 10 | key: 'message', |
| 10 | title: '资讯', | 11 | title: '资讯', |
| 12 | + class: 'fa-newspaper-o', | ||
| 11 | visible: true, | 13 | visible: true, |
| 12 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=news_list', | 14 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=news_list', |
| 13 | webview_title: '资讯', | 15 | webview_title: '资讯', |
| ... | @@ -15,6 +17,7 @@ export const getTabbarConfigFixture = () => ({ | ... | @@ -15,6 +17,7 @@ export const getTabbarConfigFixture = () => ({ |
| 15 | { | 17 | { |
| 16 | key: 'application', | 18 | key: 'application', |
| 17 | title: '应用', | 19 | title: '应用', |
| 20 | + class: 'fa-th-large', | ||
| 18 | visible: true, | 21 | visible: true, |
| 19 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', | 22 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', |
| 20 | webview_title: '应用', | 23 | webview_title: '应用', |
| ... | @@ -22,6 +25,7 @@ export const getTabbarConfigFixture = () => ({ | ... | @@ -22,6 +25,7 @@ export const getTabbarConfigFixture = () => ({ |
| 22 | { | 25 | { |
| 23 | key: 'mine', | 26 | key: 'mine', |
| 24 | title: '我的', | 27 | title: '我的', |
| 28 | + class: 'fa-user', | ||
| 25 | visible: true, | 29 | visible: true, |
| 26 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', | 30 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', |
| 27 | webview_title: '我的', | 31 | webview_title: '我的', | ... | ... |
| ... | @@ -2,6 +2,7 @@ const defaultTabbarItemMap = { | ... | @@ -2,6 +2,7 @@ const defaultTabbarItemMap = { |
| 2 | home: { | 2 | home: { |
| 3 | key: 'home', | 3 | key: 'home', |
| 4 | title: '首页', | 4 | title: '首页', |
| 5 | + class: 'fa-home', | ||
| 5 | visible: true, | 6 | visible: true, |
| 6 | page_url: '/pages/index/index', | 7 | page_url: '/pages/index/index', |
| 7 | webview_url: '', | 8 | webview_url: '', |
| ... | @@ -10,6 +11,7 @@ const defaultTabbarItemMap = { | ... | @@ -10,6 +11,7 @@ const defaultTabbarItemMap = { |
| 10 | message: { | 11 | message: { |
| 11 | key: 'message', | 12 | key: 'message', |
| 12 | title: '资讯', | 13 | title: '资讯', |
| 14 | + class: 'fa-newspaper-o', | ||
| 13 | visible: true, | 15 | visible: true, |
| 14 | page_url: '/pages/message/index', | 16 | page_url: '/pages/message/index', |
| 15 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=news_list', | 17 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=news_list', |
| ... | @@ -18,6 +20,7 @@ const defaultTabbarItemMap = { | ... | @@ -18,6 +20,7 @@ const defaultTabbarItemMap = { |
| 18 | application: { | 20 | application: { |
| 19 | key: 'application', | 21 | key: 'application', |
| 20 | title: '应用', | 22 | title: '应用', |
| 23 | + class: 'fa-th-large', | ||
| 21 | visible: true, | 24 | visible: true, |
| 22 | page_url: '/pages/application/index', | 25 | page_url: '/pages/application/index', |
| 23 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', | 26 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', |
| ... | @@ -26,6 +29,7 @@ const defaultTabbarItemMap = { | ... | @@ -26,6 +29,7 @@ const defaultTabbarItemMap = { |
| 26 | mine: { | 29 | mine: { |
| 27 | key: 'mine', | 30 | key: 'mine', |
| 28 | title: '我的', | 31 | title: '我的', |
| 32 | + class: 'fa-user', | ||
| 29 | visible: true, | 33 | visible: true, |
| 30 | page_url: '/pages/mine/index', | 34 | page_url: '/pages/mine/index', |
| 31 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', | 35 | webview_url: 'https://oa-dev.onwall.cn/f/futian_home/?f=f&p=futian_list', |
| ... | @@ -83,6 +87,7 @@ export const normalizeTabbarItem = (rawItem = {}) => { | ... | @@ -83,6 +87,7 @@ export const normalizeTabbarItem = (rawItem = {}) => { |
| 83 | ...rawItem, | 87 | ...rawItem, |
| 84 | key: fallbackItem.key, | 88 | key: fallbackItem.key, |
| 85 | title: String(rawItem.title || fallbackItem.title), | 89 | title: String(rawItem.title || fallbackItem.title), |
| 90 | + class: String(rawItem.class || rawItem.icon_class || rawItem.icon || fallbackItem.class || ''), | ||
| 86 | page_url: String(rawItem.page_url || fallbackItem.page_url || ''), | 91 | page_url: String(rawItem.page_url || fallbackItem.page_url || ''), |
| 87 | webview_url: String(rawItem.webview_url || rawItem.link_url || rawItem.url || fallbackItem.webview_url || ''), | 92 | webview_url: String(rawItem.webview_url || rawItem.link_url || rawItem.url || fallbackItem.webview_url || ''), |
| 88 | webview_title: String(rawItem.webview_title || rawItem.link_title || rawItem.title || fallbackItem.webview_title || ''), | 93 | webview_title: String(rawItem.webview_title || rawItem.link_title || rawItem.title || fallbackItem.webview_title || ''), | ... | ... |
-
Please register or login to post a comment