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