feat: #8410 added new feature to module searchbar #1272
|
@ -10,12 +10,13 @@ import routes from 'src/router/modules';
|
|||
import LeftMenuItem from './LeftMenuItem.vue';
|
||||
import LeftMenuItemGroup from './LeftMenuItemGroup.vue';
|
||||
import VnInput from './common/VnInput.vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const quasar = useQuasar();
|
||||
const navigation = useNavigationStore();
|
||||
|
||||
const router = useRouter();
|
||||
const props = defineProps({
|
||||
source: {
|
||||
type: String,
|
||||
|
@ -174,6 +175,35 @@ function normalize(text) {
|
|||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase();
|
||||
}
|
||||
const searchModule = () => {
|
||||
provira marked this conversation as resolved
Outdated
|
||||
const moduleArrays = ref([]);
|
||||
items.value.forEach((item) => {
|
||||
jorgep marked this conversation as resolved
Outdated
jorgep
commented
No es necesario que sea ref, usar variable normal. No es necesario que sea ref, usar variable normal.
provira
commented
arreglado arreglado
|
||||
moduleArrays.value.push({
|
||||
title: getLocale(item.title).normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(),
|
||||
name: item.name
|
||||
});
|
||||
})
|
||||
const searching = ref(false)
|
||||
moduleArrays.value.find((module) => {
|
||||
console.log(module.title);
|
||||
provira marked this conversation as resolved
Outdated
jorgep
commented
Quitar Quitar
|
||||
if (module.title.includes(search.value.toLowerCase()) && !searching.value) {
|
||||
searching.value = true;
|
||||
jorgep
commented
si no se usa quitar si no se usa quitar
provira
commented
quitado quitado
|
||||
router.push({ name: module.name });
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const getLocale = (label) => {
|
||||
provira marked this conversation as resolved
Outdated
jorgep
commented
Solo gastas esta función en 1 sitio, es innecesaria. Solo gastas esta función en 1 sitio, es innecesaria.
|
||||
const globalLocale = t(label);
|
||||
jorgep marked this conversation as resolved
Outdated
jorgep
commented
llamar solo a la fn searchModule() llamar solo a la fn **searchModule()** `@keyup.enter.stop="searchModule()"`
|
||||
return globalLocale;
|
||||
};
|
||||
const searchingValue = ref(false);
|
||||
jorgep marked this conversation as resolved
Outdated
jorgep
commented
Las variables ponlas juntas y las funciones lo mismo. Las variables ponlas juntas y las funciones lo mismo.
|
||||
function searchingFunction(evt) {
|
||||
provira marked this conversation as resolved
Outdated
jorgep
commented
Solo gastas esta función en 1 sitio, es innecesaria. Solo gastas esta función en 1 sitio, es innecesaria.
|
||||
searchingValue.value = true;
|
||||
if(evt === null) {
|
||||
searchingValue.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -188,10 +218,12 @@ function normalize(text) {
|
|||
filled
|
||||
dense
|
||||
autofocus
|
||||
@keyup.enter.stop="searchModule(search)"
|
||||
@update:model-value="searchingFunction($event)"
|
||||
provira marked this conversation as resolved
Outdated
jorgep
commented
en lugar de usar una función, puedes hacer searchingVal = !!$event; que te devuelve el valor booleano. Y te ahorras líneas. en lugar de usar una función, puedes hacer searchingVal = !!$event; que te devuelve el valor booleano. Y te ahorras líneas.
|
||||
/>
|
||||
</QItem>
|
||||
<QSeparator />
|
||||
<template v-if="filteredPinnedModules.size">
|
||||
<template v-if="filteredPinnedModules.size && !searchingValue">
|
||||
<LeftMenuItem
|
||||
v-for="[key, pinnedModule] of filteredPinnedModules"
|
||||
:key="key"
|
||||
|
@ -215,11 +247,11 @@ function normalize(text) {
|
|||
</LeftMenuItem>
|
||||
<QSeparator />
|
||||
</template>
|
||||
<template v-for="item in filteredItems" :key="item.name">
|
||||
<template v-for="(item, index) in filteredItems" :key="item.name">
|
||||
<template
|
||||
v-if="item.children && !filteredPinnedModules.has(item.name)"
|
||||
v-if="searchingValue ||item.children && !filteredPinnedModules.has(item.name)"
|
||||
>
|
||||
<LeftMenuItem :item="item" group="modules">
|
||||
<LeftMenuItem :item="item" group="modules" :class="searchingValue && index === 0 ? 'searched' : ''">
|
||||
<template #side>
|
||||
<QBtn
|
||||
v-if="item.isPinned === true"
|
||||
|
@ -336,6 +368,9 @@ function normalize(text) {
|
|||
.header {
|
||||
color: var(--vn-label-color);
|
||||
}
|
||||
.searched{
|
||||
jorgep
commented
Sería un mejor enfoque intentar forzar el foco del item. Sería un mejor enfoque intentar forzar el foco del item.
|
||||
background-color: var(--vn-section-hover-color);
|
||||
}
|
||||
</style>
|
||||
<i18n>
|
||||
es:
|
||||
|
|
Loading…
Reference in New Issue
Estás haciendo 2 bucles, pasar a 1. Respuesta de copilot: