8627-devToTest #1421
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { onBeforeMount } from 'vue';
|
||||
import { onBeforeMount, computed } from 'vue';
|
||||
import { useRoute, useRouter, onBeforeRouteUpdate } from 'vue-router';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
|
@ -10,6 +10,7 @@ import VnSubToolbar from '../ui/VnSubToolbar.vue';
|
|||
const props = defineProps({
|
||||
dataKey: { type: String, required: true },
|
||||
url: { type: String, default: undefined },
|
||||
customUrl: { type: String, default: undefined },
|
||||
idInWhere: { type: Boolean, default: false },
|
||||
filter: { type: Object, default: () => {} },
|
||||
descriptor: { type: Object, required: true },
|
||||
|
@ -24,6 +25,7 @@ const route = useRoute();
|
|||
const router = useRouter();
|
||||
const regex = /(\/\d+)/;
|
||||
|
||||
const url = computed(() => props.url || props.customUrl);
|
||||
const arrayData = useArrayData(props.dataKey, {
|
||||
url: props.url,
|
||||
filter: props.filter,
|
||||
|
@ -32,9 +34,11 @@ const arrayData = useArrayData(props.dataKey, {
|
|||
|
||||
onBeforeMount(async () => {
|
||||
try {
|
||||
if (props.idInWhere) arrayData.store.filter.where = { id: route.params.id };
|
||||
else if (!regex.test(props.url))
|
||||
arrayData.store.url = `${props.url}/${route.params.id}`;
|
||||
const id = route.params.id;
|
||||
if (props.idInWhere) arrayData.store.filter.where = { id };
|
||||
else if (props.customUrl) arrayData.store.url = url.value;
|
||||
else if (!regex.test(url.value)) arrayData.store.url = `${url.value}/${id}`;
|
||||
|
||||
await arrayData.fetch({ append: false, updateRouter: false });
|
||||
} catch {
|
||||
const { matched: matches } = router.currentRoute.value;
|
||||
|
@ -45,8 +49,12 @@ onBeforeMount(async () => {
|
|||
|
||||
onBeforeRouteUpdate(async (to, from) => {
|
||||
if (to.params.id !== from.params.id) {
|
||||
if (props.idInWhere) arrayData.store.filter.where = { id: to.params.id };
|
||||
else arrayData.store.url = `${props.url}/${to.params.id}`;
|
||||
const id = to.params.id;
|
||||
if (props.idInWhere) arrayData.store.filter.where = { id };
|
||||
else if (props.customUrl)
|
||||
arrayData.store.url = url.value.replace(regex, `/${id}`);
|
||||
else arrayData.store.url = `${url.value}/${id}`;
|
||||
|
||||
await arrayData.fetch({ updateRouter: false });
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue