hookehuyr

refactor(排行榜): 优化步数格式化逻辑并添加刷新功能

重构步数格式化函数,使用toLocaleString方法替代原有逻辑
在RankingCard组件中添加refreshData方法并暴露给父组件
移除crown样式中不必要的margin-bottom属性
<!--
* @Date: 2025-01-09 00:00:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-09 15:26:25
* @LastEditTime: 2025-09-09 15:54:03
* @FilePath: /lls_program/src/components/RankingCard.vue
* @Description: 排行榜卡片组件
-->
......@@ -307,12 +307,24 @@ const myRank = computed(() => {
})
/**
* 刷新排行榜数据
*/
const refreshData = async () => {
await loadLeaderboardData(true)
}
/**
* 页面初始化
*/
onMounted(async () => {
// 直接加载排行榜数据,使用current_county参数获取当前家庭所在区县信息
await loadLeaderboardData(true)
})
// 暴露刷新方法给父组件
defineExpose({
refreshData
})
</script>
<style lang="less">
......@@ -441,7 +453,7 @@ onMounted(async () => {
.crown {
font-size: 30rpx;
margin-bottom: 8rpx;
// margin-bottom: 8rpx;
&.crown-gold {
filter: grayscale(0.3) brightness(1.1);
......
......@@ -133,7 +133,7 @@
</WeRunAuth>
<!-- 排行榜卡片 -->
<RankingCard :onViewMore="openFamilyRank" />
<RankingCard ref="rankingCardRef" :onViewMore="openFamilyRank" />
<!-- Family album -->
<view class="p-5 mt-4 mb-6 bg-white rounded-xl shadow-md mx-4">
......@@ -248,6 +248,7 @@ const todaySteps = ref(0);
const isWeRunAuthorized = ref(false);
const pointsCollectorRef = ref(null)
const weRunAuthRef = ref(null)
const rankingCardRef = ref(null)
const showTotalPointsOnly = ref(false)
const finalTotalPoints = ref(0)
const pendingPoints = ref([]) // 待收集的积分数据
......@@ -436,6 +437,11 @@ useDidShow(async () => {
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
// 刷新排行榜数据
if (rankingCardRef.value) {
rankingCardRef.value.refreshData();
}
} else {
// 如果没有加入家庭(code为0),跳转到欢迎页面
Taro.redirectTo({ url: '/pages/Welcome/index' });
......
<!--
* @Date: 2025-09-01 13:07:52
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-09 14:16:08
* @LastEditTime: 2025-09-09 15:56:24
* @FilePath: /lls_program/src/pages/FamilyRank/index.vue
* @Description: 文件描述
-->
......@@ -203,10 +203,7 @@ const switchTab = async (tab) => {
* @returns {string} 格式化后的步数
*/
const formatSteps = (steps) => {
if (steps >= 10000) {
return (steps / 10000).toFixed(1) + '万'
}
return steps?.toString()
return steps ? steps.toLocaleString() : '0'
}
/**
......@@ -450,7 +447,7 @@ onMounted(async () => {
.crown {
font-size: 40rpx;
margin-bottom: 10rpx;
// margin-bottom: 10rpx;
&.crown-gold {
filter: grayscale(0.3) brightness(1.1);
......