feat: 支持游客免登录浏览核心页面

未登录用户可先浏览衣橱、穿搭、运势、分享等内容,登录改为用户主动选择,并在登录页增加协议勾选确认与暂不登录入口。
This commit is contained in:
2026-09-16 21:44:04 +08:00
parent c07a969642
commit 45222317af
47 changed files with 996 additions and 12150 deletions
+60 -1
View File
@@ -27,11 +27,27 @@ Page({
{ text: '稍后再说', value: '' },
{ text: '去完善', value: 'ok', type: 'main' },
],
// 协议同意:默认不勾选,由用户自主阅读后自行选择(微信审核合规要求)
agreed: false,
consentVisible: false,
consentButtons: [
{ text: '不同意', value: '' },
{ text: '同意并继续', value: 'ok', type: 'main' },
],
},
onLoad(query: Record<string, string>) {
logger.debug(LOG, 'onLoad, query=', JSON.stringify(query), 'isLoggedIn=', auth.isLoggedIn())
if (query.redirect) this.setData({ redirect: query.redirect })
if (query.redirect) {
// goLogin 侧对 redirect 做了 encodeURIComponent,这里解码还原(decode 失败时用原值兜底)
let redirect = query.redirect
try {
redirect = decodeURIComponent(redirect)
} catch (e) {
logger.warn(LOG, 'redirect 解码失败,使用原值, err=', e)
}
this.setData({ redirect })
}
if (auth.isLoggedIn()) {
this.goAfterLogin()
}
@@ -57,11 +73,54 @@ Page({
})
},
// 勾选 / 取消勾选协议:完全由用户操作驱动,不存在默认勾选
onToggleAgree() {
const agreed = !this.data.agreed
logger.debug(LOG, '协议勾选状态切换, agreed=', agreed)
this.setData({ agreed })
},
// 未勾选协议点击登录:弹窗二次确认,由用户主动选择是否同意
onLogin() {
if (this.data.loading) {
logger.debug(LOG, '登录中,忽略重复点击')
return
}
if (!this.data.agreed) {
logger.info(LOG, '未勾选协议,弹出确认弹窗')
this.setData({ consentVisible: true })
return
}
this.doLogin()
},
onConsentCancel() {
logger.debug(LOG, '用户未同意协议,停留在登录页')
this.setData({ consentVisible: false })
},
onConsentConfirm(e: WechatMiniprogram.CustomEvent) {
this.setData({ consentVisible: false })
// 弹窗主按钮才代表同意;其余分支(不同意)只关闭弹窗,用户仍可浏览
if (e.detail.value !== 'ok') {
logger.info(LOG, '用户选择不同意协议')
return
}
logger.info(LOG, '用户同意协议,继续登录')
this.setData({ agreed: true })
this.doLogin()
},
// 暂不登录:回到衣橱首页继续浏览(游客态),不产生任何授权请求
onBrowse() {
logger.info(LOG, '用户选择先逛逛,返回衣橱继续浏览')
wx.switchTab({
url: '/pages/wardrobe/wardrobe',
fail: (e) => logger.warn(LOG, 'switchTab 衣橱失败, err=', e && e.errMsg),
})
},
doLogin() {
logger.debug(LOG, '点击登录, redirect=', this.data.redirect)
this.setData({ loading: true })