fix: 修复评分显示问题,统一使用后端数据,所有分数保留一位小数

This commit is contained in:
davy 2025-04-07 17:33:39 +08:00
parent 59eaa69e5c
commit 4096897a05
10 changed files with 143 additions and 104 deletions

View File

@ -60,7 +60,8 @@
password: '' password: ''
}, },
showPassword: false, showPassword: false,
isAgree: false isAgree: false,
needRefresh: false
}; };
}, },
methods: { methods: {
@ -156,7 +157,8 @@
if (res.user) { if (res.user) {
this.userInfo = res.user this.userInfo = res.user
uni.setStorageSync('userInfo', res.user) uni.setStorageSync('userInfo', res.user)
this.$emit('loginSuccess') this.needRefresh = true
this.$emit('loginSuccess', { needRefresh: this.needRefresh })
// barId // barId
if (!res.user.barId) { if (!res.user.barId) {

View File

@ -420,7 +420,7 @@
} }
}) })
return return
} else if (barInfo.authState === 1) { } else if (barInfo.authState === 2) {
uni.showToast({ uni.showToast({
title: '您的门店正在认证中,请耐心等待', title: '您的门店正在认证中,请耐心等待',
icon: 'none' icon: 'none'

View File

@ -39,7 +39,7 @@
</view> </view>
<view v-if="barInfo" class="scan-box"> <view v-if="barInfo" class="scan-box">
<view v-if="barInfo.authState == 0" class="exprieTime">未认证</view> <view v-if="barInfo.authState == 0" class="exprieTime">未认证</view>
<view v-else-if="barInfo.authState == 1" class="exprieTime">认证中</view> <view v-else-if="barInfo.authState == 2" class="exprieTime">认证中</view>
<view v-else class="exprieTime">{{ barInfo.authEndTime }}认证到期</view> <view v-else class="exprieTime">{{ barInfo.authEndTime }}认证到期</view>
<text>本月累计扫码酒款数量</text> <text>本月累计扫码酒款数量</text>
<view class="margin-top"> <view class="margin-top">
@ -147,7 +147,7 @@
if (!this.isLoggedIn) return 'guest'; if (!this.isLoggedIn) return 'guest';
if (!this.barInfo || this.barInfo.authState === 0) return 'unverified'; if (!this.barInfo || this.barInfo.authState === 0) return 'unverified';
if (this.barInfo.authState === 1) return 'verifying'; if (this.barInfo.authState === 2) return 'verifying';
return 'verified'; return 'verified';
}, },
maskedPhone() { maskedPhone() {
@ -186,7 +186,7 @@
if (res && res.data) { if (res && res.data) {
this.barInfo = res.data; this.barInfo = res.data;
// //
if (this.barInfo.authState === 1) { if (this.barInfo.authState === 2) {
this.myScanData = { scanCount: 0, percent: 0 }; this.myScanData = { scanCount: 0, percent: 0 };
} }
} }
@ -194,7 +194,7 @@
console.error('获取酒吧信息失败:', err); console.error('获取酒吧信息失败:', err);
if (err.code === 500 && err.msg.includes('门店未认证')) { if (err.code === 500 && err.msg.includes('门店未认证')) {
this.barInfo = { this.barInfo = {
authState: 1, authState: 2,
barName: '', barName: '',
barNumber: '', barNumber: '',
barContactPhone: '' barContactPhone: ''
@ -206,7 +206,7 @@
}); });
// //
if (this.barInfo && this.barInfo.authState !== 1) { if (this.barInfo && this.barInfo.authState !== 2) {
await getMyScanData().then(res => { await getMyScanData().then(res => {
if (res.code === 200) { if (res.code === 200) {
this.myScanData = res.data; this.myScanData = res.data;

View File

@ -205,7 +205,7 @@
userStatus() { userStatus() {
if (!this.isLoggedIn) return 'guest' // if (!this.isLoggedIn) return 'guest' //
if (!this.barInfo || this.barInfo.authState === 0) return 'unverified' // if (!this.barInfo || this.barInfo.authState === 0) return 'unverified' //
if (this.barInfo.authState === 1) return 'verifying' // if (this.barInfo.authState === 2) return 'verifying' //
return 'verified' // return 'verified' //
} }
}, },
@ -265,7 +265,7 @@
console.log('【getBarInfoFun】认证状态(authState):', res.data.authState) console.log('【getBarInfoFun】认证状态(authState):', res.data.authState)
this.barInfo = res.data this.barInfo = res.data
this.isVerified = res.data.authState === 2 // 2 this.isVerified = res.data.authState === 1 // 1
console.log('【getBarInfoFun】更新后的认证状态(isVerified):', this.isVerified) console.log('【getBarInfoFun】更新后的认证状态(isVerified):', this.isVerified)
uni.setStorageSync('barInfo', res.data) uni.setStorageSync('barInfo', res.data)

View File

@ -201,7 +201,7 @@ export default {
latitude: '', // latitude: '', //
longitude: '', // longitude: '', //
openId: '', // openId openId: '', // openId
auth_state: 0, // 0 auth_state: 2, // 2
}, },
// //
displayArea: '', displayArea: '',

View File

@ -13,7 +13,7 @@
</view> </view>
<text class="product-subtitle">{{beerInfo.beerStyles || '--'}}</text> <text class="product-subtitle">{{beerInfo.beerStyles || '--'}}</text>
<view class="rating"> <view class="rating">
<text class="rating-score">{{reviewScoreList.avgOverallRating || 0}}/5.0</text> <text class="rating-score">{{reviewScoreList.avgOverallRating ? Number(reviewScoreList.avgOverallRating).toFixed(1) : '0.0'}}/5.0</text>
<uni-rate :value="reviewScoreList.avgOverallRating || 0" :readonly="true" :touchable="false" size="18" /> <uni-rate :value="reviewScoreList.avgOverallRating || 0" :readonly="true" :touchable="false" size="18" />
</view> </view>
<view v-if="beerInfo.breweryId" class="brand" @click="toBrand"> <view v-if="beerInfo.breweryId" class="brand" @click="toBrand">
@ -52,7 +52,7 @@
<!-- 评分总览 --> <!-- 评分总览 -->
<view class="rating-overview"> <view class="rating-overview">
<text class="rating-score-large">{{currentTab === 2 ? (reviewScoreList.avgOverallRating || '-') : (myReviewInfo ? myReviewInfo.overallRating : '-')}}</text> <text class="rating-score-large">{{currentTab === 2 ? (reviewScoreList.avgOverallRating ? Number(reviewScoreList.avgOverallRating).toFixed(1) : '-') : (myReviewInfo ? Number(myReviewInfo.overallRating).toFixed(1) : '-')}}</text>
<view class="rating-right"> <view class="rating-right">
<uni-rate <uni-rate
:value="currentTab === 2 ? (reviewScoreList.avgOverallRating || 0) : (myReviewInfo ? myReviewInfo.overallRating : 0)" :value="currentTab === 2 ? (reviewScoreList.avgOverallRating || 0) : (myReviewInfo ? myReviewInfo.overallRating : 0)"
@ -100,7 +100,7 @@
]" :key="index"> ]" :key="index">
<view class="bar-header"> <view class="bar-header">
<text class="bar-label">{{item.label}} ({{item.weight}})</text> <text class="bar-label">{{item.label}} ({{item.weight}})</text>
<text class="bar-value">{{item.value ? item.value.toFixed(1) : '0.0'}}</text> <text class="bar-value">{{item.value ? Number(item.value).toFixed(1) : '0.0'}}</text>
</view> </view>
<view class="bar"> <view class="bar">
<view class="bar-filled" :style="{width: item.value ? (item.value/5*100 + '%') : '0%'}"></view> <view class="bar-filled" :style="{width: item.value ? (item.value/5*100 + '%') : '0%'}"></view>
@ -154,14 +154,14 @@
<!-- 评分和点赞 --> <!-- 评分和点赞 -->
<view class="review-footer"> <view class="review-footer">
<uni-rate <uni-rate
:value="item.compositeScore" :value="item.overallRating"
:readonly="true" :readonly="true"
:size="16" :size="16"
:touchable="false" :touchable="false"
color="#ECECEC" color="#ECECEC"
active-color="#FEE034" active-color="#FEE034"
/> />
<text class="score-text">{{item.compositeScore}}</text> <text class="score-text">{{item.overallRating ? Number(item.overallRating).toFixed(1) : '0.0'}}</text>
<view class="like-btn" :class="{ active: item.reviewLike }" @tap.stop="handleLike(item)"> <view class="like-btn" :class="{ active: item.reviewLike }" @tap.stop="handleLike(item)">
<image class="like-icon" src="/static/like.png" mode="aspectFit"></image> <image class="like-icon" src="/static/like.png" mode="aspectFit"></image>
<text class="like-count">{{item.likeCount || 0}}</text> <text class="like-count">{{item.likeCount || 0}}</text>
@ -266,7 +266,7 @@
if (this.isLoggedIn) { if (this.isLoggedIn) {
const barInfo = uni.getStorageSync('barInfo') const barInfo = uni.getStorageSync('barInfo')
this.isBarAuthenticated = barInfo && barInfo.authState === 2 this.isBarAuthenticated = barInfo && barInfo.authState === 1 // 1
} }
}, },
@ -332,13 +332,17 @@
console.log('获取评论列表数据:', res.rows.length) console.log('获取评论列表数据:', res.rows.length)
let arr = res.rows.map(it => ({ let arr = res.rows.map(it => ({
...it, ...it,
compositeScore: this.getScore(it.aromaRating, it.tasteRating, it.colorRating),
isExpanded: false, isExpanded: false,
needExpand: it.reviewContent && it.reviewContent.length > 50 needExpand: it.reviewContent && it.reviewContent.length > 50
})) }))
if (arr.length > 0) { if (arr.length > 0) {
console.log('更新评论列表') console.log('更新评论列表')
this.reviewList = [...this.reviewList, ...arr] //
if (this.queryForm.pageNum === 1) {
this.reviewList = arr
} else {
this.reviewList = [...this.reviewList, ...arr]
}
} }
} }
this.reviewTotal = res.total this.reviewTotal = res.total
@ -379,10 +383,10 @@
if (!this.isBarAuthenticated) { if (!this.isBarAuthenticated) {
const barInfo = uni.getStorageSync('barInfo') const barInfo = uni.getStorageSync('barInfo')
if (!barInfo || barInfo.authState === 0) { if (!barInfo || barInfo.authState === 2) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请先认证门店', content: '请先完成门店认证',
showCancel: true, showCancel: true,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
@ -396,9 +400,9 @@
} }
if (barInfo.authState === 1) { if (barInfo.authState === 1) {
uni.showToast({ //
title: '您的门店正在认证中,请耐心等待', uni.navigateTo({
icon: 'none' url: '/pages/index/writeReview?beerId=' + this.beerId
}) })
return return
} }
@ -448,10 +452,10 @@
} }
// //
if (barInfo.authState === 0) { if (barInfo.authState === 2) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请先认证门店', content: '请先完成门店认证',
showCancel: true, showCancel: true,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
@ -462,12 +466,6 @@
} }
}) })
return return
} else if (barInfo.authState === 1) {
uni.showToast({
title: '您的门店正在认证中,请耐心等待',
icon: 'none'
})
return
} }
try { try {
@ -489,34 +487,49 @@
}) })
} }
}, },
// //
handleLike(item) { async handleLike(item) {
const token = uni.getStorageSync('token') if (!this.isLoggedIn) {
if (!token) {
this.$refs.loginRef.open() this.$refs.loginRef.open()
return return
} }
let data = {
reviewId: item.id, try {
status: item.reviewLike ? 2 : 1 //
} const nextStatus = item.reviewLike ? 2 : 1 // (2)(1)
likeReview(data).then(res => {
if (data.status == 1) { const res = await likeReview({
reviewId: item.id,
status: nextStatus
})
if (res.code === 200) {
// UI
if (nextStatus === 1) { //
item.reviewLike = true
item.likeCount = (item.likeCount || 0) + 1
} else { //
item.reviewLike = false
item.likeCount = Math.max(0, (item.likeCount || 1) - 1)
}
uni.showToast({ uni.showToast({
title: '点赞成功', title: nextStatus === 1 ? '点赞成功' : '取消点赞',
icon: 'none' icon: 'none'
}) })
item.reviewLike = true
item.likeCount = (item.likeCount || 0) + 1
} else { } else {
uni.showToast({ uni.showToast({
title: '取消点赞', title: '操作失败,请重试',
icon: 'none' icon: 'none'
}) })
item.reviewLike = false
item.likeCount = Math.max(0, (item.likeCount || 1) - 1)
} }
}) } catch (error) {
console.error('点赞操作失败:', error)
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}, },
// //
toWinelist() { toWinelist() {
@ -545,10 +558,10 @@
} }
// //
if (barInfo.authState === 0) { if (barInfo.authState === 2) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请先认证门店', content: '您的门店正在认证中,请耐心等待',
showCancel: true, showCancel: true,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
@ -560,15 +573,25 @@
}) })
return return
} else if (barInfo.authState === 1) { } else if (barInfo.authState === 1) {
uni.showToast({ //
title: '您的门店正在认证中,请耐心等待', uni.navigateTo({
icon: 'none' url: "/pagesActivity/winelist?beerId=" + this.beerId
}) })
return return
} }
uni.navigateTo({ //
url: "/pagesActivity/winelist?beerId=" + this.beerId uni.showModal({
title: '提示',
content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
})
}
}
}) })
}, },
// //

