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.
113 lines
2.9 KiB
113 lines
2.9 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { useProject } from '#imports'
|
||
2 years ago
|
import { currencyCodes, currencyLocales, validateCurrencyCode, validateCurrencyLocale } from '@/utils'
|
||
2 years ago
|
|
||
2 years ago
|
interface Props {
|
||
|
value: Record<string, any>
|
||
|
}
|
||
|
|
||
|
const props = defineProps<Props>()
|
||
|
const emit = defineEmits(['update:value'])
|
||
|
const vModel = useVModel(props, 'value', emit)
|
||
|
|
||
2 years ago
|
interface Option {
|
||
|
label: string
|
||
|
value: string
|
||
|
}
|
||
|
|
||
2 years ago
|
const validators = {
|
||
|
'meta.currency_locale': [
|
||
|
{
|
||
|
validator: (_: any, locale: any) => {
|
||
|
return new Promise<void>((resolve, reject) => {
|
||
|
if (!validateCurrencyLocale(locale)) {
|
||
|
return reject(new Error('Invalid locale'))
|
||
|
}
|
||
|
resolve()
|
||
|
})
|
||
2 years ago
|
},
|
||
2 years ago
|
},
|
||
|
],
|
||
|
'meta.currency_code': [
|
||
|
{
|
||
|
validator: (_: any, currencyCode: any) => {
|
||
|
return new Promise<void>((resolve, reject) => {
|
||
|
if (!validateCurrencyCode(currencyCode)) {
|
||
|
return reject(new Error('Invalid Currency Code'))
|
||
|
}
|
||
|
resolve()
|
||
|
})
|
||
2 years ago
|
},
|
||
2 years ago
|
},
|
||
|
],
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const { setAdditionalValidations, validateInfos } = useColumnCreateStoreOrThrow()
|
||
|
|
||
2 years ago
|
setAdditionalValidations({
|
||
2 years ago
|
...validators,
|
||
2 years ago
|
})
|
||
|
|
||
2 years ago
|
const { isPg } = useProject()
|
||
|
|
||
2 years ago
|
const currencyList = currencyCodes || []
|
||
2 years ago
|
|
||
2 years ago
|
const currencyLocaleList = currencyLocales() || []
|
||
2 years ago
|
|
||
2 years ago
|
const isMoney = computed(() => vModel.value.dt === 'money')
|
||
2 years ago
|
|
||
|
const message = computed(() => {
|
||
2 years ago
|
if (isMoney.value && isPg) return "PostgreSQL 'money' type has own currency settings"
|
||
2 years ago
|
return ''
|
||
|
})
|
||
2 years ago
|
|
||
|
function filterOption(input: string, option: Option) {
|
||
|
return option.value.toUpperCase().includes(input.toUpperCase())
|
||
|
}
|
||
2 years ago
|
|
||
|
// set default value
|
||
2 years ago
|
vModel.value.meta = {
|
||
2 years ago
|
currency_locale: 'en-US',
|
||
|
currency_code: 'USD',
|
||
2 years ago
|
...vModel.value.meta,
|
||
2 years ago
|
}
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-row gutter="8">
|
||
2 years ago
|
<a-col :span="12">
|
||
|
<a-form-item v-bind="validateInfos['meta.currency_locale']" label="Currency Locale">
|
||
|
<a-select
|
||
2 years ago
|
v-model:value="vModel.meta.currency_locale"
|
||
2 years ago
|
class="w-52"
|
||
|
show-search
|
||
|
:filter-option="filterOption"
|
||
|
:disabled="isMoney && isPg"
|
||
|
>
|
||
2 years ago
|
<a-select-option v-for="(currencyLocale, i) of currencyLocaleList" :key="i" :value="currencyLocale.value">
|
||
2 years ago
|
{{ currencyLocale.text }}
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
|
</a-col>
|
||
|
<a-col :span="12">
|
||
|
<a-form-item v-bind="validateInfos['meta.currency_code']" label="Currency Code">
|
||
|
<a-select
|
||
2 years ago
|
v-model:value="vModel.meta.currency_code"
|
||
2 years ago
|
class="w-52"
|
||
|
show-search
|
||
|
:filter-option="filterOption"
|
||
|
:disabled="isMoney && isPg"
|
||
|
>
|
||
2 years ago
|
<a-select-option v-for="(currencyCode, i) of currencyList" :key="i" :value="currencyCode">
|
||
2 years ago
|
{{ currencyCode }}
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
|
</a-col>
|
||
|
<a-col v-if="isMoney && isPg">
|
||
|
<span class="text-[#FB8C00]">{{ message }}</span>
|
||
|
</a-col>
|
||
|
</a-row>
|
||
2 years ago
|
</template>
|