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 }