增加线上配置分享功能+用户后台登录,不影响首页渲染

This commit is contained in:
chenglijuan
2026-05-20 14:24:54 +08:00
parent dbfc8011c4
commit 643f37b06e
8 changed files with 153 additions and 157 deletions
+20 -12
View File
@@ -34,20 +34,15 @@ Page({
},
onLoad() {
if (app.globalData.isLoggedIn) {
this._awaitLoginAndInit()
},
async _awaitLoginAndInit() {
const userInfo = await app.waitLogin(true)
if (userInfo) {
this.initPage()
} else if (app.globalData.loginFailed) {
this.showLoginTipAndGoBack()
} else {
// 登录异步未完成,等待回调
app.loginReadyCallback = (userInfo) => {
app.loginReadyCallback = null
if (userInfo) {
this.initPage()
} else {
this.showLoginTipAndGoBack()
}
}
this.showLoginTipAndGoBack()
}
},
@@ -292,5 +287,18 @@ Page({
console.error('提交预约失败', err)
wx.showToast({ title: '提交失败,请重试', icon: 'none' })
}
},
onShareAppMessage(res) {
return {
title: '访客预约',
path: '/pages/index/index'
}
},
onShareTimeline() {
return {
title: '访客预约'
}
}
})
+31 -30
View File
@@ -11,45 +11,33 @@ Page({
},
onLoad() {
// 首页不阻塞,直接渲染;有缓存登录态时立即加载数据
if (app.globalData.isLoggedIn) {
this.onLoginReady()
} else if (app.globalData.loginFailed) {
this.onLoginFailed()
} else {
app.loginReadyCallback = (userInfo) => {
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
}
}
},
onShow() {
if (app.globalData.isLoggedIn) {
this.setData({ isLoggedIn: true })
this.loadLatestRecord()
}
},
onLoginReady() {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadLatestRecord()
async onShow() {
// 每次显示时等待登录完成,再加载最新数据
const userInfo = await app.waitLogin(true)
if (userInfo) {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadLatestRecord()
} else {
this.setData({ isLoggedIn: false, loginFailed: true })
}
},
onLoginFailed() {
this.setData({ isLoggedIn: false, loginFailed: true })
},
onRetry() {
async onRetry() {
this.setData({ loginFailed: false })
app.silentLogin()
app.loginReadyCallback = (userInfo) => {
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
const userInfo = await app.waitLogin()
if (userInfo) {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadLatestRecord()
} else {
this.setData({ loginFailed: true })
}
},
@@ -85,5 +73,18 @@ Page({
showQrcode(e) {
this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
},
onShareAppMessage(res) {
return {
title: '访客预约',
path: '/pages/index/index'
}
},
onShareTimeline() {
return {
title: '访客预约'
}
}
})
+4 -11
View File
@@ -1,16 +1,9 @@
<!--index.wxml-->
<view class="page">
<!-- loading 遮罩 -->
<view class="loading-mask" wx:if="{{!isLoggedIn && !loginFailed}}">
<view class="loading-spinner"></view>
<text class="loading-text">正在获取身份信息...</text>
</view>
<!-- 登录失败 -->
<view class="loading-mask" wx:if="{{loginFailed}}">
<text class="fail-icon">⚠️</text>
<text class="fail-text">网络异常,请重试</text>
<view class="retry-btn" bindtap="onRetry">重新加载</view>
<!-- 登录失败提示条(不遮挡页面) -->
<view class="login-fail-bar" wx:if="{{loginFailed && !isLoggedIn}}">
<text>网络异常,无法获取身份信息</text>
<text class="retry-link" bindtap="onRetry">重试</text>
</view>
<view class="header">
+12 -55
View File
@@ -21,67 +21,24 @@ page {
line-height: 1;
}
/* loading 遮罩 */
.loading-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #f0f5fa;
/* 登录失败提示条(不遮挡页面) */
.login-fail-bar {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 999;
}
.loading-spinner {
width: 64rpx;
height: 64rpx;
border: 6rpx solid #dbeafe;
border-top: 6rpx solid #5b9bd5;
border-radius: 50%;
animation: spin 0.8s linear infinite;
margin-bottom: 24rpx;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.loading-text {
font-size: 28rpx;
color: #7f8fa6;
letter-spacing: 2rpx;
}
/* 登录失败 */
.fail-icon {
font-size: 80rpx;
justify-content: space-between;
background: #fff3e0;
color: #e6a23c;
font-size: 24rpx;
padding: 16rpx 24rpx;
border-radius: 12rpx;
margin-bottom: 20rpx;
}
.fail-text {
font-size: 28rpx;
color: #7f8fa6;
margin-bottom: 32rpx;
}
.retry-btn {
font-size: 28rpx;
color: #fff;
background: linear-gradient(135deg, #5b9bd5, #4a8bc2);
padding: 16rpx 56rpx;
border-radius: 40rpx;
.login-fail-bar .retry-link {
color: #5b9bd5;
font-weight: 600;
letter-spacing: 2rpx;
box-shadow: 0 4rpx 16rpx rgba(91, 155, 213, 0.3);
}
.retry-btn:active {
opacity: 0.85;
flex-shrink: 0;
margin-left: 20rpx;
}
.header-title {
+29 -29
View File
@@ -13,19 +13,16 @@ Page({
},
onLoad() {
if (app.globalData.isLoggedIn) {
this.onLoginReady()
} else if (app.globalData.loginFailed) {
this.onLoginFailed()
this._awaitLoginAndLoad()
},
async _awaitLoginAndLoad() {
const userInfo = await app.waitLogin(true)
if (userInfo) {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadRecords()
} else {
app.loginReadyCallback = (userInfo) => {
app.loginReadyCallback = null
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
}
this.setData({ isLoggedIn: false, loginFailed: true, loading: false })
}
},
@@ -36,25 +33,15 @@ Page({
}
},
onLoginReady() {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadRecords()
},
onLoginFailed() {
this.setData({ isLoggedIn: false, loginFailed: true, loading: false })
},
onRetry() {
async onRetry() {
this.setData({ loginFailed: false, loading: true })
app.silentLogin()
app.loginReadyCallback = (userInfo) => {
app.loginReadyCallback = null
if (userInfo) {
this.onLoginReady()
} else {
this.onLoginFailed()
}
const userInfo = await app.waitLogin()
if (userInfo) {
this.setData({ isLoggedIn: true, loginFailed: false })
this.loadRecords()
} else {
this.setData({ loginFailed: true })
}
},
@@ -122,5 +109,18 @@ Page({
showQrcode(e) {
this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
},
onShareAppMessage(res) {
return {
title: '访客预约',
path: '/pages/index/index'
}
},
onShareTimeline() {
return {
title: '访客预约'
}
}
})
+13
View File
@@ -94,5 +94,18 @@ Page({
this.setData({ verifying: false })
wx.showToast({ title: err.message || '核销失败,请稍后重试', icon: 'none' })
}
},
onShareAppMessage(res) {
return {
title: '访客预约',
path: '/pages/index/index'
}
},
onShareTimeline() {
return {
title: '访客预约'
}
}
})