优化:小程序记住登录与启动跳转
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const auth = require('../../utils/auth')
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const loginFlow = require('../../utils/login-flow')
|
||||
|
||||
function wxLoginCode() {
|
||||
return new Promise((resolve, reject) => wx.login({
|
||||
@@ -44,7 +45,17 @@ Page({
|
||||
|
||||
consumeAppState() {
|
||||
const state = getApp().globalData.wechatLoginState
|
||||
if (state) this.setData({ loginState: state })
|
||||
if (!state) return
|
||||
if (state.status === 'SELECT_SHOP' && state.ticket) {
|
||||
this.setData({
|
||||
loginState: state,
|
||||
shopOptions: shopOptions(state),
|
||||
loginTicket: state.ticket,
|
||||
shopSelectVisible: true
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({ loginState: state })
|
||||
},
|
||||
|
||||
async loadAgreements() {
|
||||
@@ -105,22 +116,26 @@ Page({
|
||||
wx.showToast({ title: this.data.agreementError || '协议版本加载中,请稍后重试', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!this.data.rememberMe) {
|
||||
const confirmed = await new Promise(resolve => wx.showModal({
|
||||
title: '仅本次登录',
|
||||
content: '未勾选“记住我”,下次打开小程序时需要重新点击快捷登录。',
|
||||
confirmText: '继续登录',
|
||||
success: result => resolve(result.confirm),
|
||||
fail: () => resolve(false)
|
||||
}))
|
||||
if (!confirmed) return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
async chooseRememberMode() {
|
||||
if (this.data.rememberMe) return true
|
||||
return new Promise(resolve => wx.showModal({
|
||||
title: '记住登录',
|
||||
content: loginFlow.REMEMBER_LOGIN_PROMPT,
|
||||
confirmText: '记住',
|
||||
cancelText: '不记住',
|
||||
success: result => resolve(loginFlow.resolveRememberChoice(result)),
|
||||
fail: () => resolve(null)
|
||||
}))
|
||||
},
|
||||
|
||||
async quickLogin() {
|
||||
if (this.data.loading || !(await this.ensureCanLogin())) return
|
||||
this.setData({ loading: true })
|
||||
const rememberMe = await this.chooseRememberMode()
|
||||
if (rememberMe === null) return
|
||||
this.setData({ rememberMe, loading: true })
|
||||
try {
|
||||
const result = await authApi.wechatQuickLogin({ wxCode: await wxLoginCode(), ...this.agreementPayload() })
|
||||
this.setData({ loginState: result })
|
||||
|
||||
Reference in New Issue
Block a user