feat: 优化啤酒币轮播效果 1.调整轮播切换时间为300ms 2.优化轮播指示点样式和位置

This commit is contained in:
davy 2025-04-08 12:17:00 +08:00
parent efbe517a92
commit 91888ec292

View File

@ -3,7 +3,10 @@
<!-- 顶部币种展示 -->
<view class="coin-section">
<view class="coin-box left-box">
<view class="title">通用啤酒币</view>
<view class="brand-header">
<image class="brand-logo" src="/static/logo.png" mode="aspectFill"></image>
<text class="title">通用啤酒币</text>
</view>
<view class="amount-row">
<text class="amount">{{commonCoin}}</text>
<text class="cuIcon-rechargefill coin-icon"></text>
@ -13,20 +16,30 @@
<swiper class="coin-box right-box"
:current="currentBrandIndex"
@change="onSwiperChange"
:duration="500"
:duration="300"
circular
>
<swiper-item v-for="(item, index) in sortedBrandCoins" :key="index">
<view class="brand-content">
<view class="brand-header">
<image class="brand-logo" :src="item.logo" mode="aspectFill"></image>
<text class="title">{{item.name}}</text>
<image class="brand-logo" :src="item.brandLogo || '/static/logo.png'" mode="aspectFill"></image>
<text class="title">{{item.brandName}}</text>
</view>
<view class="amount-row">
<text class="amount">{{item.balance}}</text>
<text class="cuIcon-rechargefill coin-icon"></text>
</view>
<view class="desc">{{item.exchangeCount}}款热门商品可兑换</view>
<view class="desc">{{item.goodsNum}}款热门商品可兑换</view>
</view>
</swiper-item>
<!-- 添加空数据状态提示 -->
<swiper-item v-if="sortedBrandCoins.length === 0">
<view class="brand-content empty-content">
<view class="empty-icon">
<text class="cuIcon-info"></text>
</view>
<view class="empty-text">暂未获得任何品牌啤酒币</view>
<view class="empty-desc">扫描酒款即可获得品牌啤酒币</view>
</view>
</swiper-item>
</swiper>
@ -97,31 +110,51 @@
.coin-box {
background: #FFFFFF;
border-radius: 16rpx;
padding: 24rpx;
padding: 12rpx;
box-sizing: border-box;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04); //
border: 1rpx solid rgba(242, 242, 242, 0.8); //
/* 币种标题样式 */
.title {
font-size: 28rpx;
color: #333333;
font-weight: 600;
line-height: 20rpx;
margin-bottom: 16rpx;
/* 品牌标题区域 */
.brand-header {
display: flex;
align-items: flex-start;
padding: 8rpx;
/* 品牌logo样式 */
.brand-logo {
width: 72rpx;
height: 72rpx;
border-radius: 12rpx;
margin-right: 12rpx;
}
/* 品牌名称样式 */
.title {
font-size: 28rpx;
color: #333333;
font-weight: 600;
text-align: right;
flex: 1;
padding-top: 8rpx;
}
}
/* 币种数量行样式 */
.amount-row {
margin-bottom: 26rpx;
display: flex;
align-items: center;
justify-content: flex-end;
padding-right: 12rpx;
margin-bottom: 8rpx;
margin-top: -24rpx;
/* 数量文字样式 */
.amount {
font-size: 48rpx;
color: #1A1A1A;
font-weight: 600;
line-height: 48rpx;
}
/* 币种图标样式 */
@ -129,49 +162,36 @@
color: #FFD700;
font-size: 30rpx;
margin-left: 10rpx;
line-height: 48rpx;
}
}
/* 底部描述文字样式 */
.desc {
font-size: 20rpx;
font-weight: normal;
line-height: 130%;
color: #606060;
text-align: right;
line-height: 28rpx;
padding-right: 20rpx;
}
}
/* 左侧通用啤酒币卡片样式 */
.left-box {
width: 298rpx;
height: 180rpx;
background: #FFFFFF;
height: 198rpx;
}
/* 右侧品牌啤酒币轮播卡片样式 */
.right-box {
width: 382rpx;
height: 180rpx;
background: #FFFFFF;
height: 198rpx;
/* 品牌内容容器 */
.brand-content {
height: 100%;
/* 品牌标题区域 */
.brand-header {
display: flex;
align-items: center;
margin-bottom: 16rpx;
/* 品牌logo样式 */
.brand-logo {
width: 36rpx;
height: 36rpx;
border-radius: 8rpx;
margin-right: 12rpx;
}
}
padding-right: 24rpx;
box-sizing: border-box;
}
}
}
@ -362,51 +382,37 @@ export default {
total: 0,
commonCoin: 0,
currentBrandIndex: 0,
sortedBrandCoins: [
{
id: 1,
name: '青岛啤酒',
logo: '/static/images/brand1.png',
balance: 120,
exchangeCount: 5
},
{
id: 2,
name: '百威啤酒',
logo: '/static/images/brand2.png',
balance: 80,
exchangeCount: 3
},
{
id: 3,
name: '雪花啤酒',
logo: '/static/images/brand3.png',
balance: 50,
exchangeCount: 2
}
],
sortedBrandCoins: [],
isTabFixed: false,
statusBarHeight: 0,
tabOffsetTop: 160, //
isLoadAll: false, //
tabOffsetTop: 160,
isLoadAll: false
}
},
onLoad() {
//
const systemInfo = uni.getSystemInfoSync()
this.statusBarHeight = systemInfo.statusBarHeight
try {
const systemInfo = uni.getSystemInfoSync()
this.statusBarHeight = systemInfo.statusBarHeight || 0
} catch (e) {
console.error('获取系统信息失败', e)
}
this.getGoodsListFun()
//
this.initData()
},
onShow() {
//
this.getStoreCoinBalanceFun()
},
//
onPageScroll(e) {
this.isTabFixed = e.scrollTop >= this.tabOffsetTop
if (e && typeof e.scrollTop === 'number') {
this.isTabFixed = e.scrollTop >= this.tabOffsetTop
}
},
//
@ -415,6 +421,22 @@ export default {
},
methods: {
//
async initData() {
try {
//
await this.getStoreCoinBalanceFun()
//
await this.getGoodsListFun()
} catch (error) {
console.error('初始化数据失败', error)
uni.showToast({
title: '加载失败',
icon: 'none'
})
}
},
//
async changeTag(tag) {
if (this.curTag === tag) return
@ -432,11 +454,12 @@ export default {
// UI
this.curTag = tag
this.queryForm = params
this.total = res.total
this.total = res.total || 0
this.goodsList = res.rows || []
this.isLoadAll = this.goodsList.length >= this.total //
this.isLoadAll = this.goodsList.length >= this.total
} catch (error) {
console.error('切换标签失败', error)
uni.showToast({
title: '加载失败',
icon: 'none'
@ -446,7 +469,9 @@ export default {
//
onSwiperChange(e) {
this.currentBrandIndex = e.detail.current
if (e && e.detail && typeof e.detail.current === 'number') {
this.currentBrandIndex = e.detail.current
}
},
//
@ -457,21 +482,20 @@ export default {
try {
const res = await getGoodsList(this.queryForm)
this.total = res.total
this.total = res.total || 0
//
if (this.queryForm.pageNum > 1) {
this.goodsList.push(...(res.rows || []))
this.goodsList = [...this.goodsList, ...(res.rows || [])]
} else {
this.goodsList = res.rows || []
this.isLoadAll = false //
this.isLoadAll = false
}
//
if (this.goodsList.length >= this.total) {
this.isLoadAll = true
}
this.isLoadAll = this.goodsList.length >= this.total
} catch (error) {
console.error('获取商品列表失败', error)
uni.showToast({
title: '加载失败',
icon: 'none'
@ -482,65 +506,72 @@ export default {
},
//
getStoreCoinBalanceFun() {
const token = uni.getStorageSync('token')
const userInfo = uni.getStorageSync('userInfo')
if (!token || !userInfo || userInfo.isVerified !== 1) {
this.sortedBrandCoins = []
this.commonCoin = 0
return
}
getStoreCoinBalance().then(res => {
async getStoreCoinBalanceFun() {
try {
const token = uni.getStorageSync('token');
const userInfo = uni.getStorageSync('userInfo');
if (!token || !userInfo) {
this.sortedBrandCoins = [];
this.commonCoin = 0;
return;
}
const res = await getStoreCoinBalance();
if (res.data?.length > 0) {
//
const commonCoin = res.data.find(it => it.breweryId == 0)
this.commonCoin = commonCoin?.balance || 0
const commonCoin = res.data.find(it => it.breweryId == 0);
this.commonCoin = commonCoin?.balance || 0;
//
// TODO:
const brandCoins = res.data.filter(it => it.breweryId != 0)
const brandCoins = res.data.filter(it => it.breweryId != 0);
if (brandCoins.length > 0) {
// 使使
this.sortedBrandCoins = this.sortedBrandCoins.map((brand, index) => {
const realData = brandCoins[index]
return {
...brand,
balance: realData?.balance || brand.balance
}
}).sort((a, b) => b.balance - a.balance)
this.sortedBrandCoins = brandCoins.map(item => ({
id: item.id,
breweryId: item.breweryId,
brandName: item.brandName,
brandLogo: item.brandLogo,
balance: item.balance || 0,
goodsNum: item.goodsNum || 0,
barName: item.barName,
barCode: item.barCode,
barCity: item.barCity
})).sort((a, b) => b.balance - a.balance);
} else {
this.sortedBrandCoins = [];
}
} else {
this.sortedBrandCoins = []
this.commonCoin = 0
this.sortedBrandCoins = [];
this.commonCoin = 0;
}
}).catch(() => {
this.sortedBrandCoins = []
this.commonCoin = 0
})
} catch (error) {
console.error('获取啤酒币余额失败', error);
this.sortedBrandCoins = [];
this.commonCoin = 0;
}
},
//
toDetail(item) {
if (!item || !item.id) return
uni.navigateTo({
url: `/pagesCoin/goodsDetail?id=${item.id}&breweryId=${item.breweryId}`
url: `/pagesCoin/goodsDetail?id=${item.id}&breweryId=${item.breweryId || 0}`
})
},
//
async loadMore() {
//
if (this.loading || this.isLoadAll || this.goodsList.length === 0) return
//
if (this.goodsList.length < this.total) {
this.queryForm.pageNum++
await this.getGoodsListFun()
} else {
this.isLoadAll = true
}
},
}
}
}
</script>