hookehuyr

feat(组件): 添加返回顶部组件并集成到家庭排名页

在家庭排名页面添加返回顶部功能,提升长页面浏览体验
- 创建新的BackToTop组件,支持自定义触发距离
- 在components.d.ts中注册全局组件
- 在FamilyRank页面集成并使用该组件
...@@ -8,10 +8,12 @@ export {} ...@@ -8,10 +8,12 @@ export {}
8 declare module 'vue' { 8 declare module 'vue' {
9 export interface GlobalComponents { 9 export interface GlobalComponents {
10 AppHeader: typeof import('./src/components/AppHeader.vue')['default'] 10 AppHeader: typeof import('./src/components/AppHeader.vue')['default']
11 + BackToTop: typeof import('./src/components/BackToTop.vue')['default']
11 BottomNav: typeof import('./src/components/BottomNav.vue')['default'] 12 BottomNav: typeof import('./src/components/BottomNav.vue')['default']
12 GlassCard: typeof import('./src/components/GlassCard.vue')['default'] 13 GlassCard: typeof import('./src/components/GlassCard.vue')['default']
13 NavBar: typeof import('./src/components/navBar.vue')['default'] 14 NavBar: typeof import('./src/components/navBar.vue')['default']
14 NutActionSheet: typeof import('@nutui/nutui-taro')['ActionSheet'] 15 NutActionSheet: typeof import('@nutui/nutui-taro')['ActionSheet']
16 + NutBacktop: typeof import('@nutui/nutui-taro')['Backtop']
15 NutButton: typeof import('@nutui/nutui-taro')['Button'] 17 NutButton: typeof import('@nutui/nutui-taro')['Button']
16 NutDatePicker: typeof import('@nutui/nutui-taro')['DatePicker'] 18 NutDatePicker: typeof import('@nutui/nutui-taro')['DatePicker']
17 NutImagePreview: typeof import('@nutui/nutui-taro')['ImagePreview'] 19 NutImagePreview: typeof import('@nutui/nutui-taro')['ImagePreview']
......
1 +<!--
2 + * @Date: 2025-09-02 13:06:39
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2025-09-02 13:12:20
5 + * @FilePath: /lls_program/src/components/BackToTop.vue
6 + * @Description: 文件描述
7 +-->
8 +<template>
9 + <view
10 + v-if="showBackToTop"
11 + class="back-to-top"
12 + @click="scrollToTop"
13 + >
14 + <view class="back-to-top-icon">↑</view>
15 + </view>
16 +</template>
17 +
18 +<script setup>
19 +import { ref } from 'vue'
20 +import { usePageScroll } from '@tarojs/taro'
21 +import Taro from '@tarojs/taro'
22 +
23 +/**
24 + * 返回顶部组件的属性定义
25 + */
26 +const props = defineProps({
27 + // 触发显示返回顶部按钮的滚动距离,单位rpx
28 + distance: {
29 + type: Number,
30 + default: 300
31 + }
32 +})
33 +
34 +// 是否显示返回顶部按钮
35 +const showBackToTop = ref(false)
36 +
37 +/**
38 + * 监听页面滚动事件
39 + */
40 +usePageScroll((res) => {
41 + showBackToTop.value = res.scrollTop > props.distance
42 +})
43 +
44 +/**
45 + * 滚动到页面顶部
46 + */
47 +const scrollToTop = () => {
48 + Taro.pageScrollTo({
49 + scrollTop: 0,
50 + duration: 300
51 + })
52 +}
53 +</script>
54 +
55 +<style lang="less">
56 +.back-to-top {
57 + position: fixed;
58 + right: 30rpx;
59 + bottom: 180rpx;
60 + width: 80rpx;
61 + height: 80rpx;
62 + background: rgba(64, 158, 255, 0.8);
63 + border-radius: 50%;
64 + display: flex;
65 + align-items: center;
66 + justify-content: center;
67 + box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
68 + backdrop-filter: blur(10rpx);
69 + transition: all 0.3s ease;
70 + z-index: 999;
71 +
72 + &:hover {
73 + background: rgba(64, 158, 255, 1);
74 + transform: translateY(-4rpx);
75 + }
76 +
77 + &:active {
78 + transform: translateY(0);
79 + }
80 +}
81 +
82 +.back-to-top-icon {
83 + color: white;
84 + font-size: 32rpx;
85 + font-weight: bold;
86 +}
87 +</style>
1 <!-- 1 <!--
2 * @Date: 2025-09-01 13:07:52 2 * @Date: 2025-09-01 13:07:52
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-01 16:05:41 4 + * @LastEditTime: 2025-09-02 13:13:17
5 * @FilePath: /lls_program/src/pages/FamilyRank/index.vue 5 * @FilePath: /lls_program/src/pages/FamilyRank/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -122,11 +122,15 @@ ...@@ -122,11 +122,15 @@
122 </view> 122 </view>
123 </view> 123 </view>
124 </view> 124 </view>
125 +
126 + <!-- 返回顶部组件 -->
127 + <BackToTop :distance="200" />
125 </view> 128 </view>
126 </template> 129 </template>
127 130
128 <script setup> 131 <script setup>
129 import { ref, computed } from 'vue' 132 import { ref, computed } from 'vue'
133 +import BackToTop from '@/components/BackToTop.vue'
130 134
131 // 当前激活的tab 135 // 当前激活的tab
132 const activeTab = ref('huangpu') 136 const activeTab = ref('huangpu')
...@@ -134,6 +138,8 @@ const activeTab = ref('huangpu') ...@@ -134,6 +138,8 @@ const activeTab = ref('huangpu')
134 // 内容切换状态 138 // 内容切换状态
135 const isContentSwitching = ref(false) 139 const isContentSwitching = ref(false)
136 140
141 +
142 +
137 /** 143 /**
138 * 切换tab 144 * 切换tab
139 * @param {string} tab - tab名称 145 * @param {string} tab - tab名称
...@@ -173,6 +179,8 @@ const formatStepsForList = (steps) => { ...@@ -173,6 +179,8 @@ const formatStepsForList = (steps) => {
173 return steps ? steps.toLocaleString() : '0' 179 return steps ? steps.toLocaleString() : '0'
174 } 180 }
175 181
182 +
183 +
176 // 前三名数据 184 // 前三名数据
177 const topRanks = ref([ 185 const topRanks = ref([
178 { 186 {
...@@ -649,6 +657,7 @@ const myRank = ref({ ...@@ -649,6 +657,7 @@ const myRank = ref({
649 } 657 }
650 } 658 }
651 } 659 }
652 -}
653 660
661 +
662 +}
654 </style> 663 </style>
......