|
| 1 | +<template lang="pug"> |
| 2 | +json-forms( |
| 3 | + :data="data" |
| 4 | + :schema="schema" |
| 5 | + :uischema="uischema" |
| 6 | + :renderers="renderers" |
| 7 | + validationMode="ValidateAndShow" |
| 8 | + :additionalErrors="getSchemaValidations" |
| 9 | + @change="onChange" |
| 10 | +) |
| 11 | +</template> |
| 12 | + |
| 13 | +<script setup lang="ts"> |
| 14 | +import { JsonForms } from '@jsonforms/vue'; |
| 15 | +import { |
| 16 | + defaultStyles, |
| 17 | + mergeStyles, |
| 18 | + vanillaRenderers, |
| 19 | +} from "@jsonforms/vue-vanilla"; |
| 20 | +
|
| 21 | +import type { JsonFormsChangeEvent } from '@jsonforms/vue'; |
| 22 | +import { QuasarJsonformRenderer } from './quasar-jsonform'; |
| 23 | +import { computed, provide, ref } from 'vue'; |
| 24 | +import { useFetch } from 'nuxt/app'; |
| 25 | +import type { ErrorObject } from 'ajv'; |
| 26 | +
|
| 27 | +const customStyle = mergeStyles(defaultStyles, { |
| 28 | + control: { |
| 29 | + input: 'inputstyle', |
| 30 | + error: 'errorstyle', |
| 31 | + }, |
| 32 | +}); |
| 33 | +
|
| 34 | +provide('styles', customStyle); |
| 35 | +
|
| 36 | +const renderers = Object.freeze([ |
| 37 | + //...vanillaRenderers, |
| 38 | + ...QuasarJsonformRenderer, |
| 39 | + // Add custom renderers here |
| 40 | +]); |
| 41 | +
|
| 42 | +const props = defineProps({ |
| 43 | + schemaName: { |
| 44 | + type: String, |
| 45 | + default: '', |
| 46 | + }, |
| 47 | + validations: { |
| 48 | + type: Object || null, |
| 49 | + default: {}, |
| 50 | + }, |
| 51 | +}); |
| 52 | +
|
| 53 | +const validations = defineModel('validations', { |
| 54 | + type: Object, |
| 55 | + default: {}, |
| 56 | +}); |
| 57 | +
|
| 58 | +const data = defineModel('data', { |
| 59 | + type: Object, |
| 60 | + default: {}, |
| 61 | +}); |
| 62 | +
|
| 63 | +function onChange(event: JsonFormsChangeEvent) { |
| 64 | + data.value = event.data; |
| 65 | +} |
| 66 | +
|
| 67 | +const getSchemaValidations = computed(() => { |
| 68 | + if (!props.validations || !props.validations[props.schemaName]) { |
| 69 | + return []; |
| 70 | + } |
| 71 | + const errorObject: ErrorObject[] = []; |
| 72 | + let validationList = props.validations[props.schemaName] |
| 73 | + for (const key in validationList) { |
| 74 | + errorObject.push({ |
| 75 | + message: validationList[key], |
| 76 | + instancePath: `/${key}`, |
| 77 | + keyword: 'type', |
| 78 | + params: {}, |
| 79 | + }); |
| 80 | + } |
| 81 | + return errorObject; |
| 82 | +}) |
| 83 | +
|
| 84 | +
|
| 85 | +const { data: result, pending, error, refresh } = await useHttp(`/management/identities/validation/${props.schemaName}`, { |
| 86 | + method: 'GET', |
| 87 | +}); |
| 88 | +
|
| 89 | +const { data: resultUi, pending: pendingUi, error: errorUi, refresh: refreshUi } = await useHttp(`/management/identities/jsonforms/${props.schemaName}`, { |
| 90 | + method: 'GET', |
| 91 | +}); |
| 92 | +
|
| 93 | +const schema = ref(result.value.data); |
| 94 | +const uischema = ref(resultUi.value.data); |
| 95 | +
|
| 96 | +</script> |
| 97 | + |
| 98 | +<style> |
| 99 | +.horizontal-layout { |
| 100 | + display: flex; |
| 101 | + flex-direction: row; |
| 102 | + flex-wrap: wrap; |
| 103 | + justify-content: space-around; |
| 104 | + justify-items: center; |
| 105 | +} |
| 106 | +
|
| 107 | +.horizontal-layout-item { |
| 108 | + flex: 1; |
| 109 | + min-width: 0; |
| 110 | + width: calc(33.333% - 10px); |
| 111 | + height: 100px; |
| 112 | + margin-right: 15px; |
| 113 | + justify-content: center; |
| 114 | +} |
| 115 | +
|
| 116 | +.horizontal-layout-item:last-child { |
| 117 | + margin-right: 0; |
| 118 | +} |
| 119 | +
|
| 120 | +.vertical-layout { |
| 121 | + display: flex; |
| 122 | + flex-direction: column; |
| 123 | + flex-wrap: wrap; |
| 124 | + justify-content: space-around; |
| 125 | + justify-items: flex-start; |
| 126 | +} |
| 127 | +
|
| 128 | +.inputstyle { |
| 129 | + padding: 10px 15px; |
| 130 | + font-size: 16px; |
| 131 | + border: 1px solid #ced4da; |
| 132 | + /* Couleur de bordure légère */ |
| 133 | + border-radius: 5px; |
| 134 | + /* Coins arrondis */ |
| 135 | + outline: none; |
| 136 | + /* Supprime le contour par défaut lors de la sélection */ |
| 137 | + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); |
| 138 | + /* Légère ombre pour un effet en profondeur */ |
| 139 | + transition: border-color 0.2s, box-shadow 0.2s; |
| 140 | + /* Transition douce pour l'interaction */ |
| 141 | +} |
| 142 | +
|
| 143 | +.inputstyle:focus { |
| 144 | + border-color: #007bff; |
| 145 | + /* Changement de couleur de bordure pour l'état focus */ |
| 146 | + box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); |
| 147 | + /* Ombre extérieure pour indiquer le focus */ |
| 148 | +} |
| 149 | +
|
| 150 | +.errorstyle { |
| 151 | + border-color: red; |
| 152 | + color: red; |
| 153 | + /* Set border color to red for error */ |
| 154 | +} |
| 155 | +
|
| 156 | +
|
| 157 | +.description { |
| 158 | + display: none; |
| 159 | +} |
| 160 | +</style>./form/StringControlRenderer.vue./form/QStringControlRenderer.vue./form/controls/QStringControlRenderer.vue |
0 commit comments