feat: 全局更改tabbar、首页、分享页UI重构

This commit is contained in:
2026-06-01 15:50:19 +08:00
parent aa0a289f27
commit c2388e1396
22 changed files with 852 additions and 461 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
<template>
<view class="cardTitle p-x-20 cardBg" :style="{ height: statusBarHeight + 44 + 'px' }">
<view class="cardTitle p-x-20 cardBg" :style="[{ height: statusBarHeight + 44 + 'px' }, { backgroundColor: props.bg }]">
<view :style="{ height: statusBarHeight + 'px' }"></view>
<view class="flex-center ju-between h_88">
<view class="cardLeft" v-if="props.showLeftButton">
@@ -91,7 +91,7 @@
}
.cardBg {
// 背景图片顶部显示, 超出部分隐藏, 宽等于100%
background-color: #ffffff;
background-color: transparent;
}
:deep(.uniui-left) {
font-size: 44rpx !important;
+228 -38
View File
@@ -1,47 +1,237 @@
<template>
<view class="card_tabber">
</view>
<view class="tabbar-wrap">
<view class="tabbar safe-bottom">
<image class="tabbar-bg" :src="bgSrc" mode="scaleToFill" />
<view class="tabbar-inner">
<view
v-for="(item, i) in items"
:key="item.pagePath"
class="tabbar-item flex1 flex-center flex-column"
:class="{ 'tabbar-item--mid': item.isMid }"
@click="onTap(item)"
>
<view :class="{ iconBox: item.isMid }">
<image
class="icon"
:class="{ iconMid: item.isMid, border_f: item.isMid }"
:src="getIconSrc(item)"
mode="aspectFit"
/>
</view>
<view v-if="item.text" class="s_20 text" :class="{ textActive: isActive(item) }">
{{ item.text }}
</view>
</view>
</view>
</view>
<view v-if="props.placeholder" class="tabbar-placeholder safe-bottom"></view>
</view>
</template>
<script setup>
import {ref} from 'vue'
import { computed, ref, watch } from 'vue';
import { onShow } from '@dcloudio/uni-app';
const tabber = ref({
items: [
{
text: '首页',
url: '/pages/index/index',
iconUrl: proxy.$url+'index/1.svg',
activeIconUrl: proxy.$url+'index/1_1.svg',
const props = defineProps({
path: {
type: String,
default: '',
},
placeholder: {
type: Boolean,
default: false,
},
});
const currentPath = ref('');
const normalizePath = (p) => {
if (!p) return '';
return p.startsWith('/') ? p : `/${p}`;
};
const updateCurrentPath = () => {
const pages = getCurrentPages?.() || [];
const current = pages[pages.length - 1];
const route = current?.route || '';
currentPath.value = normalizePath(route);
};
const hideNativeTabBar = () => {
try {
uni.hideTabBar({
fail: () => {},
});
} catch (e) {}
};
onShow(() => {
hideNativeTabBar();
updateCurrentPath();
});
watch(
() => props.path,
(val) => {
if (val) currentPath.value = normalizePath(val);
},
{ immediate: true },
);
const items = computed(() => [
{
pagePath: '/pages/index/index',
text: '首页',
iconPath: '/static/index/1.png',
selectedIconPath: '/static/index/1_1.png',
},
{
pagePath: '/pages/index/aiStore',
text: 'AI店铺',
iconPath: '/static/index/2.png',
selectedIconPath: '/static/index/2_1.png',
},
{
pagePath: '/pages/home/seed',
text: '',
iconPath: '/static/index/jinzhongzi.png',
selectedIconPath: '/static/index/jinzhongzi.png',
isMid: true,
},
{
pagePath: '/pages/cart/cart',
text: '购物车',
iconPath: '/static/index/3.png',
selectedIconPath: '/static/index/3_1.png',
},
{
pagePath: '/pages/index/user',
text: '我的',
iconPath: '/static/index/4.png',
selectedIconPath: '/static/index/4_1.png',
},
]);
const isActive = (item) => {
return normalizePath(item.pagePath) === normalizePath(currentPath.value);
};
const getIconSrc = (item) => {
return isActive(item) ? item.selectedIconPath : item.iconPath;
};
const onTap = (item) => {
if (item.isMid) {
hideNativeTabBar();
uni.navigateTo({ url: item.pagePath });
return;
}
if (isActive(item)) return;
hideNativeTabBar();
uni.switchTab({
url: item.pagePath,
fail: () => {
uni.reLaunch({ url: item.pagePath });
},
{
text: '分类',
url: '/pages/index/category',
iconUrl: proxy.$url+'index/2.svg',
activeIconUrl: proxy.$url+'index/2_1.svg',
},
{
text: '',
url: '/pages/home/seed',
iconUrl: proxy.$url+'index/6.svg',
activeIconUrl: proxy.$url+'index/6.svg',
},
{
text: '购物车',
url: '/pages/cart/cart',
iconUrl: proxy.$url+'index/3.svg',
activeIconUrl: proxy.$url+'index/3_1.svg',
},
{
text: '我的',
url: '/pages/index/user',
iconUrl: proxy.$url+'index/4.svg',
activeIconUrl: proxy.$url+'index/4_1.svg',
},
],
})
});
};
const bgSrc = computed(() => {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 750 150" preserveAspectRatio="none">
<path fill="#ffffff" d="M40 0 H295 Q316 0 316 21 A59 109 0 0 0 434 21 Q434 0 455 0 H710 Q750 0 750 40 V150 H0 V40 Q0 0 40 0 Z"/>
</svg>
`;
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
});
</script>
<style>
<style lang="scss">
.tabbar-wrap {
width: 100%;
}
</style>
.tabbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 80;
// background: var(--tabbar-bg, #ffffff);
overflow: visible;
}
.tabbar-bg {
position: absolute;
left: 0;
right: 0;
bottom: env(safe-area-inset-bottom);
width: 100%;
height: 100rpx;
filter: drop-shadow(0 -6rpx 24rpx rgba(0, 0, 0, 0.12));
pointer-events: none;
}
.tabbar-inner {
height: 100rpx;
display: flex;
align-items: flex-end;
padding: 0 12rpx;
position: relative;
z-index: 1;
}
.tabbar-item {
min-width: 0;
padding-bottom: 10rpx;
}
.tabbar-item--mid {
padding-bottom: 0;
transform: translateY(-25rpx);
}
.icon {
width: 44rpx;
height: 44rpx;
}
.iconBox {
height: 150rpx;
display: flex;
align-items: flex-end;
justify-content: center;
}
.iconMid {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
border-radius: 50%;
box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.12);
background: transparent;
}
.border_f {
// border: 6rpx solid #fff;
}
.text {
margin-top: 6rpx;
font-size: 22rpx;
line-height: 1;
color: var(--tabbar-text, #979797);
}
.textActive {
color: var(--color32, #fa7e31);
}
.safe-bottom {
padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-placeholder {
height: 100rpx;
}
</style>
+5 -8
View File
@@ -11,7 +11,7 @@
@click="navChange(i)"
>
<view class="navText"> {{ v.name }} </view>
<image src="/static/index/active.png" mode="scaleToFill" />
<!-- <image src="/static/index/active.png" mode="scaleToFill" /> -->
</view>
</view>
</scroll-view>
@@ -60,16 +60,11 @@
white-space: nowrap;
}
.navs {
// padding: 0 32rpx;
box-sizing: border-box;
height: 120rpx;
// padding-bottom: 10rpx;
.navItem {
color: #777777;
font-size: 32rpx;
// width: 20%;
// text-align: center;
// margin-right: 40rpx;
font-size: 28rpx;
white-space: nowrap;
flex-shrink: 0; // 防止被压缩
image {
@@ -81,8 +76,10 @@
}
.tabIndex {
color: #777777;
font-size: 36rpx;
font-weight: 500;
background: linear-gradient(135deg, #2C8CFA 0%, #3D5EFB 100%);
color: #ffffff !important;
border-radius: 12rpx;
image {
opacity: 1;
}