code refactor

This commit is contained in:
MaysWind
2021-01-04 23:52:57 +08:00
parent 5077b93105
commit b7589e57f2
20 changed files with 561 additions and 293 deletions
+6 -25
View File
@@ -86,7 +86,6 @@ export default {
const self = this;
return {
currentNickName: self.getCurrentUserNickName(),
isEnableApplicationLock: this.$settings.isEnableApplicationLock(),
exchangeRatesLastUpdateDate: self.getExchangeRatesLastUpdateDate(),
logouting: false
@@ -108,6 +107,9 @@ export default {
this.exchangeRatesLastUpdateDate = this.getExchangeRatesLastUpdateDate();
}
},
currentNickName() {
return this.$store.getters.currentUserNickname || this.$t('User');
},
isDataExportingEnabled() {
return this.$settings.isDataExportingEnabled();
},
@@ -168,14 +170,9 @@ export default {
},
methods: {
onPageAfterIn() {
this.currentNickName = this.getCurrentUserNickName();
this.isEnableApplicationLock = this.$settings.isEnableApplicationLock();
this.exchangeRatesLastUpdateDate = this.getExchangeRatesLastUpdateDate();
},
getCurrentUserNickName() {
const userInfo = this.$user.getUserInfo() || {};
return userInfo.nickname || userInfo.username || this.$t('User');
},
getExchangeRatesLastUpdateDate() {
const exchangeRates = this.$exchangeRates.getExchangeRates();
return exchangeRates && exchangeRates.date ? this.$moment(exchangeRates.date).format(this.$t('format.date.long')) : '';
@@ -188,37 +185,21 @@ export default {
self.logouting = true;
self.$showLoading(() => self.logouting);
self.$services.logout().then(response => {
self.$store.dispatch('logout').then(() => {
self.logouting = false;
self.$hideLoading();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$toast('Unable to logout');
return;
}
self.$user.clearTokenAndUserInfo(true);
self.$user.clearWebAuthnConfig();
self.$exchangeRates.clearExchangeRates();
self.$settings.clearSettings();
self.$locale.init();
router.navigate('/');
}).catch(error => {
self.$logger.error('failed to log out', error);
self.logouting = false;
self.$hideLoading();
if (error && error.processed) {
return;
}
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$toast({ error: error.response.data });
} else if (!error.processed) {
self.$toast('Unable to logout');
if (!error.processed) {
self.$toast(error.message || error);
}
});
});