Browse Source

barcode column type: fix FE issues (WIP)

pull/4641/head
flisowna 2 years ago
parent
commit
ec86f32153
  1. 18
      packages/nc-gui/components/smartsheet/column/BarcodeOptions.vue
  2. 26
      packages/nc-gui/components/virtual-cell/barcode/Barcode.vue
  3. 1
      packages/nc-gui/components/virtual-cell/barcode/JsBarcodeWrapper.ts

18
packages/nc-gui/components/smartsheet/column/BarcodeOptions.vue

@ -3,8 +3,6 @@ import type { UITypes } from 'nocodb-sdk'
import { AllowedColumnTypesForQrAndBarcodes } from 'nocodb-sdk' import { AllowedColumnTypesForQrAndBarcodes } from 'nocodb-sdk'
import type { SelectProps } from 'ant-design-vue' import type { SelectProps } from 'ant-design-vue'
import { useVModel } from '#imports' import { useVModel } from '#imports'
import * as Ewa from '@chenfengyuan/vue-barcode'
import * as Daniel from 'JsBarcode'
const props = defineProps<{ const props = defineProps<{
modelValue: any modelValue: any
@ -57,13 +55,19 @@ const supportedBarcodeFormats = [
onMounted(() => { onMounted(() => {
// set default value // set default value
vModel.value.fk_barcode_value_column_id = (column?.value?.colOptions as Record<string, any>)?.fk_barcode_value_column_id || '' vModel.value.fk_barcode_value_column_id = (column?.value?.colOptions as Record<string, any>)?.fk_barcode_value_column_id || ''
vModel.value.barcode_format = (column?.value?.colOptions as Record<string, any>)?.barcode_format || '' // vModel.value.meta.barcode_format = (column?.value?.colOptions as Record<string, any>)?.barcode_format || ''
}) })
setAdditionalValidations({ setAdditionalValidations({
fk_barcode_value_column_id: [{ required: true, message: 'Required' }], fk_barcode_value_column_id: [{ required: true, message: 'Required' }],
// barcode_format: [{ required: true, message: 'Required' }], barcode_format: [{ required: true, message: 'Required' }],
}) })
// set default meta value
vModel.value.meta = {
barcodeFormat: supportedBarcodeFormats[0].value,
...vModel.value.meta,
}
</script> </script>
<template> <template>
@ -81,18 +85,18 @@ setAdditionalValidations({
@click.stop @click.stop
/> />
</a-form-item> </a-form-item>
<!-- <a-form-item <a-form-item
class="flex w-1/2 pb-2 nc-qr-code-value-column-select" class="flex w-1/2 pb-2 nc-qr-code-value-column-select"
:label="$t('labels.barcodeFormat')" :label="$t('labels.barcodeFormat')"
v-bind="validateInfos.barcode_format" v-bind="validateInfos.barcode_format"
> >
<a-select <a-select
v-model:value="vModel.barcode_format" v-model:value="vModel.meta.barcodeFormat"
:options="supportedBarcodeFormats" :options="supportedBarcodeFormats"
placeholder="Select a Barcode format" placeholder="Select a Barcode format"
@click.stop @click.stop
/> />
</a-form-item> --> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
</template> </template>

26
packages/nc-gui/components/virtual-cell/barcode/Barcode.vue

@ -5,6 +5,8 @@ const maxNumberOfAllowedCharsForQrValue = 2000
const cellValue = inject(CellValueInj) const cellValue = inject(CellValueInj)
const column = inject(ColumnInj)
const barcodeValue = computed(() => String(cellValue?.value)) const barcodeValue = computed(() => String(cellValue?.value))
const tooManyCharsForQrCode = computed(() => barcodeValue?.value.length > maxNumberOfAllowedCharsForQrValue) const tooManyCharsForQrCode = computed(() => barcodeValue?.value.length > maxNumberOfAllowedCharsForQrValue)
@ -16,6 +18,18 @@ const showQrModal = (ev: MouseEvent) => {
modalVisible.value = true modalVisible.value = true
} }
const barcodeMeta = $computed(() => {
return {
barcodeFormat: 'CODE128',
...(column?.value?.meta || {}),
}
})
const jsBarcodeOptions = $computed(() => ({
format: barcodeMeta.barcodeFormat,
// format: 'CODE128',
}))
const handleModalOkClick = () => (modalVisible.value = false) const handleModalOkClick = () => (modalVisible.value = false)
const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = useShowNotEditableWarning() const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = useShowNotEditableWarning()
@ -30,11 +44,19 @@ const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = us
:footer="null" :footer="null"
@ok="handleModalOkClick" @ok="handleModalOkClick"
> >
<JsBarcodeWrapper v-if="barcodeValue && !tooManyCharsForQrCode" tag="svg" :value="barcodeValue" width="3" /> <JsBarcodeWrapper
v-if="barcodeValue && !tooManyCharsForQrCode"
:options="jsBarcodeOptions"
tag="svg"
:value="barcodeValue"
width="3"
/>
</a-modal> </a-modal>
<div @click="showQrModal"> <div @click="showQrModal">
FOO: {{ JSON.stringify(jsBarcodeOptions) }}
<JsBarcodeWrapper <JsBarcodeWrapper
v-if="barcodeValue && !tooManyCharsForQrCode" v-if="barcodeValue && !tooManyCharsForQrCode"
:options="jsBarcodeOptions"
tag="svg" tag="svg"
class="w-full" class="w-full"
:value="barcodeValue" :value="barcodeValue"
@ -55,6 +77,6 @@ const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = us
<style lang="scss"> <style lang="scss">
.amodal-wrapper { .amodal-wrapper {
width: 100px; // width: 100px;
} }
</style> </style>

1
packages/nc-gui/components/virtual-cell/barcode/JsBarcodeWrapper.ts

@ -57,6 +57,7 @@ export default defineComponent({
* Generate bar code. * Generate bar code.
*/ */
generate() { generate() {
// debugger
JsBarcode(this.$el, String(this.value), this.options) JsBarcode(this.$el, String(this.value), this.options)
}, },
}, },

Loading…
Cancel
Save