feat: 登录支持采集用户名,登录守卫统一到 utils/auth.js

- 我的页未登录态用 type=nickname 输入框采集昵称,wxSignin 随手机号一并提交
- 新建共享登录守卫 ensureLogin,替换 itemdetail/itemorder/home 三处副本
- 首页预约记录/就诊人/立即预约入口补充登录拦截
This commit is contained in:
lik
2026-11-08 11:59:47 +08:00
parent 1402b5a91d
commit 46627a73b9
7 changed files with 206 additions and 76 deletions
+7 -28
View File
@@ -1,5 +1,6 @@
const API = require('../../utils/api.js')
const { formatDate, LATEST_APPOINTMENT_TIME, buildTimeSlots } = require('../../utils/date.js')
const { ensureLogin } = require('../../utils/auth.js')
// 陪诊项目下拉单行高度:图标 72rpx + 单行文字 + 上下留白
const SERVICE_OPTION_HEIGHT = 108
@@ -185,28 +186,6 @@ Page({
return 'assist-icon-3'
},
async ensureLogin() {
const app = getApp()
await app.waitForAuth()
if (app.globalData.user?._id) return true
const modal = await new Promise((resolve) => {
wx.showModal({
title: '登录后预约',
content: '登录成功后将继续预约',
confirmText: '去登录',
confirmColor: '#B8520A',
success: resolve,
fail: (err) => {
console.log('登录提示弹窗失败', err)
resolve({ confirm: false })
}
})
})
if (!modal.confirm) return null
wx.removeStorageSync('has_logout')
return app.silentSignin()
},
loadProfiles() {
return API.healthProfile.getMyProfiles({ page: 1, pageSize: 50 })
.then((res) => {
@@ -362,12 +341,12 @@ Page({
if (this.data.submitting) return
this.setData({ submitting: true, showPayPopup: false })
try {
const loggedIn = await this.ensureLogin()
if (loggedIn === null) return
if (!loggedIn || !getApp().globalData.user?._id) {
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
return
}
// 登录守卫统一走 utils/auth.js:取消静默返回,失败由守卫内 toast
const loggedIn = await ensureLogin({
title: '登录后预约',
content: '登录成功后将继续预约'
})
if (!loggedIn) return
if (this.data.profiles.length === 0) await this.loadProfiles()
const error = this.validateOrder()