feat: add select options with filter fn factory
This commit is contained in:
parent
c3ac90429e
commit
0b8c0aa9ad
1 changed files with 22 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Dialog } from 'quasar';
|
import { Dialog, QSelect } from 'quasar';
|
||||||
import GlobalDialog from 'components/GlobalDialog.vue';
|
import GlobalDialog from 'components/GlobalDialog.vue';
|
||||||
import { ComposerTranslation, useI18n } from 'vue-i18n';
|
import { ComposerTranslation, useI18n } from 'vue-i18n';
|
||||||
import { defineStore } from 'pinia';
|
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 useUtilsStore = defineStore('utilsStore', () => {
|
||||||
const currentTitle = ref<{
|
const currentTitle = ref<{
|
||||||
title: string;
|
title: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue