refactor(tabbar): 将图标类型从'local'重命名为'image'并添加警告

修改图标类型命名以更准确描述其用途
在image模式下未配置iconActive时添加控制台警告
This commit is contained in:
feige996
2025-08-07 20:33:38 +08:00
parent 66bd18c336
commit ccfab5eea4
2 changed files with 9 additions and 5 deletions

View File

@@ -44,7 +44,11 @@ function getColorByIndex(index: number) {
return tabbarStore.curIdx === index ? activeColor : inactiveColor
}
function getImageByIndex(index: number, item: { iconActive: string, icon: string }) {
function getImageByIndex(index: number, item: { iconActive?: string, icon: string }) {
if (!item.iconActive) {
console.warn('image 模式下,需要配置 iconActive否则无法切换图片')
return item.icon
}
return tabbarStore.curIdx === index ? item.iconActive : item.icon
}
</script>
@@ -72,7 +76,7 @@ function getImageByIndex(index: number, item: { iconActive: string, icon: string
<template v-if="item.iconType === 'unocss' || item.iconType === 'iconfont'">
<view :class="item.icon" class="text-20px" />
</template>
<template v-if="item.iconType === 'local'">
<template v-if="item.iconType === 'image'">
<image :src="getImageByIndex(index, item)" mode="scaleToFill" class="h-20px w-20px" />
</template>
<view class="mt-2px text-12px">