fix: refs #6919 arrayData
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2025-01-09 17:32:57 +01:00
parent a46d3affde
commit 9084d918c0
2 changed files with 12 additions and 8 deletions

View File

@ -36,7 +36,7 @@ const arrayData = useArrayData(props.dataKey, {
onBeforeMount(async () => {
try {
await fetchData(route.params.id);
await fetch(route.params.id);
} catch {
const { matched: matches } = router.currentRoute.value;
const { path } = matches.at(-1);
@ -46,12 +46,14 @@ onBeforeMount(async () => {
onBeforeRouteUpdate(async (to, from) => {
const id = to.params.id;
if (id !== from.params.id) await fetchData(id, true);
if (id !== from.params.id) await fetch(id, true);
});
async function fetchData(id, append = false) {
async function fetch(id, append = false) {
const regex = /\/(\d+)/;
if (props.idInWhere) arrayData.store.filter.where = { id };
else arrayData.store.url = props.url.replace(/(\/\d+)/, `/${id}`);
else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`;
else arrayData.store.url = props.url.replace(regex, `/${id}`);
await arrayData.fetch({ append, updateRouter: false });
}
</script>

View File

@ -30,7 +30,7 @@ const arrayData = useArrayData(props.dataKey, {
onBeforeMount(async () => {
const route = router.currentRoute.value;
try {
await fetchData(route.params.id);
await fetch(route.params.id);
} catch {
const { matched: matches } = route;
const { path } = matches.at(-1);
@ -40,12 +40,14 @@ onBeforeMount(async () => {
onBeforeRouteUpdate(async (to, from) => {
const id = to.params.id;
if (id !== from.params.id) await fetchData(id, true);
if (id !== from.params.id) await fetch(id, true);
});
async function fetchData(id, append = false) {
async function fetch(id, append = false) {
const regex = /\/(\d+)/;
if (props.idInWhere) arrayData.store.filter.where = { id };
else arrayData.store.url = props.url.replace(/(\/\d+)/, `/${id}`);
else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`;
else arrayData.store.url = props.url.replace(regex, `/${id}`);
await arrayData.fetch({ append, updateRouter: false });
}
</script>