hookehuyr

feat: 优化页面数据初始化逻辑并统一使用useDidShow

refactor(组件): 提取初始化逻辑到独立函数
style: 清理无用导入和注释
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
38 </template> 38 </template>
39 39
40 <script setup> 40 <script setup>
41 -import { ref, onMounted, nextTick, defineProps, defineExpose } from 'vue' 41 +import { ref, onMounted, defineProps, defineExpose } from 'vue'
42 -import Taro from '@tarojs/taro' 42 +import Taro, { useDidShow } from '@tarojs/taro'
43 43
44 // 定义props 44 // 定义props
45 const props = defineProps({ 45 const props = defineProps({
...@@ -240,9 +240,22 @@ defineExpose({ ...@@ -240,9 +240,22 @@ defineExpose({
240 collectAll 240 collectAll
241 }) 241 })
242 242
243 +/**
244 + * 初始化数据
245 + */
246 +const initData = () => {
247 + floatingItems.value = generateMockData();
248 + console.warn('初始化数据')
249 +}
250 +
243 // 组件挂载时初始化数据 251 // 组件挂载时初始化数据
244 onMounted(() => { 252 onMounted(() => {
245 - floatingItems.value = generateMockData(); 253 + initData();
254 +})
255 +
256 +// 每次进入组件时重新获取数据
257 +useDidShow(() => {
258 + initData();
246 }) 259 })
247 260
248 /** 261 /**
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
5 <view class="px-5 py-6 bg-white rounded-xl shadow-md mx-4 mt-4"> 5 <view class="px-5 py-6 bg-white rounded-xl shadow-md mx-4 mt-4">
6 <view class="flex flex-col items-center justify-center py-8"> 6 <view class="flex flex-col items-center justify-center py-8">
7 <view class="mb-4"> 7 <view class="mb-4">
8 - <image 8 + <image
9 - src="https://placehold.co/100x100/e2f3ff/0369a1?text=步数&font=roboto" 9 + src="https://placehold.co/100x100/e2f3ff/0369a1?text=步数&font=roboto"
10 class="w-20 h-20 rounded-full" 10 class="w-20 h-20 rounded-full"
11 /> 11 />
12 </view> 12 </view>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 <text class="text-gray-500 text-center mb-6 px-4"> 14 <text class="text-gray-500 text-center mb-6 px-4">
15 授权后可查看您的步数信息,与家人一起记录健康生活 15 授权后可查看您的步数信息,与家人一起记录健康生活
16 </text> 16 </text>
17 - <view 17 + <view
18 class="bg-blue-500 text-white px-8 py-3 rounded-full text-sm" 18 class="bg-blue-500 text-white px-8 py-3 rounded-full text-sm"
19 @click="requestAuth" 19 @click="requestAuth"
20 > 20 >
...@@ -50,12 +50,12 @@ const checkAuthStatus = async () => { ...@@ -50,12 +50,12 @@ const checkAuthStatus = async () => {
50 try { 50 try {
51 const authSetting = await Taro.getSetting() 51 const authSetting = await Taro.getSetting()
52 const hasWeRunAuth = authSetting.authSetting['scope.werun'] 52 const hasWeRunAuth = authSetting.authSetting['scope.werun']
53 - 53 +
54 isAuthorized.value = hasWeRunAuth === true 54 isAuthorized.value = hasWeRunAuth === true
55 - 55 +
56 // 通知父组件授权状态变化 56 // 通知父组件授权状态变化
57 emit('auth-change', isAuthorized.value) 57 emit('auth-change', isAuthorized.value)
58 - 58 +
59 // 如果已授权,获取步数数据 59 // 如果已授权,获取步数数据
60 if (isAuthorized.value) { 60 if (isAuthorized.value) {
61 await getWeRunData() 61 await getWeRunData()
...@@ -73,25 +73,25 @@ const checkAuthStatus = async () => { ...@@ -73,25 +73,25 @@ const checkAuthStatus = async () => {
73 const requestAuth = async () => { 73 const requestAuth = async () => {
74 try { 74 try {
75 isLoading.value = true 75 isLoading.value = true
76 - 76 +
77 // 请求微信运动授权 77 // 请求微信运动授权
78 await Taro.authorize({ 78 await Taro.authorize({
79 scope: 'scope.werun' 79 scope: 'scope.werun'
80 }) 80 })
81 - 81 +
82 isAuthorized.value = true 82 isAuthorized.value = true
83 emit('auth-change', true) 83 emit('auth-change', true)
84 - 84 +
85 // 授权成功后获取步数数据 85 // 授权成功后获取步数数据
86 await getWeRunData() 86 await getWeRunData()
87 - 87 +
88 Taro.showToast({ 88 Taro.showToast({
89 title: '授权成功', 89 title: '授权成功',
90 icon: 'success' 90 icon: 'success'
91 }) 91 })
92 } catch (error) { 92 } catch (error) {
93 console.error('授权失败:', error) 93 console.error('授权失败:', error)
94 - 94 +
95 // 用户拒绝授权,引导到设置页面 95 // 用户拒绝授权,引导到设置页面
96 Taro.showModal({ 96 Taro.showModal({
97 title: '授权提示', 97 title: '授权提示',
...@@ -120,27 +120,33 @@ const requestAuth = async () => { ...@@ -120,27 +120,33 @@ const requestAuth = async () => {
120 const getWeRunData = async () => { 120 const getWeRunData = async () => {
121 try { 121 try {
122 isLoading.value = true 122 isLoading.value = true
123 - 123 +
124 // 先调用 wx.login 获取 code 124 // 先调用 wx.login 获取 code
125 const loginRes = await Taro.login() 125 const loginRes = await Taro.login()
126 - 126 +
127 // 获取微信运动数据 127 // 获取微信运动数据
128 const weRunRes = await Taro.getWeRunData() 128 const weRunRes = await Taro.getWeRunData()
129 - 129 +
130 // 这里需要将加密数据发送到后端解密 130 // 这里需要将加密数据发送到后端解密
131 // 暂时使用模拟数据 131 // 暂时使用模拟数据
132 const mockSteps = Math.floor(Math.random() * 10000) + 1000 132 const mockSteps = Math.floor(Math.random() * 10000) + 1000
133 todaySteps.value = mockSteps 133 todaySteps.value = mockSteps
134 - 134 +
135 // 通知父组件步数更新 135 // 通知父组件步数更新
136 emit('steps-update', todaySteps.value) 136 emit('steps-update', todaySteps.value)
137 - 137 +
138 console.log('微信运动数据获取成功:', { 138 console.log('微信运动数据获取成功:', {
139 encryptedData: weRunRes.encryptedData, 139 encryptedData: weRunRes.encryptedData,
140 iv: weRunRes.iv, 140 iv: weRunRes.iv,
141 code: loginRes.code 141 code: loginRes.code
142 }) 142 })
143 - 143 +
144 + // 提示获取步数成功
145 + // Taro.showToast({
146 + // title: `获取步数成功:${mockSteps}步`,
147 + // icon: 'none'
148 + // })
149 +
144 // TODO: 实际项目中需要将 encryptedData, iv, code 发送到后端解密 150 // TODO: 实际项目中需要将 encryptedData, iv, code 发送到后端解密
145 // const decryptedData = await api.decryptWeRunData({ 151 // const decryptedData = await api.decryptWeRunData({
146 // encryptedData: weRunRes.encryptedData, 152 // encryptedData: weRunRes.encryptedData,
...@@ -148,14 +154,14 @@ const getWeRunData = async () => { ...@@ -148,14 +154,14 @@ const getWeRunData = async () => {
148 // code: loginRes.code 154 // code: loginRes.code
149 // }) 155 // })
150 // todaySteps.value = decryptedData.todaySteps 156 // todaySteps.value = decryptedData.todaySteps
151 - 157 +
152 } catch (error) { 158 } catch (error) {
153 console.error('获取微信运动数据失败:', error) 159 console.error('获取微信运动数据失败:', error)
154 - 160 +
155 // 如果获取失败,使用默认值 161 // 如果获取失败,使用默认值
156 todaySteps.value = 0 162 todaySteps.value = 0
157 emit('steps-update', 0) 163 emit('steps-update', 0)
158 - 164 +
159 Taro.showToast({ 165 Taro.showToast({
160 title: '获取步数失败', 166 title: '获取步数失败',
161 icon: 'none' 167 icon: 'none'
...@@ -194,4 +200,4 @@ onMounted(() => { ...@@ -194,4 +200,4 @@ onMounted(() => {
194 .auth-prompt { 200 .auth-prompt {
195 text-align: center; 201 text-align: center;
196 } 202 }
197 -</style>
...\ No newline at end of file ...\ No newline at end of file
203 +</style>
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
2 <view class="min-h-screen flex flex-col bg-white pb-16" style="background-color: #F9FAFB;"> 2 <view class="min-h-screen flex flex-col bg-white pb-16" style="background-color: #F9FAFB;">
3 <!-- Hero section with family name and background image --> 3 <!-- Hero section with family name and background image -->
4 <view class="relative h-48"> 4 <view class="relative h-48">
5 - <image src="https://placehold.co/800x400/e2f3ff/0369a1?text=LFX&font=roboto" alt="Family background" class="w-full h-full object-cover" /> 5 + <image :src="familyCover" alt="Family background" class="w-full h-full object-cover" />
6 <view class="absolute inset-0 bg-black bg-opacity-30 flex flex-col justify-end p-5"> 6 <view class="absolute inset-0 bg-black bg-opacity-30 flex flex-col justify-end p-5">
7 <view class="absolute top-4 right-4 text-white flex items-center" @click="goToProfile"> 7 <view class="absolute top-4 right-4 text-white flex items-center" @click="goToProfile">
8 <Setting size="24" /> 8 <Setting size="24" />
9 <text class="ml-2">家庭设置</text> 9 <text class="ml-2">家庭设置</text>
10 </view> 10 </view>
11 - <h1 class="text-white text-2xl font-bold">张爷爷的家庭</h1> 11 + <h1 class="text-white text-2xl font-bold">{{ familyName }}</h1>
12 - <p class="text-white opacity-90">每日走万步,全家一起行</p> 12 + <p class="text-white opacity-90">{{ familySlogn }}</p>
13 </view> 13 </view>
14 </view> 14 </view>
15 15
16 <!-- 微信步数授权组件 --> 16 <!-- 微信步数授权组件 -->
17 - <WeRunAuth 17 + <WeRunAuth
18 ref="weRunAuthRef" 18 ref="weRunAuthRef"
19 @auth-change="handleAuthChange" 19 @auth-change="handleAuthChange"
20 @steps-update="handleStepsUpdate" 20 @steps-update="handleStepsUpdate"
21 > 21 >
22 <template #default="{ steps, isLoading }"> 22 <template #default="{ steps, isLoading }">
23 <!-- Today's steps section --> 23 <!-- Today's steps section -->
24 + <!-- TODO: 今日获取的步数怎么同步到下面那个积分池里面去 -->
24 <view class="px-5 py-6 bg-white rounded-xl shadow-md mx-4 mt-4"> 25 <view class="px-5 py-6 bg-white rounded-xl shadow-md mx-4 mt-4">
25 <view class="flex justify-between items-center mb-1"> 26 <view class="flex justify-between items-center mb-1">
26 <span class="text-gray-500">今日</span> 27 <span class="text-gray-500">今日</span>
...@@ -32,8 +33,13 @@ ...@@ -32,8 +33,13 @@
32 </span> 33 </span>
33 <span class="ml-1 text-gray-500">步</span> 34 <span class="ml-1 text-gray-500">步</span>
34 </view> 35 </view>
35 - <view class="bg-blue-500 text-white px-4 py-2 rounded-full text-sm" @click="handleCollectAll"> 36 + <view class="flex gap-2">
36 - 一键收取 37 + <!-- <view class="bg-green-500 text-white px-4 py-2 rounded-full text-xs" @click="handleRefreshSteps">
38 + 更新步数
39 + </view> -->
40 + <view class="bg-blue-500 text-white px-4 py-2 rounded-full text-sm" @click="handleCollectAll">
41 + 一键收取
42 + </view>
37 </view> 43 </view>
38 </view> 44 </view>
39 </view> 45 </view>
...@@ -98,7 +104,7 @@ ...@@ -98,7 +104,7 @@
98 104
99 <script setup> 105 <script setup>
100 import { ref, computed, onMounted } from 'vue'; 106 import { ref, computed, onMounted } from 'vue';
101 -import Taro from '@tarojs/taro'; 107 +import Taro, { useDidShow } from '@tarojs/taro';
102 import { Setting, Photograph, Right } from '@nutui/icons-vue-taro'; 108 import { Setting, Photograph, Right } from '@nutui/icons-vue-taro';
103 import BottomNav from '../../components/BottomNav.vue'; 109 import BottomNav from '../../components/BottomNav.vue';
104 import PointsCollector from '@/components/PointsCollector.vue' 110 import PointsCollector from '@/components/PointsCollector.vue'
...@@ -109,6 +115,10 @@ const isWeRunAuthorized = ref(false); ...@@ -109,6 +115,10 @@ const isWeRunAuthorized = ref(false);
109 const pointsCollectorRef = ref(null) 115 const pointsCollectorRef = ref(null)
110 const weRunAuthRef = ref(null) 116 const weRunAuthRef = ref(null)
111 117
118 +const familyName = ref('')
119 +const familySlogn = ref('')
120 +const familyCover = ref('')
121 +
112 /** 122 /**
113 * 触发积分收集组件的一键收取 123 * 触发积分收集组件的一键收取
114 */ 124 */
...@@ -119,6 +129,15 @@ const handleCollectAll = () => { ...@@ -119,6 +129,15 @@ const handleCollectAll = () => {
119 } 129 }
120 130
121 /** 131 /**
132 + * 手动刷新微信步数
133 + */
134 +const handleRefreshSteps = async () => {
135 + if (weRunAuthRef.value) {
136 + await weRunAuthRef.value.refreshSteps()
137 + }
138 +}
139 +
140 +/**
122 * 处理微信步数授权状态变化 141 * 处理微信步数授权状态变化
123 * @param {boolean} authorized - 授权状态 142 * @param {boolean} authorized - 授权状态
124 */ 143 */
...@@ -196,12 +215,20 @@ const openCamera = () => { ...@@ -196,12 +215,20 @@ const openCamera = () => {
196 Taro.navigateTo({ url: '/pages/UploadMedia/index' }); 215 Taro.navigateTo({ url: '/pages/UploadMedia/index' });
197 } 216 }
198 217
199 -onMounted(() => { 218 +const initPageData = async () => {
219 + // 获取用户信息
220 + familyName.value = '张爷爷的家庭'
221 + familySlogn.value = '每日走万步,全家一起行'
222 + familyCover.value = 'https://placehold.co/800x400/e2f3ff/0369a1?text=LFX&font=roboto'
223 +}
224 +
225 +useDidShow(() => {
200 // TODO: 等待真实接口获取用户是否加入家庭 226 // TODO: 等待真实接口获取用户是否加入家庭
201 // const hasJoinedFamily = false; // Change to true to simulate having a family 227 // const hasJoinedFamily = false; // Change to true to simulate having a family
202 228
203 // if (!hasJoinedFamily) { 229 // if (!hasJoinedFamily) {
204 // Taro.redirectTo({ url: '/pages/Welcome/index' }); 230 // Taro.redirectTo({ url: '/pages/Welcome/index' });
205 // } 231 // }
232 + initPageData();
206 }) 233 })
207 </script> 234 </script>
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-29 15:27:43 4 + * @LastEditTime: 2025-08-29 20:32:52
5 * @FilePath: /lls_program/src/pages/MyFamily/index.vue 5 * @FilePath: /lls_program/src/pages/MyFamily/index.vue
6 * @Description: 我的家庭页面 - 展示用户加入的家庭列表 6 * @Description: 我的家庭页面 - 展示用户加入的家庭列表
7 --> 7 -->
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
103 @tap="joinNewFamily" 103 @tap="joinNewFamily"
104 class="w-full bg-blue-500 text-white text-center py-3 rounded-lg font-medium" 104 class="w-full bg-blue-500 text-white text-center py-3 rounded-lg font-medium"
105 > 105 >
106 - + 加入新家庭 106 + 加入新家庭
107 </view> 107 </view>
108 </view> 108 </view>
109 109
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
113 113
114 <script setup> 114 <script setup>
115 import { ref, onMounted } from 'vue'; 115 import { ref, onMounted } from 'vue';
116 -import Taro from '@tarojs/taro'; 116 +import Taro, { useDidShow } from '@tarojs/taro';
117 import { Home } from '@nutui/icons-vue-taro'; 117 import { Home } from '@nutui/icons-vue-taro';
118 import './index.less'; 118 import './index.less';
119 119
...@@ -248,7 +248,7 @@ const joinNewFamily = () => { ...@@ -248,7 +248,7 @@ const joinNewFamily = () => {
248 248
249 249
250 // 页面加载时初始化数据 250 // 页面加载时初始化数据
251 -onMounted(() => { 251 +useDidShow(() => {
252 initPageData(); 252 initPageData();
253 }); 253 });
254 </script> 254 </script>
......
...@@ -55,8 +55,7 @@ ...@@ -55,8 +55,7 @@
55 <script setup> 55 <script setup>
56 import { ref, computed } from 'vue'; 56 import { ref, computed } from 'vue';
57 import Taro from '@tarojs/taro'; 57 import Taro from '@tarojs/taro';
58 - 58 +import { useDidShow } from '@tarojs/taro';
59 -import AppHeader from '../../components/AppHeader.vue';
60 59
61 const tabs = ref([ 60 const tabs = ref([
62 { name: 'all', label: '全部' }, 61 { name: 'all', label: '全部' },
...@@ -67,36 +66,7 @@ const tabs = ref([ ...@@ -67,36 +66,7 @@ const tabs = ref([
67 66
68 const activeTab = ref('all'); 67 const activeTab = ref('all');
69 68
70 -const rewards = ref([ 69 +const rewards = ref([]);
71 - {
72 - id: 1,
73 - title: '杏花楼集团 85折券',
74 - expiryDate: '2025-08-28',
75 - status: 'unused',
76 - usedDate: null,
77 - },
78 - {
79 - id: 2,
80 - title: '老凤祥银楼 20元抵用券',
81 - expiryDate: '2025-08-28',
82 - status: 'unused',
83 - usedDate: null,
84 - },
85 - {
86 - id: 3,
87 - title: '吴良材眼镜 5折券',
88 - expiryDate: '2024-05-20',
89 - status: 'used',
90 - usedDate: '2024-05-01',
91 - },
92 - {
93 - id: 4,
94 - title: '沈大成双酿团 免费券',
95 - expiryDate: '2024-03-15',
96 - status: 'expired',
97 - usedDate: null,
98 - },
99 -]);
100 70
101 const filteredRewards = computed(() => { 71 const filteredRewards = computed(() => {
102 if (activeTab.value === 'all') { 72 if (activeTab.value === 'all') {
...@@ -135,4 +105,55 @@ const handleUseReward = (reward) => { ...@@ -135,4 +105,55 @@ const handleUseReward = (reward) => {
135 }) 105 })
136 } 106 }
137 }; 107 };
108 +
109 +useDidShow(() => {
110 + initPageData();
111 +});
112 +
113 +const initPageData = () => {
114 + rewards.value = [
115 + {
116 + id: 1,
117 + title: '杏花楼集团 85折券',
118 + expiryDate: '2025-08-28',
119 + status: 'unused',
120 + usedDate: null,
121 + },
122 + {
123 + id: 2,
124 + title: '老凤祥银楼 20元抵用券',
125 + expiryDate: '2025-08-28',
126 + status: 'unused',
127 + usedDate: null,
128 + },
129 + {
130 + id: 3,
131 + title: '吴良材眼镜 5折券',
132 + expiryDate: '2024-05-20',
133 + status: 'used',
134 + usedDate: '2024-05-01',
135 + },
136 + {
137 + id: 4,
138 + title: '沈大成双酿团 免费券',
139 + expiryDate: '2024-03-15',
140 + status: 'expired',
141 + usedDate: null,
142 + },
143 + {
144 + id: 5,
145 + title: '沈大成双酿团 免费券',
146 + expiryDate: '2024-03-15',
147 + status: 'expired',
148 + usedDate: null,
149 + },
150 + {
151 + id: 6,
152 + title: '沈大成双酿团 免费券',
153 + expiryDate: '2024-03-15',
154 + status: 'expired',
155 + usedDate: null,
156 + },
157 + ];
158 +}
138 </script> 159 </script>
......
1 <!-- 1 <!--
2 * @Date: 2025-08-27 17:47:46 2 * @Date: 2025-08-27 17:47:46
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-29 11:12:30 4 + * @LastEditTime: 2025-08-29 20:38:36
5 * @FilePath: /lls_program/src/pages/Profile/index.vue 5 * @FilePath: /lls_program/src/pages/Profile/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 <view class="flex items-center"> 16 <view class="flex items-center">
17 <image :src="defaultAvatar" alt="User avatar" class="w-16 h-16 rounded-full border-2 border-white" /> 17 <image :src="defaultAvatar" alt="User avatar" class="w-16 h-16 rounded-full border-2 border-white" />
18 <view class="ml-4"> 18 <view class="ml-4">
19 - <h1 class="text-xl font-bold text-white">张爷爷</h1> 19 + <h1 class="text-xl font-bold text-white">{{ userInfo.nickName }}</h1>
20 </view> 20 </view>
21 </view> 21 </view>
22 <view @tap="goToEditProfile" class="text-white"> 22 <view @tap="goToEditProfile" class="text-white">
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
45 45
46 <script setup> 46 <script setup>
47 import { ref, shallowRef } from 'vue'; 47 import { ref, shallowRef } from 'vue';
48 -import Taro from '@tarojs/taro'; 48 +import Taro, { useDidShow } from '@tarojs/taro';
49 import BottomNav from '../../components/BottomNav.vue'; 49 import BottomNav from '../../components/BottomNav.vue';
50 import { My, Shop3, Cart, Message, Tips, Right } from '@nutui/icons-vue-taro'; 50 import { My, Shop3, Cart, Message, Tips, Right } from '@nutui/icons-vue-taro';
51 // 默认头像 51 // 默认头像
...@@ -96,7 +96,24 @@ const menuItems = shallowRef([ ...@@ -96,7 +96,24 @@ const menuItems = shallowRef([
96 } 96 }
97 ]); 97 ]);
98 98
99 +const userInfo = ref({
100 + nickName: '',
101 + avatarUrl: '',
102 +});
103 +
99 const goToEditProfile = () => { 104 const goToEditProfile = () => {
100 Taro.navigateTo({ url: '/pages/EditProfile/index' }); 105 Taro.navigateTo({ url: '/pages/EditProfile/index' });
101 }; 106 };
107 +
108 +const initPageData = () => {
109 + // 获取用户信息
110 + userInfo.value = {
111 + nickName: '用户10086',
112 + avatarUrl: defaultAvatar,
113 + }
114 +}
115 +
116 +useDidShow(() => {
117 + initPageData();
118 +});
102 </script> 119 </script>
......
1 <!-- 1 <!--
2 * @Date: 2025-08-27 17:47:26 2 * @Date: 2025-08-27 17:47:26
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-28 09:37:06 4 + * @LastEditTime: 2025-08-29 20:32:08
5 * @FilePath: /lls_program/src/pages/Rewards/index.vue 5 * @FilePath: /lls_program/src/pages/Rewards/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 <view class="relative z-10 flex-1 pb-20"> 14 <view class="relative z-10 flex-1 pb-20">
15 <!-- Points display --> 15 <!-- Points display -->
16 <view class="pt-8 pb-8 flex flex-col items-center"> 16 <view class="pt-8 pb-8 flex flex-col items-center">
17 - <h2 class="text-4xl font-bold text-white mb-1">2580分</h2> 17 + <h2 class="text-4xl font-bold text-white mb-1">{{ totalPoints }}分</h2>
18 <p class="text-white text-opacity-80">我的积分</p> 18 <p class="text-white text-opacity-80">我的积分</p>
19 </view> 19 </view>
20 <!-- Main content --> 20 <!-- Main content -->
...@@ -71,16 +71,16 @@ ...@@ -71,16 +71,16 @@
71 </template> 71 </template>
72 72
73 <script setup> 73 <script setup>
74 -import { ref, computed } from 'vue'; 74 +import { ref, computed, onMounted } from 'vue';
75 -import Taro from '@tarojs/taro'; 75 +import Taro, { useDidShow } from '@tarojs/taro';
76 import { ScreenLittle, Search2 } from '@nutui/icons-vue-taro'; 76 import { ScreenLittle, Search2 } from '@nutui/icons-vue-taro';
77 -import AppHeader from '../../components/AppHeader.vue';
78 -import BottomNav from '../../components/BottomNav.vue';
79 77
80 const searchQuery = ref(''); 78 const searchQuery = ref('');
81 const selectedPoints = ref(null); 79 const selectedPoints = ref(null);
82 const sortOrder = ref('desc'); // 'asc' or 'desc' 80 const sortOrder = ref('desc'); // 'asc' or 'desc'
83 81
82 +const totalPoints = ref(0);
83 +
84 const sortedRewardItems = computed(() => { 84 const sortedRewardItems = computed(() => {
85 let items = [...rewardItems.value]; 85 let items = [...rewardItems.value];
86 86
...@@ -154,4 +154,13 @@ const goToRewardDetail = (reward) => { ...@@ -154,4 +154,13 @@ const goToRewardDetail = (reward) => {
154 url: `/pages/RewardDetail/index?id=${reward.id}` 154 url: `/pages/RewardDetail/index?id=${reward.id}`
155 }); 155 });
156 }; 156 };
157 +
158 +const initData = async () => {
159 + totalPoints.value = '9856';
160 + console.warn('初始化数据')
161 +}
162 +
163 +useDidShow(() => {
164 + initData();
165 +})
157 </script> 166 </script>
......