From 0b8c0aa9ade52e0edbca1e6c2250503ebbbb751b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:29:34 +0700 Subject: [PATCH] feat: add select options with filter fn factory --- src/stores/utils/index.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index f2b6f541..45b82b70 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -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[], + filterField?: string, +) { + const options = ref([]); + 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;