code refactor

This commit is contained in:
MaysWind
2020-11-09 23:56:11 +08:00
parent b2b8dcb098
commit 8fa305212a
5 changed files with 138 additions and 114 deletions
+11 -7
View File
@@ -92,8 +92,6 @@
<script> <script>
export default { export default {
data() { data() {
const self = this;
return { return {
username: '', username: '',
password: '', password: '',
@@ -103,15 +101,16 @@ export default {
logining: false, logining: false,
verifying: false, verifying: false,
show2faSheet: false, show2faSheet: false,
twoFAVerifyType: 'passcode', twoFAVerifyType: 'passcode'
twoFAVerifyTypeSwitchName: 'Use a backup code',
allLanguages: self.$getAllLanguages()
}; };
}, },
computed: { computed: {
version() { version() {
return 'v' + this.$version(); return 'v' + this.$version();
}, },
allLanguages() {
return this.$getAllLanguages();
},
isUserRegistrationEnabled() { isUserRegistrationEnabled() {
return this.$isUserRegistrationEnabled(); return this.$isUserRegistrationEnabled();
}, },
@@ -125,6 +124,13 @@ export default {
return !this.passcode; return !this.passcode;
} }
}, },
twoFAVerifyTypeSwitchName() {
if (this.twoFAVerifyType === 'backupcode') {
return 'Use a passcode';
} else {
return 'Use a backup code';
}
},
currentLanguageName() { currentLanguageName() {
const currentLocale = this.$i18n.locale; const currentLocale = this.$i18n.locale;
let lang = this.$getLanguage(currentLocale); let lang = this.$getLanguage(currentLocale);
@@ -251,10 +257,8 @@ export default {
switch2FAVerifyType() { switch2FAVerifyType() {
if (this.twoFAVerifyType === 'passcode') { if (this.twoFAVerifyType === 'passcode') {
this.twoFAVerifyType = 'backupcode'; this.twoFAVerifyType = 'backupcode';
this.twoFAVerifyTypeSwitchName = 'Use a passcode';
} else { } else {
this.twoFAVerifyType = 'passcode'; this.twoFAVerifyType = 'passcode';
this.twoFAVerifyTypeSwitchName = 'Use a backup code';
} }
}, },
changeLanguage(locale) { changeLanguage(locale) {
+4 -4
View File
@@ -44,11 +44,8 @@
<script> <script>
export default { export default {
data() { data() {
const self = this;
return { return {
logouting: false, logouting: false
allLanguages: self.$getAllLanguages()
}; };
}, },
computed: { computed: {
@@ -59,6 +56,9 @@ export default {
const userInfo = this.$user.getUserInfo() || {}; const userInfo = this.$user.getUserInfo() || {};
return userInfo.nickname || userInfo.username || this.$t('User'); return userInfo.nickname || userInfo.username || this.$t('User');
}, },
allLanguages() {
return this.$getAllLanguages();
},
currentLocale: { currentLocale: {
get: function () { get: function () {
return this.$i18n.locale; return this.$i18n.locale;
+36 -32
View File
@@ -7,8 +7,8 @@
clear-button clear-button
:label="$t('Username')" :label="$t('Username')"
:placeholder="$t('Your username')" :placeholder="$t('Your username')"
:value="username" :value="user.username"
@input="username = $event.target.value" @input="user.username = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -16,8 +16,8 @@
clear-button clear-button
:label="$t('Password')" :label="$t('Password')"
:placeholder="$t('Your password, at least 6 characters')" :placeholder="$t('Your password, at least 6 characters')"
:value="password" :value="user.password"
@input="password = $event.target.value" @input="user.password = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -25,8 +25,8 @@
clear-button clear-button
:label="$t('Confirmation Password')" :label="$t('Confirmation Password')"
:placeholder="$t('Re-enter the password')" :placeholder="$t('Re-enter the password')"
:value="confirmPassword" :value="user.confirmPassword"
@input="confirmPassword = $event.target.value" @input="user.confirmPassword = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -34,8 +34,8 @@
clear-button clear-button
:label="$t('E-mail')" :label="$t('E-mail')"
:placeholder="$t('Your email address')" :placeholder="$t('Your email address')"
:value="email" :value="user.email"
@input="email = $event.target.value" @input="user.email = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -43,15 +43,15 @@
clear-button clear-button
:label="$t('Nickname')" :label="$t('Nickname')"
:placeholder="$t('Your nickname')" :placeholder="$t('Your nickname')"
:value="nickname" :value="user.nickname"
@input="nickname = $event.target.value" @input="user.nickname = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
type="select" type="select"
:label="$t('Default Currency')" :label="$t('Default Currency')"
:value="defaultCurrency" :value="user.defaultCurrency"
@input="defaultCurrency = $event.target.value" @input="user.defaultCurrency = $event.target.value"
> >
<option v-for="currency in allCurrencies" <option v-for="currency in allCurrencies"
:key="currency.code" :key="currency.code"
@@ -71,17 +71,21 @@ export default {
const self = this; const self = this;
return { return {
username: '', user: {
password: '', username: '',
confirmPassword: '', password: '',
email: '', confirmPassword: '',
nickname: '', email: '',
defaultCurrency: self.$t('default.currency'), nickname: '',
signuping: false, defaultCurrency: self.$t('default.currency')
allCurrencies: self.$getAllCurrencies() },
signuping: false
}; };
}, },
computed: { computed: {
allCurrencies() {
return this.$getAllCurrencies();
},
inputIsEmpty() { inputIsEmpty() {
return !!this.inputEmptyProblemMessage; return !!this.inputEmptyProblemMessage;
}, },
@@ -89,24 +93,24 @@ export default {
return !!this.inputInvalidProblemMessage; return !!this.inputInvalidProblemMessage;
}, },
inputEmptyProblemMessage() { inputEmptyProblemMessage() {
if (!this.username) { if (!this.user.username) {
return 'Username cannot be empty'; return 'Username cannot be empty';
} else if (!this.password) { } else if (!this.user.password) {
return 'Password cannot be empty'; return 'Password cannot be empty';
} else if (!this.confirmPassword) { } else if (!this.user.confirmPassword) {
return 'Confirmation password cannot be empty'; return 'Confirmation password cannot be empty';
} else if (!this.email) { } else if (!this.user.email) {
return 'Email address cannot be empty'; return 'Email address cannot be empty';
} else if (!this.nickname) { } else if (!this.user.nickname) {
return 'Nickname cannot be empty'; return 'Nickname cannot be empty';
} else if (!this.defaultCurrency) { } else if (!this.user.defaultCurrency) {
return 'Default currency cannot be empty'; return 'Default currency cannot be empty';
} else { } else {
return null; return null;
} }
}, },
inputInvalidProblemMessage() { inputInvalidProblemMessage() {
if (this.password && this.confirmPassword && this.password !== this.confirmPassword) { if (this.user.password && this.user.confirmPassword && this.user.password !== this.user.confirmPassword) {
return 'Password and confirmation password do not match'; return 'Password and confirmation password do not match';
} else { } else {
return null; return null;
@@ -129,11 +133,11 @@ export default {
self.$showLoading(() => self.signuping); self.$showLoading(() => self.signuping);
self.$services.register({ self.$services.register({
username: self.username, username: self.user.username,
password: self.password, password: self.user.password,
email: self.email, email: self.user.email,
nickname: self.nickname, nickname: self.user.nickname,
defaultCurrency: self.defaultCurrency defaultCurrency: self.user.defaultCurrency
}).then(response => { }).then(response => {
self.signuping = false; self.signuping = false;
self.$hideLoading(); self.$hideLoading();
+35 -29
View File
@@ -6,8 +6,8 @@
<f7-list-input <f7-list-input
type="select" type="select"
:label="$t('Account Category')" :label="$t('Account Category')"
:value="category" :value="account.category"
@input="category = $event.target.value" @input="account.category = $event.target.value"
> >
<option v-for="accountCategory in allAccountCategories" <option v-for="accountCategory in allAccountCategories"
:key="accountCategory.id" :key="accountCategory.id"
@@ -18,8 +18,8 @@
type="select" type="select"
disabled disabled
:label="$t('Account Type')" :label="$t('Account Type')"
:value="type" :value="account.type"
@input="type = $event.target.value" @input="account.type = $event.target.value"
> >
<option value="1">{{ $t('Single Account') }}</option> <option value="1">{{ $t('Single Account') }}</option>
<option value="2">{{ $t('Multi Sub Accounts') }}</option> <option value="2">{{ $t('Multi Sub Accounts') }}</option>
@@ -30,15 +30,15 @@
clear-button clear-button
:label="$t('Account Name')" :label="$t('Account Name')"
:placeholder="$t('Your account name')" :placeholder="$t('Your account name')"
:value="name" :value="account.name"
@input="name = $event.target.value" @input="account.name = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
type="select" type="select"
:label="$t('Currency')" :label="$t('Currency')"
:value="currency" :value="account.currency"
@input="currency = $event.target.value" @input="account.currency = $event.target.value"
> >
<option v-for="currency in allCurrencies" <option v-for="currency in allCurrencies"
:key="currency.code" :key="currency.code"
@@ -49,8 +49,8 @@
type="textarea" type="textarea"
:label="$t('Description')" :label="$t('Description')"
:placeholder="$t('Your account description (optional)')" :placeholder="$t('Your account description (optional)')"
:value="comment" :value="account.comment"
@input="comment = $event.target.value" @input="account.comment = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item> <f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item>
@@ -66,18 +66,24 @@ export default {
const self = this; const self = this;
return { return {
category: 1, account: {
type: 1, category: 1,
name: '', type: 1,
icon: "1", name: '',
currency: self.$user.getUserInfo() ? self.$user.getUserInfo().defaultCurrency : self.$t('default.currency'), icon: "1",
comment: '', currency: self.$user.getUserInfo() ? self.$user.getUserInfo().defaultCurrency : self.$t('default.currency'),
submitting: false, comment: ''
allAccountCategories: self.$constants.account.allCategories, },
allCurrencies: self.$getAllCurrencies() submitting: false
}; };
}, },
computed: { computed: {
allAccountCategories() {
return this.$constants.account.allCategories;
},
allCurrencies() {
return this.$getAllCurrencies();
},
inputIsEmpty() { inputIsEmpty() {
return !!this.inputEmptyProblemMessage; return !!this.inputEmptyProblemMessage;
}, },
@@ -85,13 +91,13 @@ export default {
return !!this.inputInvalidProblemMessage; return !!this.inputInvalidProblemMessage;
}, },
inputEmptyProblemMessage() { inputEmptyProblemMessage() {
if (!this.category) { if (!this.account.category) {
return 'Account category cannot be empty'; return 'Account category cannot be empty';
} else if (!this.type) { } else if (!this.account.type) {
return 'Account type cannot be empty'; return 'Account type cannot be empty';
} else if (!this.name) { } else if (!this.account.name) {
return 'Account name cannot be empty'; return 'Account name cannot be empty';
} else if (!this.currency) { } else if (!this.account.currency) {
return 'Account currency cannot be empty'; return 'Account currency cannot be empty';
} else { } else {
return null; return null;
@@ -117,12 +123,12 @@ export default {
self.$showLoading(() => self.signuping); self.$showLoading(() => self.signuping);
self.$services.addAccount({ self.$services.addAccount({
category: parseInt(self.category), category: parseInt(self.account.category),
type: parseInt(self.type), type: parseInt(self.account.type),
name: self.name, name: self.account.name,
icon: self.icon, icon: self.account.icon,
currency: self.currency, currency: self.account.currency,
comment: self.comment comment: self.account.comment
}).then(response => { }).then(response => {
self.submitting = false; self.submitting = false;
self.$hideLoading(); self.$hideLoading();
+52 -42
View File
@@ -16,8 +16,8 @@
clear-button clear-button
:label="$t('Password')" :label="$t('Password')"
:placeholder="$t('Your password')" :placeholder="$t('Your password')"
:value="password" :value="newProfile.password"
@input="password = $event.target.value" @input="newProfile.password = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -25,8 +25,8 @@
clear-button clear-button
:label="$t('Confirmation Password')" :label="$t('Confirmation Password')"
:placeholder="$t('Re-enter the password')" :placeholder="$t('Re-enter the password')"
:value="confirmPassword" :value="newProfile.confirmPassword"
@input="confirmPassword = $event.target.value" @input="newProfile.confirmPassword = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -34,8 +34,8 @@
clear-button clear-button
:label="$t('E-mail')" :label="$t('E-mail')"
:placeholder="$t('Your email address')" :placeholder="$t('Your email address')"
:value="email" :value="newProfile.email"
@input="email = $event.target.value" @input="newProfile.email = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
@@ -43,15 +43,15 @@
clear-button clear-button
:label="$t('Nickname')" :label="$t('Nickname')"
:placeholder="$t('Your nickname')" :placeholder="$t('Your nickname')"
:value="nickname" :value="newProfile.nickname"
@input="nickname = $event.target.value" @input="newProfile.nickname = $event.target.value"
></f7-list-input> ></f7-list-input>
<f7-list-input <f7-list-input
type="select" type="select"
:label="$t('Default Currency')" :label="$t('Default Currency')"
:value="defaultCurrency" :value="newProfile.defaultCurrency"
@input="defaultCurrency = $event.target.value" @input="newProfile.defaultCurrency = $event.target.value"
> >
<option v-for="currency in allCurrencies" <option v-for="currency in allCurrencies"
:key="currency.code" :key="currency.code"
@@ -61,7 +61,7 @@
<f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item> <f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item>
</f7-list> </f7-list>
<f7-button large fill :class="{ 'disabled': inputIsNotChanged || updating }" :text="$t('Update')" @click="update"></f7-button> <f7-button large fill :class="{ 'disabled': inputIsNotChanged || inputIsInvalid || updating }" :text="$t('Update')" @click="update"></f7-button>
<f7-sheet <f7-sheet
style="height:auto" style="height:auto"
@@ -93,25 +93,29 @@
<script> <script>
export default { export default {
data() { data() {
const self = this;
return { return {
newProfile: {
password: '',
confirmPassword: '',
email: '',
nickname: '',
defaultCurrency: ''
},
oldProfile: {
email: '',
nickname: '',
defaultCurrency: ''
},
currentPassword: '', currentPassword: '',
password: '',
confirmPassword: '',
oldEmail: '',
email: '',
oldNickname: '',
nickname: '',
defaultCurrency: '',
oldDefaultCurrency: '',
loading: true, loading: true,
updating: false, updating: false,
showInputPasswordSheet: false, showInputPasswordSheet: false
allCurrencies: self.$getAllCurrencies()
}; };
}, },
computed: { computed: {
allCurrencies() {
return this.$getAllCurrencies();
},
inputIsNotChanged() { inputIsNotChanged() {
return !!this.inputIsNotChangedProblemMessage; return !!this.inputIsNotChangedProblemMessage;
}, },
@@ -119,24 +123,30 @@ export default {
return !!this.inputInvalidProblemMessage; return !!this.inputInvalidProblemMessage;
}, },
inputIsNotChangedProblemMessage() { inputIsNotChangedProblemMessage() {
if (!this.password && !this.confirmPassword && !this.email && !this.nickname) { if (!this.newProfile.password && !this.newProfile.confirmPassword && !this.newProfile.email && !this.newProfile.nickname) {
return 'Nothing has been modified'; return 'Nothing has been modified';
} else if (!this.password && !this.confirmPassword && } else if (!this.newProfile.password && !this.newProfile.confirmPassword &&
this.email === this.oldEmail && this.newProfile.email === this.oldProfile.email &&
this.nickname === this.oldNickname && this.newProfile.nickname === this.oldProfile.nickname &&
this.defaultCurrency === this.oldDefaultCurrency) { this.newProfile.defaultCurrency === this.oldProfile.defaultCurrency) {
return 'Nothing has been modified'; return 'Nothing has been modified';
} else if (!this.password && this.confirmPassword) { } else if (!this.newProfile.password && this.newProfile.confirmPassword) {
return 'Password cannot be empty'; return 'Password cannot be empty';
} else if (this.password && !this.confirmPassword) { } else if (this.newProfile.password && !this.newProfile.confirmPassword) {
return 'Confirmation password cannot be empty'; return 'Confirmation password cannot be empty';
} else { } else {
return null; return null;
} }
}, },
inputInvalidProblemMessage() { inputInvalidProblemMessage() {
if (this.password && this.confirmPassword && this.password !== this.confirmPassword) { if (this.newProfile.password && this.newProfile.confirmPassword && this.newProfile.password !== this.newProfile.confirmPassword) {
return 'Password and confirmation password do not match'; return 'Password and confirmation password do not match';
} else if (!this.newProfile.email) {
return 'Email address cannot be empty';
} else if (!this.newProfile.nickname) {
return 'Nickname cannot be empty';
} else if (!this.newProfile.defaultCurrency) {
return 'Default currency cannot be empty';
} else { } else {
return null; return null;
} }
@@ -159,13 +169,13 @@ export default {
return; return;
} }
self.oldEmail = data.result.email; self.oldProfile.email = data.result.email;
self.oldNickname = data.result.nickname; self.oldProfile.nickname = data.result.nickname;
self.oldDefaultCurrency = data.result.defaultCurrency; self.oldProfile.defaultCurrency = data.result.defaultCurrency;
self.email = self.oldEmail self.newProfile.email = self.oldProfile.email
self.nickname = self.oldNickname; self.newProfile.nickname = self.oldProfile.nickname;
self.defaultCurrency = self.oldDefaultCurrency; self.newProfile.defaultCurrency = self.oldProfile.defaultCurrency;
}).catch(error => { }).catch(error => {
self.loading = false; self.loading = false;
@@ -194,7 +204,7 @@ export default {
return; return;
} }
if (self.password && !self.currentPassword) { if (self.newProfile.password && !self.currentPassword) {
self.showInputPasswordSheet = true; self.showInputPasswordSheet = true;
return; return;
} }
@@ -203,11 +213,11 @@ export default {
self.$showLoading(() => self.updating); self.$showLoading(() => self.updating);
self.$services.updateProfile({ self.$services.updateProfile({
password: self.password, password: self.newProfile.password,
oldPassword: self.currentPassword, oldPassword: self.currentPassword,
email: self.email, email: self.newProfile.email,
nickname: self.nickname, nickname: self.newProfile.nickname,
defaultCurrency: self.defaultCurrency defaultCurrency: self.newProfile.defaultCurrency
}).then(response => { }).then(response => {
self.updating = false; self.updating = false;
self.$hideLoading(); self.$hideLoading();