fix: 修复记录页登录状态检测和重试逻辑

This commit is contained in:
ws
2026-04-30 12:17:14 +08:00
parent 98f5c7bc49
commit c6bef45940
3 changed files with 52 additions and 7 deletions
+2 -1
View File
@@ -1,8 +1,9 @@
{
"pages": [
"pages/records/records",
"pages/index/index",
"pages/appointment/appointment",
"pages/records/records",
"pages/scan/result/index"
],
"window": {
+41 -4
View File
@@ -7,20 +7,57 @@ Page({
records: [],
filteredRecords: [],
currentTab: 'all',
loading: true
loading: true,
isLoggedIn: false,
loginFailed: false
},
onLoad() {
this.loadRecords()
if (app.globalData.isLoggedIn) {
this.onLoginReady()
} else if (app.globalData.loginFailed) {
this.onLoginFailed()
} else {
app.loginReadyCallback = (userInfo) => {
app.loginReadyCallback = null
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
}
}
},
onShow() {
// 仅从预约页返回时刷新,避免 onLoad + onShow 双重加载
if (this.data._loaded) {
// 已加载过且已登录时刷新(从预约页返回等场景)
if (this.data._loaded && app.globalData.isLoggedIn) {
this.loadRecords()
}
},
onLoginReady() {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadRecords()
},
onLoginFailed() {
this.setData({ isLoggedIn: false, loginFailed: true, loading: false })
},
onRetry() {
this.setData({ loginFailed: false, loading: true })
app.silentLogin()
app.loginReadyCallback = (userInfo) => {
app.loginReadyCallback = null
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
}
},
async loadRecords() {
this.setData({ loading: true })
try {
+9 -2
View File
@@ -20,7 +20,7 @@
</view>
<!-- 记录列表 -->
<view class="record-list" wx:if="{{!loading && filteredRecords.length > 0}}">
<view class="record-list" wx:if="{{!loading && !loginFailed && filteredRecords.length > 0}}">
<view class="record-card" wx:for="{{filteredRecords}}" wx:key="_id">
<view class="record-header">
<view wx:if="{{item.status === 'approved'}}" class="qrcode-btn" bindtap="showQrcode" data-id="{{item._id}}">
@@ -70,8 +70,15 @@
<text class="empty-text">加载中...</text>
</view>
<!-- 登录失败 -->
<view class="empty" wx:if="{{loginFailed}}">
<text class="empty-icon">⚠️</text>
<text class="empty-text">登录失败,请重试</text>
<view class="empty-btn" bindtap="onRetry">重新登录</view>
</view>
<!-- 空状态 -->
<view class="empty" wx:if="{{!loading && filteredRecords.length === 0}}">
<view class="empty" wx:if="{{!loading && !loginFailed && filteredRecords.length === 0}}">
<text class="empty-icon">📭</text>
<text class="empty-text">暂无预约记录</text>
<view class="empty-btn" bindtap="goAppointment">去预约</view>