feat: 优化酒评页面评分交互效果

This commit is contained in:
davy 2025-04-07 10:20:42 +08:00
parent a069a9e7cc
commit 12a5c6771a

View File

@ -243,60 +243,76 @@
}, },
isFavor: false, // isFavor: false, //
sortType: 'latest', sortType: 'latest',
isLoggedIn: false,
isBarAuthenticated: false,
ratingAnimation: null,
isAnimating: false
}; };
}, },
onLoad({beerId}) { onLoad({beerId}) {
this.beerId = beerId this.beerId = beerId
this.queryForm.beerId = beerId this.queryForm.beerId = beerId
this.getBeerInfoFun() this.initPageData()
this.getReviewListFun()
this.getReviewScoreListFun()
//
const token = uni.getStorageSync('token')
if (token) {
this.getBeerFavorStatusFun()
this.getMyReviewInfoFun()
}
}, },
onShow() { onShow() {
console.log('show') this.checkLoginStatus()
this.reviewList = [] this.initPageData()
this.queryForm.pageNum = 1
this.getReviewListFun()
this.getReviewScoreListFun()
//
const token = uni.getStorageSync('token')
if (token) {
this.getBeerFavorStatusFun()
this.getMyReviewInfoFun()
}
//
uni.pageScrollTo({
scrollTop: 0,
duration: 0,
})
}, },
methods: { methods: {
toPageBottom() { //
uni.pageScrollTo({ checkLoginStatus() {
scrollTop: 9999,
})
},
//
getBeerFavorStatusFun() {
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
if (!token) { this.isLoggedIn = !!token
this.$refs.loginRef.open()
return if (this.isLoggedIn) {
const barInfo = uni.getStorageSync('barInfo')
this.isBarAuthenticated = barInfo && barInfo.authState === 2
} }
getBeerFavorStatus(this.beerId).then(res => { },
if(res.data) {
this.isFavor = true //
}else { async initPageData() {
this.isFavor = false //
} this.reviewList = []
this.queryForm.pageNum = 1
//
await Promise.all([
this.getBeerInfoFun(),
this.getReviewListFun(),
this.getReviewScoreListFun()
])
//
if (this.isLoggedIn) {
await Promise.all([
this.getBeerFavorStatusFun(),
this.getMyReviewInfoFun()
])
}
//
uni.pageScrollTo({
scrollTop: 0,
duration: 0
}) })
}, },
//
async getBeerFavorStatusFun() {
try {
if (!this.isLoggedIn) {
this.isFavor = false
return
}
const res = await getBeerFavorStatus(this.beerId)
this.isFavor = !!res.data
} catch (error) {
console.error('获取收藏状态失败:', error)
this.isFavor = false
}
},
// //
getBeerInfoFun() { getBeerInfoFun() {
getBeerInfo(this.beerId).then(res => { getBeerInfo(this.beerId).then(res => {
@ -340,18 +356,73 @@
}) })
}, },
// //
getMyReviewInfoFun() { async getMyReviewInfoFun() {
const token = uni.getStorageSync('token') try {
if (!token) { if (!this.isLoggedIn) {
this.$refs.loginRef.open() this.myReviewInfo = null
return return
} }
getMyReviewInfo(this.beerId).then(res => { const res = await getMyReviewInfo(this.beerId)
this.myReviewInfo = res.data this.myReviewInfo = res.data
}) } catch (error) {
console.error('获取我的酒评信息失败:', error)
this.myReviewInfo = null
}
}, },
// //
toWrite() { toWrite() {
if (!this.isLoggedIn) {
this.$refs.loginRef.open()
return
}
if (!this.isBarAuthenticated) {
const barInfo = uni.getStorageSync('barInfo')
if (!barInfo || barInfo.authState === 0) {
uni.showModal({
title: '提示',
content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
})
}
}
})
return
}
if (barInfo.authState === 1) {
uni.showToast({
title: '您的门店正在认证中,请耐心等待',
icon: 'none'
})
return
}
}
uni.navigateTo({
url: '/pages/index/writeReview?beerId=' + this.beerId
})
},
//
getScore(a, b, c) {
let score = 0
score = (a + b + c) / 3
return score.toFixed(0)
},
//
toBrand() {
if (!this.beerInfo.breweryId) return
uni.navigateTo({
url: '/pages/index/brandHome?breweryId=' + this.beerInfo.breweryId
})
},
//
async favorBeerFun(status) {
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
if (!token) { if (!token) {
this.$refs.loginRef.open() this.$refs.loginRef.open()
@ -399,97 +470,24 @@
return return
} }
uni.navigateTo({ try {
url: '/pages/index/writeReview?beerId=' + this.beerId await favorBeer({
}) beerId: this.beerId,
}, status
//
getScore(a, b, c) {
let score = 0
score = (a + b + c) / 3
return score.toFixed(0)
},
//
toBrand() {
if (!this.beerInfo.breweryId) return
uni.navigateTo({
url: '/pages/index/brandHome?breweryId=' + this.beerInfo.breweryId
})
},
//
favorBeerFun(status) {
const token = uni.getStorageSync('token')
if (!token) {
this.$refs.loginRef.open()
return
}
//
const barInfo = uni.getStorageSync('barInfo')
if (!barInfo || barInfo.authState === 0) {
uni.showModal({
title: '提示',
content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
})
}
}
}) })
return
}
if (barInfo.authState === 1) { this.isFavor = status === 1
uni.showToast({ uni.showToast({
title: '您的门店正在认证中,请耐心等待', title: status === 1 ? '收藏成功' : '取消收藏',
icon: status === 1 ? 'success' : 'none'
})
} catch (error) {
console.error('收藏操作失败:', error)
uni.showToast({
title: error.msg || '操作失败',
icon: 'none' icon: 'none'
}) })
return
} }
let data = {
beerId: this.beerId,
status
}
favorBeer(data).then(res => {
if (status == 1) {
this.isFavor = true
uni.showToast({
title: '收藏成功',
icon: 'success'
})
} else {
this.isFavor = false
uni.showToast({
title: '取消收藏',
icon: 'none'
})
}
}).catch(err => {
console.error('收藏操作失败:', err)
if (err.code === 500 && err.msg.includes('门店未认证')) {
uni.showModal({
title: '提示',
content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
})
}
}
})
} else {
uni.showToast({
title: err.msg || '操作失败',
icon: 'none'
})
}
})
}, },
// //
handleLike(item) { handleLike(item) {
@ -653,6 +651,45 @@
url: '/pages/index/allReviews?beerId=' + this.beerId url: '/pages/index/allReviews?beerId=' + this.beerId
}) })
}, },
//
handleRatingChange(newValue, type) {
if (this.isAnimating) return;
this.isAnimating = true;
//
const animation = uni.createAnimation({
duration: 300,
timingFunction: 'ease'
});
//
animation.scale(1.2).step();
animation.scale(1.0).step();
this.ratingAnimation = animation.export();
//
if (uni.vibrateShort) {
uni.vibrateShort();
}
// 300ms
setTimeout(() => {
this.isAnimating = false;
}, 300);
},
//
handleTabChange(tab) {
if (this.currentTab === tab) return;
//
if (uni.vibrateShort) {
uni.vibrateShort();
}
this.currentTab = tab;
}
} }
} }
</script> </script>
@ -1190,4 +1227,61 @@
} }
} }
} }
.rating-bars {
.rating-bar {
.bar {
.bar-filled {
transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
}
.bar-value {
transition: all 0.3s ease;
}
}
}
.rating-overview {
.rating-score-large {
transition: all 0.3s ease;
}
}
.rating-tabs {
.tab-item {
transition: all 0.3s ease;
&:active {
transform: scale(0.95);
}
}
}
.review-sort {
.sort-item {
transition: all 0.3s ease;
&:active {
transform: scale(0.95);
}
}
}
.write-review {
transition: all 0.3s ease;
&:active {
transform: scale(0.98);
opacity: 0.9;
}
}
.like-btn {
transition: all 0.3s ease;
&:active {
transform: scale(0.95);
}
}
</style> </style>