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.$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: {

View File

@@ -262,9 +262,9 @@ export default {
return this.whetherCollection;
} else {
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 {
this.$refs.login.open(this.shareUrl, 'redirectTo');
this.redirectTologin(this.shareUrl);
}
}
},

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -122,9 +122,7 @@ export default {
this.getFenXiaoLevel();
if (!this.storeToken) {
this.$nextTick(() => {
this.$refs.login.open('/pages_promotion/fenxiao/team', 'redirectTo');
});
this.redirectTologin('/pages_promotion/fenxiao/team');
}
},
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.storeToken) {
this.$nextTick(() => {
this.$refs.login.open('/pages_promotion/fenxiao/withdraw_list', 'redirectTo');
});
this.redirectTologin('/pages_promotion/fenxiao/withdraw_list');
}
},
mixins: [fenxiaoWords],

View File

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

View File

@@ -442,7 +442,7 @@ export default {
// 立即购买
exchange() {
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;
}
this.$refs.goodsSku.show('point');

View File

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

View File

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

View File

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

View File

@@ -200,7 +200,8 @@ export default {
});
} else {
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) {
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -81,11 +81,10 @@ export default {
currentFilter: 'all'
};
},
onLoad() {
onLoad() {},
onShow() {
if (!this.storeToken) {
this.$nextTick(() => {
this.$refs.login.open('/pages_tool/member/card_log', 'redirectTo');
});
this.redirectTologin('/pages_tool/member/card_log');
return;
}
this.loadStat();

View File

@@ -84,7 +84,8 @@ export default {
};
},
onLoad(data) {
setTimeout( () => {
setTimeout(() => {
this.$nextTick(() => {
if (!this.addonIsExist.coupon) {
this.$util.showToast({
title: this.$lang('merchantNotEnabled'),
@@ -95,18 +96,18 @@ export default {
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;
this.isIphoneX = this.$util.uniappIsIPhoneX();
},
onShow() {
if (!this.storeToken) {
setTimeout(() => {
this.$refs.login.open('/pages_tool/member/coupon', 'redirectTo');
}, 100);
this.redirectTologin('/pages_tool/member/coupon');
return;
}
if (this.$refs.mescroll) this.$refs.mescroll.refresh();
},
methods: {

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,11 @@
export default {
methods: {
// 跳转至登录页
// 跳转至登录页(跨平台兼容)
toLogin(url) {
const currentRoute = this.$util.getCurrentRoute();
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() {
if (!this.storeToken) {
// 使用redirectTo模式:当前页被登录页替换,返回时直接回到上一页,不会产生循环
setTimeout(() => {
this.$refs.login.open('/pages_tool/member/info', 'redirectTo');
}, 100);
this.redirectTologin('/pages_tool/member/info');
return;
}
this.getInfo();
},
onHide() {

View File

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

View File

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

View File

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