|
| 1 | +<template lang="pug"> |
| 2 | +//control-wrapper(v-bind="controlWrapper" :styles="styles" :isFocused="isFocused" :appliedOptions="appliedOptions") |
| 3 | +div(style="cursor: pointer") |
| 4 | + q-input( |
| 5 | + :id="control.id + '-input'" |
| 6 | + :disable="!control.enabled" |
| 7 | + :placeholder="appliedOptions.placeholder" |
| 8 | + :label="computedLabel" |
| 9 | + :model-value="control.data" |
| 10 | + :clearable="true" |
| 11 | + readonly |
| 12 | + @click="open" |
| 13 | + @update:model-value="onChangeControl" |
| 14 | + @focus="isFocused = true" |
| 15 | + @blur="isFocused = false" |
| 16 | + :style="{paddingBottom: control.errors !== '' ? 'revert-layer' : 0}" |
| 17 | + filled |
| 18 | + ) |
| 19 | + template(v-slot:prepend) |
| 20 | + q-icon(name="mdi-paperclip") |
| 21 | + q-card(style="border-radius: 0") |
| 22 | + img(:src="baseUrl + '/management/identities/photo/raw?' + photoUrlQuery.params") |
| 23 | +</template> |
| 24 | + |
| 25 | +<script lang="ts"> |
| 26 | +import { defineComponent } from 'vue'; |
| 27 | +import { useFileDialog } from '@vueuse/core' |
| 28 | +import { rendererProps, useJsonFormsControl } from '@jsonforms/vue'; |
| 29 | +import { isArray, isObject, isString, iterate } from 'radash'; |
| 30 | +import type { RendererProps } from '@jsonforms/vue'; |
| 31 | +import type { ControlElement } from '@jsonforms/core'; |
| 32 | +import { useQuasarControl } from '../util'; |
| 33 | +import { ControlWrapper } from '@jsonforms/vue-vanilla'; |
| 34 | +
|
| 35 | +const QStringControlRenderer = defineComponent({ |
| 36 | + name: 'q-string-control-renderer', |
| 37 | + components: { |
| 38 | + ControlWrapper, |
| 39 | + }, |
| 40 | + props: { |
| 41 | + ...rendererProps<ControlElement>(), |
| 42 | + }, |
| 43 | + inject: ['jsonforms'], |
| 44 | + setup(props: RendererProps<ControlElement>) { |
| 45 | + const { files, open, reset, onChange: onChangeFile } = useFileDialog({ |
| 46 | + accept: 'image/*', |
| 47 | + multiple: false, |
| 48 | + directory: false, |
| 49 | + }) |
| 50 | + const config = useAppConfig(); |
| 51 | +
|
| 52 | + return { |
| 53 | + open, |
| 54 | + onChangeFile, |
| 55 | + photo: null, |
| 56 | + baseUrl: config.baseUrl, |
| 57 | + ...useQuasarControl( |
| 58 | + useJsonFormsControl(props), |
| 59 | + (value) => isObject(value) ? (value as any).value : value || undefined, |
| 60 | + ) |
| 61 | + } |
| 62 | + }, |
| 63 | + methods: { |
| 64 | + onChangeControl(val) { |
| 65 | + console.log('val', val) |
| 66 | + debugger |
| 67 | + this.onChange([ |
| 68 | + this.control?.uischema.options?.storage || 'data', |
| 69 | + val.name, |
| 70 | + ].join(':')); |
| 71 | + }, |
| 72 | + }, |
| 73 | + async mounted() { |
| 74 | + this.onChangeFile((files) => { |
| 75 | + this.onChangeControl(files?.length ? files[0] : null); |
| 76 | + }); |
| 77 | + }, |
| 78 | + computed: { |
| 79 | + computedLabel() { |
| 80 | + return this.control.label === undefined ? this.control.schema.title : this.control.label; |
| 81 | + }, |
| 82 | + photoUrlQuery() { |
| 83 | + const query = new URLSearchParams(); |
| 84 | + const employeeNumber = (this.jsonforms as any)?.core?.data?.employeeNumber; |
| 85 | + const employeeType = (this.jsonforms as any)?.core?.data?.employeeType; |
| 86 | +
|
| 87 | + query.append('filters[:inetOrgPerson.employeeNumber]', employeeNumber); |
| 88 | + query.append('filters[:inetOrgPerson.employeeType]', employeeType); |
| 89 | +
|
| 90 | + return { |
| 91 | + params: query.toString(), |
| 92 | + employeeNumber, |
| 93 | + employeeType, |
| 94 | + }; |
| 95 | + }, |
| 96 | + }, |
| 97 | +}); |
| 98 | +export default QStringControlRenderer; |
| 99 | +
|
| 100 | +</script> |
0 commit comments