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

@@ -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() {
if (!this.storeToken) {
this.redirectTologin('/pages_tool/member/address');
return;
}
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.$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;
@@ -160,9 +156,9 @@ export default {
value: charge_rule[key]
});
});
this.levelInfo = levelInfo;
},
onShow() {
this.levelInfo = levelInfo;
//小程序分享
// #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,14 +81,13 @@ 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();
this.loadStat();
},
methods: {
// 加载统计数据

View File

@@ -84,29 +84,30 @@ export default {
};
},
onLoad(data) {
setTimeout( () => {
if (!this.addonIsExist.coupon) {
this.$util.showToast({
title: this.$lang('merchantNotEnabled'),
mask: true,
duration: 2000
});
setTimeout(() => {
this.$util.redirectTo(this.$util.INDEX_PAGE_URL);
}, 2000);
}
},1000);
setTimeout(() => {
this.$nextTick(() => {
if (!this.addonIsExist.coupon) {
this.$util.showToast({
title: this.$lang('merchantNotEnabled'),
mask: true,
duration: 2000
});
setTimeout(() => {
this.$util.redirectTo(this.$util.INDEX_PAGE_URL);
}, 2000);
}
});
}, 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: {