Showing
2 changed files
with
42 additions
and
4 deletions
| ... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
| 4 | <view class="center-circle"> | 4 | <view class="center-circle"> |
| 5 | <view class="total-points" @tap="handleGoToRewards"> | 5 | <view class="total-points" @tap="handleGoToRewards"> |
| 6 | <text v-if="!isOwner" class="family-points-label">家庭总积分</text> | 6 | <text v-if="!isOwner" class="family-points-label">家庭总积分</text> |
| 7 | - <text class="points-number">{{ animatedTotalPoints }}分</text> | 7 | + <text class="points-number" :style="{ fontSize: dynamicFontSize }">{{ animatedTotalPoints }}分</text> |
| 8 | <text v-if="isOwner" class="points-label">去兑换</text> | 8 | <text v-if="isOwner" class="points-label">去兑换</text> |
| 9 | </view> | 9 | </view> |
| 10 | </view> | 10 | </view> |
| ... | @@ -35,7 +35,7 @@ | ... | @@ -35,7 +35,7 @@ |
| 35 | </template> | 35 | </template> |
| 36 | 36 | ||
| 37 | <script setup> | 37 | <script setup> |
| 38 | -import { ref, onMounted, defineProps, defineExpose, defineEmits, watch } from 'vue' | 38 | +import { ref, onMounted, defineProps, defineExpose, defineEmits, watch, computed } from 'vue' |
| 39 | import Taro, { useDidShow } from '@tarojs/taro' | 39 | import Taro, { useDidShow } from '@tarojs/taro' |
| 40 | import { collectPointAPI } from '@/api/points' | 40 | import { collectPointAPI } from '@/api/points' |
| 41 | 41 | ||
| ... | @@ -68,6 +68,25 @@ const animatedTotalPoints = ref(props.totalPoints) // 动画中的总积分 | ... | @@ -68,6 +68,25 @@ const animatedTotalPoints = ref(props.totalPoints) // 动画中的总积分 |
| 68 | const floatingItems = ref([]) // 漂浮的积分项 | 68 | const floatingItems = ref([]) // 漂浮的积分项 |
| 69 | const isCollecting = ref(false) // 是否正在收集,防止重复触发 | 69 | const isCollecting = ref(false) // 是否正在收集,防止重复触发 |
| 70 | 70 | ||
| 71 | +/** | ||
| 72 | + * 根据数值长度动态计算字体大小 | ||
| 73 | + */ | ||
| 74 | +const dynamicFontSize = computed(() => { | ||
| 75 | + const pointsStr = animatedTotalPoints.value + '分' | ||
| 76 | + const length = pointsStr.length | ||
| 77 | + | ||
| 78 | + // 基础字体大小36rpx,超过6位数开始缩小 | ||
| 79 | + if (length <= 6) { | ||
| 80 | + return '36rpx' | ||
| 81 | + } else if (length <= 8) { | ||
| 82 | + return '32rpx' | ||
| 83 | + } else if (length <= 10) { | ||
| 84 | + return '28rpx' | ||
| 85 | + } else { | ||
| 86 | + return '24rpx' | ||
| 87 | + } | ||
| 88 | +}) | ||
| 89 | + | ||
| 71 | // source_type 中英文映射 | 90 | // source_type 中英文映射 |
| 72 | const sourceTypeMap = { | 91 | const sourceTypeMap = { |
| 73 | 'WALKING': '步数积分', | 92 | 'WALKING': '步数积分', | ... | ... |
| ... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
| 4 | <view class="center-circle1"> | 4 | <view class="center-circle1"> |
| 5 | <view class="total-points" @tap="handleGoToRewards"> | 5 | <view class="total-points" @tap="handleGoToRewards"> |
| 6 | <text v-if="!isOwner" class="family-points-label">家庭总积分</text> | 6 | <text v-if="!isOwner" class="family-points-label">家庭总积分</text> |
| 7 | - <text class="points-number">{{ animatedTotalPoints }}分</text> | 7 | + <text class="points-number" :style="{ fontSize: dynamicFontSize }">{{ animatedTotalPoints }}分</text> |
| 8 | <text v-if="isOwner" class="points-label">去兑换</text> | 8 | <text v-if="isOwner" class="points-label">去兑换</text> |
| 9 | </view> | 9 | </view> |
| 10 | </view> | 10 | </view> |
| ... | @@ -12,7 +12,7 @@ | ... | @@ -12,7 +12,7 @@ |
| 12 | </template> | 12 | </template> |
| 13 | 13 | ||
| 14 | <script setup> | 14 | <script setup> |
| 15 | -import { ref, watch, onMounted, defineProps } from 'vue' | 15 | +import { ref, watch, onMounted, defineProps, computed } from 'vue' |
| 16 | import Taro from '@tarojs/taro' | 16 | import Taro from '@tarojs/taro' |
| 17 | 17 | ||
| 18 | // 定义props | 18 | // 定义props |
| ... | @@ -36,6 +36,25 @@ const props = defineProps({ | ... | @@ -36,6 +36,25 @@ const props = defineProps({ |
| 36 | const animatedTotalPoints = ref(0) | 36 | const animatedTotalPoints = ref(0) |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | + * 根据数值长度动态计算字体大小 | ||
| 40 | + */ | ||
| 41 | +const dynamicFontSize = computed(() => { | ||
| 42 | + const pointsStr = animatedTotalPoints.value + '分' | ||
| 43 | + const length = pointsStr.length | ||
| 44 | + | ||
| 45 | + // 基础字体大小36rpx,超过6位数开始缩小 | ||
| 46 | + if (length <= 6) { | ||
| 47 | + return '36rpx' | ||
| 48 | + } else if (length <= 8) { | ||
| 49 | + return '32rpx' | ||
| 50 | + } else if (length <= 10) { | ||
| 51 | + return '28rpx' | ||
| 52 | + } else { | ||
| 53 | + return '24rpx' | ||
| 54 | + } | ||
| 55 | +}) | ||
| 56 | + | ||
| 57 | +/** | ||
| 39 | * 数字滚动动画 | 58 | * 数字滚动动画 |
| 40 | * @param {number} start - 动画开始值 | 59 | * @param {number} start - 动画开始值 |
| 41 | * @param {number} end - 动画结束值 | 60 | * @param {number} end - 动画结束值 | ... | ... |
-
Please register or login to post a comment