Files
boursecu_user/src/components/BasicPacks/BasicInput.vue
T

132 lines
3.2 KiB
Vue
Raw Normal View History

2026-01-18 13:01:46 +03:30
<template>
<div :class="[prefixCls]">
<div>
{{ props.title }}
</div>
<a-input-password
v-if="isPassword"
v-model:value="localValue"
:addon-after="props.addonAfter"
:addon-before="props.addonBefore"
:disabled="props.disabled"
:placeHolder="props.placeHolder"
:size="props.size"
:type="props.type"
class=""
2026-07-02 00:34:07 +03:30
@input="handlerChange"
2026-01-18 13:01:46 +03:30
@change="handlerChange"
/>
<a-input
v-else
v-model:value="localValue"
:addon-after="props.addonAfter"
:addon-before="props.addonBefore"
:disabled="props.disabled"
:placeHolder="props.placeHolder"
:size="props.size"
:type="props.type === 'price'? 'tel':props.type"
:inputmode="props.inputmode"
:pattern="props.pattern"
class=""
2026-07-02 00:34:07 +03:30
@input="handlerChange"
2026-01-18 13:01:46 +03:30
@change="handlerChange"
/>
</div>
</template>
<script lang="ts" setup>
import {usePrefix} from "@/utils/usePrefix";
import {computed} from "vue";
2026-06-17 13:51:29 +03:30
import {usePrice} from "@/utils/usePrice";
2026-06-30 22:19:27 +03:30
import {persianToEnglishDigits, shouldNormalizeInputDigits} from '@/utils/persianDigits';
2026-01-18 13:01:46 +03:30
//Props
interface Prop {
title?: String
value?: String | Number
size?: String
type?: String
inputmode?: String
pattern?: String
isPassword?: boolean
disabled?: boolean
addonAfter?: String
addonBefore?: String
addonBgColor?: String
addonTextColor?: String
placeHolder?: String
}
const addonBgColor = computed(() => props.addonBgColor)
const addonTextColor = computed(() => props.addonTextColor)
//emits
const localValue = computed({
set(value) {
2026-06-30 22:19:27 +03:30
emits('update:value', normalizeValue(value))
2026-01-18 13:01:46 +03:30
},
get() {
2026-06-17 13:51:29 +03:30
return props.type === 'price'
? props.value ? usePrice(props.value as number, true, '').trim() : ''
: props.value
2026-01-18 13:01:46 +03:30
},
})
const props = withDefaults(defineProps<Prop>(), {
isPassword: false
})
const emits = defineEmits(['update:value', 'onchange'])
2026-06-30 22:19:27 +03:30
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
2026-01-18 13:01:46 +03:30
}
2026-07-02 00:34:07 +03:30
const handlerChange = (e: Event | string) => {
const raw = typeof e === 'string' ? e : (e.target as HTMLInputElement | null)?.value
const normalized = normalizeValue(raw)
2026-06-30 22:19:27 +03:30
emits('update:value', normalized)
emits('onchange', normalized)
}
2026-01-18 13:01:46 +03:30
const {prefixCls} = usePrefix('input')
</script>
<style lang="less">
@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;
}
.ant-input-group > .ant-input-rtl:first-child,
.ant-input-group-rtl .ant-input-group-addon:first-child {
border-radius: @border-radius-base 0 0 @border-radius-base;
}
.ant-input-group > .ant-input:last-child,
.ant-input-group-addon:last-child {
border-radius: 0 @border-radius-base @border-radius-base 0;
}
.ant-input-group-addon {
background-color: v-bind(addonBgColor);
color: v-bind(addonTextColor);
}
}
</style>