code refactor

This commit is contained in:
MaysWind
2023-08-13 15:18:38 +08:00
parent 66f0b38008
commit 957bcf790f
3 changed files with 22 additions and 24 deletions
+14
View File
@@ -61,6 +61,20 @@ export const useUserStore = defineStore('user', {
} }
}, },
actions: { actions: {
generateNewUserInfo(language) {
const settingsStore = useSettingsStore();
return {
username: '',
password: '',
confirmPassword: '',
email: '',
nickname: '',
language: language,
defaultCurrency: settingsStore.localeDefaultSettings.currency,
firstDayOfWeek: settingsStore.localeDefaultSettings.firstDayOfWeek,
};
},
storeUserInfo(userInfo) { storeUserInfo(userInfo) {
this.currentUserInfo = userInfo; this.currentUserInfo = userInfo;
userState.updateUserInfo(userInfo); userState.updateUserInfo(userInfo);
+4 -12
View File
@@ -249,6 +249,7 @@ import { useTheme } from 'vuetify';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js'; import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.js'; import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js'; import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js'; import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
@@ -266,20 +267,11 @@ import {
export default { export default {
data() { data() {
const self = this; const userStore = useUserStore();
const settingsStore = useSettingsStore(); const newUser = userStore.generateNewUserInfo(this.$locale.getCurrentLanguageCode());
return { return {
user: { user: newUser,
username: '',
password: '',
confirmPassword: '',
email: '',
nickname: '',
language: self.$locale.getCurrentLanguageCode(),
defaultCurrency: settingsStore.localeDefaultSettings.currency,
firstDayOfWeek: settingsStore.localeDefaultSettings.firstDayOfWeek,
},
currentStep: 'basicSetting', currentStep: 'basicSetting',
isPasswordVisible: false, isPasswordVisible: false,
isConfirmPasswordVisible: false, isConfirmPasswordVisible: false,
+4 -12
View File
@@ -177,6 +177,7 @@
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js'; import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.js'; import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js'; import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js'; import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
@@ -188,20 +189,11 @@ export default {
'f7router' 'f7router'
], ],
data() { data() {
const self = this; const userStore = useUserStore();
const settingsStore = useSettingsStore(); const newUser = userStore.generateNewUserInfo(this.$locale.getCurrentLanguageCode());
return { return {
user: { user: newUser,
username: '',
password: '',
confirmPassword: '',
email: '',
nickname: '',
language: self.$locale.getCurrentLanguageCode(),
defaultCurrency: settingsStore.localeDefaultSettings.currency,
firstDayOfWeek: settingsStore.localeDefaultSettings.firstDayOfWeek,
},
submitting: false, submitting: false,
usePresetCategories: false, usePresetCategories: false,
showPresetCategories: false, showPresetCategories: false,