feat: add select options with filter fn factory

This commit is contained in:
Methapon2001 2024-07-26 11:29:34 +07:00
parent c3ac90429e
commit 0b8c0aa9ad

View file

@ -1,4 +1,4 @@
import { Dialog } from 'quasar';
import { Dialog, QSelect } from 'quasar';
import GlobalDialog from 'components/GlobalDialog.vue';
import { ComposerTranslation, useI18n } from 'vue-i18n';
import { defineStore } from 'pinia';
@ -74,6 +74,27 @@ export function formatNumberDecimal(num: number, point: number): string {
});
}
export function selectOptionFilter(
list: Record<string, any>[],
filterField?: string,
) {
const options = ref<typeof list>([]);
const filter = ((value, update) => {
if (value === '') update(() => (options.value = list));
else
update(() => {
options.value = list.filter(
(v) =>
v[filterField || 'label']
.toLocaleLowerCase()
.indexOf(value.toLocaleLowerCase()) > -1,
);
});
}) satisfies QSelect['onFilter'];
return { options, filter };
}
const useUtilsStore = defineStore('utilsStore', () => {
const currentTitle = ref<{
title: string;