mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
code refactor
This commit is contained in:
@@ -363,32 +363,6 @@ function setSortable(): void {
|
|||||||
displayOrderModified.value = false;
|
displayOrderModified.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSort(event: { el: { id: string }; from: number; to: number }): void {
|
|
||||||
if (!event || !event.el || !event.el.id) {
|
|
||||||
showToast('Unable to move account');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = parseAccountIdFromDomId(event.el.id);
|
|
||||||
|
|
||||||
if (!id) {
|
|
||||||
showToast('Unable to move account');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
accountsStore.changeAccountDisplayOrder({
|
|
||||||
accountId: id,
|
|
||||||
from: event.from - 1, // first item in the list is title, so the index need minus one
|
|
||||||
to: event.to - 1,
|
|
||||||
updateListOrder: true,
|
|
||||||
updateGlobalListOrder: true
|
|
||||||
}).then(() => {
|
|
||||||
displayOrderModified.value = true;
|
|
||||||
}).catch(error => {
|
|
||||||
showToast(error.message || error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveSortResult(): void {
|
function saveSortResult(): void {
|
||||||
if (!displayOrderModified.value) {
|
if (!displayOrderModified.value) {
|
||||||
showHidden.value = false;
|
showHidden.value = false;
|
||||||
@@ -416,6 +390,32 @@ function saveSortResult(): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onSort(event: { el: { id: string }; from: number; to: number }): void {
|
||||||
|
if (!event || !event.el || !event.el.id) {
|
||||||
|
showToast('Unable to move account');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = parseAccountIdFromDomId(event.el.id);
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
showToast('Unable to move account');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
accountsStore.changeAccountDisplayOrder({
|
||||||
|
accountId: id,
|
||||||
|
from: event.from - 1, // first item in the list is title, so the index need minus one
|
||||||
|
to: event.to - 1,
|
||||||
|
updateListOrder: true,
|
||||||
|
updateGlobalListOrder: true
|
||||||
|
}).then(() => {
|
||||||
|
displayOrderModified.value = true;
|
||||||
|
}).catch(error => {
|
||||||
|
showToast(error.message || error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onPageAfterIn(): void {
|
function onPageAfterIn(): void {
|
||||||
if (accountsStore.accountListStateInvalid && !loading.value) {
|
if (accountsStore.accountListStateInvalid && !loading.value) {
|
||||||
reload(null);
|
reload(null);
|
||||||
|
|||||||
@@ -347,14 +347,6 @@ function saveSortResult(): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPageAfterIn(): void {
|
|
||||||
if (transactionCategoriesStore.transactionCategoryListStateInvalid && !loading.value) {
|
|
||||||
reload(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
routeBackOnError(props.f7router, loadingError);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSort(event: { el: { id: string }; from: number; to: number }): void {
|
function onSort(event: { el: { id: string }; from: number; to: number }): void {
|
||||||
if (!event || !event.el || !event.el.id) {
|
if (!event || !event.el || !event.el.id) {
|
||||||
showToast('Unable to move category');
|
showToast('Unable to move category');
|
||||||
@@ -379,6 +371,14 @@ function onSort(event: { el: { id: string }; from: number; to: number }): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPageAfterIn(): void {
|
||||||
|
if (transactionCategoriesStore.transactionCategoryListStateInvalid && !loading.value) {
|
||||||
|
reload(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
routeBackOnError(props.f7router, loadingError);
|
||||||
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ const props = defineProps<{
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { tt } = useI18n();
|
const { tt } = useI18n();
|
||||||
const { showToast, routeBackOnError } = useI18nUIComponents();
|
const { showAlert, showToast, routeBackOnError } = useI18nUIComponents();
|
||||||
|
|
||||||
const transactionTagsStore = useTransactionTagsStore();
|
const transactionTagsStore = useTransactionTagsStore();
|
||||||
|
|
||||||
@@ -207,7 +207,24 @@ function parseTagIdFromDomId(domId: string): string | null {
|
|||||||
return domId.substring(4); // tag_
|
return domId.substring(4); // tag_
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload(done?: () => void): void {
|
function init(): void {
|
||||||
|
loading.value = true;
|
||||||
|
|
||||||
|
transactionTagsStore.loadAllTags({
|
||||||
|
force: false
|
||||||
|
}).then(() => {
|
||||||
|
loading.value = false;
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.processed) {
|
||||||
|
loading.value = false;
|
||||||
|
} else {
|
||||||
|
loadingError.value = error;
|
||||||
|
showToast(error.message || error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reload(done: (() => void) | null): void {
|
||||||
if (sortable.value || hasEditingTag.value) {
|
if (sortable.value || hasEditingTag.value) {
|
||||||
done?.();
|
done?.();
|
||||||
return;
|
return;
|
||||||
@@ -273,6 +290,55 @@ function cancelSave(tag: TransactionTag): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hide(tag: TransactionTag, hidden: boolean): void {
|
||||||
|
showLoading();
|
||||||
|
|
||||||
|
transactionTagsStore.hideTag({
|
||||||
|
tag: tag,
|
||||||
|
hidden: hidden
|
||||||
|
}).then(() => {
|
||||||
|
hideLoading();
|
||||||
|
}).catch(error => {
|
||||||
|
hideLoading();
|
||||||
|
|
||||||
|
if (!error.processed) {
|
||||||
|
showToast(error.message || error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(tag: TransactionTag | null, confirm: boolean): void {
|
||||||
|
if (!tag) {
|
||||||
|
showAlert('An error occurred');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
tagToDelete.value = tag;
|
||||||
|
showDeleteActionSheet.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showDeleteActionSheet.value = false;
|
||||||
|
tagToDelete.value = null;
|
||||||
|
showLoading();
|
||||||
|
|
||||||
|
transactionTagsStore.deleteTag({
|
||||||
|
tag: tag,
|
||||||
|
beforeResolve: (done) => {
|
||||||
|
onSwipeoutDeleted(getTagDomId(tag), done);
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
hideLoading();
|
||||||
|
}).catch(error => {
|
||||||
|
hideLoading();
|
||||||
|
|
||||||
|
if (!error.processed) {
|
||||||
|
showToast(error.message || error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setSortable(): void {
|
function setSortable(): void {
|
||||||
if (sortable.value || hasEditingTag.value) {
|
if (sortable.value || hasEditingTag.value) {
|
||||||
return;
|
return;
|
||||||
@@ -310,59 +376,6 @@ function saveSortResult(): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide(tag: TransactionTag, hidden: boolean): void {
|
|
||||||
showLoading();
|
|
||||||
|
|
||||||
transactionTagsStore.hideTag({
|
|
||||||
tag: tag,
|
|
||||||
hidden: hidden
|
|
||||||
}).then(() => {
|
|
||||||
hideLoading();
|
|
||||||
}).catch(error => {
|
|
||||||
hideLoading();
|
|
||||||
|
|
||||||
if (!error.processed) {
|
|
||||||
showToast(error.message || error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove(tag: TransactionTag | null, confirm: boolean): void {
|
|
||||||
if (!tag) {
|
|
||||||
showToast('An error occurred');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!confirm) {
|
|
||||||
tagToDelete.value = tag;
|
|
||||||
showDeleteActionSheet.value = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showDeleteActionSheet.value = false;
|
|
||||||
tagToDelete.value = null;
|
|
||||||
showLoading();
|
|
||||||
|
|
||||||
transactionTagsStore.deleteTag({
|
|
||||||
tag: tag,
|
|
||||||
beforeResolve: (done) => {
|
|
||||||
onSwipeoutDeleted(getTagDomId(tag), done);
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
hideLoading();
|
|
||||||
}).catch(error => {
|
|
||||||
hideLoading();
|
|
||||||
|
|
||||||
if (!error.processed) {
|
|
||||||
showToast(error.message || error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPageAfterIn(): void {
|
|
||||||
routeBackOnError(props.f7router, loadingError);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSort(event: { el: { id: string }, from: number, to: number }): void {
|
function onSort(event: { el: { id: string }, from: number, to: number }): void {
|
||||||
if (!event || !event.el || !event.el.id) {
|
if (!event || !event.el || !event.el.id) {
|
||||||
showToast('Unable to move tag');
|
showToast('Unable to move tag');
|
||||||
@@ -387,18 +400,15 @@ function onSort(event: { el: { id: string }, from: number, to: number }): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionTagsStore.loadAllTags({
|
function onPageAfterIn(): void {
|
||||||
force: false
|
if (transactionTagsStore.transactionTagListStateInvalid && !loading.value) {
|
||||||
}).then(() => {
|
reload(null);
|
||||||
loading.value = false;
|
|
||||||
}).catch(error => {
|
|
||||||
if (error.processed) {
|
|
||||||
loading.value = false;
|
|
||||||
} else {
|
|
||||||
loadingError.value = error;
|
|
||||||
showToast(error.message || error);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
routeBackOnError(props.f7router, loadingError);
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user