mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
<script setup lang="ts"> |
|
import { useVModel } from '#imports' |
|
|
|
const props = defineProps<{ |
|
value: any |
|
}>() |
|
|
|
const emit = defineEmits(['update:value']) |
|
|
|
const precisionFormats = [1, 2, 3, 4, 5, 6, 7, 8] |
|
|
|
const { t } = useI18n() |
|
|
|
const precisionFormatsDisplay = { |
|
1: t('placeholder.decimal1'), |
|
2: t('placeholder.decimal2'), |
|
3: t('placeholder.decimal3'), |
|
4: t('placeholder.decimal4'), |
|
5: t('placeholder.decimal5'), |
|
6: t('placeholder.decimal6'), |
|
7: t('placeholder.decimal7'), |
|
8: t('placeholder.decimal8'), |
|
} |
|
|
|
const vModel = useVModel(props, 'value', emit) |
|
|
|
onMounted(() => { |
|
if (!vModel.value.meta?.precision) { |
|
if (!vModel.value.meta) vModel.value.meta = {} |
|
vModel.value.meta.precision = precisionFormats[0] |
|
} |
|
}) |
|
|
|
// update datatype precision when precision is less than the new value |
|
// avoid downgrading precision if the new value is less than the current precision |
|
// to avoid fractional part data loss(eg. 1.2345 -> 1.23) |
|
const onPrecisionChange = (value: number) => { |
|
vModel.value.dtxs = Math.max(value, vModel.value.dtxs) |
|
} |
|
</script> |
|
|
|
<template> |
|
<a-form-item :label="$t('placeholder.precision')"> |
|
<a-select |
|
v-if="vModel.meta?.precision" |
|
v-model:value="vModel.meta.precision" |
|
dropdown-class-name="nc-dropdown-decimal-format" |
|
@change="onPrecisionChange" |
|
> |
|
<a-select-option v-for="(format, i) of precisionFormats" :key="i" :value="format"> |
|
<div class="flex gap-2 w-full justify-between items-center"> |
|
{{ (precisionFormatsDisplay as any)[format] }} |
|
<component |
|
:is="iconMap.check" |
|
v-if="vModel.meta.precision === format" |
|
id="nc-selected-item-icon" |
|
class="text-primary w-4 h-4" |
|
/> |
|
</div> |
|
</a-select-option> |
|
</a-select> |
|
</a-form-item> |
|
</template>
|
|
|