refactor(member): 提取公共登录态清理和注销逻辑到mixin
重构会员相关页面的重复代码,将清除登录态、退出登录、账号注销相关逻辑抽离到公共mixin中,统一复用代码并减少重复维护成本
This commit is contained in:
@@ -76,6 +76,7 @@
|
||||
<script>
|
||||
import diyJs from '@/common/js/diy.js';
|
||||
import indexJs from './public/js/index.js';
|
||||
import memberPublic from './public/js/member-public.js';
|
||||
|
||||
import nsBirthdayGift from '../_components/ns-birthday-gift/ns-birthday-gift.vue';
|
||||
import nsNewGift from '../_components/ns-new-gift/ns-new-gift.vue';
|
||||
@@ -85,7 +86,7 @@ export default {
|
||||
nsBirthdayGift,
|
||||
nsNewGift
|
||||
},
|
||||
mixins: [diyJs, indexJs],
|
||||
mixins: [diyJs, indexJs, memberPublic],
|
||||
onLoad() {
|
||||
this.$util.hideHomeButton();
|
||||
},
|
||||
@@ -96,55 +97,6 @@ export default {
|
||||
|
||||
tourl(url) {
|
||||
this.$util.redirectTo(url);
|
||||
},
|
||||
|
||||
// 退出登录
|
||||
logout() {
|
||||
uni.showModal({
|
||||
title: this.$lang('logoutTitle'),
|
||||
content: this.$lang('logoutContent'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.$store.commit('setToken', '');
|
||||
this.$store.commit('setMemberInfo', '');
|
||||
this.$store.dispatch('emptyCart');
|
||||
uni.removeStorageSync('authInfo');
|
||||
uni.removeStorageSync('privacyAgreed');
|
||||
this.$util.redirectTo(this.$util.MEMBER_PAGE_URL);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 账号注销
|
||||
cancellation() {
|
||||
uni.showModal({
|
||||
title: this.$lang('cancellationTitle'),
|
||||
content: this.$lang('cancellationContent'),
|
||||
confirmColor: '#000000',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
this.$api.sendRequest({
|
||||
url: '/membercancel/api/membercancel/apply',
|
||||
success: rres => {
|
||||
if (rres.code >= 0) {
|
||||
this.$store.commit('setToken', '');
|
||||
this.$store.commit('setMemberInfo', '');
|
||||
this.$store.dispatch('emptyCart');
|
||||
uni.removeStorageSync('authInfo');
|
||||
uni.removeStorageSync('privacyAgreed');
|
||||
this.$util.redirectTo(this.$util.MEMBER_PAGE_URL);
|
||||
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: rres.message
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user