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.
55 lines
1.3 KiB
55 lines
1.3 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { VNodeRef } from '@vue/runtime-core'
|
||
2 years ago
|
import { ColumnInj, computed, inject, useVModel } from '#imports'
|
||
|
import { EditModeInj } from '~/context'
|
||
2 years ago
|
|
||
2 years ago
|
interface Props {
|
||
2 years ago
|
modelValue: number | null | undefined
|
||
2 years ago
|
}
|
||
|
|
||
|
const props = defineProps<Props>()
|
||
2 years ago
|
|
||
|
const emit = defineEmits(['update:modelValue'])
|
||
|
|
||
2 years ago
|
const column = inject(ColumnInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const editEnabled = inject(EditModeInj)
|
||
2 years ago
|
|
||
2 years ago
|
const vModel = useVModel(props, 'modelValue', emit)
|
||
2 years ago
|
|
||
|
const currencyMeta = computed(() => {
|
||
|
return {
|
||
|
currency_locale: 'en-US',
|
||
|
currency_code: 'USD',
|
||
2 years ago
|
...(column.value.meta ? column.value.meta : {}),
|
||
2 years ago
|
}
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const currency = computed(() => {
|
||
|
try {
|
||
2 years ago
|
return !vModel.value || isNaN(vModel.value)
|
||
2 years ago
|
? vModel.value
|
||
2 years ago
|
: new Intl.NumberFormat(currencyMeta.value.currency_locale || 'en-US', {
|
||
2 years ago
|
style: 'currency',
|
||
2 years ago
|
currency: currencyMeta.value.currency_code || 'USD',
|
||
2 years ago
|
}).format(vModel.value)
|
||
2 years ago
|
} catch (e) {
|
||
2 years ago
|
return vModel.value
|
||
2 years ago
|
}
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus()
|
||
3 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<template>
|
||
2 years ago
|
<input
|
||
|
v-if="editEnabled"
|
||
|
:ref="focus"
|
||
|
v-model="vModel"
|
||
|
class="w-full h-full border-none outline-none"
|
||
|
@blur="editEnabled = false"
|
||
|
/>
|
||
2 years ago
|
<span v-else-if="vModel">{{ currency }}</span>
|
||
3 years ago
|
<span v-else />
|
||
|
</template>
|