add category preset for desktop page

This commit is contained in:
MaysWind
2023-08-03 22:47:52 +08:00
parent 8c7875d7ea
commit 19d3d80013
5 changed files with 140 additions and 157 deletions
+36
View File
@@ -77,6 +77,24 @@ export function isEquals(obj1, obj2) {
}
}
export function getObjectOwnFieldCount(object) {
let count = 0;
if (!object || !isObject(object)) {
return count;
}
for (let field in object) {
if (!Object.prototype.hasOwnProperty.call(object, field)) {
continue;
}
count++;
}
return count;
}
export function appendThousandsSeparator(value, enable) {
if (!enable || value.length <= 3) {
return value;
@@ -284,6 +302,24 @@ export function copyArrayTo(fromArray, toArray) {
return toArray;
}
export function categoriedArrayToPlainArray(object) {
const ret = [];
for (let field in object) {
if (!Object.prototype.hasOwnProperty.call(object, field)) {
continue;
}
const array = object[field];
for (let i = 0; i < array.length; i++) {
ret.push(array[i]);
}
}
return ret;
}
export function arrangeArrayWithNewStartIndex(array, startIndex) {
if (startIndex <= 0 || startIndex >= array.length) {
return array;
+59 -1
View File
@@ -4,11 +4,13 @@ import { defaultLanguage, allLanguages } from '@/locales/index.js';
import datetime from '@/consts/datetime.js';
import timezone from '@/consts/timezone.js';
import currency from '@/consts/currency.js';
import category from '@/consts/category.js';
import statistics from '@/consts/statistics.js';
import {
isString,
isNumber
isNumber,
copyArrayTo
} from './common.js';
import {
@@ -747,6 +749,61 @@ function getAllTransactionEditScopeTypes(translateFn) {
}];
}
function getAllTransactionDefaultCategories(categoryType, locale, translateFn) {
const allCategories = {};
const categoryTypes = [];
if (categoryType === 0) {
for (let i = category.allCategoryTypes.Income; i <= category.allCategoryTypes.Transfer; i++) {
categoryTypes.push(i);
}
} else {
categoryTypes.push(categoryType);
}
for (let i = 0; i < categoryTypes.length; i++) {
const categories = [];
const categoryType = categoryTypes[i];
let defaultCategories = [];
if (categoryType === category.allCategoryTypes.Income) {
defaultCategories = copyArrayTo(category.defaultIncomeCategories, []);
} else if (categoryType === category.allCategoryTypes.Expense) {
defaultCategories = copyArrayTo(category.defaultExpenseCategories, []);
} else if (categoryType === category.allCategoryTypes.Transfer) {
defaultCategories = copyArrayTo(category.defaultTransferCategories, []);
}
for (let j = 0; j < defaultCategories.length; j++) {
const category = defaultCategories[j];
const submitCategory = {
name: translateFn('category.' + category.name, locale),
type: categoryType,
icon: category.categoryIconId,
color: category.color,
subCategories: []
}
for (let k = 0; k < category.subCategories.length; k++) {
const subCategory = category.subCategories[k];
submitCategory.subCategories.push({
name: translateFn('category.' + subCategory.name, locale),
type: categoryType,
icon: subCategory.categoryIconId,
color: subCategory.color
});
}
categories.push(submitCategory);
}
allCategories[categoryType] = categories;
}
return allCategories;
}
function getAllDisplayExchangeRates(exchangeRatesData, translateFn) {
if (!exchangeRatesData || !exchangeRatesData.exchangeRates) {
return [];
@@ -1069,6 +1126,7 @@ export function i18nFunctions(i18nGlobal) {
getAllStatisticsChartDataTypes: () => getAllStatisticsChartDataTypes(i18nGlobal.t),
getAllStatisticsSortingTypes: () => getAllStatisticsSortingTypes(i18nGlobal.t),
getAllTransactionEditScopeTypes: () => getAllTransactionEditScopeTypes(i18nGlobal.t),
getAllTransactionDefaultCategories: (categoryType, locale) => getAllTransactionDefaultCategories(categoryType, locale, i18nGlobal.t),
getAllDisplayExchangeRates: (exchangeRatesData) => getAllDisplayExchangeRates(exchangeRatesData, i18nGlobal.t),
getEnableDisableOptions: () => getEnableDisableOptions(i18nGlobal.t),
getDisplayCurrency: (value, currencyCode, options) => getDisplayCurrency(value, currencyCode, options, i18nGlobal.t),