Browse Source

Merge pull request #2893 from nocodb/feat/gui-v2-currency-cell

feat(gui-v2): Currency Cell
pull/2899/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
b80f25c25a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 65
      packages/nc-gui-v2/components/cell/Currency.vue
  2. 3
      packages/nc-gui-v2/components/smartsheet-header/CellIcon.vue
  3. 2
      packages/nc-gui-v2/components/smartsheet/Cell.vue

65
packages/nc-gui-v2/components/cell/Currency.vue

@ -1,36 +1,49 @@
<script> <script setup lang="ts">
export default { import { computed, inject } from '#imports'
name: 'CurrencyCell', import { ColumnInj } from '~/context'
props: {
column: Object, const { modelValue: value } = defineProps<Props>()
value: [String, Number],
}, const emit = defineEmits(['update:modelValue'])
computed: {
currency() { const column = inject(ColumnInj)
try {
return isNaN(this.value) const editEnabled = inject<boolean>('editEnabled')
? this.value
: new Intl.NumberFormat(this.currencyMeta.currency_locale || 'en-US', { interface Props {
style: 'currency', modelValue: number
currency: this.currencyMeta.currency_code || 'USD', }
}).format(this.value) const root = ref<HTMLInputElement>()
} catch (e) {
return this.value const localState = computed({
} get: () => value,
}, set: (val) => emit('update:modelValue', val),
currencyMeta() { })
const currencyMeta = computed(() => {
return { return {
currency_locale: 'en-US', currency_locale: 'en-US',
currency_code: 'USD', currency_code: 'USD',
...(this.column && this.column.meta ? this.column.meta : {}), ...(column && column.meta ? column.meta : {}),
} }
}, })
}, const currency = computed(() => {
} try {
return isNaN(value)
? value
: new Intl.NumberFormat(currencyMeta?.value?.currency_locale || 'en-US', {
style: 'currency',
currency: currencyMeta?.value?.currency_code || 'USD',
}).format(value)
} catch (e) {
return value
}
})
</script> </script>
<template> <template>
<a v-if="value">{{ currency }}</a> <input v-if="editEnabled" ref="root" v-model="localState" />
<span v-else-if="value">{{ currency }}</span>
<span v-else /> <span v-else />
</template> </template>

3
packages/nc-gui-v2/components/smartsheet-header/CellIcon.vue

@ -17,6 +17,7 @@ import GenericIcon from '~icons/mdi/square-rounded'
import AttachmentIcon from '~icons/mdi/image-multiple-outline' import AttachmentIcon from '~icons/mdi/image-multiple-outline'
import URLIcon from '~icons/mdi/link' import URLIcon from '~icons/mdi/link'
import EmailIcon from '~icons/mdi/email' import EmailIcon from '~icons/mdi/email'
import CurrencyIcon from '~icons/mdi/currency-usd-circle-outline'
const column = inject(ColumnInj) const column = inject(ColumnInj)
@ -51,6 +52,8 @@ const icon = computed(() => {
// } // }
else if (additionalColMeta.isURL) { else if (additionalColMeta.isURL) {
return URLIcon return URLIcon
} else if (additionalColMeta.isCurrency) {
return CurrencyIcon
} else if (additionalColMeta.isString) { } else if (additionalColMeta.isString) {
return h(StringIcon, { return h(StringIcon, {
class: 'text-[1.5rem]', class: 'text-[1.5rem]',

2
packages/nc-gui-v2/components/smartsheet/Cell.vue

@ -51,7 +51,6 @@ const {
<!-- <!--
todo : todo :
JSONCell JSONCell
Currency
--> -->
<!-- <RatingCell --> <!-- <RatingCell -->
@ -197,6 +196,7 @@ todo :
<!-- v-on="parentListeners" <!-- v-on="parentListeners"
/> />
--> -->
<CellCurrency v-else-if="isCurrency" v-model="localState" />
<CellText v-else-if="isString" v-model="localState" /> <CellText v-else-if="isString" v-model="localState" />
<!-- v-on="parentListeners" <!-- v-on="parentListeners"
/> />

Loading…
Cancel
Save