refactor: 统一替换登录跳转逻辑为通用方法

将项目内多处手动调用$refs.login.open的登录跳转逻辑,统一替换为新增的redirectTologin通用方法,简化代码并提升维护性,同时统一处理了延迟和nextTick调用逻辑。
This commit is contained in:
2026-06-27 16:52:25 +08:00
parent aee630b546
commit f794a2ae27
38 changed files with 130 additions and 155 deletions

View File

@@ -245,6 +245,19 @@ export default {
this.$store.dispatch('getCartNumber'); //重新获取购物车数据 this.$store.dispatch('getCartNumber'); //重新获取购物车数据
this.$util.redirectTo(this.$util.INDEX_PAGE_URL); this.$util.redirectTo(this.$util.INDEX_PAGE_URL);
} }
},
/**
* 重新定向到登录授权
* @param {String} backUrl
* @param {Object} params
*/
redirectTologin(backUrl = '', params = {}) {
setTimeout(() => {
this.$nextTick(() => {
this.$refs?.login?.open(backUrl, 'redirectTo');
});
}, 0);
} }
}, },
filters: { filters: {

View File

@@ -983,4 +983,4 @@
] ]
} }
} }
} }

View File

@@ -262,9 +262,9 @@ export default {
return this.whetherCollection; return this.whetherCollection;
} else { } else {
if (this.source_member) { if (this.source_member) {
this.$refs.login.open(this.shareUrl + '&source_member=' + this.source_member, 'redirectTo'); this.redirectTologin(this.shareUrl + '&source_member=' + this.source_member);
} else { } else {
this.$refs.login.open(this.shareUrl, 'redirectTo'); this.redirectTologin(this.shareUrl);
} }
} }
}, },

View File

@@ -83,7 +83,7 @@ export default {
}); });
}, },
toLogin() { toLogin() {
this.$refs.login.open('/pages_goods/category', 'redirectTo'); this.redirectTologin('/pages_goods/category');
} }
}, },
onPullDownRefresh() { onPullDownRefresh() {

View File

@@ -260,7 +260,7 @@ export default {
// 加入购物车 // 加入购物车
joinCart() { joinCart() {
if (!this.storeToken && this.preview == 0) { if (!this.storeToken && this.preview == 0) {
this.$refs.login.open(this.shareUrl, 'redirectTo'); this.redirectTologin(this.shareUrl);
return; return;
} }
if (this.goodsSkuDetail.is_virtual == 1) { if (this.goodsSkuDetail.is_virtual == 1) {
@@ -276,7 +276,7 @@ export default {
// 立即购买 // 立即购买
buyNow() { buyNow() {
if (!this.storeToken && this.preview == 0) { if (!this.storeToken && this.preview == 0) {
this.$refs.login.open(this.shareUrl, 'redirectTo'); this.redirectTologin(this.shareUrl);
return; return;
} }
this.$refs.goodsSku.show("buy_now", () => { this.$refs.goodsSku.show("buy_now", () => {
@@ -352,7 +352,7 @@ export default {
}, },
}); });
} else { } else {
this.$refs.login.open(this.shareUrl, 'redirectTo'); this.redirectTologin(this.shareUrl);
this.couponBtnSwitch = false; this.couponBtnSwitch = false;
} }
}, },

View File

@@ -76,7 +76,7 @@ export default {
} else { } else {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.loadingCover.hide(); this.$refs.loadingCover.hide();
this.$refs.login.open(this.$util.getCurrentRoute().path, 'redirectTo'); this.redirectTologin(this.$util.getCurrentRoute().path);
}) })
} }
this.getTransactionAgreement(); this.getTransactionAgreement();

View File

