hookehuyr

fix: 移除手动更新步数功能并优化401处理

移除Dashboard页面中手动更新步数的按钮及相关逻辑
在WeRunAuth组件中添加测试用户检查逻辑
简化401未授权状态的处理条件
...@@ -125,6 +125,27 @@ const getWeRunData = async () => { ...@@ -125,6 +125,27 @@ const getWeRunData = async () => {
125 try { 125 try {
126 isLoading.value = true 126 isLoading.value = true
127 127
128 + // 检查是否为测试用户(openid以h-开头),如果是则跳过步数同步
129 + try {
130 + const { getUserProfileAPI } = await import('@/api/user')
131 + const profileResponse = await getUserProfileAPI()
132 + if (profileResponse.code === 1 && profileResponse.data?.user?.openid) {
133 + const openid = profileResponse.data.user.openid
134 + if (openid.startsWith('h-')) {
135 + console.log('检测到测试用户openid:', openid, '跳过步数同步')
136 + Taro.showToast({
137 + title: '测试用户无需同步步数',
138 + icon: 'none',
139 + duration: 2000
140 + })
141 + isLoading.value = false
142 + return
143 + }
144 + }
145 + } catch (profileError) {
146 + console.warn('获取用户信息失败,继续执行步数同步:', profileError)
147 + }
148 +
128 // 先调用 wx.login 获取 code 149 // 先调用 wx.login 获取 code
129 const loginRes = await Taro.login() 150 const loginRes = await Taro.login()
130 151
......
...@@ -35,11 +35,7 @@ ...@@ -35,11 +35,7 @@
35 <span class="ml-1 text-gray-500">步</span> 35 <span class="ml-1 text-gray-500">步</span>
36 </view> 36 </view>
37 <view class="flex gap-2"> 37 <view class="flex gap-2">
38 - <view v-if="showManualUpdateButton" class="bg-green-500 text-white px-4 py-2 rounded-full text-xs" @click="handleRefreshSteps" :class="{ 'opacity-50': isRefreshingSteps }"> 38 + <view class="bg-blue-500 text-white px-4 py-2 rounded-full text-sm" @click="handleCollectAll">
39 - <text v-if="!isRefreshingSteps">手动更新</text>
40 - <text v-else>更新中...</text>
41 - </view>
42 - <view class="bg-blue-500 text-white px-4 py-2 rounded-full text-xs" @click="handleCollectAll">
43 一键收取 39 一键收取
44 </view> 40 </view>
45 </view> 41 </view>
...@@ -216,8 +212,6 @@ const weRunAuthRef = ref(null) ...@@ -216,8 +212,6 @@ const weRunAuthRef = ref(null)
216 const showTotalPointsOnly = ref(false) 212 const showTotalPointsOnly = ref(false)
217 const finalTotalPoints = ref(0) 213 const finalTotalPoints = ref(0)
218 const pendingPoints = ref([]) // 待收集的积分数据 214 const pendingPoints = ref([]) // 待收集的积分数据
219 -const showManualUpdateButton = ref(false) // 是否显示手动更新步数按钮
220 -const isRefreshingSteps = ref(false) // 手动更新步数的loading状态
221 215
222 const familyName = ref('') 216 const familyName = ref('')
223 const familySlogn = ref('') 217 const familySlogn = ref('')
...@@ -276,22 +270,6 @@ const handleCollectionComplete = (points) => { ...@@ -276,22 +270,6 @@ const handleCollectionComplete = (points) => {
276 }; 270 };
277 271
278 /** 272 /**
279 - * 手动刷新微信步数
280 - */
281 -const handleRefreshSteps = async () => {
282 - if (weRunAuthRef.value && !isRefreshingSteps.value) {
283 - try {
284 - isRefreshingSteps.value = true
285 - await weRunAuthRef.value.refreshSteps()
286 - } catch (error) {
287 - console.error('手动刷新步数失败:', error)
288 - } finally {
289 - isRefreshingSteps.value = false
290 - }
291 - }
292 -}
293 -
294 -/**
295 * 处理微信步数授权状态变化 273 * 处理微信步数授权状态变化
296 * @param {boolean} authorized - 授权状态 274 * @param {boolean} authorized - 授权状态
297 */ 275 */
...@@ -306,10 +284,6 @@ const handleAuthChange = (authorized) => { ...@@ -306,10 +284,6 @@ const handleAuthChange = (authorized) => {
306 */ 284 */
307 const handleStepsSynced = async (data) => { 285 const handleStepsSynced = async (data) => {
308 console.log('微信步数同步完成:', data) 286 console.log('微信步数同步完成:', data)
309 - // 同步成功后重置失败状态
310 - stepsStore.resetUpdateFailed()
311 - // 同步成功后隐藏手动更新按钮
312 - showManualUpdateButton.value = false
313 // 步数同步完成后,重新获取家庭数据 287 // 步数同步完成后,重新获取家庭数据
314 await initPageData() 288 await initPageData()
315 } 289 }
...@@ -320,12 +294,6 @@ const handleStepsSynced = async (data) => { ...@@ -320,12 +294,6 @@ const handleStepsSynced = async (data) => {
320 */ 294 */
321 const handleSyncFailed = (data) => { 295 const handleSyncFailed = (data) => {
322 console.log('微信步数同步失败:', data) 296 console.log('微信步数同步失败:', data)
323 - // 记录更新失败状态到store
324 - stepsStore.setUpdateFailed()
325 - // 显示手动更新按钮
326 - if (data.showManualUpdate) {
327 - showManualUpdateButton.value = true
328 - }
329 } 297 }
330 298
331 /** 299 /**
...@@ -402,19 +370,12 @@ useDidShow(async () => { ...@@ -402,19 +370,12 @@ useDidShow(async () => {
402 // 先初始化基础页面数据(不包含步数相关数据) 370 // 先初始化基础页面数据(不包含步数相关数据)
403 await initPageData(); 371 await initPageData();
404 372
405 - // 检查是否应该显示手动更新按钮 373 + // 正常刷新微信步数数据
406 - if (stepsStore.shouldShowManualUpdate()) {
407 - // 如果之前有更新失败记录,直接显示手动更新按钮,不自动获取步数
408 - showManualUpdateButton.value = true;
409 - console.log('检测到之前步数更新失败,显示手动更新按钮');
410 - } else {
411 - // 没有失败记录,正常刷新微信步数数据
412 if (weRunAuthRef.value) { 374 if (weRunAuthRef.value) {
413 weRunAuthRef.value.checkAuthStatus(true); 375 weRunAuthRef.value.checkAuthStatus(true);
414 } 376 }
415 } 377 }
416 } 378 }
417 - }
418 }) 379 })
419 380
420 useReady(async () => { 381 useReady(async () => {
......
...@@ -149,7 +149,7 @@ service.interceptors.response.use( ...@@ -149,7 +149,7 @@ service.interceptors.response.use(
149 * 处理401未授权状态 149 * 处理401未授权状态
150 * 清除本地sessionid并跳转到登录页 150 * 清除本地sessionid并跳转到登录页
151 */ 151 */
152 - if (response.data.code === 401 && !response.data.msg.includes('同步微信步数失败')) { 152 + if (response.data.code === 401) {
153 // 清除无效的sessionid 153 // 清除无效的sessionid
154 clearSessionId(); 154 clearSessionId();
155 /** 155 /**
......