mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
code refactor
This commit is contained in:
@@ -20,13 +20,11 @@ import {
|
|||||||
import {
|
import {
|
||||||
getYearMonthFirstUnixTime,
|
getYearMonthFirstUnixTime,
|
||||||
getYearMonthLastUnixTime,
|
getYearMonthLastUnixTime,
|
||||||
getAllYearsStartAndEndUnixTimes,
|
|
||||||
getAllQuartersStartAndEndUnixTimes,
|
|
||||||
getAllMonthsStartAndEndUnixTimes,
|
|
||||||
getDateTypeByDateRange
|
getDateTypeByDateRange
|
||||||
} from '@/lib/datetime.js';
|
} from '@/lib/datetime.js';
|
||||||
import {
|
import {
|
||||||
sortStatisticsItems
|
sortStatisticsItems,
|
||||||
|
getAllDateRanges
|
||||||
} from '@/lib/statistics.js';
|
} from '@/lib/statistics.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -87,44 +85,7 @@ export default {
|
|||||||
return map;
|
return map;
|
||||||
},
|
},
|
||||||
allDateRanges: function () {
|
allDateRanges: function () {
|
||||||
let startYearMonth = this.startYearMonth;
|
return getAllDateRanges(this.items, this.startYearMonth, this.endYearMonth, this.dateAggregationType);
|
||||||
let endYearMonth = this.endYearMonth;
|
|
||||||
|
|
||||||
if ((!this.startYearMonth || !this.endYearMonth) && this.items && this.items.length) {
|
|
||||||
let minYear = Number.MAX_SAFE_INTEGER, minMonth = Number.MAX_SAFE_INTEGER, maxYear = 0, maxMonth = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.items.length; i++) {
|
|
||||||
const item = this.items[i];
|
|
||||||
|
|
||||||
for (let j = 0; j < item.items.length; j++) {
|
|
||||||
const dataItem = item.items[j];
|
|
||||||
|
|
||||||
if (dataItem.year < minYear || (dataItem.year === minYear && dataItem.month < minMonth)) {
|
|
||||||
minYear = dataItem.year;
|
|
||||||
minMonth = dataItem.month;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataItem.year > maxYear || (dataItem.year === maxYear && dataItem.month > maxMonth)) {
|
|
||||||
maxYear = dataItem.year;
|
|
||||||
maxMonth = dataItem.month;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
startYearMonth = `${minYear}-${minMonth}`;
|
|
||||||
endYearMonth = `${maxYear}-${maxMonth}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!startYearMonth || !endYearMonth) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (this.dateAggregationType === statisticsConstants.allDateAggregationTypes.Year.type) {
|
|
||||||
return getAllYearsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
|
||||||
} else if (this.dateAggregationType === statisticsConstants.allDateAggregationTypes.Quarter.type) {
|
|
||||||
return getAllQuartersStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
|
||||||
} else { // if (this.dateAggregationType === statisticsConstants.allDateAggregationTypes.Month.type) {
|
|
||||||
return getAllMonthsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
allDisplayDateRanges: function () {
|
allDisplayDateRanges: function () {
|
||||||
const allDisplayDateRanges = [];
|
const allDisplayDateRanges = [];
|
||||||
@@ -301,14 +262,14 @@ export default {
|
|||||||
displayItems.push({
|
displayItems.push({
|
||||||
name: name,
|
name: name,
|
||||||
color: color,
|
color: color,
|
||||||
displayOrders:displayOrders,
|
displayOrders: displayOrders,
|
||||||
totalAmount: amount
|
totalAmount: amount
|
||||||
});
|
});
|
||||||
|
|
||||||
totalAmount += amount;
|
totalAmount += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
sortStatisticsItems(displayItems, self.sortingType)
|
sortStatisticsItems(displayItems, self.sortingType);
|
||||||
|
|
||||||
for (let i = 0; i < displayItems.length; i++) {
|
for (let i = 0; i < displayItems.length; i++) {
|
||||||
const item = displayItems[i];
|
const item = displayItems[i];
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import statisticsConstants from '@/consts/statistics.js';
|
import statisticsConstants from '@/consts/statistics.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getAllMonthsStartAndEndUnixTimes,
|
||||||
|
getAllQuartersStartAndEndUnixTimes,
|
||||||
|
getAllYearsStartAndEndUnixTimes
|
||||||
|
} from '@/lib/datetime.js';
|
||||||
|
|
||||||
export function isChartDataTypeAvailableForAnalysisType(chartDataType, analysisType) {
|
export function isChartDataTypeAvailableForAnalysisType(chartDataType, analysisType) {
|
||||||
for (const dataTypeField in statisticsConstants.allChartDataTypes) {
|
for (const dataTypeField in statisticsConstants.allChartDataTypes) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allChartDataTypes, dataTypeField)) {
|
if (!Object.prototype.hasOwnProperty.call(statisticsConstants.allChartDataTypes, dataTypeField)) {
|
||||||
@@ -52,3 +58,41 @@ export function sortStatisticsItems(items, sortingType) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAllDateRanges(items, startYearMonth, endYearMonth, dateAggregationType) {
|
||||||
|
if ((!startYearMonth || !endYearMonth) && items && items.length) {
|
||||||
|
let minYear = Number.MAX_SAFE_INTEGER, minMonth = Number.MAX_SAFE_INTEGER, maxYear = 0, maxMonth = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const item = items[i];
|
||||||
|
|
||||||
|
for (let j = 0; j < item.items.length; j++) {
|
||||||
|
const dataItem = item.items[j];
|
||||||
|
|
||||||
|
if (dataItem.year < minYear || (dataItem.year === minYear && dataItem.month < minMonth)) {
|
||||||
|
minYear = dataItem.year;
|
||||||
|
minMonth = dataItem.month;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataItem.year > maxYear || (dataItem.year === maxYear && dataItem.month > maxMonth)) {
|
||||||
|
maxYear = dataItem.year;
|
||||||
|
maxMonth = dataItem.month;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startYearMonth = `${minYear}-${minMonth}`;
|
||||||
|
endYearMonth = `${maxYear}-${maxMonth}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!startYearMonth || !endYearMonth) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Year.type) {
|
||||||
|
return getAllYearsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||||
|
} else if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Quarter.type) {
|
||||||
|
return getAllQuartersStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||||
|
} else { // if (dateAggregationType === statisticsConstants.allDateAggregationTypes.Month.type) {
|
||||||
|
return getAllMonthsStartAndEndUnixTimes(startYearMonth, endYearMonth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ export default {
|
|||||||
alwaysShowNav: mdAndUp.value,
|
alwaysShowNav: mdAndUp.value,
|
||||||
showNav: mdAndUp.value,
|
showNav: mdAndUp.value,
|
||||||
analysisType: statisticsConstants.allAnalysisTypes.CategoricalAnalysis,
|
analysisType: statisticsConstants.allAnalysisTypes.CategoricalAnalysis,
|
||||||
trendDateAggregationType: statisticsConstants.allDateAggregationTypes.Month.type,
|
trendDateAggregationType: statisticsConstants.defaultDateAggregationType,
|
||||||
showCustomDateRangeDialog: false,
|
showCustomDateRangeDialog: false,
|
||||||
showCustomMonthRangeDialog: false,
|
showCustomMonthRangeDialog: false,
|
||||||
showFilterAccountDialog: false,
|
showFilterAccountDialog: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user