code refactor

This commit is contained in:
MaysWind
2024-11-08 17:47:40 +08:00
parent 9a009b73dc
commit 01bc9becc0
9 changed files with 167 additions and 111 deletions
+6 -16
View File
@@ -201,6 +201,10 @@ import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import categoryConstants from '@/consts/category.js';
import {
isNoAvailableCategory,
getAvailableCategoryCount
} from '@/lib/category.js';
import { getNavSideBarOuterHeight } from '@/lib/ui.desktop.js';
import {
@@ -278,27 +282,13 @@ export default {
}
},
noAvailableCategory() {
for (let i = 0; i < this.categories.length; i++) {
if (this.showHidden || !this.categories[i].hidden) {
return false;
}
}
return true;
return isNoAvailableCategory(this.categories, this.showHidden);
},
noCategory() {
return this.categories.length < 1;
},
availableCategoryCount() {
let count = 0;
for (let i = 0; i < this.categories.length; i++) {
if (this.showHidden || !this.categories[i].hidden) {
count++;
}
}
return count;
return getAvailableCategoryCount(this.categories, this.showHidden);
}
},
created() {
+7 -16
View File
@@ -226,6 +226,11 @@
import { mapStores } from 'pinia';
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import {
isNoAvailableTag,
getAvailableTagCount
} from '@/lib/tag.js';
import {
mdiRefresh,
mdiPlus,
@@ -276,24 +281,10 @@ export default {
return this.transactionTagsStore.allTransactionTags;
},
noAvailableTag() {
for (let i = 0; i < this.tags.length; i++) {
if (this.showHidden || !this.tags[i].hidden) {
return false;
}
}
return true;
return isNoAvailableTag(this.tags, this.showHidden);
},
availableTagCount() {
let count = 0;
for (let i = 0; i < this.tags.length; i++) {
if (this.showHidden || !this.tags[i].hidden) {
count++;
}
}
return count;
return getAvailableTagCount(this.tags, this.showHidden);
},
hasEditingTag() {
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
+6 -16
View File
@@ -152,6 +152,10 @@ import { mapStores } from 'pinia';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import templateConstants from '@/consts/template.js';
import {
isNoAvailableTemplate,
getAvailableTemplateCount
} from '@/lib/template.js';
import {
mdiRefresh,
@@ -206,24 +210,10 @@ export default {
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
},
noAvailableTemplate() {
for (let i = 0; i < this.templates.length; i++) {
if (this.showHidden || !this.templates[i].hidden) {
return false;
}
}
return true;
return isNoAvailableTemplate(this.templates, this.showHidden);
},
availableTemplateCount() {
let count = 0;
for (let i = 0; i < this.templates.length; i++) {
if (this.showHidden || !this.templates[i].hidden) {
count++;
}
}
return count;
return getAvailableTemplateCount(this.templates, this.showHidden);
},
allTemplateTypes() {
return templateConstants.allTemplateTypes;
+8 -21
View File
@@ -91,6 +91,11 @@ import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import categoryConstants from '@/consts/category.js';
import {
isNoAvailableCategory,
getFirstShowingId,
getLastShowingId
} from '@/lib/category.js';
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
export default {
@@ -163,31 +168,13 @@ export default {
return title + ' Categories';
},
firstShowingId() {
for (let i = 0; i < this.categories.length; i++) {
if (this.showHidden || !this.categories[i].hidden) {
return this.categories[i].id;
}
}
return null;
return getFirstShowingId(this.categories, this.showHidden);
},
lastShowingId() {
for (let i = this.categories.length - 1; i >= 0; i--) {
if (this.showHidden || !this.categories[i].hidden) {
return this.categories[i].id;
}
}
return null;
return getLastShowingId(this.categories, this.showHidden);
},
noAvailableCategory() {
for (let i = 0; i < this.categories.length; i++) {
if (this.showHidden || !this.categories[i].hidden) {
return false;
}
}
return true;
return isNoAvailableCategory(this.categories, this.showHidden);
},
noCategory() {
return this.categories.length < 1;
+8 -21
View File
@@ -147,6 +147,11 @@
import { mapStores } from 'pinia';
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import {
isNoAvailableTag,
getFirstShowingId,
getLastShowingId
} from '@/lib/tag.js';
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
export default {
@@ -179,31 +184,13 @@ export default {
return this.transactionTagsStore.allTransactionTags;
},
firstShowingId() {
for (let i = 0; i < this.tags.length; i++) {
if (this.showHidden || !this.tags[i].hidden) {
return this.tags[i].id;
}
}
return null;
return getFirstShowingId(this.tags, this.showHidden);
},
lastShowingId() {
for (let i = this.tags.length - 1; i >= 0; i--) {
if (this.showHidden || !this.tags[i].hidden) {
return this.tags[i].id;
}
}
return null;
return getLastShowingId(this.tags, this.showHidden);
},
noAvailableTag() {
for (let i = 0; i < this.tags.length; i++) {
if (this.showHidden || !this.tags[i].hidden) {
return false;
}
}
return true;
return isNoAvailableTag(this.tags, this.showHidden);
},
hasEditingTag() {
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
+8 -21
View File
@@ -90,6 +90,11 @@ import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import templateConstants from '@/consts/template.js';
import { isDefined } from '@/lib/common.js';
import {
isNoAvailableTemplate,
getFirstShowingId,
getLastShowingId
} from '@/lib/template.js';
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
export default {
@@ -117,31 +122,13 @@ export default {
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
},
firstShowingId() {
for (let i = 0; i < this.templates.length; i++) {
if (this.showHidden || !this.templates[i].hidden) {
return this.templates[i].id;
}
}
return null;
return getFirstShowingId(this.templates, this.showHidden);
},
lastShowingId() {
for (let i = this.templates.length - 1; i >= 0; i--) {
if (this.showHidden || !this.templates[i].hidden) {
return this.templates[i].id;
}
}
return null;
return getLastShowingId(this.templates, this.showHidden);
},
noAvailableTemplate() {
for (let i = 0; i < this.templates.length; i++) {
if (this.showHidden || !this.templates[i].hidden) {
return false;
}
}
return true;
return isNoAvailableTemplate(this.templates, this.showHidden);
},
allTemplateTypes() {
return templateConstants.allTemplateTypes;