From 4fa2c0d57d01d9d3cc6ee37e9f580e79df520e55 Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 30 Jun 2026 22:21:56 +0330 Subject: [PATCH] fix bugs --- src/components/BasicPacks/BasicInput.vue | 51 +++++++++++-------- .../BasicPriceInput/src/BasicPriceInput.vue | 7 ++- src/utils/inputRules.ts | 18 ++++++- src/utils/persianDigits.ts | 29 +++++++++++ src/views/login/components/Login.vue | 2 +- src/views/login/components/Register.vue | 2 +- 6 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 src/utils/persianDigits.ts diff --git a/src/components/BasicPacks/BasicInput.vue b/src/components/BasicPacks/BasicInput.vue index 95db065..cf17223 100644 --- a/src/components/BasicPacks/BasicInput.vue +++ b/src/components/BasicPacks/BasicInput.vue @@ -36,6 +36,7 @@ import {usePrefix} from "@/utils/usePrefix"; import {computed} from "vue"; import {usePrice} from "@/components/BasicPacks/BasicPriceInput/src/utils/usePrice"; +import {persianToEnglishDigits, shouldNormalizeInputDigits} from '@/utils/persianDigits'; //Props interface Prop { @@ -56,29 +57,42 @@ interface Prop { const addonBgColor = computed(() => props.addonBgColor) const addonTextColor = computed(() => props.addonTextColor) -//emits -const localValue = computed({ - set(value) { - // console.log(value?.toString().replaceAll(',', '')) - props.type === 'price' ? emits('update:value', value?.toString().replaceAll(',', '')) : emits('update:value', value) - }, - get() { - let a = props.type === 'price' ? props.value ? usePrice(props.value as number, true, '').trim() : '' : props.value - // console.log(props.value) - return a - }, -}) const props = withDefaults(defineProps(), { isPassword: false }) const emits = defineEmits(['update:value', 'onchange']) +const localValue = computed({ + set(value) { + emits('update:value', normalizeValue(value)) + }, + get() { + return props.type === 'price' + ? props.value ? usePrice(props.value as number, true, '').trim() : '' + : props.value + }, +}) + +function normalizeValue(value: unknown) { + if (value == null || value === '') { + return value + } + + let normalized = String(value) + if (shouldNormalizeInputDigits(props)) { + normalized = persianToEnglishDigits(normalized) + } + if (props.type === 'price') { + normalized = normalized.replaceAll(',', '') + } + return normalized +} + const handlerChange = (e: any) => { - // emits('onchange', e.target.value) - props.type === 'price' ? emits('update:value', e.target.value?.toString().replaceAll(',', '')) : emits('update:value', e.target.value) - props.type === 'price' ? emits('onchange', e.target.value?.toString().replaceAll(',', '')) : emits('onchange', e.target.value) - // console.log('sas') + const normalized = normalizeValue(e.target.value) + emits('update:value', normalized) + emits('onchange', normalized) } //css style @@ -89,11 +103,6 @@ const {prefixCls} = usePrefix('input') @prefix: ~'@{prefixCls}-input'; .@{prefix} { - /* .ant-input-group-addon:first-child { - !* border: #d9d9d9 1px solid; - border-radius: 0 6px 6px 0;*! - }*/ - .ant-input-group { direction: ltr; } diff --git a/src/components/BasicPacks/BasicPriceInput/src/BasicPriceInput.vue b/src/components/BasicPacks/BasicPriceInput/src/BasicPriceInput.vue index e722116..2c7bb55 100644 --- a/src/components/BasicPacks/BasicPriceInput/src/BasicPriceInput.vue +++ b/src/components/BasicPacks/BasicPriceInput/src/BasicPriceInput.vue @@ -1,5 +1,5 @@