fix:登录跳转优化

main
wx-jincw 2 weeks ago
parent 71aa31628d
commit 175974b438

@ -8,6 +8,47 @@ import auth from './wechat';
import { LOGIN_STATUS, USER_INFO, EXPIRES_TIME, STATE_R_KEY, BACK_URL} from './../config/cache';
const LOGIN_PAGE_ROUTE = 'pages/users/login/index';
const WECHAT_LOGIN_PAGE_ROUTE = 'pages/users/wechat_login/index';
function normalizeRoute(route) {
return (route || '').replace(/^\//, '');
}
function getPrevPageRoute() {
const pages = getCurrentPages();
if (pages.length < 2) {
return '';
}
return normalizeRoute(pages[pages.length - 2].route);
}
/**
* 登录页 微信登录页切换上一页已是目标页则返回避免反复 navigateTo 堆栈
*/
export function switchLoginPage(url) {
const targetRoute = normalizeRoute((url || '').split('?')[0].replace(/^\//, ''));
const prevRoute = getPrevPageRoute();
if (prevRoute && prevRoute === targetRoute && url.indexOf('?') === -1) {
uni.navigateBack();
return;
}
uni.navigateTo({ url });
}
/**
* 微信授权后进入账号绑定页replace 当前页避免栈里叠多层登录相关页面
*/
export function openLoginBindPage(authKey) {
const url = `/pages/users/login/index?bindWechat=1&authKey=${encodeURIComponent(authKey)}`;
const prevRoute = getPrevPageRoute();
if (prevRoute === LOGIN_PAGE_ROUTE) {
uni.redirectTo({ url });
return;
}
uni.redirectTo({ url });
}
function prePage(){
let pages = getCurrentPages();
let prePage = pages[pages.length - 1];

@ -88,6 +88,9 @@
import {
VUE_APP_API_URL
} from "@/utils";
import {
switchLoginPage
} from '@/libs/login';
// #ifdef MP-WEIXIN
import {
wxGZHAuth
@ -520,9 +523,7 @@
});
},
goWechatLogin() {
uni.navigateTo({
url: "/pages/users/wechat_login/index"
});
switchLoginPage('/pages/users/wechat_login/index');
},
getUserInfo(data){
this.$store.commit("SETUID", data.uid);

@ -63,6 +63,10 @@
} from '@/api/user.js'
import Routine from '@/libs/routine';
import wechat from "@/libs/wechat";
import {
switchLoginPage,
openLoginBindPage
} from '@/libs/login';
export default {
data() {
return {
@ -182,24 +186,18 @@
title: '请先点击上方「微信登录」完成授权'
});
}
uni.navigateTo({
url: '/pages/users/login/index?bindWechat=1&authKey=' + encodeURIComponent(this.pendingBindAuthKey)
});
openLoginBindPage(this.pendingBindAuthKey);
},
/**
* 新微信用户且关闭强制手机号跳转绑定页
*/
goWechatBindLogin(authKey) {
this.pendingBindAuthKey = authKey;
uni.navigateTo({
url: '/pages/users/login/index?bindWechat=1&authKey=' + encodeURIComponent(authKey)
});
openLoginBindPage(authKey);
},
// #endif
goAccountLogin() {
uni.navigateTo({
url: '/pages/users/login/index'
});
switchLoginPage('/pages/users/login/index');
},
back() {
uni.navigateBack();

Loading…
Cancel
Save