功能:新增微信小程序一键登录
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const auth = require('./auth')
|
||||
const { TAB_PAGES } = require('./config')
|
||||
|
||||
let waitingForAutoLoginNavigation = false
|
||||
|
||||
function buildUrl(path, params) {
|
||||
const query = Object.keys(params || {})
|
||||
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
|
||||
@@ -131,27 +133,51 @@ function openAuth(redirect) {
|
||||
})
|
||||
}
|
||||
|
||||
function showLoginToast(actionText) {
|
||||
wx.showToast({
|
||||
title: `${actionText || '继续操作'}前请先登录`,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
function scheduleOpenAuth(actionText) {
|
||||
showLoginToast(actionText)
|
||||
setTimeout(() => {
|
||||
openAuth()
|
||||
}, 120)
|
||||
}
|
||||
|
||||
function ensureLogin(actionText) {
|
||||
if (auth.isLoggedIn()) {
|
||||
return true
|
||||
}
|
||||
|
||||
wx.showToast({
|
||||
title: `${actionText || '继续操作'}前请先登录`,
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
openAuth()
|
||||
}, 120)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function openProducts(filter) {
|
||||
const app = getApp()
|
||||
app.globalData.pendingProductFilter = filter || {}
|
||||
return switchTab('/pages/products/index')
|
||||
const hasAutoLoginHelpers = app
|
||||
&& typeof app.isWechatMiniAutoLoginPending === 'function'
|
||||
&& typeof app.waitForWechatMiniAutoLogin === 'function'
|
||||
|
||||
if (hasAutoLoginHelpers && app.isWechatMiniAutoLoginPending()) {
|
||||
if (waitingForAutoLoginNavigation) {
|
||||
return false
|
||||
}
|
||||
|
||||
waitingForAutoLoginNavigation = true
|
||||
Promise.resolve(app.waitForWechatMiniAutoLogin())
|
||||
.catch(() => false)
|
||||
.then(() => {
|
||||
if (!auth.isLoggedIn()) {
|
||||
scheduleOpenAuth(actionText)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
waitingForAutoLoginNavigation = false
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
scheduleOpenAuth(actionText)
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -164,5 +190,9 @@ module.exports = {
|
||||
redirectAfterLogin,
|
||||
openAuth,
|
||||
ensureLogin,
|
||||
openProducts
|
||||
openProducts(filter) {
|
||||
const app = getApp()
|
||||
app.globalData.pendingProductFilter = filter || {}
|
||||
return switchTab('/pages/products/index')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user