code refactor

This commit is contained in:
MaysWind
2023-06-24 17:02:57 +08:00
parent a9338ed822
commit fb7790ba4a
36 changed files with 644 additions and 354 deletions
+107 -9
View File
@@ -2,27 +2,125 @@ import { defineStore } from 'pinia';
import currencyConstants from '@/consts/currency.js';
import datetimeConstants from '@/consts/datetime.js';
import * as settings from '@/lib/settings.js';
export const useSettingsStore = defineStore('settings', {
state: () => ({
defaultSetting: {
language: '',
appSettings: {
theme: settings.getTheme(),
fontSize: settings.getFontSize(),
timeZone: settings.getTimeZone(),
applicationLock: settings.isEnableApplicationLock(),
applicationLockWebAuthn: settings.isEnableApplicationLockWebAuthn(),
autoUpdateExchangeRatesData: settings.isAutoUpdateExchangeRatesData(),
autoGetCurrentGeoLocation: settings.isAutoGetCurrentGeoLocation(),
thousandsSeparator: settings.isEnableThousandsSeparator(),
currencyDisplayMode: settings.getCurrencyDisplayMode(),
showAmountInHomePage: settings.isShowAmountInHomePage(),
showTotalAmountInTransactionListPage: settings.isShowTotalAmountInTransactionListPage(),
showAccountBalance: settings.isShowAccountBalance(),
statistics: {
defaultChartType: settings.getStatisticsDefaultChartType(),
defaultChartDataType: settings.getStatisticsDefaultChartDataType(),
defaultDataRangeType: settings.getStatisticsDefaultDateRange(),
defaultAccountFilter: settings.getStatisticsDefaultAccountFilter(),
defaultTransactionCategoryFilter: settings.getStatisticsDefaultTransactionCategoryFilter(),
defaultSortingType: settings.getStatisticsSortingType()
},
animate: settings.isEnableAnimate()
},
localeDefaultSettings: {
currency: currencyConstants.defaultCurrency,
firstDayOfWeek: datetimeConstants.defaultFirstDayOfWeek,
longDateFormat: 0,
shortDateFormat: 0,
longTimeFormat: 0,
shortTimeFormat: 0
firstDayOfWeek: datetimeConstants.defaultFirstDayOfWeek
}
}),
actions: {
setTheme(value) {
settings.setTheme(value);
this.appSettings.theme = value;
},
setFontSize(value) {
settings.setFontSize(value);
this.appSettings.fontSize = value;
},
setTimeZone(value) {
settings.setTimeZone(value);
this.appSettings.timeZone = value;
},
setEnableApplicationLock(value) {
settings.setEnableApplicationLock(value);
this.appSettings.applicationLock = value;
},
setEnableApplicationLockWebAuthn(value) {
settings.setEnableApplicationLockWebAuthn(value);
this.appSettings.applicationLockWebAuthn = value;
},
setAutoUpdateExchangeRatesData(value) {
settings.setAutoUpdateExchangeRatesData(value);
this.appSettings.autoUpdateExchangeRatesData = value;
},
setAutoGetCurrentGeoLocation(value) {
settings.setAutoGetCurrentGeoLocation(value);
this.appSettings.autoGetCurrentGeoLocation = value;
},
setEnableThousandsSeparator(value) {
settings.setEnableThousandsSeparator(value);
this.appSettings.thousandsSeparator = value;
},
setCurrencyDisplayMode(value) {
settings.setCurrencyDisplayMode(value);
this.appSettings.currencyDisplayMode = value;
},
setShowAmountInHomePage(value) {
settings.setShowAmountInHomePage(value);
this.appSettings.showAmountInHomePage = value;
},
setShowTotalAmountInTransactionListPage(value) {
settings.setShowTotalAmountInTransactionListPage(value);
this.appSettings.showTotalAmountInTransactionListPage = value;
},
setShowAccountBalance(value) {
settings.setShowAccountBalance(value);
this.appSettings.showAccountBalance = value;
},
setStatisticsDefaultChartType(value) {
settings.setStatisticsDefaultChartType(value);
this.appSettings.statistics.defaultChartType = value;
},
setStatisticsDefaultChartDataType(value) {
settings.setStatisticsDefaultChartDataType(value);
this.appSettings.statistics.defaultChartDataType = value;
},
setStatisticsDefaultDateRange(value) {
settings.setStatisticsDefaultDateRange(value);
this.appSettings.statistics.defaultDataRangeType = value;
},
setStatisticsDefaultAccountFilter(value) {
settings.setStatisticsDefaultAccountFilter(value);
this.appSettings.statistics.defaultAccountFilter = value;
},
setStatisticsDefaultTransactionCategoryFilter(value) {
settings.setStatisticsDefaultTransactionCategoryFilter(value);
this.appSettings.statistics.defaultTransactionCategoryFilter = value;
},
setStatisticsSortingType(value) {
settings.setStatisticsSortingType(value);
this.appSettings.statistics.defaultSortingType = value;
},
setEnableAnimate(value) {
settings.setEnableAnimate(value);
this.appSettings.animate = value;
},
clearAppSettings() {
settings.clearSettings();
},
updateLocalizedDefaultSettings(localeDefaultSettings) {
if (!localeDefaultSettings) {
return;
}
this.defaultSetting.currency = localeDefaultSettings.defaultCurrency;
this.defaultSetting.firstDayOfWeek = localeDefaultSettings.defaultFirstDayOfWeek;
this.localeDefaultSettings.currency = localeDefaultSettings.defaultCurrency;
this.localeDefaultSettings.firstDayOfWeek = localeDefaultSettings.defaultFirstDayOfWeek;
}
}
});