fix the problem that the time zone setting did not take effect immediately

This commit is contained in:
MaysWind
2023-07-24 00:23:27 +08:00
parent 5dd0f7ea10
commit aafdbab781
5 changed files with 36 additions and 18 deletions
+1
View File
@@ -1023,6 +1023,7 @@ export function i18nFunctions(i18nGlobal) {
getDisplayCurrency: (value, currencyCode, options) => getDisplayCurrency(value, currencyCode, options, i18nGlobal.t), getDisplayCurrency: (value, currencyCode, options) => getDisplayCurrency(value, currencyCode, options, i18nGlobal.t),
joinMultiText: (textArray) => joinMultiText(textArray, i18nGlobal.t), joinMultiText: (textArray) => joinMultiText(textArray, i18nGlobal.t),
setLanguage: (locale, force) => setLanguage(i18nGlobal, locale, force), setLanguage: (locale, force) => setLanguage(i18nGlobal, locale, force),
setTimeZone: (timezone) => setTimeZone(timezone),
initLocale: (lastUserLanguage, timezone) => initLocale(i18nGlobal, lastUserLanguage, timezone) initLocale: (lastUserLanguage, timezone) => initLocale(i18nGlobal, lastUserLanguage, timezone)
}; };
} }
+17 -14
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useSettingsStore } from './setting.js';
import { useAccountsStore } from './account.js'; import { useAccountsStore } from './account.js';
import { useTransactionCategoriesStore } from './transactionCategory.js'; import { useTransactionCategoriesStore } from './transactionCategory.js';
import { useOverviewStore } from './overview.js'; import { useOverviewStore } from './overview.js';
@@ -26,13 +27,13 @@ const emptyTransactionResult = {
transactionsNextTimeId: 0 transactionsNextTimeId: 0
}; };
function loadTransactionList(state, exchangeRatesStore, { transactions, reload, autoExpand, defaultCurrency }) { function loadTransactionList(state, settingsStore, exchangeRatesStore, { transactions, reload, autoExpand, defaultCurrency }) {
if (reload) { if (reload) {
state.transactions = []; state.transactions = [];
} }
if (transactions.items && transactions.items.length) { if (transactions.items && transactions.items.length) {
const currentUtcOffset = getTimezoneOffsetMinutes(); const currentUtcOffset = getTimezoneOffsetMinutes(settingsStore.appSettings.timeZone);
let currentMonthListIndex = -1; let currentMonthListIndex = -1;
let currentMonthList = null; let currentMonthList = null;
@@ -86,8 +87,8 @@ function loadTransactionList(state, exchangeRatesStore, { transactions, reload,
} }
} }
function updateTransactionInTransactionList(state, exchangeRatesStore, { transaction, defaultCurrency }) { function updateTransactionInTransactionList(state, settingsStore, exchangeRatesStore, { transaction, defaultCurrency }) {
const currentUtcOffset = getTimezoneOffsetMinutes(); const currentUtcOffset = getTimezoneOffsetMinutes(settingsStore.appSettings.timeZone);
const transactionTime = parseDateFromUnixTime(transaction.time, transaction.utcOffset, currentUtcOffset); const transactionTime = parseDateFromUnixTime(transaction.time, transaction.utcOffset, currentUtcOffset);
const transactionYear = getYear(transactionTime); const transactionYear = getYear(transactionTime);
const transactionMonth = getMonth(transactionTime); const transactionMonth = getMonth(transactionTime);
@@ -378,6 +379,7 @@ export const useTransactionsStore = defineStore('transactions', {
}, },
loadTransactions({ reload, autoExpand, defaultCurrency }) { loadTransactions({ reload, autoExpand, defaultCurrency }) {
const self = this; const self = this;
const settingsStore = useSettingsStore();
const exchangeRatesStore = useExchangeRatesStore(); const exchangeRatesStore = useExchangeRatesStore();
let actualMaxTime = self.transactionsNextTimeId; let actualMaxTime = self.transactionsNextTimeId;
@@ -389,18 +391,18 @@ export const useTransactionsStore = defineStore('transactions', {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
services.getTransactions({ services.getTransactions({
maxTime: actualMaxTime, maxTime: actualMaxTime,
minTime: self.transactionsFilter.minTime * 1000, minTime: self.transactionsFilter.minTime * 1000,
type: self.transactionsFilter.type, type: self.transactionsFilter.type,
categoryId: self.transactionsFilter.categoryId, categoryId: self.transactionsFilter.categoryId,
accountId: self.transactionsFilter.accountId, accountId: self.transactionsFilter.accountId,
keyword: self.transactionsFilter.keyword keyword: self.transactionsFilter.keyword
}).then(response => { }).then(response => {
const data = response.data; const data = response.data;
if (!data || !data.success || !data.result) { if (!data || !data.success || !data.result) {
if (reload) { if (reload) {
loadTransactionList(self, exchangeRatesStore, { loadTransactionList(self, settingsStore, exchangeRatesStore, {
transactions: emptyTransactionResult, transactions: emptyTransactionResult,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
@@ -416,7 +418,7 @@ export const useTransactionsStore = defineStore('transactions', {
return; return;
} }
loadTransactionList(self, exchangeRatesStore, { loadTransactionList(self, settingsStore, exchangeRatesStore, {
transactions: data.result, transactions: data.result,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
@@ -434,7 +436,7 @@ export const useTransactionsStore = defineStore('transactions', {
logger.error('failed to load transaction list', error); logger.error('failed to load transaction list', error);
if (reload) { if (reload) {
loadTransactionList(self, exchangeRatesStore, { loadTransactionList(self, settingsStore, exchangeRatesStore, {
transactions: emptyTransactionResult, transactions: emptyTransactionResult,
reload: reload, reload: reload,
autoExpand: autoExpand, autoExpand: autoExpand,
@@ -484,6 +486,7 @@ export const useTransactionsStore = defineStore('transactions', {
}, },
saveTransaction({ transaction, defaultCurrency }) { saveTransaction({ transaction, defaultCurrency }) {
const self = this; const self = this;
const settingsStore = useSettingsStore();
const exchangeRatesStore = useExchangeRatesStore(); const exchangeRatesStore = useExchangeRatesStore();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -512,7 +515,7 @@ export const useTransactionsStore = defineStore('transactions', {
self.updateTransactionListInvalidState(true); self.updateTransactionListInvalidState(true);
} }
} else { } else {
updateTransactionInTransactionList(self, exchangeRatesStore, { updateTransactionInTransactionList(self, settingsStore, exchangeRatesStore, {
transaction: data.result, transaction: data.result,
defaultCurrency: defaultCurrency defaultCurrency: defaultCurrency
}); });
@@ -167,6 +167,9 @@ 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 { useUserStore } from '@/stores/user.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useOverviewStore } from '@/stores/overview.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js'; import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import currencyConstants from '@/consts/currency.js'; import currencyConstants from '@/consts/currency.js';
@@ -174,7 +177,7 @@ import { getSystemTheme } from '@/lib/ui.js';
export default { export default {
computed: { computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useExchangeRatesStore), ...mapStores(useRootStore, useSettingsStore, useUserStore, useTransactionsStore, useOverviewStore, useStatisticsStore, useExchangeRatesStore),
enableDisableOptions() { enableDisableOptions() {
return this.$locale.getEnableDisableOptions(); return this.$locale.getEnableDisableOptions();
}, },
@@ -206,6 +209,10 @@ export default {
}, },
set: function (value) { set: function (value) {
this.settingsStore.setTimeZone(value); this.settingsStore.setTimeZone(value);
this.$locale.setTimeZone(value);
this.transactionsStore.updateTransactionListInvalidState(true);
this.overviewStore.updateTransactionOverviewInvalidState(true);
this.statisticsStore.updateTransactionStatisticsInvalidState(true);
} }
}, },
isAutoUpdateExchangeRatesData: { isAutoUpdateExchangeRatesData: {
+8 -1
View File
@@ -90,6 +90,9 @@ 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 { useUserStore } from '@/stores/user.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useOverviewStore } from '@/stores/overview.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js'; import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import currencyConstants from '@/consts/currency.js'; import currencyConstants from '@/consts/currency.js';
@@ -108,7 +111,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapStores(useRootStore, useSettingsStore, useUserStore, useExchangeRatesStore), ...mapStores(useRootStore, useSettingsStore, useUserStore, useTransactionsStore, useOverviewStore, useStatisticsStore, useExchangeRatesStore),
version() { version() {
return 'v' + this.$version; return 'v' + this.$version;
}, },
@@ -141,6 +144,10 @@ export default {
}, },
set: function (value) { set: function (value) {
this.settingsStore.setTimeZone(value); this.settingsStore.setTimeZone(value);
this.$locale.setTimeZone(value);
this.transactionsStore.updateTransactionListInvalidState(true);
this.overviewStore.updateTransactionOverviewInvalidState(true);
this.statisticsStore.updateTransactionStatisticsInvalidState(true);
} }
}, },
exchangeRatesLastUpdateDate() { exchangeRatesLastUpdateDate() {
+2 -2
View File
@@ -480,7 +480,7 @@ export default {
return true; return true;
}, },
currentTimezoneOffsetMinutes() { currentTimezoneOffsetMinutes() {
return getTimezoneOffsetMinutes(); return getTimezoneOffsetMinutes(this.settingsStore.appSettings.timeZone);
}, },
firstDayOfWeek() { firstDayOfWeek() {
return this.userStore.currentUserFirstDayOfWeek; return this.userStore.currentUserFirstDayOfWeek;
@@ -671,7 +671,7 @@ export default {
changeDateFilter(dateType) { changeDateFilter(dateType) {
if (dateType === this.allDateRanges.Custom.type) { // Custom if (dateType === this.allDateRanges.Custom.type) { // Custom
if (!this.query.minTime || !this.query.maxTime) { if (!this.query.minTime || !this.query.maxTime) {
this.query.maxTime = getActualUnixTimeForStore(getCurrentUnixTime(), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()); this.query.maxTime = getActualUnixTimeForStore(getCurrentUnixTime(), this.currentTimezoneOffsetMinutes, getBrowserTimezoneOffsetMinutes());
this.query.minTime = getSpecifiedDayFirstUnixTime(this.query.maxTime); this.query.minTime = getSpecifiedDayFirstUnixTime(this.query.maxTime);
} }