Skip to content

Commit 557e508

Browse files
committed
feat: add JSON encoding and decoding functions for query parameters
1 parent 951c744 commit 557e508

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

adminforth/spa/src/utils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,23 @@ export function checkShowIf(c: AdminForthResourceColumnInputCommon, record: Reco
478478
};
479479

480480
return evaluatePredicate(c.showIf);
481-
}
481+
}
482+
483+
484+
export function encodeQueryJSON(obj) {
485+
return JSON.stringify(obj)
486+
.replace(/{/g, '(')
487+
.replace(/}/g, ')')
488+
.replace(/\[/g, '<')
489+
.replace(/]/g, '>')
490+
}
491+
492+
export function decodeQueryJSON(str) {
493+
return JSON.parse(
494+
str
495+
.replace(/\(/g, '{')
496+
.replace(/\)/g, '}')
497+
.replace(/</g, '[')
498+
.replace(/>/g, ']')
499+
);
500+
}

adminforth/spa/src/views/CreateView.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
7979
import ResourceForm from '@/components/ResourceForm.vue';
8080
import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
8181
import { useCoreStore } from '@/stores/core';
82-
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown } from '@/utils';
82+
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, decodeQueryJSON } from '@/utils';
8383
import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
8484
import { onMounted, ref, watch } from 'vue';
8585
import { useRoute, useRouter } from 'vue-router';
@@ -136,14 +136,14 @@ onMounted(async () => {
136136
if (userUseMultipleEncoding) {
137137
initialValues.value = { ...initialValues.value, ...JSON.parse(decodeURIComponent((route.query.values as string))) };
138138
} else {
139-
initialValues.value = { ...initialValues.value, ...JSON.parse((route.query.values as string)) };
139+
initialValues.value = { ...initialValues.value, ...JSON.parse(decodeQueryJSON(route.query.values as string)) };
140140
}
141141
}
142142
if (route.query.readonlyColumns) {
143143
if (userUseMultipleEncoding) {
144144
readonlyColumns.value = JSON.parse(decodeURIComponent((route.query.readonlyColumns as string)));
145145
} else {
146-
readonlyColumns.value = JSON.parse((route.query.readonlyColumns as string));
146+
readonlyColumns.value = JSON.parse(decodeQueryJSON(route.query.readonlyColumns as string));
147147
}
148148
}
149149
record.value = initialValues.value;

0 commit comments

Comments
 (0)