332 lines
7.8 KiB
Vue
332 lines
7.8 KiB
Vue
<template>
|
||
<view class="container">
|
||
|
||
<!-- 优化2:轮播图 UI 升级,置于顶部 -->
|
||
<view class="hero-banner animate-fade-in-up">
|
||
<swiper
|
||
class="product-swiper"
|
||
circular
|
||
autoplay
|
||
interval="5000"
|
||
duration="800"
|
||
indicator-dots
|
||
indicator-color="rgba(255,255,255,0.4)"
|
||
indicator-active-color="#FFFFFF"
|
||
>
|
||
<swiper-item v-for="(item, index) in carousel" :key="index" class="swiper-item-box">
|
||
<view class="image-wrapper">
|
||
<image :src="item.url" mode="aspectFill" class="swiper-image" />
|
||
<view class="swiper-overlay"></view>
|
||
</view>
|
||
</swiper-item>
|
||
</swiper>
|
||
</view>
|
||
|
||
<!-- 优化1:Search Bar 移动到轮播图下方,且上滑时具备吸顶效果 -->
|
||
<view class="search-wrapper">
|
||
<view class="search-box">
|
||
<up-search
|
||
type="text"
|
||
placeholder="搜索心仪的产品型号"
|
||
placeholder-class="search-placeholder"
|
||
v-model="title"
|
||
:showAction="true"
|
||
:animation="true"
|
||
actionText="搜索"
|
||
:disabled="true"
|
||
bgColor="#FFFFFF"
|
||
searchIconColor="#B4854D"
|
||
@search="handleSearch"
|
||
@click="handleSearch"
|
||
/>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 优化3:分类区块 UI 重构 -->
|
||
<view class="category-wrapper">
|
||
<!-- 全新的标题排版:居中对齐,中英文堆叠 -->
|
||
<view class="section-header animate-fade-in-up" style="animation-delay: 0.1s;">
|
||
<text class="title-en">- CATEGORIES -</text>
|
||
<text class="title-cn">产品分类</text>
|
||
<text class="header-desc">探索您的理想生活方式</text>
|
||
</view>
|
||
|
||
<!-- 保持 3 列布局,优化卡片细节质感 -->
|
||
<view class="category-grid">
|
||
<view
|
||
v-for="(item, index) in categories"
|
||
:key="index"
|
||
class="category-card animate-fade-in-up"
|
||
:style="{ animationDelay: (index * 0.08 + 0.2) + 's' }"
|
||
@tap="navigateToList(item.id)"
|
||
>
|
||
<!-- 画框式图片容器 -->
|
||
<view class="category-image-box">
|
||
<image :src="item.url" mode="aspectFill" class="cat-img"></image>
|
||
<view class="cat-mask"></view>
|
||
</view>
|
||
<!-- 更精致的文字区域 -->
|
||
<view class="category-info">
|
||
<text class="category-name">{{ item.name }}</text>
|
||
<view class="category-indicator"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
// JS 逻辑完全保留
|
||
import {getCarouselApi, getCategoryListApi} from "@/api/page/home";
|
||
import {getCache} from "@/utils/cache";
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
categoriesList: [],
|
||
categories: [],
|
||
carousel: [],
|
||
title: ""
|
||
}
|
||
},
|
||
onShow() {
|
||
const userInfo = getCache('user_info')
|
||
if (userInfo) {
|
||
uni.setNavigationBarTitle({
|
||
title: userInfo?.enterprise.name || '家具优选'
|
||
})
|
||
}
|
||
},
|
||
onShareAppMessage() {
|
||
const userInfo = getCache('user_info')
|
||
return {
|
||
title: userInfo?.enterprise.name || '家具优选',
|
||
path: `pages/goods/index`,
|
||
imageUrl: 'http://qiniu.boerman.top/b_a2d78f027b3d26c0b0621655726c0c54.jpg'
|
||
};
|
||
},
|
||
mounted() {
|
||
this.getCarousel();
|
||
this.getCategoryList();
|
||
},
|
||
methods: {
|
||
navigateToList(pid) {
|
||
uni.navigateTo({
|
||
url: `/pages/product/product?pid=${pid}`
|
||
})
|
||
},
|
||
getCarousel() {
|
||
getCarouselApi().then((res) => {
|
||
this.carousel = res;
|
||
});
|
||
},
|
||
getCategoryList() {
|
||
getCategoryListApi().then((res) => {
|
||
this.categories = res;
|
||
});
|
||
},
|
||
handleSearch() {
|
||
uni.navigateTo({
|
||
url: `/pages/search/search?title=${this.title}`
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/* --- 动画系统 --- */
|
||
@keyframes fadeInUp {
|
||
from { opacity: 0; transform: translateY(40rpx); }
|
||
to { opacity: 1; transform: translateY(0); }
|
||
}
|
||
|
||
.animate-fade-in-up {
|
||
animation: fadeInUp 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
|
||
opacity: 0;
|
||
}
|
||
|
||
/* --- 全局容器 --- */
|
||
.container {
|
||
min-height: 100vh;
|
||
/* 偏苹果风的高级灰背景色 */
|
||
background-color: #F5F5F7;
|
||
padding-bottom: 60rpx;
|
||
}
|
||
|
||
/* --- 轮播图 --- */
|
||
.hero-banner {
|
||
position: relative;
|
||
height: 420rpx;
|
||
/* 顶部留白适配状态栏区域(可根据实际需求调整) */
|
||
padding: 20rpx 30rpx 0;
|
||
}
|
||
|
||
.product-swiper {
|
||
height: 100%;
|
||
border-radius: 24rpx;
|
||
overflow: hidden;
|
||
/* 硬件加速,防止在 iOS 上出现圆角渲染 bug */
|
||
transform: translateY(0);
|
||
box-shadow: 0 12rpx 30rpx rgba(0, 0, 0, 0.08);
|
||
}
|
||
|
||
.image-wrapper {
|
||
width: 100%;
|
||
height: 100%;
|
||
position: relative;
|
||
}
|
||
|
||
.swiper-image {
|
||
width: 100%;
|
||
height: 100%;
|
||
transition: transform 0.3s ease;
|
||
}
|
||
|
||
.swiper-overlay {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
/* 优化后的高级渐变遮罩,增强内敛感 */
|
||
background: linear-gradient(180deg, rgba(0,0,0,0.02) 0%, rgba(0,0,0,0) 40%, rgba(0,0,0,0.35) 100%);
|
||
}
|
||
|
||
/* --- 搜索栏 (毛玻璃悬浮) --- */
|
||
.search-wrapper {
|
||
/* 设定为 sticky 吸顶,随页面滚动到顶部时自动固定 */
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 100;
|
||
background: rgba(245, 245, 247, 0.85);
|
||
backdrop-filter: saturate(180%) blur(20px);
|
||
padding: 24rpx 30rpx 20rpx;
|
||
}
|
||
|
||
.search-box {
|
||
border-radius: 100rpx;
|
||
overflow: hidden;
|
||
/* 细微边框+阴影提升搜索框立体感 */
|
||
border: 1px solid rgba(255, 255, 255, 0.8);
|
||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
|
||
}
|
||
|
||
/* --- 分类模块 --- */
|
||
.category-wrapper {
|
||
padding: 30rpx 30rpx 50rpx;
|
||
}
|
||
|
||
/* --- 分类标题 (居中设计) --- */
|
||
.section-header {
|
||
margin-bottom: 40rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center; /* 居中对齐 */
|
||
justify-content: center;
|
||
text-align: center;
|
||
}
|
||
|
||
.title-en {
|
||
font-size: 20rpx;
|
||
color: #B4854D;
|
||
letter-spacing: 6rpx; /* 加宽字符间距 */
|
||
font-weight: 600;
|
||
margin-bottom: 12rpx;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.title-cn {
|
||
font-size: 40rpx;
|
||
color: #1D1D1F;
|
||
font-weight: 600;
|
||
letter-spacing: 4rpx;
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.header-desc {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: #86868B;
|
||
letter-spacing: 2rpx;
|
||
}
|
||
|
||
/* --- 3列布局分类卡片 --- */
|
||
.category-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 24rpx 20rpx;
|
||
}
|
||
|
||
.category-card {
|
||
background: #FFFFFF;
|
||
border-radius: 24rpx;
|
||
padding: 12rpx;
|
||
/* 优化细节:增加极细的高级感边框与柔和阴影 */
|
||
border: 1px solid rgba(200, 200, 205, 0.3);
|
||
box-shadow: 0 6rpx 20rpx rgba(149, 157, 165, 0.06);
|
||
transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
|
||
will-change: transform;
|
||
}
|
||
|
||
/* 点击/触摸时的弹性微交互 */
|
||
.category-card:active {
|
||
transform: scale(0.94);
|
||
box-shadow: 0 2rpx 8rpx rgba(149, 157, 165, 0.04);
|
||
border-color: rgba(180, 133, 77, 0.4); /* 点击时边框呼应主题色 */
|
||
}
|
||
|
||
.category-image-box {
|
||
height: 160rpx;
|
||
width: 100%;
|
||
position: relative;
|
||
border-radius: 16rpx;
|
||
overflow: hidden;
|
||
background-color: #F9F9F9;
|
||
}
|
||
|
||
.cat-img {
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
|
||
.cat-mask {
|
||
position: absolute;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.03);
|
||
mix-blend-mode: multiply;
|
||
}
|
||
|
||
.category-info {
|
||
padding: 16rpx 4rpx 8rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.category-name {
|
||
font-size: 26rpx;
|
||
color: #333333;
|
||
font-weight: 500;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
max-width: 100%;
|
||
}
|
||
|
||
/* 卡片文字下方的点缀,增加设计感 */
|
||
.category-indicator {
|
||
width: 24rpx;
|
||
height: 4rpx;
|
||
background-color: #E5E5EA;
|
||
border-radius: 4rpx;
|
||
margin-top: 10rpx;
|
||
transition: background-color 0.3s;
|
||
}
|
||
|
||
.category-card:active .category-indicator {
|
||
background-color: #B4854D;
|
||
}
|
||
</style> |