feat: refs #6919 add customUrl prop to VnCard for dynamic URL handling
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
52e1cfc828
commit
74dd49ffe0
|
@ -11,6 +11,7 @@ import RightMenu from 'components/common/RightMenu.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 },
|
||||||
filter: { type: Object, default: () => {} },
|
filter: { type: Object, default: () => {} },
|
||||||
descriptor: { type: Object, required: true },
|
descriptor: { type: Object, required: true },
|
||||||
filterPanel: { type: Object, default: undefined },
|
filterPanel: { type: Object, default: undefined },
|
||||||
|
@ -28,17 +29,20 @@ const searchRightDataKey = computed(() => {
|
||||||
if (!props.searchDataKey) return route.name;
|
if (!props.searchDataKey) return route.name;
|
||||||
return props.searchDataKey;
|
return props.searchDataKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const url = computed(() => props.url || props.customUrl);
|
||||||
const arrayData = useArrayData(props.dataKey, {
|
const arrayData = useArrayData(props.dataKey, {
|
||||||
url: props.url,
|
url: url.value,
|
||||||
filter: props.filter,
|
filter: props.filter,
|
||||||
oneRecord: true,
|
oneRecord: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -50,8 +54,11 @@ 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 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import CustomerFilter from '../CustomerFilter.vue';
|
||||||
<template>
|
<template>
|
||||||
<VnCard
|
<VnCard
|
||||||
data-key="Client"
|
data-key="Client"
|
||||||
:url="`Clients/${$route.params.id}/getCard`"
|
:custom-url="`Clients/${$route.params.id}/getCard`"
|
||||||
:descriptor="CustomerDescriptor"
|
:descriptor="CustomerDescriptor"
|
||||||
:filter-panel="$route.name != 'CustomerConsumption' && CustomerFilter"
|
:filter-panel="$route.name != 'CustomerConsumption' && CustomerFilter"
|
||||||
search-data-key="CustomerList"
|
search-data-key="CustomerList"
|
||||||
|
|
Loading…
Reference in New Issue