mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
code refactor
This commit is contained in:
+6
-6
@@ -43,7 +43,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (resetUserInfoAndSettings) {
|
if (resetUserInfoAndSettings) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.resetUserInfo();
|
userStore.resetUserBasicInfo();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
authorize({ loginName, password }) {
|
authorize({ loginName, password }) {
|
||||||
@@ -81,7 +81,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (data.result.user && isObject(data.result.user)) {
|
if (data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(data.result);
|
resolve(data.result);
|
||||||
@@ -142,7 +142,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (data.result.user && isObject(data.result.user)) {
|
if (data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(data.result);
|
resolve(data.result);
|
||||||
@@ -192,7 +192,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (data.result.user && isObject(data.result.user)) {
|
if (data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(data.result);
|
resolve(data.result);
|
||||||
@@ -267,7 +267,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (data.result.user && isObject(data.result.user)) {
|
if (data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(data.result);
|
resolve(data.result);
|
||||||
@@ -401,7 +401,7 @@ export const useRootStore = defineStore('root', {
|
|||||||
|
|
||||||
if (data.result.user && isObject(data.result.user)) {
|
if (data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountsStore = useAccountsStore();
|
const accountsStore = useAccountsStore();
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ export const useTokensStore = defineStore('tokens', {
|
|||||||
|
|
||||||
if (data && data.success && data.result && data.result.user && isObject(data.result.user)) {
|
if (data && data.success && data.result && data.result.user && isObject(data.result.user)) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
userStore.storeUserInfo(data.result.user);
|
userStore.storeUserBasicInfo(data.result.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data && data.success && data.result && data.result.newToken) {
|
if (data && data.success && data.result && data.result.newToken) {
|
||||||
|
|||||||
+21
-21
@@ -9,73 +9,73 @@ import { isNumber } from '@/lib/common.js';
|
|||||||
|
|
||||||
export const useUserStore = defineStore('user', {
|
export const useUserStore = defineStore('user', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
currentUserInfo: userState.getUserInfo()
|
currentUserBasicInfo: userState.getUserInfo()
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
currentUserNickname(state) {
|
currentUserNickname(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.nickname || userInfo.username || null;
|
return userInfo.nickname || userInfo.username || null;
|
||||||
},
|
},
|
||||||
currentUserAvatar(state) {
|
currentUserAvatar(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.avatar || null;
|
return userInfo.avatar || null;
|
||||||
},
|
},
|
||||||
currentUserDefaultAccountId(state) {
|
currentUserDefaultAccountId(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.defaultAccountId || '';
|
return userInfo.defaultAccountId || '';
|
||||||
},
|
},
|
||||||
currentUserLanguage(state) {
|
currentUserLanguage(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.language;
|
return userInfo.language;
|
||||||
},
|
},
|
||||||
currentUserDefaultCurrency(state) {
|
currentUserDefaultCurrency(state) {
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.defaultCurrency || settingsStore.localeDefaultSettings.currency;
|
return userInfo.defaultCurrency || settingsStore.localeDefaultSettings.currency;
|
||||||
},
|
},
|
||||||
currentUserFirstDayOfWeek(state) {
|
currentUserFirstDayOfWeek(state) {
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : settingsStore.localeDefaultSettings.firstDayOfWeek;
|
return isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : settingsStore.localeDefaultSettings.firstDayOfWeek;
|
||||||
},
|
},
|
||||||
currentUserLongDateFormat(state) {
|
currentUserLongDateFormat(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.longDateFormat;
|
return userInfo.longDateFormat;
|
||||||
},
|
},
|
||||||
currentUserShortDateFormat(state) {
|
currentUserShortDateFormat(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.shortDateFormat;
|
return userInfo.shortDateFormat;
|
||||||
},
|
},
|
||||||
currentUserLongTimeFormat(state) {
|
currentUserLongTimeFormat(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.longTimeFormat;
|
return userInfo.longTimeFormat;
|
||||||
},
|
},
|
||||||
currentUserShortTimeFormat(state) {
|
currentUserShortTimeFormat(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.shortTimeFormat;
|
return userInfo.shortTimeFormat;
|
||||||
},
|
},
|
||||||
currentUserDecimalSeparator(state) {
|
currentUserDecimalSeparator(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.decimalSeparator;
|
return userInfo.decimalSeparator;
|
||||||
},
|
},
|
||||||
currentUserDigitGroupingSymbol(state) {
|
currentUserDigitGroupingSymbol(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.digitGroupingSymbol;
|
return userInfo.digitGroupingSymbol;
|
||||||
},
|
},
|
||||||
currentUserDigitGrouping(state) {
|
currentUserDigitGrouping(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.digitGrouping;
|
return userInfo.digitGrouping;
|
||||||
},
|
},
|
||||||
currentUserCurrencyDisplayType(state) {
|
currentUserCurrencyDisplayType(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.currencyDisplayType;
|
return userInfo.currencyDisplayType;
|
||||||
},
|
},
|
||||||
currentUserExpenseAmountColor(state) {
|
currentUserExpenseAmountColor(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.expenseAmountColor;
|
return userInfo.expenseAmountColor;
|
||||||
},
|
},
|
||||||
currentUserIncomeAmountColor(state) {
|
currentUserIncomeAmountColor(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserBasicInfo || {};
|
||||||
return userInfo.incomeAmountColor;
|
return userInfo.incomeAmountColor;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -94,12 +94,12 @@ export const useUserStore = defineStore('user', {
|
|||||||
firstDayOfWeek: settingsStore.localeDefaultSettings.firstDayOfWeek,
|
firstDayOfWeek: settingsStore.localeDefaultSettings.firstDayOfWeek,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
storeUserInfo(userInfo) {
|
storeUserBasicInfo(userInfo) {
|
||||||
this.currentUserInfo = userInfo;
|
this.currentUserBasicInfo = userInfo;
|
||||||
userState.updateUserInfo(userInfo);
|
userState.updateUserInfo(userInfo);
|
||||||
},
|
},
|
||||||
resetUserInfo() {
|
resetUserBasicInfo() {
|
||||||
this.currentUserInfo = null;
|
this.currentUserBasicInfo = null;
|
||||||
userState.clearUserInfo();
|
userState.clearUserInfo();
|
||||||
},
|
},
|
||||||
getCurrentUserProfile() {
|
getCurrentUserProfile() {
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ export default {
|
|||||||
self.verifyingByWebAuthn = true;
|
self.verifyingByWebAuthn = true;
|
||||||
|
|
||||||
webauthn.verifyCredential(
|
webauthn.verifyCredential(
|
||||||
self.userStore.currentUserInfo,
|
self.userStore.currentUserBasicInfo,
|
||||||
self.$user.getWebAuthnCredentialId()
|
self.$user.getWebAuthnCredentialId()
|
||||||
).then(({ id, userName, userSecret }) => {
|
).then(({ id, userName, userSecret }) => {
|
||||||
self.verifyingByWebAuthn = false;
|
self.verifyingByWebAuthn = false;
|
||||||
@@ -217,7 +217,7 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = self.userStore.currentUserInfo;
|
const user = self.userStore.currentUserBasicInfo;
|
||||||
|
|
||||||
if (!user || !user.username) {
|
if (!user || !user.username) {
|
||||||
self.$refs.snackbar.showMessage('An error occurred');
|
self.$refs.snackbar.showMessage('An error occurred');
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export default {
|
|||||||
|
|
||||||
webauthn.registerCredential(
|
webauthn.registerCredential(
|
||||||
self.$user.getUserAppLockState(),
|
self.$user.getUserAppLockState(),
|
||||||
self.userStore.currentUserInfo,
|
self.userStore.currentUserBasicInfo,
|
||||||
).then(({ id }) => {
|
).then(({ id }) => {
|
||||||
self.enablingWebAuthn = false;
|
self.enablingWebAuthn = false;
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = this.userStore.currentUserInfo;
|
const user = this.userStore.currentUserBasicInfo;
|
||||||
|
|
||||||
if (!user || !user.username) {
|
if (!user || !user.username) {
|
||||||
this.pinCode = '';
|
this.pinCode = '';
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export default {
|
|||||||
|
|
||||||
webauthn.registerCredential(
|
webauthn.registerCredential(
|
||||||
self.$user.getUserAppLockState(),
|
self.$user.getUserAppLockState(),
|
||||||
self.userStore.currentUserInfo,
|
self.userStore.currentUserBasicInfo,
|
||||||
).then(({ id }) => {
|
).then(({ id }) => {
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = this.userStore.currentUserInfo;
|
const user = this.userStore.currentUserBasicInfo;
|
||||||
|
|
||||||
if (!user || !user.username) {
|
if (!user || !user.username) {
|
||||||
this.$alert('An error occurred');
|
this.$alert('An error occurred');
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export default {
|
|||||||
self.$showLoading();
|
self.$showLoading();
|
||||||
|
|
||||||
webauthn.verifyCredential(
|
webauthn.verifyCredential(
|
||||||
self.userStore.currentUserInfo,
|
self.userStore.currentUserBasicInfo,
|
||||||
self.$user.getWebAuthnCredentialId()
|
self.$user.getWebAuthnCredentialId()
|
||||||
).then(({ id, userName, userSecret }) => {
|
).then(({ id, userName, userSecret }) => {
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
@@ -175,7 +175,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const router = self.f7router;
|
const router = self.f7router;
|
||||||
const user = self.userStore.currentUserInfo;
|
const user = self.userStore.currentUserBasicInfo;
|
||||||
|
|
||||||
if (!user || !user.username) {
|
if (!user || !user.username) {
|
||||||
self.$alert('An error occurred');
|
self.$alert('An error occurred');
|
||||||
|
|||||||
Reference in New Issue
Block a user