fix: 修复记录页登录状态检测和重试逻辑
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
|
"pages/records/records",
|
||||||
"pages/index/index",
|
"pages/index/index",
|
||||||
"pages/appointment/appointment",
|
"pages/appointment/appointment",
|
||||||
"pages/records/records",
|
|
||||||
"pages/scan/result/index"
|
"pages/scan/result/index"
|
||||||
],
|
],
|
||||||
"window": {
|
"window": {
|
||||||
|
|||||||
@@ -7,20 +7,57 @@ Page({
|
|||||||
records: [],
|
records: [],
|
||||||
filteredRecords: [],
|
filteredRecords: [],
|
||||||
currentTab: 'all',
|
currentTab: 'all',
|
||||||
loading: true
|
loading: true,
|
||||||
|
isLoggedIn: false,
|
||||||
|
loginFailed: false
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
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() {
|
onShow() {
|
||||||
// 仅从预约页返回时刷新,避免 onLoad + onShow 双重加载
|
// 已加载过且已登录时刷新(从预约页返回等场景)
|
||||||
if (this.data._loaded) {
|
if (this.data._loaded && app.globalData.isLoggedIn) {
|
||||||
this.loadRecords()
|
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() {
|
async loadRecords() {
|
||||||
this.setData({ loading: true })
|
this.setData({ loading: true })
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</view>
|
</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-card" wx:for="{{filteredRecords}}" wx:key="_id">
|
||||||
<view class="record-header">
|
<view class="record-header">
|
||||||
<view wx:if="{{item.status === 'approved'}}" class="qrcode-btn" bindtap="showQrcode" data-id="{{item._id}}">
|
<view wx:if="{{item.status === 'approved'}}" class="qrcode-btn" bindtap="showQrcode" data-id="{{item._id}}">
|
||||||
@@ -70,8 +70,15 @@
|
|||||||
<text class="empty-text">加载中...</text>
|
<text class="empty-text">加载中...</text>
|
||||||
</view>
|
</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-icon">📭</text>
|
||||||
<text class="empty-text">暂无预约记录</text>
|
<text class="empty-text">暂无预约记录</text>
|
||||||
<view class="empty-btn" bindtap="goAppointment">去预约</view>
|
<view class="empty-btn" bindtap="goAppointment">去预约</view>
|
||||||
|
|||||||
Reference in New Issue
Block a user