refs #6694 VnLocation #154
|
@ -7,11 +7,12 @@ const emit = defineEmits(['update:modelValue', 'update:options']);
|
|||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
const citiesLocationOptions = ref([]);
|
||||
const provincesLocationOptions = ref([]);
|
||||
const countriesOptions = ref([]);
|
||||
// const citiesLocationOptions = ref([]);
|
||||
// const provincesLocationOptions = ref([]);
|
||||
// const countriesOptions = ref([]);
|
||||
// const townsRef = ref([]);
|
||||
const postcodesOptions = ref([]);
|
||||
const postcodeFetchDataRef = ref(null);
|
||||
const postcodesRef = ref(null);
|
||||
|
||||
const $props = defineProps({
|
||||
modelValue: {
|
||||
|
@ -66,25 +67,61 @@ watch(options, (newValue) => {
|
|||
setOptions(newValue);
|
||||
});
|
||||
|
||||
function showLabel(data){
|
||||
return `${data.code} - ${data.town.name}(${data.town.province.name}), ${data.town.province.country.country}`;
|
||||
function showLabel(data) {
|
||||
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
||||
}
|
||||
|
||||
</script>
|
||||
function locationFilter(value) {
|
||||
// if(value==='') return [];
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
let where = { limit: 30 };
|
||||
const params = { value };
|
||||
postcodesRef.value.fetch({ where: Object.assign(where, params) });
|
||||
// postcodesRef.value.fetch({
|
||||
// where: {
|
||||
// or: [
|
||||
// { code: { like: '%4660%' } },
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
De esta manera te estas descargando toda la tabla
Por eso decia que no veia la funcion de filtrado. Yo no haría el filtrado en el front dado que te obliga a descargar todos los registros. Y en este caso lo veo inviable. (añadir limits tambien) De esta manera te estas descargando toda la tabla
- La tabla town tiene 71.691 registros.
- La tabla postCode 271.259 registros.
- ...
Por eso decia que no veia la funcion de filtrado. Yo no haría el filtrado en el front dado que te obliga a descargar todos los registros. Y en este caso lo veo inviable. (añadir limits tambien)
jsegarra
commented
Tendré en cuenta estos datos para hacer unos cambios con respecto al código original. Tendré en cuenta estos datos para hacer unos cambios con respecto al código original.
Gracias por la aportación.
|
||||
// { 'town.name': { like: '%Alz%' } }
|
||||
// ]
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Si solo se usa una vez, llamar directamente a locationFilter Si solo se usa una vez, llamar directamente a locationFilter
jsegarra
commented
Por mantener el formato en el uso de este componente. Por mantener el formato en el uso de este componente.
Pero se puede borrar.
|
||||
// }});
|
||||
// const townParams = { name: { like: `%${val}%` } };
|
||||
jsegarra marked this conversation as resolved
Outdated
jsegarra
commented
Opcion A=> limit="30" Opcion A=> limit="30"
|
||||
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Sin auto-load y hacer con codigo per con limit Sin auto-load y hacer con codigo per con **limit**
O con auto-load pero con limit
jsegarra
commented
El limit lo tienes definido en la línea 71, es correcto? El limit lo tienes definido en la línea 71, es correcto?
alexm
commented
Si y no. Eso sirve para las demás peticiones. Si y no. Eso sirve para las demás peticiones.
Pero no da más abrir la sección te carga toda la tabla (sin limit) al estar puesto el auto-load
(Lo he probado entrando en las ramas)
|
||||
<template>
|
||||
<FetchData
|
||||
ref="postcodeFetchDataRef"
|
||||
url="Postcodes/location"
|
||||
@on-fetch="(data) => (postcodesOptions = data)"
|
||||
auto-load
|
||||
/>
|
||||
<FetchData
|
||||
@on-fetch="(data) => (citiesLocationOptions = data)"
|
||||
// townsRef.value.fetch({ where: Object.assign(where, townParams) });
|
||||
}
|
||||
function handleFetch( data) {
|
||||
// if (from === 'towns') {
|
||||
// data = data.reduce((acc, town) => {
|
||||
// for (const postcode of town.postcodes) {
|
||||
// console.log(postcode);
|
||||
// acc.push({ ...postcode, town:{name: town.name, province: town.province} });
|
||||
// }
|
||||
|
||||
// return acc;
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Igual se lo pondria mas alto, ver como esta en salix Igual se lo pondria mas alto, ver como esta en salix
jsegarra
commented
Corregido Corregido 6809e9bddb37ba812c3e56a8f62f3beb255a051d
|
||||
// }, []);
|
||||
// }
|
||||
// console.log(from, data);
|
||||
postcodesOptions.value = data;
|
||||
}
|
||||
</script>
|
||||
<!-- let where = { limit: 30 };
|
||||
|
||||
const params = { 'town': false, 'townsFk': {like: ``} };
|
||||
where = Object.assign(where, params);
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Com veus esta part? @jgallego Com veus esta part? @jgallego
Es una reglat de filtrat que t'obliga a escriure al menys 3 caracters per a que te filtre.
No ho acabe de vore. Pq si per exemple lo que volen es filtrar per pais pq hi ha un pais q saben q soles tenen 1 codi postal o molt pocs. i fiquen per exemple "J" (pq estan buscant Japon). no els trauria res
jgallego
commented
Si la consulta no es muy lenta/pesada yo no pondria nada. Si la consulta no es muy lenta/pesada yo no pondria nada.
jsegarra
commented
Lo comentamos.
> Es una reglat de filtrat que t'obliga a escriure al menys 3 caracters per a que te filtre.
> No ho acabe de vore. Pq si per exemple lo que volen es filtrar per pais pq hi ha un pais q saben q soles tenen 1 codi postal o molt pocs. i fiquen per exemple "J" (pq estan buscant Japon). no els trauria res
>
Lo comentamos.
|
||||
postcodesRef.value.fetch({ where});
|
||||
} -->
|
||||
<!-- <FetchData
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Si al final se fa la peticio en la back li possaria un delay (input-bounce) crec que se dia Si al final se fa la peticio en la back li possaria un delay (input-bounce) crec que se dia
jsegarra
commented
Lo comentamos Lo comentamos
jsegarra
commented
corregido corregido 655c8210751f819ad4aff1480f94e57f73e22931
|
||||
ref="townsRef"
|
||||
@on-fetch="(data) => handleFetch('towns', data)"
|
||||
auto-load
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Y tampoco veo que se este usando el evento no? Y tampoco veo que se este usando el evento no?
jsegarra
commented
Por mantener el formato en el uso de este componente. Por mantener el formato en el uso de este componente.
Diría que el valor de $event no se está gestionando de ninguna manera en el resto de instancias
En este caso se reemplaza por locationFilter() porque queremos los datos con otro formato
|
||||
url="Towns/location"
|
||||
/>
|
||||
/> -->
|
||||
<template>
|
||||
<FetchData
|
||||
ref="postcodesRef"
|
||||
url="Postcodes/filter"
|
||||
@on-fetch="(data) =>handleFetch(data)"
|
||||
auto-load
|
||||
/>
|
||||
<!-- <FetchData
|
||||
@on-fetch="(data) => (provincesLocationOptions = data)"
|
||||
auto-load
|
||||
url="Provinces/location"
|
||||
|
@ -93,23 +130,26 @@ function showLabel(data){
|
|||
@on-fetch="(data) => (countriesOptions = data)"
|
||||
auto-load
|
||||
url="Countries"
|
||||
/>
|
||||
/> -->
|
||||
<!-- :filter-options="['code','town.name']"
|
||||
:filter-rules="['val.length>2']" -->
|
||||
<VnSelectCreate
|
||||
v-if="postcodesRef"
|
||||
v-model="value"
|
||||
:options="postcodesOptions"
|
||||
:label="t('Location')"
|
||||
:option-label="showLabel"
|
||||
:placeholder="t('Search by postalCode or town (at least 3 characters')"
|
||||
:placeholder="t('Search by postalCode, town, province or country')"
|
||||
v-bind="$attrs"
|
||||
emit-value
|
||||
map-options
|
||||
use-input
|
||||
:filter-options="['code','town.name']"
|
||||
:filter-rules="['val.length>2']"
|
||||
clearable
|
||||
hide-selected
|
||||
fill-input
|
||||
:class="{ required: $attrs.required }"
|
||||
@input-value="locationFilter"
|
||||
:default-filter="false"
|
||||
>
|
||||
<template #form>
|
||||
<CreateNewPostcode @on-data-saved="onPostcodeCreated($event)" />
|
||||
|
@ -118,9 +158,7 @@ function showLabel(data){
|
|||
<QItem v-bind="scope.itemProps">
|
||||
<QItemSection v-if="scope.opt">
|
||||
<QItemLabel>{{ scope.opt.code }}</QItemLabel>
|
||||
<QItemLabel caption
|
||||
>{{ showLabel(scope.opt)}}</QItemLabel
|
||||
>
|
||||
<QItemLabel caption>{{ showLabel(scope.opt) }}</QItemLabel>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
</template>
|
||||
|
@ -137,5 +175,5 @@ function showLabel(data){
|
|||
<i18n>
|
||||
es:
|
||||
Location: Ubicación
|
||||
Search by postalCode or town (at least 3 characters): Buscar por código postal o nombre ( al menos 3 letras)
|
||||
Search by postalCode, town, province or country: Buscar por código postal, ciudad o país
|
||||
</i18n>
|
||||
|
|
No veo en que momento se hace el filtrado de datos a las tablas.