@@ -65,9 +65,8 @@ export default {
}, 1000); }, 1000);
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/childfenxiao');
this.$refs.login.open('/pages_promotion/fenxiao/childfenxiao', 'redirectTo'); return;
});
} }
}, },
methods: { methods: {

View File

@@ -290,16 +290,14 @@ export default {
}, },
mixins: [fenxiaoWords], mixins: [fenxiaoWords],
onShow() { onShow() {
if (this.fenxiaoWords && this.fenxiaoWords.concept) this.$langConfig.title(this.fenxiaoWords.concept + this.$lang('center')); if (!this.storeToken) {
this.redirectTologin('/pages_promotion/fenxiao/index');
if (this.storeToken) { return;
this.checkFenxiaoIsStart();
} else {
this.$nextTick(() => {
this.$refs.login.open('/pages_promotion/fenxiao/index', 'redirectTo');
});
} }
if (this.fenxiaoWords && this.fenxiaoWords.concept) this.$langConfig.title(this.fenxiaoWords.concept + this.$lang('center'));
this.checkFenxiaoIsStart();
this.getTemplateId(); this.getTemplateId();
this.getPoster(); this.getPoster();
}, },

View File

@@ -155,9 +155,7 @@ export default {
if (this.fenxiaoWords && this.fenxiaoWords.concept) this.$langConfig.title(this.fenxiaoWords.concept + this.$lang('orderSuffix')); if (this.fenxiaoWords && this.fenxiaoWords.concept) this.$langConfig.title(this.fenxiaoWords.concept + this.$lang('orderSuffix'));
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/order');
this.$refs.login.open('/pages_promotion/fenxiao/order', 'redirectTo');
});
} }
}, },
methods: { methods: {

View File

@@ -115,9 +115,7 @@ export default {
if (this.storeToken) { if (this.storeToken) {
this.getOrderData(); this.getOrderData();
} else { } else {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/order_detail?id=' + this.orderId);
this.$refs.login.open('/pages_promotion/fenxiao/order_detail?id=' + this.orderId, 'redirectTo');
});
} }
}, },
methods: { methods: {

View File

@@ -94,9 +94,7 @@ export default {
this.getPromoteRule(); this.getPromoteRule();
this.getFenxiaoDetail(); this.getFenxiaoDetail();
} else { } else {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/promote_code');
this.$refs.login.open('/pages_promotion/fenxiao/promote_code', 'redirectTo');
});
} }
}, },
onLoad() { onLoad() {

View File

@@ -174,9 +174,7 @@ export default {
} }
} else { } else {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/promote_code');
this.$refs.login.open('/pages_promotion/fenxiao/promote_code', 'redirectTo');
});
} }
}, },
onShow() { onShow() {

View File

@@ -122,9 +122,7 @@ export default {
this.getFenXiaoLevel(); this.getFenXiaoLevel();
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/team');
this.$refs.login.open('/pages_promotion/fenxiao/team', 'redirectTo');
});
} }
}, },
methods: { methods: {

View File

@@ -78,9 +78,7 @@ export default {
if (this.fenxiaoWords && this.fenxiaoWords.withdraw) this.$langConfig.title(this.fenxiaoWords.withdraw + this.$lang('detailSuffix')); if (this.fenxiaoWords && this.fenxiaoWords.withdraw) this.$langConfig.title(this.fenxiaoWords.withdraw + this.$lang('detailSuffix'));
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_promotion/fenxiao/withdraw_list');
this.$refs.login.open('/pages_promotion/fenxiao/withdraw_list', 'redirectTo');
});
} }
}, },
mixins: [fenxiaoWords], mixins: [fenxiaoWords],

View File

@@ -218,7 +218,7 @@
}, },
toLogin() { toLogin() {
this.$refs.login.open('/pages_goods/category', 'redirectTo'); this.redirectTologin('/pages_goods/category');
} }
}, },
// onPullDownRefresh() { // onPullDownRefresh() {

View File

@@ -442,7 +442,7 @@ export default {
// 立即购买 // 立即购买
exchange() { exchange() {
if (!this.storeToken) { if (!this.storeToken) {
this.$refs.login.open('/pages_promotion/point/detail?id=' + this.id, 'redirectTo'); this.redirectTologin('/pages_promotion/point/detail?id=' + this.id);
return; return;
} }
this.$refs.goodsSku.show('point'); this.$refs.goodsSku.show('point');

View File

@@ -490,7 +490,7 @@ export default {
}, },
//跳转至登录页面 //跳转至登录页面
login() { login() {
this.$refs.login.open('/pages_promotion/point/list', 'redirectTo'); this.redirectTologin('/pages_promotion/point/list');
}, },
imgError(index) { imgError(index) {
this.goodsList[index].image = this.$util.getDefaultImage().goods; this.goodsList[index].image = this.$util.getDefaultImage().goods;
@@ -521,7 +521,8 @@ export default {
*/ */
redirect(url) { redirect(url) {
if (!this.storeToken) { if (!this.storeToken) {
this.$refs.login.open(url, 'redirectTo'); this.redirectTologin(url);
return;
} else { } else {
this.$util.redirectTo(url); this.$util.redirectTo(url);
} }

View File

@@ -124,14 +124,13 @@ export default {
}, 2000); }, 2000);
} }
}, 1000); }, 1000);
if (!this.storeToken) {
this.$nextTick(() => {
this.$refs.login.open('/pages_promotion/point/order_list', 'redirectTo');
});
}
}, },
onShow() { onShow() {
if (!this.storeToken) {
this.redirectTologin('/pages_promotion/point/order_list');
return;
}
if (this.$refs.mescroll) this.$refs.mescroll.refresh(); if (this.$refs.mescroll) this.$refs.mescroll.refresh();
}, },
watch: { watch: {

View File

@@ -44,13 +44,14 @@
}); });
} }
} }
if (this.storeToken) { },
this.getData(); onShow() {
} else { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/form/form?id=' + this.id);
this.$refs.login.open('/pages_tool/form/form?id=' + this.id, 'redirectTo'); return;
}) }
}
this.getData();
}, },
watch: { watch: {
storeToken: function(nVal, oVal) { storeToken: function(nVal, oVal) {

View File

@@ -200,7 +200,8 @@ export default {
}); });
} else { } else {
this.couponBtnSwitch = false; this.couponBtnSwitch = false;
this.$refs.login.open('/pages_tool/goods/coupon', 'redirectTo'); this.redirectTologin('/pages_tool/goods/coupon');
return;
} }
}, },
//获取优惠券列表 //获取优惠券列表

View File

@@ -133,7 +133,7 @@
}, },
receiveGoodsCoupon(couponTypeId) { receiveGoodsCoupon(couponTypeId) {
if (!this.storeToken) { if (!this.storeToken) {
this.$refs.login.open('/pages_tool/goods/coupon_receive?coupon_type_id=' + this.couponTypeId); this.redirectTologin('/pages_tool/goods/coupon_receive?coupon_type_id=' + this.couponTypeId);
return; return;
} }

View File

@@ -84,9 +84,7 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/account');
this.$refs.login.open('/pages_tool/member/account', 'redirectTo');
}, 100);
return; return;
} }
this.getTransferType(); this.getTransferType();

View File

@@ -128,16 +128,13 @@ export default {
if (option.type) this.localType = option.type; if (option.type) this.localType = option.type;
}, },
onShow() { onShow() {
if (!this.storeToken) {
this.redirectTologin('/pages_tool/member/address');
return;
}
uni.removeStorageSync('addressInfo'); uni.removeStorageSync('addressInfo');
if (this.$refs.mescroll) this.$refs.mescroll.refresh();
if (this.storeToken) {
if (this.$refs.mescroll) this.$refs.mescroll.refresh();
} else {
// 使用redirectTo模式:当前页被登录页替换,返回时直接回到上一页,不会产生循环
setTimeout(() => {
this.$refs.login.open('/pages_tool/member/address', 'redirectTo');
}, 100);
}
}, },
methods: { methods: {
getListData(mescroll) { getListData(mescroll) {

View File

@@ -85,11 +85,9 @@ export default {
menuButtonBounding: {} // 小程序胶囊属性 menuButtonBounding: {} // 小程序胶囊属性
}; };
}, },
async onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/balance');
this.$refs.login.open('/pages_tool/member/balance', 'redirectTo');
}, 100);
return; return;
} }
this.getWithdrawConfig(); this.getWithdrawConfig();

View File

