fix: 修复记录页登录状态检测和重试逻辑
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user