mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
transaction tag selection sheet supports filtering content (#38)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<f7-sheet swipe-to-close swipe-handler=".swipe-handler"
|
<f7-sheet swipe-to-close swipe-handler=".swipe-handler"
|
||||||
:class="heightClass" :opened="show"
|
style="height: auto" :opened="show"
|
||||||
@sheet:open="onSheetOpen" @sheet:closed="onSheetClosed">
|
@sheet:open="onSheetOpen" @sheet:closed="onSheetClosed">
|
||||||
<f7-toolbar>
|
<f7-toolbar>
|
||||||
<div class="swipe-handler"></div>
|
<div class="swipe-handler"></div>
|
||||||
@@ -13,7 +13,14 @@
|
|||||||
:text="tt('Add')" v-if="!allTags || !allTags.length || noAvailableTag" @click="addNewTag"></f7-link>
|
:text="tt('Add')" v-if="!allTags || !allTags.length || noAvailableTag" @click="addNewTag"></f7-link>
|
||||||
</div>
|
</div>
|
||||||
</f7-toolbar>
|
</f7-toolbar>
|
||||||
<f7-page-content>
|
<f7-searchbar ref="searchbar" custom-searchs
|
||||||
|
:value="filterContent"
|
||||||
|
:placeholder="tt('Find tag')"
|
||||||
|
:disable-button="false"
|
||||||
|
v-if="enableFilter"
|
||||||
|
@input="filterContent = $event.target.value">
|
||||||
|
</f7-searchbar>
|
||||||
|
<f7-page-content :class="'no-padding-top ' + heightClass">
|
||||||
<f7-list class="no-margin-top no-margin-bottom" v-if="(!allTags || !allTags.length || noAvailableTag) && !newTag">
|
<f7-list class="no-margin-top no-margin-bottom" v-if="(!allTags || !allTags.length || noAvailableTag) && !newTag">
|
||||||
<f7-list-item :title="tt('No available tag')"></f7-list-item>
|
<f7-list-item :title="tt('No available tag')"></f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
@@ -24,7 +31,6 @@
|
|||||||
:checked="isChecked(tag.id)"
|
:checked="isChecked(tag.id)"
|
||||||
:key="tag.id"
|
:key="tag.id"
|
||||||
v-for="tag in allTags"
|
v-for="tag in allTags"
|
||||||
v-show="!tag.hidden || isChecked(tag.id)"
|
|
||||||
@change="changeTagSelection">
|
@change="changeTagSelection">
|
||||||
<template #title>
|
<template #title>
|
||||||
<f7-block class="no-padding no-margin">
|
<f7-block class="no-padding no-margin">
|
||||||
@@ -77,7 +83,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed, useTemplateRef } from 'vue';
|
||||||
|
import type { Searchbar } from 'framework7/types';
|
||||||
|
|
||||||
import { useI18n } from '@/locales/helpers.ts';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
import { useI18nUIComponents, showLoading, hideLoading } from '@/lib/ui/mobile.ts';
|
import { useI18nUIComponents, showLoading, hideLoading } from '@/lib/ui/mobile.ts';
|
||||||
@@ -91,6 +98,7 @@ import { type Framework7Dom, scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: string[];
|
modelValue: string[];
|
||||||
allowAddNewTag?: boolean;
|
allowAddNewTag?: boolean;
|
||||||
|
enableFilter?: boolean;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -104,11 +112,33 @@ const { showToast } = useI18nUIComponents();
|
|||||||
|
|
||||||
const transactionTagsStore = useTransactionTagsStore();
|
const transactionTagsStore = useTransactionTagsStore();
|
||||||
|
|
||||||
|
const searchbar = useTemplateRef<Searchbar.Searchbar>('searchbar');
|
||||||
|
|
||||||
|
const filterContent = ref<string>('');
|
||||||
const selectedItemIds = ref<string[]>(copyArrayTo(props.modelValue, []));
|
const selectedItemIds = ref<string[]>(copyArrayTo(props.modelValue, []));
|
||||||
const newTag = ref<TransactionTag | null>(null);
|
const newTag = ref<TransactionTag | null>(null);
|
||||||
const heightClass = ref<string>(getHeightClass());
|
const heightClass = ref<string>(getHeightClass());
|
||||||
|
|
||||||
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
const allTags = computed<TransactionTag[]>(() => {
|
||||||
|
const finalTags: TransactionTag[] = [];
|
||||||
|
|
||||||
|
for (const tag of transactionTagsStore.allTransactionTags) {
|
||||||
|
if (tag.hidden && !isChecked(tag.id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!props.enableFilter || !filterContent.value) {
|
||||||
|
finalTags.push(tag);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.name.toLowerCase().indexOf(filterContent.value.toLowerCase()) >= 0) {
|
||||||
|
finalTags.push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalTags;
|
||||||
|
});
|
||||||
|
|
||||||
const noAvailableTag = computed<boolean>(() => {
|
const noAvailableTag = computed<boolean>(() => {
|
||||||
if (transactionTagsStore.allTransactionTags) {
|
if (transactionTagsStore.allTransactionTags) {
|
||||||
@@ -123,12 +153,12 @@ const noAvailableTag = computed<boolean>(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function getHeightClass(): string {
|
function getHeightClass(): string {
|
||||||
if (transactionTagsStore.allTransactionTags && transactionTagsStore.allTransactionTags.length > 8) {
|
if (transactionTagsStore.allTransactionTags && transactionTagsStore.allVisibleTagsCount > 8) {
|
||||||
return 'tag-selection-huge-sheet';
|
return 'tag-selection-huge-sheet';
|
||||||
} else if (transactionTagsStore.allTransactionTags && transactionTagsStore.allTransactionTags.length > 4) {
|
} else if (transactionTagsStore.allTransactionTags && transactionTagsStore.allVisibleTagsCount > 4) {
|
||||||
return 'tag-selection-large-sheet';
|
return 'tag-selection-large-sheet';
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return 'tag-selection-default-sheet';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,17 +228,23 @@ function onSheetOpen(event: { $el: Framework7Dom }): void {
|
|||||||
|
|
||||||
function onSheetClosed(): void {
|
function onSheetClosed(): void {
|
||||||
emit('update:show', false);
|
emit('update:show', false);
|
||||||
|
filterContent.value = '';
|
||||||
|
searchbar.value?.clear();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@media (min-height: 630px) {
|
@media (min-height: 630px) {
|
||||||
|
.tag-selection-default-sheet {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
.tag-selection-large-sheet {
|
.tag-selection-large-sheet {
|
||||||
height: 310px;
|
height: 250px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-selection-huge-sheet {
|
.tag-selection-huge-sheet {
|
||||||
height: 400px;
|
height: 340px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1819,6 +1819,7 @@
|
|||||||
"Transaction Tags": "Transaction Tags",
|
"Transaction Tags": "Transaction Tags",
|
||||||
"Tag Title": "Tag Title",
|
"Tag Title": "Tag Title",
|
||||||
"No available tag": "No available tag",
|
"No available tag": "No available tag",
|
||||||
|
"Find tag": "Find tag",
|
||||||
"Unable to retrieve tag list": "Unable to retrieve tag list",
|
"Unable to retrieve tag list": "Unable to retrieve tag list",
|
||||||
"Tag list is up to date": "Tag list is up to date",
|
"Tag list is up to date": "Tag list is up to date",
|
||||||
"Tag list has been updated": "Tag list has been updated",
|
"Tag list has been updated": "Tag list has been updated",
|
||||||
|
|||||||
@@ -1819,6 +1819,7 @@
|
|||||||
"Transaction Tags": "Etiquetas de transacción",
|
"Transaction Tags": "Etiquetas de transacción",
|
||||||
"Tag Title": "Título de la etiqueta",
|
"Tag Title": "Título de la etiqueta",
|
||||||
"No available tag": "No hay etiqueta disponible",
|
"No available tag": "No hay etiqueta disponible",
|
||||||
|
"Find tag": "Find tag",
|
||||||
"Unable to retrieve tag list": "No se puede recuperar la lista de etiquetas",
|
"Unable to retrieve tag list": "No se puede recuperar la lista de etiquetas",
|
||||||
"Tag list is up to date": "La lista de etiquetas está actualizada.",
|
"Tag list is up to date": "La lista de etiquetas está actualizada.",
|
||||||
"Tag list has been updated": "La lista de etiquetas ha sido actualizada.",
|
"Tag list has been updated": "La lista de etiquetas ha sido actualizada.",
|
||||||
|
|||||||
@@ -1819,6 +1819,7 @@
|
|||||||
"Transaction Tags": "Теги транзакций",
|
"Transaction Tags": "Теги транзакций",
|
||||||
"Tag Title": "Название тега",
|
"Tag Title": "Название тега",
|
||||||
"No available tag": "Нет доступных тегов",
|
"No available tag": "Нет доступных тегов",
|
||||||
|
"Find tag": "Find tag",
|
||||||
"Unable to retrieve tag list": "Не удалось получить список тегов",
|
"Unable to retrieve tag list": "Не удалось получить список тегов",
|
||||||
"Tag list is up to date": "Список тегов актуален",
|
"Tag list is up to date": "Список тегов актуален",
|
||||||
"Tag list has been updated": "Список тегов обновлен",
|
"Tag list has been updated": "Список тегов обновлен",
|
||||||
|
|||||||
@@ -1819,6 +1819,7 @@
|
|||||||
"Transaction Tags": "Thẻ giao dịch",
|
"Transaction Tags": "Thẻ giao dịch",
|
||||||
"Tag Title": "Tiêu đề thẻ",
|
"Tag Title": "Tiêu đề thẻ",
|
||||||
"No available tag": "Không có thẻ nào khả dụng",
|
"No available tag": "Không có thẻ nào khả dụng",
|
||||||
|
"Find tag": "Find tag",
|
||||||
"Unable to retrieve tag list": "Không thể truy xuất danh sách thẻ",
|
"Unable to retrieve tag list": "Không thể truy xuất danh sách thẻ",
|
||||||
"Tag list is up to date": "Danh sách thẻ đã được cập nhật",
|
"Tag list is up to date": "Danh sách thẻ đã được cập nhật",
|
||||||
"Tag list has been updated": "Danh sách thẻ đã được cập nhật",
|
"Tag list has been updated": "Danh sách thẻ đã được cập nhật",
|
||||||
|
|||||||
@@ -1819,6 +1819,7 @@
|
|||||||
"Transaction Tags": "交易标签",
|
"Transaction Tags": "交易标签",
|
||||||
"Tag Title": "标签标题",
|
"Tag Title": "标签标题",
|
||||||
"No available tag": "没有可用的标签",
|
"No available tag": "没有可用的标签",
|
||||||
|
"Find tag": "查找标签",
|
||||||
"Unable to retrieve tag list": "无法获取标签列表",
|
"Unable to retrieve tag list": "无法获取标签列表",
|
||||||
"Tag list is up to date": "标签列表已是最新",
|
"Tag list is up to date": "标签列表已是最新",
|
||||||
"Tag list has been updated": "标签列表已更新",
|
"Tag list has been updated": "标签列表已更新",
|
||||||
|
|||||||
@@ -315,7 +315,7 @@
|
|||||||
:header="tt('Tags')"
|
:header="tt('Tags')"
|
||||||
@click="showTransactionTagSheet = true"
|
@click="showTransactionTagSheet = true"
|
||||||
>
|
>
|
||||||
<transaction-tag-selection-sheet :allow-add-new-tag="true"
|
<transaction-tag-selection-sheet :allow-add-new-tag="true" :enable-filter="true"
|
||||||
v-model:show="showTransactionTagSheet"
|
v-model:show="showTransactionTagSheet"
|
||||||
v-model="transaction.tagIds">
|
v-model="transaction.tagIds">
|
||||||
</transaction-tag-selection-sheet>
|
</transaction-tag-selection-sheet>
|
||||||
|
|||||||
Reference in New Issue
Block a user