refs #6772: use onBeforeRouteUpdate
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
56333937ce
commit
2ead151f3b
|
@ -1,8 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, watch, computed } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -92,13 +92,13 @@ watch(
|
||||||
store.data = props.data;
|
store.data = props.data;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
watch(
|
onBeforeRouteUpdate((to, from, next) => {
|
||||||
() => route.params.id,
|
if (to.params.id !== from.params.id) {
|
||||||
() => {
|
arrayData.reloadRoute(to.params.id);
|
||||||
arrayData.reloadRoute();
|
|
||||||
fetch();
|
fetch();
|
||||||
}
|
}
|
||||||
);
|
next();
|
||||||
|
});
|
||||||
const addFilter = async (filter, params) => {
|
const addFilter = async (filter, params) => {
|
||||||
await arrayData.addFilter({ filter, params });
|
await arrayData.addFilter({ filter, params });
|
||||||
};
|
};
|
||||||
|
@ -190,7 +190,7 @@ defineExpose({ fetch, addFilter });
|
||||||
</QCard>
|
</QCard>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<QInfiniteScroll
|
<QInfiniteScroll
|
||||||
v-if="store.data"
|
v-if="store.data"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
|
|
|
@ -131,13 +131,6 @@ async function search() {
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
|
||||||
v-if="searchText !== ''"
|
|
||||||
name="close"
|
|
||||||
@click="searchText = ''"
|
|
||||||
class="cursor-pointer"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<QIcon
|
<QIcon
|
||||||
v-if="props.info && $q.screen.gt.xs"
|
v-if="props.info && $q.screen.gt.xs"
|
||||||
name="info"
|
name="info"
|
||||||
|
|
|
@ -33,19 +33,19 @@ export function useArrayData(key, userOptions) {
|
||||||
setOptions();
|
setOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadRoute() {
|
function reloadRoute(newId = route.params.id) {
|
||||||
if (route.path === store.url) return;
|
if (route.path === store.url) return;
|
||||||
//Así fuerzo al reinicio
|
//Así fuerzo al reinicio
|
||||||
store.data = null;
|
store.data = null;
|
||||||
if (!store?.filter?.where) {
|
if (!store?.filter?.where) {
|
||||||
//Cuando el cambio viene por VnSearchbar
|
//Cuando el cambio viene por VnSearchbar
|
||||||
if (route.params.id) store.url = store.url.replace(/(\d+)/, route.params.id);
|
if (newId) store.url = store.url.replace(/(\d+)/, newId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Cuando el usuario cambia en la URL
|
// Cuando el usuario cambia en la URL
|
||||||
const keyFk = Object.keys(store.filter.where).find((key) => key.endsWith('Fk'));
|
const keyFk = Object.keys(store.filter.where).find((key) => key.endsWith('Fk'));
|
||||||
if (keyFk) {
|
if (keyFk) {
|
||||||
store.filter.where[keyFk] = route.params.id;
|
store.filter.where[keyFk] = newId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue