You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
943 B

export function hasLogin() {
return !!uni.getStorageSync('id')
}
export function getCurrentPagePath() {
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
const page = pages[pages.length - 1]
if (!page || !page.route) return '/pages/index/index'
const options = page.options || {}
const query = Object.keys(options)
.filter(key => options[key] !== undefined && options[key] !== null && options[key] !== '')
.map(key => key + '=' + encodeURIComponent(String(options[key])))
.join('&')
return '/' + page.route + (query ? '?' + query : '')
}
export function requireLoginToCurrentPage() {
if (hasLogin()) return true
const redirectKey = 'login_redirect_' + Date.now()
const targetPath = getCurrentPagePath()
uni.setStorageSync(redirectKey, targetPath)
uni.setStorageSync('authPendingTargetPath', targetPath)
uni.redirectTo({
url: '/package2/login/login?redirect=' + redirectKey
})
return false
}