hookehuyr

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

移除Dashboard页面中手动更新步数的按钮及相关逻辑
在WeRunAuth组件中添加测试用户检查逻辑
简化401未授权状态的处理条件
......@@ -125,6 +125,27 @@ const getWeRunData = async () => {
try {
isLoading.value = true
// 检查是否为测试用户(openid以h-开头),如果是则跳过步数同步
try {
const { getUserProfileAPI } = await import('@/api/user')
const profileResponse = await getUserProfileAPI()
if (profileResponse.code === 1 && profileResponse.data?.user?.openid) {
const openid = profileResponse.data.user.openid
if (openid.startsWith('h-')) {
console.log('检测到测试用户openid:', openid, '跳过步数同步')
Taro.showToast({
title: '测试用户无需同步步数',
icon: 'none',
duration: 2000
})
isLoading.value = false
return
}
}
} catch (profileError) {
console.warn('获取用户信息失败,继续执行步数同步:', profileError)
}
// 先调用 wx.login 获取 code
const loginRes = await Taro.login()
......
......@@ -35,11 +35,7 @@
<span class="ml-1 text-gray-500">步</span>
</view>
<view class="flex gap-2">
<view v-if="showManualUpdateButton" class="bg-green-500 text-white px-4 py-2 rounded-full text-xs" @click="handleRefreshSteps" :class="{ 'opacity-50': isRefreshingSteps }">
<text v-if="!isRefreshingSteps">手动更新</text>
<text v-else>更新中...</text>
</view>
<view class="bg-blue-500 text-white px-4 py-2 rounded-full text-xs" @click="handleCollectAll">
<view class="bg-blue-500 text-white px-4 py-2 rounded-full text-sm" @click="handleCollectAll">
一键收取
</view>
</view>
......@@ -216,8 +212,6 @@ const weRunAuthRef = ref(null)
const showTotalPointsOnly = ref(false)
const finalTotalPoints = ref(0)
const pendingPoints = ref([]) // 待收集的积分数据
const showManualUpdateButton = ref(false) // 是否显示手动更新步数按钮
const isRefreshingSteps = ref(false) // 手动更新步数的loading状态
const familyName = ref('')
const familySlogn = ref('')
......@@ -276,22 +270,6 @@ const handleCollectionComplete = (points) => {
};
/**
* 手动刷新微信步数
*/
const handleRefreshSteps = async () => {
if (weRunAuthRef.value && !isRefreshingSteps.value) {
try {
isRefreshingSteps.value = true
await weRunAuthRef.value.refreshSteps()
} catch (error) {
console.error('手动刷新步数失败:', error)
} finally {
isRefreshingSteps.value = false
}
}
}
/**
* 处理微信步数授权状态变化
* @param {boolean} authorized - 授权状态
*/
......@@ -306,10 +284,6 @@ const handleAuthChange = (authorized) => {
*/
const handleStepsSynced = async (data) => {
console.log('微信步数同步完成:', data)
// 同步成功后重置失败状态
stepsStore.resetUpdateFailed()
// 同步成功后隐藏手动更新按钮
showManualUpdateButton.value = false
// 步数同步完成后,重新获取家庭数据
await initPageData()
}
......@@ -320,12 +294,6 @@ const handleStepsSynced = async (data) => {
*/
const handleSyncFailed = (data) => {
console.log('微信步数同步失败:', data)
// 记录更新失败状态到store
stepsStore.setUpdateFailed()
// 显示手动更新按钮
if (data.showManualUpdate) {
showManualUpdateButton.value = true
}
}
/**
......@@ -402,16 +370,9 @@ useDidShow(async () => {
// 先初始化基础页面数据(不包含步数相关数据)
await initPageData();
// 检查是否应该显示手动更新按钮
if (stepsStore.shouldShowManualUpdate()) {
// 如果之前有更新失败记录,直接显示手动更新按钮,不自动获取步数
showManualUpdateButton.value = true;
console.log('检测到之前步数更新失败,显示手动更新按钮');
} else {
// 没有失败记录,正常刷新微信步数数据
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
// 正常刷新微信步数数据
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
}
}
......
......@@ -149,7 +149,7 @@ service.interceptors.response.use(
* 处理401未授权状态
* 清除本地sessionid并跳转到登录页
*/
if (response.data.code === 401 && !response.data.msg.includes('同步微信步数失败')) {
if (response.data.code === 401) {
// 清除无效的sessionid
clearSessionId();
/**
......