@@ -95,9 +95,7 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/balance_detail');
this.$refs.login.open('/pages_tool/member/balance_detail', 'redirectTo');
}, 100);
return; return;
} }
}, },

View File

@@ -80,9 +80,7 @@
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/bind_mobile');
this.$refs.login.open('/pages_tool/member/bind_mobile', 'redirectTo');
}, 100);
return; return;
} }
}, },

View File

@@ -138,17 +138,13 @@ export default {
mpShareData: null //小程序分享数据 mpShareData: null //小程序分享数据
}; };
}, },
onLoad() { onShow() {
//会员卡
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/member/card');
this.$refs.login.open('/pages_tool/member/card', 'redirectTo');
});
return; return;
} }
this.isIphoneX = this.$util.uniappIsIPhoneX(); this.isIphoneX = this.$util.uniappIsIPhoneX();
this.levelId = this.memberInfo.member_level; this.levelId = this.memberInfo.member_level;
let levelInfo = this.memberInfo.member_level_info; let levelInfo = this.memberInfo.member_level_info;
@@ -160,9 +156,9 @@ export default {
value: charge_rule[key] value: charge_rule[key]
}); });
}); });
this.levelInfo = levelInfo; this.levelInfo = levelInfo;
},
onShow() {
//小程序分享 //小程序分享
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
this.$util.getMpShare('/pages_tool/member/card').then(res => { this.$util.getMpShare('/pages_tool/member/card').then(res => {

View File

@@ -293,17 +293,16 @@ export default {
onLoad() { onLoad() {
//会员卡 //会员卡
this.isIphoneX = this.$util.uniappIsIPhoneX(); this.isIphoneX = this.$util.uniappIsIPhoneX();
},
if (this.storeToken) { onShow() {
this.getCardList(); if (!this.storeToken) {
} else { this.redirectTologin('/pages_tool/member/card_buy');
this.$nextTick(() => { return;
this.$refs.login.open('/pages_tool/member/card_buy', 'redirectTo');
});
} }
this.getCardList();
this.getAgreement(); this.getAgreement();
}, },
onShow() { },
watch: { watch: {
storeToken: function (nVal, oVal) { storeToken: function (nVal, oVal) {
if (nVal) { if (nVal) {

View File

@@ -81,14 +81,13 @@ export default {
currentFilter: 'all' currentFilter: 'all'
}; };
}, },
onLoad() { onLoad() {},
onShow() {
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/member/card_log');
this.$refs.login.open('/pages_tool/member/card_log', 'redirectTo');
});
return; return;
} }
this.loadStat(); this.loadStat();
}, },
methods: { methods: {
// 加载统计数据 // 加载统计数据

View File

@@ -84,29 +84,30 @@ export default {
}; };
}, },
onLoad(data) { onLoad(data) {
setTimeout( () => { setTimeout(() => {
if (!this.addonIsExist.coupon) { this.$nextTick(() => {
this.$util.showToast({ if (!this.addonIsExist.coupon) {
title: this.$lang('merchantNotEnabled'), this.$util.showToast({
mask: true, title: this.$lang('merchantNotEnabled'),
duration: 2000 mask: true,
}); duration: 2000
setTimeout(() => { });
this.$util.redirectTo(this.$util.INDEX_PAGE_URL); setTimeout(() => {
}, 2000); this.$util.redirectTo(this.$util.INDEX_PAGE_URL);
} }, 2000);
},1000); }
});
}, 0);
if (data.related_id) this.related_id = data.related_id ? data.related_id : 0; if (data.related_id) this.related_id = data.related_id ? data.related_id : 0;
this.isIphoneX = this.$util.uniappIsIPhoneX(); this.isIphoneX = this.$util.uniappIsIPhoneX();
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/coupon');
this.$refs.login.open('/pages_tool/member/coupon', 'redirectTo');
}, 100);
return; return;
} }
if (this.$refs.mescroll) this.$refs.mescroll.refresh(); if (this.$refs.mescroll) this.$refs.mescroll.refresh();
}, },
methods: { methods: {

View File

@@ -245,17 +245,16 @@
posterMsg: '' //海报错误信息 posterMsg: '' //海报错误信息
}; };
}, },
onLoad(option) { onLoad(option) {},
this.getBaseInfo(); onShow() {
if (this.storeToken) { if (!this.storeToken) {
this.getList(); this.redirectTologin('/pages_tool/member/invite_friends');
} else { return;
this.$nextTick(() => {
this.$refs.login.open('/pages_tool/member/invite_friends', 'redirectTo');
});
} }
this.getBaseInfo();
this.getList();
}, },
onShow() {},
mixins: [inviteFriends], mixins: [inviteFriends],
onReady() {} onReady() {}
}; };