View File

@ -165,11 +165,11 @@
// //
if (barInfo) { if (barInfo) {
if (barInfo.authState === 2) { if (barInfo.authState === 1) {
// //
this.isVerified = true this.isVerified = true
this.isVerifying = false this.isVerifying = false
} else if (barInfo.authState === 1) { } else if (barInfo.authState === 2) {
// //
this.isVerified = false this.isVerified = false
this.isVerifying = true this.isVerifying = true

View File

@ -341,7 +341,7 @@
const barInfo = uni.getStorageSync('barInfo'); const barInfo = uni.getStorageSync('barInfo');
this.isLoggedIn = !!token; this.isLoggedIn = !!token;
this.isVerified = barInfo && barInfo.authState === 2; this.isVerified = barInfo && barInfo.authState === 1;
}, },
handleButtonClick() { handleButtonClick() {
const token = uni.getStorageSync('token'); const token = uni.getStorageSync('token');
@ -369,10 +369,10 @@
} }
// //
if (barInfo.authState === 0) { if (barInfo.authState === 2) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请先认证门店', content: '您的门店正在认证中,请耐心等待',
showCancel: true, showCancel: true,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
@ -384,23 +384,38 @@
}); });
return; return;
} else if (barInfo.authState === 1) { } else if (barInfo.authState === 1) {
uni.showToast({ //
title: '您的门店正在认证中,请耐心等待', this.handleScan();
icon: 'none'
});
return; return;
} }
// //
this.handleScan(); uni.showModal({
title: '提示',
content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
});
}
}
});
}, },
onLoginSuccess() { onLoginSuccess(data) {
// //
this.checkLoginStatus(); this.checkLoginStatus();
//
if (data && data.needRefresh) {
//
this.init();
}
// //
const barInfo = uni.getStorageSync('barInfo'); const barInfo = uni.getStorageSync('barInfo');
if (!barInfo || barInfo.authState === 0) { if (!barInfo) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '请先认证门店', content: '请先认证门店',
@ -414,18 +429,42 @@
} }
}); });
return; return;
} else if (barInfo.authState === 1) { }
uni.showToast({
title: '您的门店正在认证中,请耐心等待', //
icon: 'none' if (barInfo.authState === 2) {
uni.showModal({
title: '提示',
content: '您的门店正在认证中,请耐心等待',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
});
}
}
}); });
return; return;
} else if (barInfo.authState === 1) {
//
this.handleScan();
return;
} }
// //
if (this.isVerified) { uni.showModal({
this.handleScan(); title: '提示',
} content: '请先认证门店',
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/index/registration'
});
}
}
});
} }
}, },
onUnload() { onUnload() {

View File

@ -216,31 +216,6 @@
return return
} }
//
const token = uni.getStorageSync('token')
const isAuth = uni.getStorageSync('isAuth')
if (!token) {
this.$refs.loginRef.open()
return
}
if (!isAuth) {
uni.showModal({
title: '提示',
content: '您还未认证门店,请先完成认证',
confirmText: '去认证',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pagesActivity/barAuth'
})
}
}
})
return
}
if (this.currentStep < 3) { if (this.currentStep < 3) {
this.currentStep++ this.currentStep++
} }

View File

@ -204,11 +204,11 @@
// //
if (barInfo) { if (barInfo) {
if (barInfo.authState === 2) { if (barInfo.authState === 1) {
// //
this.isVerified = true this.isVerified = true
this.isVerifying = false this.isVerifying = false
} else if (barInfo.authState === 1) { } else if (barInfo.authState === 2) {
// //
this.isVerified = false this.isVerified = false
this.isVerifying = true this.isVerifying = true