View File

@@ -217,22 +217,20 @@
} }
} }
}, },
onLoad() { onShow() {
this.getLevelRule();
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/member/level');
this.$refs.login.open('/pages_tool/member/level', 'redirectTo'); return;
}); }
} else {
this.getLevelList(); this.getLevelRule();
} this.getLevelList();
// #ifdef MP-ALIPAY // #ifdef MP-ALIPAY
this.scaleX = 1 this.scaleX = 1
this.scaleY = 1 this.scaleY = 1
// #endif // #endif
}, },
onShow() {
},
filters: { filters: {
rate(index, list, growth) { rate(index, list, growth) {
let nowGrowth = Number(growth); let nowGrowth = Number(growth);

View File

@@ -90,11 +90,10 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/member/point');
this.$refs.login.open('/pages_tool/member/point', 'redirectTo');
}, 100);
return; return;
} }
this.getMemberPoint(); this.getMemberPoint();
}, },
onLoad() { onLoad() {

View File

@@ -1,10 +1,11 @@
export default { export default {
methods: { methods: {
// 跳转至登录页 // 跳转至登录页(跨平台兼容)
toLogin(url) { toLogin(url) {
const currentRoute = this.$util.getCurrentRoute(); const currentRoute = this.$util.getCurrentRoute();
const backUrl = url ?? (currentRoute && currentRoute.path ? currentRoute.path : ''); const backUrl = url ?? (currentRoute && currentRoute.path ? currentRoute.path : '');
this.$refs.login.open(backUrl, 'redirectTo');
this.redirectTologin(backUrl);
} }
} }
} }

View File

@@ -88,12 +88,10 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
// 使用redirectTo模式:当前页被登录页替换,返回时直接回到上一页,不会产生循环 this.redirectTologin('/pages_tool/member/info');
setTimeout(() => {
this.$refs.login.open('/pages_tool/member/info', 'redirectTo');
}, 100);
return; return;
} }
this.getInfo(); this.getInfo();
}, },
onHide() { onHide() {

View File

@@ -45,9 +45,7 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/member/signin');
this.$refs.login.open('/pages_tool/member/signin', 'redirectTo');
});
return; return;
} }

View File

@@ -124,11 +124,10 @@ export default {
}, },
confirm() { confirm() {
if (!this.storeToken) { if (!this.storeToken) {
this.$nextTick(() => { this.redirectTologin('/pages_tool/pay/cashier?out_trade_no=' + this.outTradeNo);
this.$refs.login.open('/pages_tool/pay/cashier?out_trade_no=' + this.outTradeNo);
});
return; return;
} }
if (this.payTypeList.length == 0 && this.payInfo.pay_money > 0) { if (this.payTypeList.length == 0 && this.payInfo.pay_money > 0) {
this.$util.showToast({ this.$util.showToast({
title: this.$lang('pay.cashier.pleaseSelectPayMethod') title: this.$lang('pay.cashier.pleaseSelectPayMethod')

View File

@@ -49,11 +49,10 @@ export default {
}, },
onShow() { onShow() {
if (!this.storeToken) { if (!this.storeToken) {
setTimeout(() => { this.redirectTologin('/pages_tool/recharge/order_list');
this.$refs.login.open('/pages_tool/recharge/order_list', 'redirectTo');
}, 100);
return; return;
} }
if (this.$refs.mescroll) this.$refs.mescroll.refresh(); if (this.$refs.mescroll) this.$refs.mescroll.refresh();
}, },
methods: { methods: {